fork download
  1. while True:
  2. S = input()
  3. X = {"":1}
  4. print("#occurrences up-to-3-maximizers #maximizers")
  5. for c in S:
  6. Y = {}
  7. for ss in X: Y[ss+c] = X[ss]
  8. for ss in Y:
  9. if ss in X: X[ss] += Y[ss]
  10. else: X[ss] = Y[ss]
  11.  
  12. n = len(S)
  13. mv = [-1]*(n+1)
  14. ms = [-1]*(n+1)
  15.  
  16. for ss in X:
  17. if X[ss] > mv[len(ss)]:
  18. mv[len(ss)] = X[ss]
  19. ms[len(ss)] = [ss]
  20. elif X[ss] == mv[len(ss)]:
  21. ms[len(ss)] += [ss]
  22.  
  23. for i in range(n+1):
  24. print(mv[i], ms[i][0:3], len(ms[i]))
  25.  
Runtime error #stdin #stdout 0.26s 8840KB
stdin
stdin line 1
cucumber
mississippi
angled angels
12312312
crash after this
stdout
#occurrences up-to-3-maximizers #maximizers
1 [''] 1
2 ['n', ' ', 'i'] 3
3 ['in', 'i ', 'n '] 3
4 ['in '] 1
4 ['tin ', 'din ', 'in 1'] 4
4 ['sin 1', 'stin ', 'din 1'] 6
4 ['tdin 1', 'sdin 1', 'stdin '] 4
4 ['stdin 1'] 1
3 ['stdine 1'] 1
1 ['ti line 1', 'sdinlie 1', 'stin ine1'] 220
1 ['tin line 1', 'sti line 1', 'tdinline 1'] 66
1 ['stin line 1', 'stdinline 1', 'stdin line1'] 12
1 ['stdin line 1'] 1
#occurrences up-to-3-maximizers #maximizers
1 [''] 1
2 ['c', 'u'] 2
3 ['cu'] 1
3 ['cur', 'cue', 'cub'] 4
3 ['cube', 'cubr', 'cume'] 6
3 ['cuber', 'cumer', 'cumbr'] 4
3 ['cumber'] 1
1 ['cuumber', 'cucumer', 'ccumber'] 8
1 ['cucumber'] 1
#occurrences up-to-3-maximizers #maximizers
1 [''] 1
4 ['s', 'i'] 2
10 ['si'] 1
14 ['isi'] 1
16 ['isip'] 1
16 ['isipi', 'misip', 'issip'] 3
16 ['issipi', 'misipi', 'missip'] 3
16 ['missipi'] 1
8 ['misisipi', 'misssipi', 'missippi'] 3
4 ['misisippi', 'missisipi', 'misissipi'] 4
2 ['misissippi', 'missisippi', 'mississipi'] 3
1 ['mississippi'] 1
#occurrences up-to-3-maximizers #maximizers
1 [''] 1
2 ['l', 'a', 'e'] 5
3 ['ae', 'ag', 'al'] 9
4 ['agl', 'age', 'nge'] 7
5 ['ange', 'angl'] 2
5 ['angel', 'anges', 'angls'] 3
5 ['angels'] 1
2 ['anglels'] 1
1 ['anl aels', 'l angels', 'gedagels'] 1287
1 ['ngedagels', 'anged ngl', 'ngleanges'] 715
1 ['angl anels', 'ngle agels', 'angd agels'] 286
1 ['anled agels', 'agle angels', 'angld anels'] 78
1 ['angled anges', 'angled angel', 'angled agels'] 13
1 ['angled angels'] 1
#occurrences up-to-3-maximizers #maximizers
1 [''] 1
3 ['2', '1'] 2
6 ['12'] 1
4 ['212', '132', '131'] 10
5 ['1312', '2312', '1231'] 5
6 ['12312'] 1
1 ['121212', '123132', '123231'] 28
1 ['1232312', '1312312', '1231232'] 8
1 ['12312312'] 1
#occurrences up-to-3-maximizers #maximizers
1 [''] 1
2 ['s', ' ', 'r'] 6
4 ['at'] 1
4 ['aft', 'a t', 'cat'] 8
4 ['afts', 'afti', 'afth'] 24
4 ['ratis', 'athis', 'aftis'] 36
4 ['cra th', 'cra ti', 'cra ts'] 29
4 ['rafthis', 'ca this', 'cafthis'] 12
4 ['cra this', 'crafthis'] 2
3 ['crah this', 'cras this', 'crash tis'] 8
3 ['crash this'] 1
2 ['crafte this', 'crater this', 'craftr this'] 22
2 ['crafter this', 'crash afthis'] 2
1 ['crash ter thi', 'crashter this', 'crahafter tis'] 560
1 ['rsh after this', 'rash after thi', 'rash after ths'] 120
1 ['crash aftr this', 'crash afer this', 'crash after tis'] 16
1 ['crash after this'] 1