fork download
  1. from collections import Counter
  2.  
  3. c = input()
  4. n = int(input())
  5. k = []
  6. idx = -1
  7. mx = 0
  8.  
  9. for i in range(n):
  10. s=input()
  11. cnt = s.count(c)
  12. if mx < cnt:
  13. mx = cnt
  14. idx = i
  15. k.append(s)
  16.  
  17. s=sorted(k[idx])
  18. d=Counter(s)
  19. best=d.most_common(1)
  20. print(*list(best[0]))
  21.  
Success #stdin #stdout 0.02s 9356KB
stdin
z
8
did
you
ever
yyyzzz
hear
zzzeee
the
tragedy
stdout
y 3