Problem:


Score: 300 points

Problem Statement

We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it.

Print all strings that are written on the most number of votes, in lexicographical order.

Constraints

1 \leq N \leq 2 \times 10^5

S_i (1 \leq i \leq N) are strings consisting of lowercase English letters.

The length of S_i (1 \leq i \leq N) is between 1 and 10 (inclusive).

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

Print all strings in question in lexicographical order.

Sample Input 1

7
beat
vet
beet
bed
vet
bet
beet

Sample Output 1

beet
vet

beet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.

Sample Input 2

8
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo

Sample Output 2

buffalo

Sample Input 3

7
bass
bass
kick
kick
bass
kick
kick

Sample Output 3

kick

Sample Input 4

4
ushi
tapu
nichia
kun

Sample Output 4

kun
nichia
tapu
ushi



Sample input:
7
beat
vet
beet
bed
vet
bet
beet


Sample output:
beet
vet

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter
import datetime

n = int(input())
sn = []
cntlist = []

for i in range(n):
    s = input()
    for j in sn:
        if(j[0] == s):
            j[1] += 1
            break
    else:
        sn.append([s,1])
        continue

sn.sort(key=itemgetter(1))
#sn.sort(key=cntlist)
sn.reverse()
#print(sn)

cnt = sn[0][1]
for i in sn:
    if(int(i[1]) == cnt):
        print(i[0])
        continue
    else:
        break

Submission status: Time Limit Exceeded

Solution code:
inp = int(input())

l = []
for i in range(0, inp):
  l.append(input())

# print(sorted(l))
max_num = 1
max_words = []
for i in list(set(l)):
  c = int(l.count(i))
  if c < max_num:
    pass
  elif c == max_num:
    max_words.append(i)
  elif c > max_num:
    max_num = l.count(i)
    max_words = [i]

for i in sorted(max_words):
  print(i)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lk = [0]*n
k = 0
k_max = 0
ls = []
ls_max = []
for i in range(n):
  s = str(input())
  if s in ls:
    dup = ls.index(s)
    lk[dup] += 1
    if k_max < lk[dup]:
      ls_max = []
      ls_max.append(s)
      k_max = lk[dup]
    elif k_max == lk[dup]:
      ls_max.append(s)
  else:
    ls.append(s)
    lk[k] += 1
    k += 1

if k_max == 0:
  ls_max = ls
ls_s = sorted(ls_max)
for i in range(len(ls_s)):
  print(ls_s[i])

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
List = [input() for i in range(n)]
res = []

c = collections.Counter(List)

leng = len(c)

res.append(c.most_common()[0][0])
for i in range(1, leng):
    if c.most_common()[i][1] >= c.most_common()[i-1][1]:
        res.append(c.most_common()[i][0])
    else:
        break

res = sorted(res)
for j in range(len(res)):
    print(res[j])

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from functools import lru_cache
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s

#main
n=int(input())
#A,B,C=map(int,input().split())
S=[]
C={}
for a in range(n):
    s=readline()
    if not s in C:
        C[s]=1
    else:
        C[s]+=1
A=[]
for a,b in C.items():
    A.append([b,a])
A.sort(key=lambda x:(-x[0],x[1]))
max_=A[0][0]
for a in A:
    if(a[0]!=max_):break
    print(a[1])

Submission status: Time Limit Exceeded

Solution code:
import heapq

n= int(input())
s=[input() for i in range(n)]

ss = list(set(s))

if(len(s)==len(ss)):
    s.sort()
    for i in s:
        print(i)

else:
    li = []
    heapq.heapify(li)
    for i in ss:
        ans = s.count(i)
        heapq.heappush(li,(-ans,i))
    
    for i in range(len(ss)):
        amount,st = heapq.heappop(li)
        if(i==0):
            print(st)
            ri=amount
            continue
        
        if(ri==amount):
            print(st)
        else:
            break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from operator import itemgetter

N=int(input())
List=[input() for i in range(N)]
SetList=list(set(List))
nc=[List.count(SetList[i]) for i in range(len(SetList))]

indexmax=np.where(np.array(nc) == np.array(nc).max())[0]
if(len(indexmax)==1):
    print(itemgetter(*indexmax)(SetList))
else:
    for i in sorted(itemgetter(*indexmax)(SetList)):
        print(i)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
import collections
mylist = []
for i in range(N):
  val = input("")
  if val:
    mylist.append(val)
if len(mylist) != len(set(mylist)):
    c = collections.Counter(mylist)
    A = [i for i in range(len(set(mylist))) if c.most_common()[0][1] == c.most_common()[i][1]]
    B = [c.most_common()[i][0] for i in range(len(A))]
    C = sorted(B)
    for item in C:
        print(item)
else:
    D = sorted(mylist)
    for item in D:
            print(item)

Submission status: Time Limit Exceeded

Solution code:
import collections

N=int(input())
l=[]
for i in range(N):
    S=input()
    l.append(S)
#print(l)

c=collections.Counter(l)

ret = [letter for letter,count in c.most_common() if count == c.most_common()[0][1]]
ret.sort()

s_n = '\n'.join(ret)
print(s_n)

Submission status: Time Limit Exceeded

Solution code:
#!usr/bin/env python3


import sys


def I(): return int(sys.stdin.readline())


def solve():
    n = I()
    sli = [input() for i in range(n)]
    setli = set(sli)
    rank = {}
    for i in setli:
        j = sli.count(i)
        rank[i] = j
    print(
        '\n'.join(sorted([k for k, v in rank.items() if v == max(rank.values())])))


# Solve
if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())

buf = []
cnt = []

for i in range(n):
    buf2 = input()
    if buf2 not in buf:
        buf.append(buf2)
        cnt.append(0)
    cnt[buf.index(buf2)] += 1

aaa = max(cnt)
ans2 = np.array(buf)[np.array(cnt) == aaa]
ans3 = sorted(ans2)

for i in ans3:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())
S = [input() for i in range(N)]
SS = []
c = collections.Counter(S)
n = len(c.most_common())
if(n != 1):
    if(c.most_common()[0][1] == c.most_common()[1][1]):
        for j in range(1, n):
            if(c.most_common()[0][1] == c.most_common()[j][1]):
                b = c.most_common()[j][0]
                SS.append(b)

SS.append(c.most_common()[0][0])
sortedS = sorted(SS)
[print(k) for k in sortedS]

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = [input() for i in range(N)]
    
    dictionary = {}
    for i in range(N):
        if A[i] in dictionary:
            dictionary[A[i]] += 1
        else:
            dictionary[A[i]] = 1
    extracted = [kv[0] for kv in dictionary.items() if kv[1] == max(dictionary.values())]
    extracted = sorted(extracted)
    
    for i in range(len(extracted)):
        print(extracted[i])
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())
s = [input() for i in range(N)]
k = 0
i = 0
ans =[]

c = collections.Counter(s)
for i in range(len(c)):
    if c.most_common()[i][1] ==c.most_common()[0][1]:
        ans.append(c.most_common()[i][0])

ans_A =sorted(ans)
for i in range(len(ans_A)):
    print(ans_A[i])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[input() for i in range(n)]
cnt=0
ans=[]

for i in s:
    cnt=max(cnt,s.count(i))

for j in s:
    if cnt==s.count(j):
        if j not in ans:
            ans.append(j)

ans=sorted(ans)
for k in ans:
    print(k)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
s=[input() for i in range(n)]
ans = list()

c = collections.Counter(s)
k = c.most_common()[0][1]

if n == 1:
    print(s[0])
elif n >= 2 and len(c.keys()) == 1:
    print(c.most_common()[0][0])
elif n >= 2 and len(c.keys()) == len(s):
    ans = s
else:
    for i in range(n):
        if k == c.most_common()[i][1]:
            ans.append(c.most_common()[i][0])
        else:
            break

ans = sorted(ans)
[print(i) for i in ans]

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[]
for i in range(n):
    s.append(input())

s=sorted(s)
t=0
c=0
ct=[]
for i in range(1,n):
    c+=1
    if s[t]!=s[i]:
        ct.append(c)
        c=0
        t=i
ct.append(c+1)
u=0
for i in ct:
    if i==max(ct):
        print(s[u])
    u+=i

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
b = {}
for i in range(n):
    temp = input()
    if temp not in b:
        b[temp] = 1
    else:
        b[temp] += 1

list1 = sorted(b.items(), key=lambda x: x[1], reverse=True)

a = 0
list2=[]
while a<len(list1) and list1[0][1] == list1[a][1]:
    list2.append(list1[a][0])
    list2.sort()
    a += 1

for a in list2:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a = [input() for i in range(n)]
b = sorted(list(set(a)))
d = {}
m = 0

for i in b:
    t = a.count(i)
    if m > 0 and t < m:
        continue

    d.setdefault(t,[])
    d[t].append(i)

for i in d[max(d.keys())]:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
 
mes_dict = {}
for i in range(N):
  m = input()
  try:
    mes_dict[m] += 1
  except:
    mes_dict[m] = 1

answer = sorted([k for k, v in mes_dict.items() if v == max(mes_dict.values())])
for ans in answer:
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input()) #1行目のNを取得する
s = [input() for i in range(N)] #複数行の数値の入力を取得

moji = sorted(s)

#重複削除
mow = set(moji)
mo2 = sorted(mow)

co=[]
for i in range(len(mo2)) :
	co.append(moji.count(mo2[i]))
	
	
#最大値
m_co = max(co)
i = 0
ou=[]

ou=[mo2[i] for i in range(len(mo2)) if moji.count(mo2[i]) == m_co]

print('\n'.join(map(str, ou)))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
S = [input() for i in range(n)]

L = Counter(S)
K = sorted([kv[0] for kv in L.items() if kv[1] == max(L.values())])

for i in range(len(K)):
    print(K[i])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [input() for x in range(N)]

S_L = list(set(S))

# for i in S:
    # if i not in S_L:
        # S_L.append(i)
# print(S_L)

S_N = [0] * len(S_L)

for j in S:
    ind = S_L.index(j)
    S_N[ind] += 1
# print(S_N)

S_max = [] # 最大の数を持つ文字列を入れるリスト
S_N_max = max(S_N) # 最大の数を追加

for k in range(len(S_N)):
    if S_N[k] == S_N_max:
        S_max.append(S_L[k])

ans_L = sorted(S_max)

ans = ''
cnt = 0
rng = len(ans_L)
while cnt < rng:
    ans += ans_L[cnt]
    cnt += 1
    if cnt != rng:
        ans += ' '
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = input()
n = int(n)
slist = []
countlist = []
resultlist = []

for _ in range(0,n):
  slist.append(input())

setlist = list(set(slist))

for i in setlist:
  countlist.append(slist.count(i))
maxlist = countlist.index(max(countlist))

for i in range(0,len(setlist)):
  if countlist[i] == max(countlist):
    resultlist.append(setlist[i])
resultlist = sorted(resultlist)
for i in resultlist:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools
N=int(input())
S=[]


for i in range(N):
    S.append(input())

counted= collections.Counter(S)

ret = [letter for letter,count in counted.most_common() if count == counted.most_common()[0][1]]

ans=sorted(ret)
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
listOfS = []
for count in range(N):
    S = input()
    listOfS.append(S)
maximumValue = 0
listOfMaximumS = []
for count in range(len(listOfS)):
    S = listOfS[count]
    countValue = listOfS.count(S)
    if (countValue > maximumValue):
        listOfMaximumS = []
        listOfMaximumS.append(S)
        maximumValue = countValue
    elif (countValue == maximumValue):
        if (not (listOfMaximumS.count(S)>0)):
            listOfMaximumS.append(S)
sorted_list = sorted(listOfMaximumS, key=str.lower)
for count in range(len(sorted_list)):
    print(sorted_list[count])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i in range(n)]
set_s = sorted(set(s))
max_num = 0
for i in set_s:
    max_num = max(max_num, s.count(i))
for i in set_s:
    if s.count(i) == max_num:
        print(i)

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())
S = []
T = []
for i in range(N):
    S.append(input())
c = collections.Counter(S)
values,counts = zip(*c.most_common())
for i in range(len(c.most_common())):
    T.append(values[i])
    if i + 1 <= len(c.most_common()) - 1:
        if counts[i] != counts[i + 1]:
            break
T.sort()
for i in range(len(T)):
    print(T[i])

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())
S = [input() for i in range(N)]
c = collections.Counter(S)
uniqueS = list(set(S))
result = []
max = c.most_common()[0][1]

for i in range(len(uniqueS)):
    if c.most_common()[i][1] != max:
        break
    result.append(c.most_common()[i][0])
result.sort()

for i in range(len(result)):
    print(result[i])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input() for _ in range(n))

l = list(set(s))

if len(l) == len(s):
    s.sort()
    for i in s:
        print(i)
    exit()

count = [0] * len(l)
for i, v in enumerate(l):
    count[i] = s.count(v)

m = max(count)
indexes = [i for i, x in enumerate(count) if x == m]

ans = [0] * len(indexes)
for i, v in enumerate(indexes):
    ans[i] = l[v]

ans.sort()

for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i in range(n)]
s.sort()
l = sorted(set(s))

ans = 0
ans_l = []
for i in l:
    sc = s.count(i)
    if sc > ans:
        ans_l = [i]
        ans = sc
    elif sc == ans:
        ans_l.append(i)
      
print("\n".join(ans_l))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=sorted([input() for k in range(n)])
p=[]
if(len(set(s))==len(s)):
    for u in range(len(s)):
        print(s[u])
    exit()
else:
    s1=s2 = [m for m in sorted(list(set(s))) if s.count(m)>1]
    i = 2
    while(len(s2)!=0):
        s2 = [m for m in sorted(list(set(s))) if s.count(m)>i]
        if(len(s2) == 0):
            break
        else:
            s1 = s2
            i+=1

for j in s1:
    print(j)

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())
s = [input() for i in range(N)]
k = 0
i = 0
ans =[]

ss=sorted(s)
c = collections.Counter(ss)
for i in range(len(c)):
    if c.most_common()[i][1] ==c.most_common()[0][1]:
        ans.append(c.most_common()[i][0])

ans_A =sorted(ans)
for i in range(len(ans_A)):
    print(ans_A[i])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

s = []
t = []

for i in range(n):
    s.append(input())

s.sort()

for j in range(n):
    t.append(s.count(s[j]))

u = max(t)

st = 0

for k in range(n):
    if s.count(s[k]) == u and st != s[k]:
        print (s[k])
        st = s[k]

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
list0 = [] 
list2 = []
for i in range(0, n):
  temp = input()
  list0.append(temp)
counter=collections.Counter(list0)
max = max(counter.keys(), key=(lambda k: counter[k]))
max = counter[max]
list3 = list(set(list0))
for i in list3:
  if list0.count(i) == max:
    list2.append(i)
list2.sort()
for i in list2:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import Counter
n = int(input())
c = Counter()

for _ in range(n):
  c += Counter([input()])
  
m = 0
mc = []
  
for item, count in c.most_common():  
  if m == 0:
    m = count
  
  if m > count:
    break
  else:
    mc += [item]

mc.sort()

print(*mc, sep="\n")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
content = []
for i in range(n):
  str_input = input()
  check = 0
  for co in content:
    if co[0] == str_input:
      check = 1
      co[1] += 1
  if check == 0:
    content.append([str_input, 1])

max_count = 0
for co in content:
  if co[1] > max_count:
    max_count = co[1]
    
max_index = []
for co in content:
  if co[1] == max_count:
    max_index.append(co[0])

max_index.sort()

for answer in max_index:
  print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [input() for i in range(N)]

dictionary = {}
for i in range(N):
    if A[i] in dictionary:
        dictionary[A[i]] += 1
    else:
        dictionary[A[i]] = 1
extracted = [kv[0] for kv in dictionary.items() if kv[1] == max(dictionary.values())]
extracted = sorted(extracted)

for i in range(len(extracted)):
    print(extracted[i])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
words = [input() for i in range(n)]

d_words = {word:words.count(word) for word in set(words)}

answer=[k for k, v in d_words.items() if v == max(d_words.values())]
answer.sort()

print(*answer, sep='\n')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

l = []
for x in range(N):
    x = input()
    l.append(x)
    

lst = sorted(list(set(l)))
n_list = []


for x in lst:
    n = l.count(x)
    n_list.append(n)

max_n = max(n_list)
l_max = [i for i, x in enumerate(n_list) if x == max_n]

for x in l_max:
    print(lst[x])

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=[input() for i in range(N)]
S=sorted(s)
a=1
num=[]
st=[]
for i in range(N-1):
  if S[i+1]==S[i]:
    a+=1
    if i == (N-2):
        num.append(a)
        st.append(S[-1])
  elif S[i+1]!=S[i]:
    num.append(a)
    st.append(S[i])
    a=1
if S[-1]!=S[-2]:
    num.append(1)
    st.append(S[-1])

d=max(num)
x=[]

ind=[i for i, v in enumerate(num) if v == max(num)]# 複数の最大値のインデックスを全て取得
st2=[]
for i in range(len(ind)):
    st2.append(st[ind[i]])
[print(i) for i in st2]

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []

for _ in range(N):
    S.append(input())

# 重複除外
seiri = sorted(list(dict.fromkeys(S)))
P = []
d = {}
count = 0

for i in range(len(seiri)):
    if S.count(seiri[i]) >= 2:
        count = 1
        d[seiri[i]] = S.count(seiri[i])

max_k_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]

if count == 0:
    max_k_list = sorted(S)
for i in range(len(max_k_list)):
    print(max_k_list[i])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

str_list = []
for n in range(n):
    str_list.append(input())

cnt_dict = {_ : str_list.count(_) for _ in set(str_list)}

tmp = max(cnt_dict.values())
for ans in sorted([l[0] for l in cnt_dict.items() if l[1] == tmp]):
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
inputs = []
for i in range(N):
    inputs.append(input())
max_em = {i:inputs.count(i) for i in inputs}
maxes = [i for i,v in max_em.items() if v == max(max_em.values())]
for x in sorted(maxes):
    print(x)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8


def main():
    n = int(input())
    polls_dict = {}
    for _ in range(n):
        poll = input()
        if poll not in polls_dict:
            polls_dict[poll] = 1
        else:
            polls_dict[poll] += 1

    max_poll = max(polls_dict.values())
    polls_set = sorted(polls_dict.keys())
    for key, value in polls_dict.items():
        if value < max_poll:
            polls_set.remove(key)

    for poll in polls_set:
        print(poll)
    
    return 0


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
put = []
stor = {}
i=0
while i<num :
    name = input()
    if name in stor.keys():
        stor[name] += 1
    else:
        stor[name] = 1
    i += 1
keyAll = list(stor.keys())
valueAll = list(stor.values())


for i in range(0,len(keyAll)):
    flag = 0
    flag2 = 0
    if i==len(keyAll)-1:
        put.append(keyAll[i])
        break

    for j in range(i+1,len(keyAll)):
        if valueAll[i]<valueAll[j]:
            flag = 1
            break
        if valueAll[i]==valueAll[j]:
            flag2 = 1#存在相等的
    if flag == 0:
        put.append(keyAll[i])
        if flag2==0:
            break
put.sort()
for i in put:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lisa=[]
ans=1
add=[]
coua=0
for i in range(n):
    a=input()
    lisa.append(a)
    coua=lisa.count(a)
    if ans<coua:
        add=[]
        ans=coua
        add.append(a)
    elif ans==coua:
        add.append(a)
add=sorted(set(add))
for i in range(len(add)):
    print(add[i])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
words = [input() for i in range(n)]

d_words = {word:words.count(word) for word in set(words)}

answer=[k for k, v in d_words.items() if v == max(d_words.values())]
answer.sort()

for a in answer:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
import collections
N=int(input())
word=[]
for i in range(N):
    word.append(input())
c = collections.Counter(word)
counts=list(c.values())
wordlist=list(c.keys())
ans=[]
for i in range(len(counts)):
    if(counts[i]==max(counts)):
        ans.append(wordlist[i])
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
ls = []
for _ in range(n):
    ls.append(input())
res = []
counter = Counter(ls).most_common(1)
check=counter[0][1]
for x in set(ls):
    if ls.count(x) == check:
        res.append(x)
print("\n".join(sorted(res)))

Submission status: Time Limit Exceeded

Solution code:
def my_index(l, x, default):
    return l.index(x) if x in l else default

n=int(input())
lk = [0]*n
k = 0
k_max = 0
ls = []
ls_max = []
for i in range(n):
  s = str(input())
  dup = my_index(ls, s, -1)
  if dup == -1:
    ls.append(s)
    lk[k] += 1
    k += 1
  else:
    lk[dup] += 1
    if k_max < lk[dup]:
      ls_max = []
      ls_max.append(s)
      k_max = lk[dup]
    elif k_max == lk[dup]:
      ls_max.append(s)

if k_max == 0:
  ls_max = ls
ls_s = sorted(ls_max)
for i in range(len(ls_s)):
  print(ls_s[i])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a = [input() for i in range(n)]
b = sorted(list(set(a)))
d = {}
for i in b:
    t = a.count(i)
    d.setdefault(t,[])
    d[t].append(i)

for i in d[max(d.keys())]:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
all_str = [input() for i in range(N)]

import collections
count = max(collections.Counter(all_str).values())

for hikaku in sorted(set(all_str)):
  if all_str.count(hikaku) == count:
    print(hikaku)

Submission status: Time Limit Exceeded

Solution code:

def main():
    n =int( input())
    sn=[]
    for i in range(n):
        
        inWord = str(input())
        addFlag = True
        for s in sn:
            if s["word"] == inWord and len(sn) !=0:
                s["count"]+=1
                addFlag = False
                break
        if addFlag ==True:
            sn.append( {"word":inWord,"count":1})
        
    a= sorted(sn, reverse=True,key=lambda x:x['count'])
    most = a[0]["count"]

    mostWords=[]
    for elm in a:
        if elm["count"] == most:
            mostWords.append(elm["word"])
        
    mostWords.sort()

    for elm in mostWords:
        print(elm)
    return

main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
s = [None]*n
for i in range(n):
    s[i] = input()
d = Counter(s)
if max(d.values()) == 1:
    for x in sorted(s):
        print(x)
else:
    key = max(d, key=d.get)
    m = d.pop(key)
    l = [key]
    while d:
        key = max(d, key=d.get)
        if m == d.pop(key):
            l.append(key)
        else:
            break
    for x in sorted(l):
        print(x)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
sl = []
for i in range(n):
    s = input()
    bisect.insort_left(sl, s)  # 2 最も左(前)の挿入箇所が返ってきている

# print(sl)
c = 0
anss = []
max_n = 0
for i, t in enumerate(sl):
    if i == 0:
        c += 1
        target = t
        continue

    if t == target:
        c += 1
    else:
        if max_n < c:
            anss = []
            anss.append(target)
            max_n = c
        elif max_n == c:
            anss.append(target)
            max_n = c
        target = t
        c = 1

if max_n < c:
    anss = []
    anss.append(t)
elif max_n == c:
    anss.append(t)


print(*anss)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
wordl = [input() for i in range(N)]
#print(wordl)
max = wordl.count(wordl[0])
for i in range(len(wordl) - 1):
  if wordl.count(wordl[i + 1]) >  wordl.count(wordl[i]):
    max = wordl.count(wordl[i + 1])
#print(max)
maxwordl = []
for i in range(len(wordl)):
  if wordl.count(wordl[i]) == max:
    maxwordl.append(wordl[i])
#print(maxwordl)
ans = sorted(set(maxwordl))
#print(ans)
[print(ans[i]) for i in range(len(ans))]

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [input() for i in range(N)]
S_set = list(set(S))
#print(S_set)
word_buf = []
cnt = []
mmax = -1
cnt.append(S.count(S_set[0]))
word_buf.append(S_set[0])
mmax = max(mmax,cnt[0])
for i in range(1,len(S_set)) :
    cnt.append(S.count(S_set[i]))
    if cnt[i] < mmax :
        pass
    elif cnt[i] == mmax :
        word_buf.append(S_set[i])
    else :
        word_buf.clear()
        word_buf.append(S_set[i])
    mmax = max(mmax,cnt[i]) # 現時点での最大値
word_buf = sorted(word_buf)
#print("--")
for i in range(len(word_buf)) :
    print(word_buf[i])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
listOfS = []
for count in range(N):
    S = input()
    listOfS.append(S)
maximumValue = 0
listOfMaximumS = []
for count in range(len(listOfS)):
    if (listOfS.count(listOfS[count]) > maximumValue):
        listOfMaximumS = []
        listOfMaximumS.append(listOfS[count])
        maximumValue = listOfS.count(listOfS[count])
    elif (listOfS.count(listOfS[count]) == maximumValue):
        if (not (listOfMaximumS.count(listOfS[count])>0)):
            listOfMaximumS.append(listOfS[count])
sorted_list = sorted(listOfMaximumS, key=str.lower)
for count in range(len(sorted_list)):
    print(sorted_list[count])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [[str(input())] for _ in range(n) ]

s.sort()
tmp = '0'
sl = []
ans = []

for i in range(n):
    cnt = s.count(s[i])
    s[i].append(int(cnt))

s.sort(key=lambda x: x[1])

for i in range(n-1,-1,-1):
    ans.append(s[i][0])
    try:
        if s[i][1] == s[i-1][1]:
            continue
        else:
            break
    except:
        break

for i in range(len(ans)-1,-1,-1):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
b = {}
for i in range(n):
    temp = input()
    if temp not in b:
        b[temp] = 1
    else:
        b[temp] += 1

list1 = sorted(b.items(), key=lambda x: x[1])
list1.reverse()

a = 0
list2=[]
while a<len(list1) and list1[0][1] == list1[a][1]:
    list2.append(list1[a][0])
    list2.sort()
    a += 1

for a in list2:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
ls = []
for _ in range(n):
    ls.append(input())
res = []
counter = Counter(ls).most_common(1)
check=counter[0][1]
for x in set(ls):
    if ls.count(x) == check:
        res.append(x)
r = sorted(res)
print("\n".join(r))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [[str(input())] for _ in range(n) ]

s.sort()
tmp = '0'
sl = []
ans = []

for i in range(n):
    cnt = s.count(s[i])
    s[i].append(int(cnt))

s.sort(key=lambda x: x[1])

for i in range(n-1,-1,-1):
    ans.append(s[i][0])
    try:
        if s[i][1] == s[i-1][1]:
            continue
        else:
            break
    except:
        break

for i in range(len(ans)-1,-1,-1):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
string_list=[input() for i in range(n)]
s=set(string_list)
t=list(s)
l=[0]*len(t)
a = len(t)
for i in range(n):
  for j in range(a):
    if t[j] == string_list[i]:
      l[j]+=1
u=[]
b = max(l)
for k in range(a):
  if l[k] == b:
    u.append(t[k])
u.sort()
for x in u:
	print(x)

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())
S = list(input() for i in range(N))

c = collections.Counter(S)

max_k_list = [kv[0] for kv in c.items() if kv[1] == max(c.values())]

max_k_list.sort()

for i in max_k_list:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
li=[input() for _ in range(n)]
c = collections.Counter(li)
max_list = [kv[0] for kv in c.items() if kv[1] == max(c.values())]
max_list.sort()
for s in max_list:
  print(s)