# Pre-condition: s is a string of lowercase letters only. def whatdoesitdo(s): n = len(s) # Works like an array but we can index with anything. chart = {} sz = 0 for i in range(n-1): # Grabs a substring of s starting at index i of length 2. tmp = s[i:i+2] # Checks if our "array" has an entry for tmp. if tmp in chart: chart[tmp] += 1 else: chart[tmp] = 1 sz = max(sz, chart[tmp]) # Creates sz+1 lists. res = [] for i in range(sz+1): res.append([]) for tmp in chart: res[chart[tmp]].append(tmp) # Sorts each list in alphabetical order. for i in range(sz+1): if len(res[i]) > 0: res[i].sort() return res def main(): inp = input().strip() res = whatdoesitdo(inp) # Loops from length of res downto 2. for i in range(len(res)-1,1,-1): print(i) print("--------") for x in res[i]: print(x) print() main()