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 collections import Counter
n = int(input())
l=[input() for x in range(n)]
c=Counter(l)
key=[]
val=[0]
for i,j in c.most_common():
    if j>=max(val):
        val.append(j)
        key.append(i)
    else:
        break
key.sort()
for i in key:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import sys
input_first = input()
N= int(input_first)

worddic={}

for i in range(N):
    S = input()
    if S in worddic:
        worddic[S] +=1
    else:
        worddic[S] =1

result=[keyval[0] for keyval in worddic.items() if keyval[1]==max(worddic.values())]

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

S = []
cnt = []
for i in range(N):
  s = input()
  if s in S:
    cnt[S.index(s)] += 1
  else:
    S.append(s)
    cnt.append(1)

cnt = np.array(cnt)
S = np.array(S)

ans = S[cnt==cnt.max()]
ans.sort()

for s in ans:
  print(s)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

S = []
cnt = []
for i in range(N):
  s = input()
  if s in S:
    cnt[S.index(s)] += 1
  else:
    S.append(s)
    cnt.append(1)

M = max(cnt)
ans = [S[i] for i in range(len(S)) if cnt[i]==M]
ans.sort()

for s in ans:
  print(s)

Submission status: Time Limit Exceeded

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

for _ in range(n):
    car = input()
    s.append(car)

for i in range(n):
    if s[i] not in dict:
        dict[s[i]] = s.count(s[i])

max_d_list = [d[0] for d in dict.items() if d[1] == max(dict.values())]
sorted_list = sorted(max_d_list)
for i in sorted_list:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
s=[input() for i in range(n)]
c=Counter(s)
t=[]
v=c.most_common()[0][1]
t.append(c.most_common()[0][0])
for i in range(1,len(c)):
  a=c.most_common()[i][1]
  if v>a:
    break
  else:
    t.append(c.most_common()[i][0])
t.sort()
for i in t:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input() for _ in range(n))
s.sort()
a = [0]
for i in range(n-1):
  if s[i] != s[i+1]:
    a.append(i+1)
l = int(len(a))
t = 0
b = []
for u in range(l):
  p = s.count(s[a[u]])
  if t<p:
    t=p
    b.clear()
    b.append(a[u])
  elif t==p:
    b.append(a[u])
k = int(len(b))    
for r in range(k):
    print(s[b[r]])

Submission status: Time Limit Exceeded

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

S_set=set(S)

c_max=0
ans=[]
for i in S_set:
    c= S.count(i)
    if c > c_max:
        c_max = c
        ans=[]
        ans.append(i)
    elif c == c_max:
        ans.append(i)

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

Submission status: Time Limit Exceeded

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

S_set=set(S)

c_max=0
ans=[]
for i in S_set:
    c= S.count(i)
    if c > c_max:
        c_max = c
        ans=[]
        ans.append(i)
    elif c == c_max:
        ans.append(i)

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
S = Counter(input() for _ in range(N))
if len(S) == 1:
    print(list(S)[0])
    exit()
for k, val in sorted(S.most_common()):
    if val == max(S.values()):
        print(k)

Submission status: Time Limit Exceeded

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

cnt = []
l_t = list(set(l))
keys = []
max_v = 0
for item in l_t:
    if max_v < l.count(item):
        max_v = l.count(item)
        keys = []
        keys.append(item)
    elif max_v == l.count(item):
        keys.append(item)

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

Submission status: Time Limit Exceeded

Solution code:

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

cnt = []
l_t = list(set(l))
keys = []
max_v = 0
for item in l_t:
    if max_v < l.count(item):
        max_v = l.count(item)
        keys = []
        keys.append(item)
    elif max_v == l.count(item):
        keys.append(item)

for i in sorted(keys):
    print(i)
    
    keys.append(item)

Submission status: Time Limit Exceeded

Solution code:

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

cnt = []
l_t = list(set(l))
for item in l_t:
    cnt.append(l.count(item))

max_v = max(cnt)

keys = []

for i in range(0,len(cnt)):
    if cnt[i] == max_v:
        keys.append(l_t[i])

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
S = Counter([input() for _ in range(N)])
if len(S) == 1:
    print(list(S)[0])
    exit()
for k, val in sorted(S.most_common()):
    if val == max(S.values()):
        print(k)

Submission status: Time Limit Exceeded

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

cnt = []
l_t = list(set(l))
for item in l_t:
    cnt.append(l.count(item))

num_dict = dict(zip(l_t,cnt))
max_v = max(num_dict.values())

keys = []

for word, num in num_dict.items():
    if num == max_v:
        keys.append(word)

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

Submission status: Time Limit Exceeded

Solution code:

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

cnt = []
for item in list(set(l)):
    cnt.append(l.count(item))

num_dict = dict(zip(list(set(l)),cnt))
max_v = max(num_dict.values())

keys = []

for word, num in num_dict.items():
    if num == max_v:
        keys.append(word)

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lis=[]
t=[]
for i in range(n):
    x=input()
    if lis.count(x)==0:
        lis.append(x)
        t.append(1)
    else:
        k=lis.index(x)
        t[k]+=1
m=max(t)
lis1=[]
for i in range(len(t)):
    if t[i]==m:lis1.append(lis[i])
lis1.sort()
for x in lis1:
    print(x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dic ={}
for i in range(n):
    a = input()
    if dic.get(a):
        dic[a] += 1
    else:
        dic[a] = 1
res = sorted(list(filter(lambda key:dic[key]==max(dic.values()),list(dic))))
for key in res:
    print(key)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dic ={}
for i in range(n):
    key = input()
    if key not in dic:
        dic[key] = 1
    if key in dic:
        dic[key] += 1
res = sorted(list(filter(lambda key:dic[key]==max(dic.values()),list(dic))))
for key in res:
    print(key)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i in range(n)]
dic ={}
for key in s:
    if key not in dic:
        dic[key] = 1
    if key in dic:
        dic[key] += 1
res = sorted(list(filter(lambda key:dic[key]==max(dic.values()),list(dic))))
for key in res:
    print(key)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

L = []
LL = []
S = set()
for i in range(N):
  s = input()
  L.append(s)
  if s not in S:
    S.add(s)
    LL.append(s)

L.sort()
LL.sort()

M = 0
for i in LL:
  M = max(M, L.count(i))
for i in LL:
  if L.count(i) == M:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

L = []
LL = []
S = set()
for i in range(N):
  s = input()
  L.append(s)
  if s not in S:
    S.add(s)
    LL.append(s)

L.sort()
LL.sort()

M = 0
for i in LL:
  M = max(M, L.count(i))
for i in LL:
  if L.count(i) == M:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
dict = {}
for i in range(int(input())):
    a = input()
    if dict.get(a):
        dict[a] += 1
    else:
        dict[a] = 1



ans = [key for key, value in dict.items() if value == max(dict.values())]
ans.sort()
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

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

for _ in range(n):
    car = input()
    s.append(car)

for i in range(n):
    if s[i] not in list1:
        list1.append(s[i])
        list2.append(s.count(s[i]))

maxs = [i for i in range(len(list2)) if list2[i] == max(list2)]
max_char = [list1[i] for i in maxs]
max_char_jisho = sorted(max_char)

for i in max_char_jisho:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import collections as cl
import sys
input = sys.stdin.readline

N = int(input().strip())
S_list = [input().strip() for _ in range(N)]
# print(S_list)
c = cl.Counter(S_list)
# print(c)

max_list = sorted([kv[0] for kv in c.items() if kv[1] == max(c.values())])
print(*max_list)

Submission status: Time Limit Exceeded

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

for _ in range(n):
    car = input()
    s.append(car)

for i in range(n):
    if s[i] in list1:
        list2[list1.index(s[i])] += 1
    else:
        list1.append(s[i])
        list2.append(1)

maxs = [i for i in range(len(list2)) if list2[i] == max(list2)]
max_char = [list1[i] for i in maxs]
max_char_jisho = sorted(max_char)

for i in max_char_jisho:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
 
for i in range(n):
    s.append(input())
 
buf = []
cnt = []
for i in s:
    if i not in buf:
        buf.append(i)
        cnt.append(0)
    cnt[buf.index(i)] += 1
 
max_cnt = max(cnt)
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())
s = []

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

word_buf = {}

for i in s:
    if i in word_buf.keys():
        word_buf[i] += 1
    else:
        word_buf[i] = 1

max_word = [i[0] for i in word_buf.items() if i[1] == max(word_buf.values())]
max_word.sort()

for i in max_word:
    print(i)

Submission status: Time Limit Exceeded

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

ans = {}
for i in S:
    if i in ans:
        ans[i] += 1
    else:
        ans[i] = 1

ANS = []
for key, value in sorted(ans.items(), key=lambda x: -x[1]):
    if ans[key] == max(ans.values()):
        ANS.append(key)

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

Submission status: Time Limit Exceeded

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

c = []
for j in s:
    if j not in c:
        c.append(j)

g = []
for t in c:
    g.append([s.count(t),t])
g.sort(reverse=True)
h = max(g)[0]
hh = []
for ii in range(len(g)):
    if g[ii][0] == h:
        hh.append(g[ii])
    else:
        break
hh.sort(key=lambda x: x[1])
ans = []
for k in range(len(hh)):
    print(hh[k][1])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
for i in range(N):
    s = str(input())
    S.append(s)
s = list(set(S))
num = []
for i in s:
    num.append([S.count(i),i])
num.sort(reverse=True)
h = max(num)[0]
before = []
for i in range(len(s)):
    if num[i][0] == h:
        before.append(num[i])
    else:
        pass
ans = []
for i in before:
    ans.append(i[1])
ans.sort()
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
S = []
for _ in range(n):
    S.append(input())

S_c = collections.Counter(S)
cnt = S_c.most_common()[0][1]
S_u = sorted(set(S))

for s in S_u:
    if S.count(s) == cnt:
        print(s)

Submission status: Time Limit Exceeded

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

list_val = list(set(L))
list_size = [0]*N
for i,v in enumerate(list_val):
    list_size[i] = L.count(v)

max_size = max(list_size)
#sorted_index = sorted(range(len(list_size)), key=lambda k: list_size[k], reverse=True)

ans = []
for i,s in enumerate(list_size):
    if s == max_size:
      ans.append(list_val[i])
print("\n".join(sorted(ans)))

Submission status: Time Limit Exceeded

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

list_val = list(set(L))
list_size = [0]*N
for i,v in enumerate(list_val):
    list_size[i] = L.count(v)

max_size = max(list_size)
sorted_index = sorted(range(len(list_size)), key=lambda k: list_size[k], reverse=True)

ans = []
for s in sorted_index:
    if list_size[s] == max_size:
      ans.append(list_val[s])
    else:
      break
print("\n".join(sorted(ans)))

Submission status: Time Limit Exceeded

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

list_val = list(set(L))
list_size = [0]*N
for i,v in enumerate(list_val):
    list_size[i] = L.count(v)

max_size = max(list_size)

ans = []
for i,s in enumerate(list_size):
    if s == max_size:
      ans.append(list_val[i])
print("\n".join(sorted(ans)))

Submission status: Time Limit Exceeded

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

list_val = list(set(L))
list_size = [0]*N
for i,v in enumerate(list_val):
    list_size[i] = L.count(v)

max_size = max(list_size)

ans = []
while max(list_size) == max_size:
    max_idx = list_size.index(max_size)
    ans.append(list_val[max_idx])
    list_size[max_idx] = 0
print("\n".join(sorted(ans)))

Submission status: Time Limit Exceeded

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

list_val = list(set(L))
list_size = [0]*N
for i,v in enumerate(list_val):
    list_size[i] = L.count(v)

max_size = max(list_size)

ans = []
while max(list_size) == max_size:
    max_idx = list_size.index(max_size)
    ans.append(list_val[max_idx])
    list_size[max_idx] = 0
print("\n".join(sorted(ans)))

Submission status: Time Limit Exceeded

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

list_val = list(set(L))
list_size = []
for i in list_val:
    list_size.append(L.count(i))

max_size = max(list_size)

ans = []
while max(list_size) == max_size:
    max_idx = list_size.index(max_size)
    ans.append(list_val[max_idx])
    list_size[max_idx] = 0
print("\n".join(sorted(ans)))

Submission status: Time Limit Exceeded

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

list_val = list(set(L))
list_val.sort()
list_size = []
for i in list_val:
    list_size.append(L.count(i))

max_size = max(list_size)

while max(list_size) == max_size:
    max_idx = list_size.index(max_size)
    print(list_val[max_idx])
    list_size[max_idx] = 0

Submission status: Time Limit Exceeded

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

tt = [[],[]]
for i in s:
    if i not in tt[0]:
        tt[0] += [i]
        tt[1] += [1]
    else:
        idx = tt[0].index(i)
        tt[1][idx] += 1
t = tt
m = max(t[1])
ans = []
for i in range(len(t[1])):
    if t[1][i] == m:
        ans += [t[0][i]]

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

Submission status: Time Limit Exceeded

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

import numpy as np
s = np.array(s)
tt = [[],[]]
for i in s:
    if i not in tt[0]:
        tt[0] += [i]
        tt[1] += [1]
    else:
        idx = tt[0].index(i)
        tt[1][idx] += 1
tt = np.array(tt)

tidx = np.argsort(tt[0])
t = tt[:, tidx]
m = max(t[1])
ans = []
for i in range(len(t[1])):
    if t[1][i] == m:
        ans += [t[0][i]]

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


def words_sort_ordered(words_list):
    cnt = Counter()
    for word in words_list:
        cnt[word] += 1

    written_words_number = []
    for x in cnt.values():
        written_words_number.append(x)

    answer_words_list = []

    for word, number in dict(cnt).items():
        if number == max(written_words_number):
            answer_words_list.append(word)

    return sorted(answer_words_list)


if __name__ == '__main__':
    words_num = int(input())
    words_list = [input() for i in range(words_num)]
    for w in words_sort_ordered(words_list):
        print(w)

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)

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

Submission status: Time Limit Exceeded

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

d = {}
for ss in s:
    d[ss] = d.get(ss, 0) + 1

t = set([ ss for ss in s if d[ss] == max(d.values())])
print("\n".join( sorted(list(t)) ))

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())]
sort = answer.sort()
sort

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = {}
for i in range(N):
  a_i = input()
  if a_i in D.keys():
    D[a_i] += 1
  else:
    D[a_i] = 1
D_list = [kv[0] for kv in D.items() if kv[1] == max(D.values())]
A = sorted(D_list)
for x in A:
  print(x)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

def abc155c(num, s):
    appearance_dict = {} # 文字列:出現回数
    array = [[] for _ in range(num)] # (出現回数-1)をindexにして文字列を配列で管理する
    max_cnt = 0

    for i in range(0, num):
        target = s[i]
        cnt = 0 # appearance count

        if( target in appearance_dict ):
            cnt = appearance_dict[target]
            array[cnt-1].remove(target)
        appearance_dict[target] = cnt+1

        # sortしながら配列に追加する
        insert_idx = 0
        target_array = array[cnt]
        if( target_array != [] ):
            for sort_idx in range(0, len(target_array)):
                if( target < target_array[sort_idx] ): 
                    break
                insert_idx += 1
        array[cnt].insert(insert_idx, target)

        if( cnt > max_cnt ) : max_cnt = cnt

    return(array[max_cnt])

###
# main
if(__name__ == '__main__'):
    # input
    num = int(input())
    s = [None for _ in range(num)]
    for i in range(0, num):
        s[i] = input()

    ans = abc155c(num, s)

    # output
    for name in ans :
        print(name)
# else:
# do nothing

Submission status: Time Limit Exceeded

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

ses = list(set(s))
setnums = []
for i in ses:
    setnums.append(s.count(i))

num = max(setnums)
pl = []
for i in ses:
    if num == s.count(i):
        pl.append(i)

pl = sorted(pl)
for i in pl:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
# 1行目は入力ワード数
# word を1行ずつ入力し、最も投票数が多かったwordを出力

import collections

def check(input_list):

    vote_dict = collections.Counter(input_list)

    result_list = [k for k, v in vote_dict.items() if v == max(vote_dict.values())]
    result_list.sort()
    
    return result_list

if __name__ == '__main__':
    num = int(input())
    input_list = [input() for a in range(num)]

    for str in check(input_list):
        print(str)

Submission status: Time Limit Exceeded

Solution code:
# 1行目は入力ワード数
# word を1行ずつ入力し、最も投票数が多かったwordを出力

def check(input_list):
    vote_dict = {}
    
    for a in input_list:
        if(a in vote_dict.keys()):
            vote_dict[a] += 1
        else:
            vote_dict[a] = 1
            
    result_list = [k for k, v in vote_dict.items() if v == max(vote_dict.values())]
    result_list.sort()
    
    return result_list

if __name__ == '__main__':
    num = int(input())
    input_list = [input() for a in range(num)]

    for str in check(input_list):
        print(str)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
mp={}
m=0
for i in range(n):
  s=input()
  if s in mp.keys():
    mp[s]+=1
    m=max(m,mp[s])
  else:
    mp[s]=1
    m=max(m,1)
for s in sorted(mp.keys()):
  if mp[s]==m:
    print(s)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=[input().split() for i in range(N)]
A=[]
L=len(S)
while L>0:
    S=[s for s in S if s!=S[0]]
    A.append(L-len(S))
print(max(A))

Submission status: Time Limit Exceeded

Solution code:

from collections import Counter
 
n=int(input())
a=[input() for i in range(n)]

c = Counter(a)
keys = [k for k, v in c.items() if v ==c.most_common()[0][1] ]
 
keys.sort()
string = "\n".join(keys)
print(string)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = []
D = {}
for _ in range(N):
    x = input()
    L.append(x)

for x in L:
    D[x] = 0
    
for x in L:
    D[x] += 1

max_k_list = [kv[0] for kv in D.items() if kv[1] == max(D.values())]
print("\n".join(sorted(max_k_list)))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

def abc155c(num, s):
    array = [[] for _ in range(2*(10**5))]
    max_cnt = 0

    for i in range(0, num):
        target = s[i]
        cnt = 0 # appearance count
        iter_num = 0
        # array内で一致する文字列を見つける
        for iter in array:
            iter_num += 1
            for string in iter:
                if( target == string ):
                    cnt = iter_num
                    break
            if( cnt != 0 ): break

        if( cnt != 0 ):
            array[cnt-1].remove(target)
        # sortしながらリスト追加する
        insert_idx = 0
        target_array = array[cnt]
        if( target_array != [] ):
            for sort_idx in range(0, len(target_array)):
                if( target < target_array[sort_idx] ): 
                    insert_idx = sort_idx
                    break
        array[cnt].insert(insert_idx, target)

        if( cnt > max_cnt ) : max_cnt = cnt

    return(array[max_cnt])

###
# main
if(__name__ == '__main__'):
    # input
    s = [None for _ in range(2*(10**5))]
    num = int(input())
    for i in range(0, num):
        s[i] = input()

    ans = abc155c(num, s)

    # output
    for name in ans :
        print(name)
# else:
# do nothing

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline

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

c = Counter(l)

for k, v in sorted(c.items(), key=lambda x: x[0]):
    if v == max(c.values()):
        print(k)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
L = [input() for _ in range(N)]
#for n in range(N):
    #S = input()
    #L.append(S)
Dic = Counter(L)

max_k_list = [i for i, j in Dic.items() if j == max(Dic.values())]
max_k_list = sorted(max_k_list)
for t in max_k_list:
    print(t)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
#L = []
L = [input() for _ in range(N)]
#for n in range(N):
    #S = input()
    #L.append(S)
Dic = Counter(L)
max_k_list = [kv[0] for kv in Dic.items() if kv[1] == max(Dic.values())]
max_k_list = sorted(max_k_list)
for t in max_k_list:
    print(t)

Submission status: Time Limit Exceeded

Solution code:
import collections


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


tmp = collections.Counter(ss).most_common()

target = tmp[0][1]
ans = ''
for i in tmp:
    if i[1] == target:
        ans += i[0] + ' '
    else:
        break
ans = sorted(ans.split(), key=str.lower)
print(*ans)

Submission status: Time Limit Exceeded

Solution code:

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

    cnt=dict()
    for _ in range(n):
        s=input()
        if s in cnt:
            cnt[s]+=1
        else :
            cnt[s]=1
    #print(cnt)
    
    a = [k for k, v in cnt.items() if v == max(cnt.values())]


    a.sort()
    for elm in a:
        print(elm)

main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

def abc155c(num, s):
    array = [[] for _ in range(2*(10**5))]
    max_cnt = 0

    for i in range(0, num):
        target = s[i]
        cnt = 0 # appearance count
        iter_num = 0
        # array内で一致する文字列を見つける
        for iter in array:
            iter_num += 1
            for string in iter:
                if( target == string ):
                    cnt = iter_num
                    break
            if( cnt != 0 ): break

        if( cnt != 0 ):
            array[cnt-1].remove(target)
        array[cnt].append(target)
        if( cnt > max_cnt ) : max_cnt = cnt

    # sort in array[max_cnt]
    sortedArray = sorted(array[max_cnt])

    return(sortedArray)

###
# main
if(__name__ == '__main__'):
    # input
    s = [None for _ in range(2*(10**5))]
    num = int(input())
    for i in range(0, num):
        s[i] = input()

    ans = abc155c(num, s)

    # output
    for name in ans :
        print(name)
# else:
# do nothing

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Dic = {}
for n in range(N):
    S = input()
    if S in Dic.keys():
        Dic[S] = Dic[S] + 1
    else:
        Dic[S] = 1
        
max_k_list = [kv[0] for kv in Dic.items() if kv[1] == max(Dic.values())]
max_k_list = sorted(max_k_list)

print(*max_k_list, sep="\n")
#for t in max_k_list:
    #print(t)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dic = {}
for _ in range(n):
  k = input()
  dic[k] = 1 if k not in dic else dic[k] + 1
result = []
for i,j in dic.items():
  result.append((j,i))
  result.sort()
  maxi = result[-1][0]
  reresult=[]
  for i in result:
    if maxi == i[0]:
      reresult.append(i[1])
for i in sorted(reresult):
  print(i)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = [input().strip() for i in range(N)]
    S.sort()
    set_S = 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)

    ll.sort()
    print("\n".join(ll))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

S = []
Sdict = dict()
for _ in range(N):
    s = input()
    if s in S:
        Sdict[s] += 1
    else:
        S.append(s)
        Sdict[s] = 0
    
maxi = max(Sdict.values())

def get_keys_from_value(d, val):
	return [k for k, v in d.items() if v == val]

for k in sorted(get_keys_from_value(Sdict,maxi)):
	print(k)

Submission status: Time Limit Exceeded

Solution code:
import  collections 
N = int(input())
list_a = [input() for i in range(N)]
dict_a = collections.Counter(list_a)


list_ans = []

list_ans.append(dict_a.most_common()[0][0])
for i in range (1,len(dict_a)):
    if dict_a.most_common()[0][1] == dict_a.most_common()[i][1]:
        list_ans.append(dict_a.most_common()[i][0])

list_ans.sort()
for i in range (0,len(list_ans)):
    print(list_ans[i])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
b=[]
c=[]
for i in range(n):
    b=str(input())
    if b in a:
        c[a.index(b)]+=1
    else:
        a.append(b)
        c.append(1)
t=max(c)
e=[]
for i in range(len(c)):
    if c[i]==t:
        e.append(a[i])
e.sort()
for i in range(len(e)):
    print(e[i])

Submission status: Time Limit Exceeded

Solution code:
import collections as col
N=int(input())
S=[]
answer=[]

for _ in range(N):
    S.append(input())
T=sorted(S)
s=col.Counter(T)
values, counts = zip(*s.most_common())
#print(values,counts)



for i in range(len(counts)):
    if counts[i]==max(counts):
        answer.append(values[i])
answer.sort()
for j in answer:
    print(j)

Submission status: Time Limit Exceeded

Solution code:
import collections

def main():
    n =int( input())
    sn = []

    for _ 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})
    
    sn.sort(reverse=True,key=lambda x:x['count'])
    
    most = int(sn[0]["count"])
    mostWords=[]
    for elm in sn:
        if elm["count"] == most:
            mostWords.append(elm["word"])
        else:
            break

    mostWords.sort()

    for elm in mostWords:
        print(elm)
    return
main()

Submission status: Time Limit Exceeded

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

q = int(input())
a = [input().rstrip() for _ in range(q)]

dic = collections.Counter(a)

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

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 = []

for i in range(len(c)):
    p = c.most_common()
    if p[i][1] == count:
        ans.append(p[i][0])
    else:
        break   
ans = sorted(ans)
for i in ans:
    print(i)

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})
    
    sn.sort(reverse=True,key=lambda x:x['count'])
    
    most = int(sn[0]["count"])
    mostWords=[]
    for elm in sn:
        if elm["count"] == most:
            mostWords.append(elm["word"])
        else:
            break
        
    mostWords.sort()

    for elm in mostWords:
        print(elm)
    return
main()

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())
data = [input() for i in range(N)]

dicdata = collections.Counter(data)

newdata = [k for k, v in dicdata.items() if v == max(dicdata.values())]

newdata.sort()

[print(i) for i in newdata]

Submission status: Time Limit Exceeded

Solution code:
from itertools import groupby
import collections
N=int(input())
a=[input() for i in range(N)]

a = sorted(a)
#print(a)

groups = []
uniquekeys = []
for k, g in groupby(a):
    groups.append(len(list(g)))      # Store group iterator as a list
    uniquekeys.append(k)
#print(max(groups))

for q in range(len(groups)):
  if groups[q] == max(groups):
    print(uniquekeys[q])