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:
N = int(input())
votes = [input() for i in range(N)]
votes_set = set(votes)
temp = {}
for i in votes_set:
    count = votes.count(i)
    if count in temp:
        temp[count].append(i)
    else:
        temp[votes.count(i)] = [i]
max_vote = max(temp.keys())
temp[max_vote].sort()
for i in temp[max_vote]:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
str_lis = []
for i in range(N):
  A = str(input())
  a = []
  for i in range(len(A)):
    a.append(ord(A[i]))
  str_lis.append(a)

max_num = 0
max_str = []
for i in str_lis:
  if str_lis.count(i) > max_num and not i in max_str:
    max_num = str_lis.count(i)
    max_str = []
    max_str.append(i)
  elif str_lis.count(i) == max_num and not i in max_str:
    max_num = str_lis.count(i)
    max_str.append(i)
    
new_max_str = sorted(max_str)
 
for i in new_max_str:
  for j in range(len(i)):
    i[j] = chr(i[j])

for i in new_max_str:
  print(''.join(i))

Submission status: Time Limit Exceeded

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

s_cnt = [0]*n
for i in range(n):
  s_cnt[s.index(s[i])] += 1

s_cnt_max = max(s_cnt)
for i in range(n):
  if (s_cnt[i] == s_cnt_max):
  	print(s[i])

Submission status: Time Limit Exceeded

Solution code:
n =int(input())
P = [input() for i in range(n)]
S = list(set(P))
S.sort()
N = [0] * len(S)

for i in range(len(S)):
  for x in P:
    if S[i] == x:
      N[i] += 1

M = max(N)
for i in range(len(S)):
  if N[i] == M:
    print(S[i])

Submission status: Time Limit Exceeded

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

ls=[]
for i in S:
    if i not in ls:
        ls.append(i)
str_ls =[]
num_ls = []

for i in ls:
    num_ls.append(S.count(i))


for i in range(len(ls)):
    if num_ls[i] == max(num_ls):
        str_ls.append(ls[i])

str_ls.sort()
for i in str_ls:
    print(i)

Submission status: Time Limit Exceeded

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

    li.sort()
B=[]

for i in range(N):
    B.append(int(li.count(li[i])))

M=max(B)
C=[]
for i in range(N):
    if li.count(li[i])==M and not li[i] in C:
        C.append(li[i])
    else:
        pass

C.sort()

S=len(C)

L=len(C)

for k in range(L):
    print(C[k])

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
d = defaultdict(int)


def main():
    n = int(input())
    polls = [input() for i in range(n)]

    for i in polls:
        d[i] += 1

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

    for ans in max_k_list:
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
int = int(input())
word = [input() for i in range(int)]
s = Counter(word)
t = list(s.values())
u = [k for k, v in s.items() if v == max(t)]
u.sort()
for i in range(len(u)):
    print(u[i])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
C = [0] * N
for i in range(N):
  s = str(input())
  if s in A:
    C[A.index(s)] += 1
  else:
    A.append(s)
  
m = max(C)
ans = [A[n] for n, v in enumerate(C) if v == m]
ans.sort()
for i in ans:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
import sys
N=int(input())
lines = sys.stdin.readlines()
from collections import defaultdict
d = defaultdict(int)
for s in lines:
  d[s.rstrip('\n')]+=1
max_k_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]
max_k_list.sort()
for a in max_k_list:
  print(a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
for _ in range(N):
    S.append(input())

S_set = set(S)
S_dict = {}
ans = []
for s in S_set:
    S_dict[s] = S.count(s)
S_dict = sorted(S_dict.items(), key=lambda x:x[1])
max = S_dict[-1][1]
while S_dict[-1][1] == max:
    ans.append(S_dict[-1][0])
    S_dict.pop(-1)
    if len(S_dict) == 0:
        break
ans.sort()

for s in ans:
    print(s)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
kaisuu = []
solution = []
index = 0

for i in range(N):
  tmp = input()
  
  if (tmp in S) == False:
    S.append(tmp)
    kaisuu.append(1)
    index += 1
  
  if (tmp in S) == True:
    index_tmp = S.index(tmp)
    kaisuu[index_tmp] += 1
  
max_ = max(kaisuu)

for i, k in enumerate(kaisuu):
  if k == max_:
    solution.append(S[i])
    
solution.sort()

for i in solution:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input() for i in range(N))
set = set(S)
dic = {}

for i in set:
    dic[i] = S.count(i)

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

max_k_list.sort()

for i in max_k_list:
    print(i)

Submission status: Time Limit Exceeded

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

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

no_ol = list(set(S))
max_s = 0
ans_list = []

for i in no_ol:
    tmp = S.count(i)
    if max_s == tmp:
        ans_list.append(i)
    elif tmp>max_s:
        ans_list = []
        max_s = tmp
        ans_list.append(i)


ans_list.sort()
[print(i) for i in ans_list]

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

input_line=int(input())
count=0
input_list=[]
while count < input_line:
  input_list.append(input())
  count+=1
ans={}
ans_list=[]
list_set=set(input_list)
max_appeard=Counter(input_list).most_common(1)[0][1]
for item in list_set:
    appeard=Counter(input_list)[item]
    if appeard >= max_appeard:
        max_appeard=appeard
        ans[item]=appeard
for key,value in ans.items():
    if value==max_appeard:
        ans_list.append(key)
ans_list.sort()
for item in ans_list:
  print (item)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
dict1 = {}
for i in range(N):
  a = str(input())
  if(a in dict1):
    dict1[a] += 1
  else:
    dict1[a] = 1
max_k_list = sorted([kv[0] for kv in dict1.items() if kv[1] == max(dict1.values())])

for i in max_k_list:
  print(i)

Submission status: Time Limit Exceeded

Solution code:


N=int(input())

S_list = []
S_count = []
max = 1
for i in range(N):
    s = input()
    temp_list = []
    temp_list.append(s)
    #if s in S_list:
    if not set(S_list).isdisjoint(set(temp_list)):   
        index = S_list.index(s)
        #S_count.append(S_count[index]+1)
        S_count[index] += 1
        if max < S_count[index]:
            max = S_count[index]
    else:
        S_list.append(s)
        S_count.append(1)
        #if max < S_count[i]:
        #    max = S_count[i]
     
#print(S_list)
#print(S_count)
#print(max)
S_max = []
for j in range(len(S_list)):
    if S_count[j] == max:
        S_max.append(S_list[j])

S_max.sort()
for k in range(len(S_max)):
    print(S_max[k])

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

c = Counter(l).most_common()
top=c.pop(0)
ans=[top[0]]
freq=top[1]

while len(c) > 0:
    top=c.pop(0)
    if top[1] == freq:
        ans.append(top[0])
    else:
        break

ans.sort()

for e in ans:
    print(e)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

S = [input() for i in range(N)]

result = {}

for s in S:
    if s in result.keys():
        result[s] += 1
    else:
        result[s] = 0
result_max = sorted([i for i in result.keys() if result[i] == max(result.values())])

for r in result_max:
    print(r)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = [input() for i in range(N)]
    set_S = list(set(S))
    cnt = 0
    ll = []
    for s in set_S:
        s_num = S.count(s)
        if cnt < s_num:
            cnt = s_num
            ll = [s]
        elif cnt == s_num:
            ll.append(s)
        elif cnt > s_num:
            pass

    ll.sort()
    for l in ll:
        print(l,end="")


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(input())
z={}
z= set(a)
c=list(z)
l=len(c)
b=[0]*l
for i in range(n):
    if(a[i] in c):
        inn=c.index(a[i])
        b[inn]=b[inn]+1
d=[]
tt=0
max=0
for i in range(l):
    if(b[i]>max):
        max=b[i]
        d.clear()
        tt=1
        d.append(c[i])
    elif(b[i]==max):
        tt=tt+1
        d.append(c[i])
d.sort()
for i in range(tt):
    print(d[i])

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

c = Counter(s)

max_count = c.most_common()[0][1]

a = []

for i in range(len(c)):
    if max_count == c.most_common()[i][1]:
        a.append(c.most_common()[i][0])
    else:
        break

b = sorted(a)

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

Submission status: Time Limit Exceeded

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

s_dic = {}
for i in range(n):
    if s_list[i] in s_dic:
        continue
    s_dic[s_list[i]] = s_list.count(s_list[i])

value_max = max(s_dic.values())
anser_list = []
for key,value in s_dic.items():
    if value == value_max:
        anser_list.append(key)

anser_list.sort()
for i in range(len(anser_list)):
    print(anser_list[i])

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = {}
    for _ in range(n):
        string = input()
        if string in s:
            s[string] += 1
        else:
            s[string] = 1
    s = sorted(list(s.items()), key=lambda x: (x[1], x[0]), reverse=True)
    lst = []
    max_num = s[0][1]
    for string, num in s:
        if num != max_num:
            break
        lst.append(string)
    for l in reversed(lst):
        print(l)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S = [input() for i in range(N)]
result=[]
max=0
name=[]

for i in range(N):
    C=S.count(S[i])
    result.append(C)
    if C>max:
        max=C
for i in range(N):
    if max==result[i]:
        name.append(S[i])
name_set=set(name)
name_list=sorted(list(name_set))

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    words = []
    for _ in range(n):
        words.append(input())
    words_set = set(words)
    pairs = {}
    for i in words_set:
        pairs[i] = words.count(i)
    results = [kv[0] for kv in pairs.items() if kv[1] == max(pairs.values())]
    results.sort()
    print(' '.join(map(str, results)))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

A=[]
B=[]
for i in range(n):
  s=input()
  if s not in B:
    A.append([1,s])
    B.append(s)
  else:
    A[B.index(s)][0] += 1
A=sorted(A,reverse=True)
A.sort(key=lambda x:(x[0], x[1]), reverse=True)

C=[]
for i in range(len(A)):
  C.append(A[i][1])
  if i == len(A)-1:
    break
  if A[i][0] != A[i+1][0]:
    break
C.sort()
for i in range(len(C)):
  print(C[i])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [input() for i in range(N)]
S = sorted(S)
def count(S):
    A = []
    s = 1
    for i in range(0,len(S)-1):
        if S[i] == S[i+1]:
            s = s + 1
        else:
            A.append(s)
            s = 1
    A.append(s)
    return A
def search(S):
    A = count(S)
    a = []
    x = A[0]
    for i in range(1,len(A)):
        if x < A[i]:
            x = A[i]
    for i in range(0,len(A)):
        if x == A[i]:
            a.append(i)
    C = []
    for i in range(0,len(a)):
        s = 0
        for j in range(0,a[i]):
            s = s + A[j]
        C.append(S[s])
    return C
print('\n'.join(map(str,search(S))))

Submission status: Time Limit Exceeded

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

S = sorted(S)

v = S[0]
c = 0
for i in range(N):
    if v == S[i]:
        c +=1
    else:
        break
del S[0:c]
N = N -c
L = [[v,c]]

while S != []:
    v = S[0]
    c = 0
    for i in range(N):
        if v == S[i]:
            c +=1
        else:
            break
    del S[0:c]
    N = N-c
    if L[0][1] == c:
        L.append([v,c])
    elif L[0][1] < c:
        L = [[v,c]]

for l in L:
    print(l[0])

Submission status: Time Limit Exceeded

Solution code:
import heapq

n=int(input())
word={}

for i in range(n):
    tmpword=input()
    if tmpword in word:
        word[tmpword] = word[tmpword]+1
    else:
        word[tmpword] = 1


#ans.append(max(word.items(),key=lambda x:x[1])[0])
ans=[k for k, v in word.items() if v == max(word.values())]
cnt=len(ans)
heapq.heapify(ans)
for i in range(cnt):
    print(heapq.heappop(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
d={}
for i in range(n):
    tmp = input()
    if tmp in d:
        d[tmp]+=1
    else:
        d[tmp]=1
max_k_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]
max_k_list.sort()
for i in max_k_list:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import collections
def resolve_c():
    n = input()
    s_l = [input() for i in range(int(n))]
    c = collections.Counter(s_l)
    results = []
    for k, v in c.most_common():
        if v == c.most_common()[0][1]:
            results.append(k)
        else:
            break
    results = sorted(results)
    for r in results:
        print(r)
resolve_c()

Submission status: Time Limit Exceeded

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

S_L = []

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
while cnt < len(ans_L):
    ans += ans_L[cnt]
    cnt += 1
    if cnt != len(ans_L):
        ans += ' '
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list()
for i in range(n):
  a.append(input())
a.sort()
b = list(set(a))
b.sort()
c = list()
for i in b:
  c.append([a.count(i),i])
c.sort()
c.reverse()
count = 1
for i in range(len(c)-1):
  if c[i][0] == c[i+1][0]:
    count+=1
  else:
    break
d = list()
for i in range(count):
  d.append(c[i][1])
d.sort()
for i in d:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S = [input() for i in range(N)]
P=[]
A=[]
for i in range(len(S)):
    P.append(S.count(S[i]))

for k in range(len(P)):
    if P[k]==max(P):
        A.append(S[k])

A0=set(A)
A1=list(A0)
A1.sort()

for List in A1:
    print(List)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S_list = []
S_count_list = []
S_set = set()

for n in range(N):
    s = input()

    if s in S_set:
        index_s = S_list.index(s)
        S_count_list[index_s] += 1
    
    else:
        S_set.add(s)
        S_list.append(s)
        S_count_list.append(1)

max_list = [i for i, v in enumerate(S_count_list) if v == max(S_count_list)]

max_S_list = []
for i in max_list:
    max_S_list.append(S_list[i])

max_S_list.sort()

for ans_s in max_S_list:
    print(ans_s)

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
l = [input() for i in range(n)]
c = collections.Counter(l)

m = c.most_common()[0][1]

ans = []
for i in range(len(c)):
    if m > c.most_common()[i][1]:
        break
    ans.append(c.most_common()[i][0])

ans.sort()
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import collections


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

# 以下のような数値の入力があったとする
a = ss
c = []

b = list(set(a))
for x in b:
    c.append(a.count(x))

d = dict(zip(b, c))
max_val = max(d.values())
keys_v = [i for i in d if d[i] == max_val]
keys_v.sort()
e = " ".join((map(str, keys_v)))

print(e)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input() for _ in range(N))

S_sorted = sorted(list(set(S)))

dic = dict(zip(S_sorted, [0 for _ in range(len(S_sorted))]))

for s in S: dic[s] += 1

K_max = max(list(dic.values()))

for (k, v) in dic.items():
    if K_max != v:
        S_sorted.pop(S_sorted.index(k))
        
for s in S_sorted: print(s)

Submission status: Time Limit Exceeded

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

l = [kv[0] for kv in s.items() if kv[1] == max(s.values())]

l.sort()

for i in l:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
wordlist = [input() for i in range(n)]
wordlist2 = list(set(wordlist))
ans = []
maxnum = 0
for j in range(len(wordlist2)) :
    countnum = wordlist.count(wordlist2[j])
    if countnum == maxnum :
        ans.append(wordlist2[j])
    if countnum > maxnum :
        maxnum = countnum
        ans = []
        ans.append(wordlist2[j])
ans.sort()
for l in range(len(ans)) :
    print(ans[l])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S_list = []
for _ in range(N):
    S_list.append(input())

str_list = set(S_list)
str_count_dict = {}
for val in str_list:
    str_count_dict[val] = S_list.count(val)

max_key = sorted([key for key, val in str_count_dict.items()\
                  if val == max(str_count_dict.values())])

print('\n'.join(max_key))

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = [input() for i in range(a)]

q = sorted(set(b))
e = [b.count(k) for k in q]

t = max(e)
[print(q[l]) for l, p in enumerate(e) if p == t]

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sis = []
for i in range(n):
  si = input()
  sis.append(si)
s_one = list(set(sis))
if len(s_one) == 1:
  print(s_one[0])
  quit()
s_max = []
m = 0
for so in s_one:
  c = sis.count(so)
  if c > m:
    m = c
    s_max = []
    s_max.append(so)
  elif c == m:
    s_max.append(so)
s_max2 = sorted(s_max)
for sm in s_max2:
  print(sm)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = ""
for _ in range(n):
    s += input()+" "
ls = s.split()
counter = 0
res = []
counter = ls.count(max(ls,key=ls.count))
for x in set(ls):
    if ls.count(x) == counter:
        res.append(x)
r = sorted(res)
print("\n".join(r))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []

# for i in range(n):
#     s.append(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

# for i in s:
#     if i not in buf:
#         buf.append(i)
#         cnt.append(0)
#     cnt[buf.index(i)] += 1

ans = [i for i, x in enumerate(cnt) if x == max(cnt)]

ans2 = [buf[i] for i in range(len(buf)) if i in ans]

ans3 = sorted(ans2)

for i in ans3:
    print(i)

Submission status: Time Limit Exceeded

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

sl_s = sorted(list(set(sl)))

if len(sl_s) == 1:
    print(sl[0])
else:
    ans = []
    count = 1
    for s in sl_s:
        if sl.count(s) == count and ans.count(s) == 0:
            ans.append(s)
        elif sl.count(s) > count and ans.count(s) == 0:
            ans.clear()
            ans.append(s)
            count = sl.count(s)
    print('\n'.join(ans))

Submission status: Time Limit Exceeded

Solution code:
#C - Poll
import collections
N = int(input())
S = [str(input()) for i in range(N)]
S = sorted(S)
#print(S)

A = collections.Counter(S)
maxS = [kv[0] for kv in A.items() if kv[1] == max(A.values())]
maxS = sorted(maxS)
for l in range(len(maxS)):
    print(maxS[l])

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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

s_set = sorted(list(set(s)))
s_num = [0]*len(s_set)

for i in range(n):
    s_num[s_set.index(s[i])] += 1

ans_num = max(s_num)
for i in range(len(s_set)):
    if s_num[i] == ans_num:
        print(s_set[i])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

s = []
cnt = [0] * n
for i in range(n):
  tmp = input()
  if tmp not in s:
    s.append(tmp)
  else:
    cnt[s.index(tmp)] += 1

_max = 0
for c in cnt:
  if _max < c:
    _max = c
results = []
for i in range(len(cnt)):
  if cnt[i] == _max:
    results.append(s[i])

results.sort()

for result in results:
  print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i in range(n)]
s_set = list(set(s))
d = [None]*len(s_set)
for i in range(len(s_set)):
    d[i] = s.count(s_set[i])
maxn = max(d)
lst = [i for i, x in enumerate(d) if x == maxn]
ans = []
for i in lst:
    ans.append(s_set[i])
ans = sorted(ans)
print("\n".join(ans))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def main():
  num = int(input())

  tmp = [input() for i in range(num)]

  count = Counter(tmp)

  tmp2 = [k for k, v in count.items() if count.most_common(1)[0][1] == v]

  for t in sorted(tmp2):
    print(t)

main()

Submission status: Time Limit Exceeded

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


a_f = list(set(a))
num = []


for i in a_f: 
    num.append(a.count(i))
    
result=[]
    
for n, i in enumerate(num):
    if i == max(num):
        result.append(a_f[n])
        
a_i=sorted(result)

for i in a_i:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = []
for i in range(n):
    l.append(str(input()))
    
l_s = set(l)
max_l = []
max_w = []
l_d = {}
for i in l_s:
    j = l.count(i)
    max_l.append(j)
    l_d[i] = j
    
max_c = max(max_l)

ans = []
for k,v in l_d.items():
    if v == max_c:
        ans.append(k)

ans.sort()
for m in ans:
    print(m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(input())
    
dic = {}
for i in range(len(s)):
    if s[i] not in dic:
        dic[s[i]]=s.count(s[i])
    
ans = sorted([k for k, v in dic.items() if v == max(dic.values())])

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = list()
for i in range(n):
    arr.append(input())

maxi = 0
res = list()
flag = True
while True:
    if arr:
        x = max(set(arr), key = arr.count)
        if flag:
            maxi = arr.count(x)
            flag = False
            res.append(x)
            while x in arr:
                arr.remove(x)
        else:
            if arr.count(x) == maxi:
                res.append(x)
                while x in arr:
                    arr.remove(x)
            else:
                break
    else:
        break
for i in sorted(res):
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    tmp = int(input().replace('\n',''))
    strlist = [input().split()[0] for i in range(tmp)]
    res = []
    setstrlist = set(strlist)
    for i in setstrlist:
        res.append([strlist.count(i),i])
    res = sorted(res,reverse=True)
    maxtmp = res[0][0]
    res2=[]
    for i in res:
        if i[0] == maxtmp:
            res2.append(i[1])
        else:
            break
    res2 = sorted(res2)
    print('\n'.join(res2))
if __name__ == '__main__':
    input = sys.stdin.readline
    main()

Submission status: Time Limit Exceeded

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

import collections

Ss_counted = collections.Counter(Ss)
max_val = max(Ss_counted.values())

# # https://note.nkmk.me/python-dict-value-max-min/

result = []
for k, v in Ss_counted.items():
    if v == max_val:
        result.append(k)

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lst=[]
while n>0:
    lst.append(input())
    n-=1

s=sorted(set(lst))
maximium = max(lst.count(ele)for ele in s)
print()
for ele in s:
    if lst.count(ele)==maximium:
        print(ele)

Submission status: Time Limit Exceeded

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

setlist = list(set(slist))
countlist = []
for i in range(0,len(setlist)):
  countlist.append(slist.count(setlist[i]))

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n = int(input())

    count = {}
    for _ in range(n):
        name = input()
        if name not in count.keys():
            count[name] = 1

        else:
            count[name] += 1

    max_polls = max(count.values())

    names = []
    for k, v in count.items():
        if v == max_polls:
            names.append(k)

    names.sort()
    for name in names:
        print(name)
        
resolve()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
str_dic = {}
for _ in range(n):
    inp = input()
    if inp in str_dic:
        str_dic[inp] += 1
    else:
        str_dic[inp] = 1

max_str = [s[0] for s in str_dic.items() if s[1] == max(str_dic.values())]

for s in sorted(max_str):
    print(s)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

ans = []
n = 1
for _ in range(N):
    tmp = input()


    for a in ans:
        if a[0] == tmp:
            a[1] = a[1] + 1
            if a[1] > n:
                n = a[1]
            continue
    
    ans.append([tmp, 1])
last = []
for a in ans:
    if a[1] == n:
        last.append(a[0])
last.sort()
# print()
for l in last:
    print(l)

Submission status: Time Limit Exceeded

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

unique_S_lis = list(set(S_lis))
res = []
for unique_str in unique_S_lis:
    res.append(S_lis.count(unique_str))

maxind = [i for i, x in enumerate(res) if x == max(res)]
lis_ans = sorted([unique_S_lis[i] for i in maxind])

for ans in lis_ans:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import itertools as it
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
n = i()
s = [input() for _ in range(n)]
s.sort()
ss = list(set(s))
ss.sort()
a = [0]*len(ss)
i = 0
while n-1 > i:
    if s[i] == s[i+1]:
        a[ss.index(s[i])] += 1
        i += 1
    else:
        i += 1
m = max(a)
for k in range(len(a)):
    if a[k] == m:
        print(ss[k])

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

ss = list(set(s))
ss.sort()
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 collections
n = int(input())
ls = [input() for i in range(n)]    
c = collections.Counter(ls)
count = c.most_common()[0][1]
ans = []
if c.most_common()[0][1] == 1:
    ls.sort()
    for i in ls:
        print(i)
elif c.most_common()[-1][1] == 2 and c.most_common()[0][1] == 2:
    ls.sort()
    for i in ls:
        print(i)
elif c.most_common()[-1][1] == 3 and c.most_common()[0][1] == 3:
    ls.sort()
    for i in ls:
        print(i)
else:
    for i in range(len(c)):
        p = c.most_common()
        if p[i][1] == count:
            ans.append(p[i][0])
        else:
            break   
    ans.sort()
    for i in ans:
      print(i)

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections

n = input()
arr = [_.replace('\n', '') for _ in sys.stdin]
dic = collections.Counter(arr)

s = [k for k,v in dic.items() if v == max(dic.values())]
for i in sorted(s):
  print(i)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
emp = []
for i in range(num):
   string = input()
   emp.append(string)
   string = ""
d = {i:emp.count(i) for i in emp}

maximum = max(d.values())
keys = [key for key, value in d.items() if value == maximum]
keys.sort()
for i in keys:
   print(i)

Submission status: Time Limit Exceeded

Solution code:
def maxCount(lst):
    count = 0
    for i in lst:
        if lst.count(i) > count:
            count = lst.count(i)
    return count

n = int(input())
lst = []
for i in range(n):
    lst.append(input())

res = sorted(list(set([x for x in lst if lst.count(x) == maxCount(lst)])))

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [''] * N
for i in range(N):
    S[i] = input()

dic = {'': 1, '': 1}
for i in range(N):
    if S[i] not in dic:
        dic[S[i]] = 1
    else:
        dic[S[i]] += 1

max_kv_list = [kv for kv in dic.items() if kv[1] == max(dic.values())]
max_k_list = sorted([t[0] for t in max_kv_list])

for w in max_k_list:
    print(w)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
moji = set()
moji2 = list()
count = list()
mojisuu = 0
for i in range(n):
    a=input()
    moji.add(a)
    if(len(moji)==mojisuu):
        count[moji2.index(a)]+=1
    else:
        mojisuu+=1
        count.append(1)
        moji2.append(a)
ma=max(count)
selected = list()
for i in range(mojisuu):
    if(count[i]==ma):
        selected.append(moji2[i])
selected.sort()
for i in selected:
    print(i)

Submission status: Time Limit Exceeded

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

s_unique   = []
s_cnt      = [0]*n
unique_num = 0
for i in range(n):
  # 新しい文字列の場合は配列に加える
  if (not(s[i] in s_unique)):
  	s_unique.append(s[i])
  else:
    s_cnt[s_unique.index(s[i])] += 1

# 最大カウントの要素で再構成
cnt_max = max(s_cnt)
s_max = []
for i in range(n):
  if (s_cnt[i] == cnt_max):
    s_max.append(s_unique[i])

s_max = sorted(s_max)
for s in s_max:
  print(s)