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:
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    words = {}
    for _ in range(n):
        a = input()
        if a in words:
            words[a] += 1
        else:
            words[a] = 1
    results = [kv[0] for kv in words.items() if kv[1] == max(words.values())]
    results.sort()
    print(' '.join(map(str, results)))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from operator import itemgetter

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 = np.where(cnt == np.max(cnt))[0].tolist()
ans2 = np.array(buf)[np.array(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 = np.sort(ans2)

for i in ans3:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=["as"]*n
for i in range(0,n):
  s[i]=input()
st=[s[0]]
count=[1]
#st.append(st[0])
#count.append(1)
for i in range(1,n):
  k=False
  for j in range(0,len(st)):
    if s[i]==st[j]:
      count[j]+=1
      k=True
      break
  if k==False:
    st.append(s[i])
    count.append(1)
maxcount=0
maxs=[]
#maxn=[]
for i in range(0,len(st)):
  if count[i]>maxcount:
    #maxn=[i]
    maxs=[st[i]]
    maxcount=count[i]
    #maxn.append(i)
    #maxs.append(st[i])
  elif count[i]==maxcount:
    #maxn.append(i)
    maxs.append(st[i])
maxed=sorted(maxs)
for i in range(0,len(maxed)):
  print("%s"% maxed[i])

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s10=[]*10
S=[s10]*N
Li=[0]*N
Ls=['']*N
Ld=[]
max_id=0
ii=0
for i in range(N):
    S[i]=input()
for i in range(N):
    if S[i] in Ls:
        idx=Ls.index(S[i])
        Li[idx]+=1
        a=Li[idx]
    else:
        Li[ii]=1
        Ls[ii]=S[i]
        a=1
        ii+=1
    if max_id<a:
        max_id=a
for i in range(ii):
    if max_id==Li[i]:
        Ld.append(Ls[i])
Ld=sorted(Ld)
for i in range(len(Ld)):
    print(Ld[i])

Submission status: Time Limit Exceeded

Solution code:
import collections

q = int(input())
a = [input() 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:
n = int(input())
wordlist = [input() for i in range(n)]
wordtuple = tuple(set(wordlist))
ans = []
maxnum = 0
a = len(wordtuple)
for j in range(a) :
    countnum = wordlist.count(wordtuple[j])
    if countnum == maxnum :
        ans.append(wordtuple[j])
    if countnum > maxnum :
        maxnum = countnum
        ans = []
        ans.append(wordtuple[j])
ans.sort()
for l in range(len(ans)) :
    print(ans[l])

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
list = [input() for _ in range(0,N)]
counted = Counter(list)
res = [letter for letter,count in counted.most_common() if count == counted.most_common()[0][1]]
[print(i) for i in sorted(res)]

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

S = [input() for i in range(N)]
kinds = set(S)
result = {}

for i in kinds:
    result[i] = S.count(i)
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:
N=input()
list=[]
a=[]
b=[]
c=[]
s=[]
t=0
for i in range(int(N)):
    list.append(input())
    for l in range(len(a)):
        if(a[l]==list[i]):
            b[l]+=1
            t=1
            break
    if t==0:
        a.append(list[i])
        b.append(1)
    else:
        t=0

for i in range(len(a)):
    if b[i]==max(b):
        c.append(a[i])
s=sorted(c)
for i in range(len(s)):
    print(s[i])

Submission status: Time Limit Exceeded

Solution code:
def main():
	n = int(input())
	l = [str(input()) for i in range(n)]
	
	import collections

	c = collections.Counter(l)

	keys = [k for k, v in c.items() if v == max(c.values())]
	keys.sort()
	print('\n'.join(map(str, keys)))

	
	
 
if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import collections

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

c = collections.Counter(a)

i = 0
list = []
if(len(c.most_common()) == 1):
	list.append(c.most_common()[0][0])
elif(len(c.most_common()) == N):
  list = a
else:
  ##for i in range(0,len(c.most_common())-1):
    while(c.most_common()[i][1] == c.most_common()[0][1]):
        list.append(c.most_common()[i][0])
        i += 1



list.sort()

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
CNT = []
for i in range(N):
    dummy = input()
    S.append(dummy)
    CNT.append(S.count(S[i]))
MAX = max(CNT)
new_S = []
for i in range(N):
    if (CNT[i] == MAX and S[i] not in new_S):
        new_S.append(S[i])
new_S = sorted(new_S)
for x in new_S:
    print(x)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
s = []
for i in range(n):
    s.append(input())
    
dic = collections.Counter(s)
    
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:
amount = int(input())
l = []
max = 1

for i in range(amount):
    a = input()
    l.append(a)

output = []

while len(l) != 0:
    check = l[0]
    many = l.count(check)
    if many == max:
        if check not in output:
            output.append(check)
    elif many > max:
        output = []
        max = many
        output.append(check)
    while check in l:
        l.remove(check)
output.sort()
for k in range(len(output)):
    print(output[k])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(range(n))
for x in range(n):
  v[x] = input()

import collections
c = collections.Counter(v)
values, counts = zip(*c.most_common())
num = 0

for y in list(counts):
  if y == max(counts):
    num += 1
answers = list(values[:num])
answers.sort()
for z in range(num):
  print(answers[z])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

li_str = []
for i in range(n):
    s = str(raw_input())
    li_str.append(s)    

unique_str = list(set(li_str))
# print unique_str
unique_str.sort()

# print unique_str
max_num = 0

for s in unique_str:
    n = li_str.count(s)
    if n > max_num:
        max_num = n

for s in unique_str:
    n = li_str.count(s)
    if n == max_num:
        print s

Submission status: Time Limit Exceeded

Solution code:
import collections
import sys
input = sys.stdin.readline
num = int(input())
word_list = []
for i in range(num):
    word_list.append(input())
word_dict = collections.Counter(word_list)
word_list = [k for k,v in word_dict.items() if v == word_dict.most_common()[0][1]]
word_list.sort()
for word in word_list:
    print(word)

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))

for i in setlist:
  if slist.count(i) == max(countlist):
    resultlist.append(i)
resultlist = sorted(resultlist)
for i in resultlist:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i in range(n)]
dic = {}
set_s = sorted(set(s))
[dic.update({i:s.count(i)}) for i in set_s]
max_num = max(dic.values())
for i in set_s:
    if dic[i] == max_num:
        print(i)

Submission status: Time Limit Exceeded

Solution code:
def poll(arr):
    ans_h = {}
    for ele in arr:
        if ele in ans_h.keys():
            ans_h[ele] += 1
        else:
            ans_h[ele] = 0
    max_kv_list = sorted([kv for kv in ans_h.items() if kv[1] == max(ans_h.values())])
    for ele in max_kv_list:
        print(ele[0])

if __name__ == "__main__":
    n = int(input())
    arr = [input() for _ in range(0, n)]
    poll(arr)

Submission status: Time Limit Exceeded

Solution code:
import collections, sys

n = int(input())
s = []
for _ in range(0,n):
  s.append(input())

if len(set(s)) == 1:
  print(s[0])
  sys.exit()  

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

l = []
l.append(c.most_common()[0][0])
for i in range(0,len(s)):
  if c.most_common()[i][1] == max:
    l.append(c.most_common()[i][0])
  else:
    break
ll = sorted(set(l))
for ls in ll:
  print(ls)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
import collections

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

s_dict=collections.Counter(s_list)
    
ans = [kv[0] for kv in s_dict.items() if kv[1] == max(s_dict.values())]
for a in sorted(ans):
  print(a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
dict1 = {}
dict2 = {}
for i in range(N):
  a = str(input())
  if(a in dict1):
    dict1[a] += 1
    dict2[a] = dict1[a]
  else:
    dict1[a] = 1
if(len(dict2) != 0):
	max_k_list = sorted([kv[0] for kv in dict2.items() if kv[1] == max(dict2.values())])
else:
  	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:
from collections import Counter

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
word_num = int(input())
word_list = []
word_num_list = []
for _ in range(word_num):
  word = input()
  if word not in word_num_list:
    word_num_list.append(word)
  word_list.append(word)
word_num_list = sorted(word_num_list)
num_list = [0] * len(word_num_list)
for ind, i in enumerate(word_num_list):
  num_list[ind] = word_list.count(i)
max_num = max(num_list)
for i in range(len(word_num_list)):
  if num_list[i] == max_num:
    print(word_num_list[i])

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
  s=input()
  d[s]+=1
x=max(d.values())
max_k_list=[]
while len(d)>0 and max(d.values())==x:
  max_k_list.append(max(d, key=d.get))
  del d[max_k_list[-1]]
max_k_list.sort()
for a in max_k_list:
  print(a)

Submission status: Time Limit Exceeded

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

S_lst = list(set(s_lst))
if len(S_lst) == len(s_lst):
    s_lst.sort()
    [print(i) for i in s_lst]
    sys.exit()
tmp,ans = 0,[]
for i in S_lst:
    if s_lst.count(i) > tmp:
        ans.clear()
        ans.append(i)
        tmp = s_lst.count(i)
    elif s_lst.count(i) == tmp:
        ans.append(i)

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

Submission status: Time Limit Exceeded

Solution code:

#a = int(input())
#b, c = map(int, input().split())
#l = list(map(int, input().split()))


n = int(input())
s=['']*n
st=[]
for i in range(0,n):
  s[i]=input()
  if not s[i] in st:
    st.append(s[i])

maxc=0
anss=[]
for i in range(0,len(st)):
  cc=s.count(st[i])
  if cc>maxc:
    maxc=cc
    anss=[st[i]]
  elif cc==maxc:
    anss.append(st[i])

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
all_str = []
count = 0

for i in range(N):
  in_str = input()
  all_str.append(in_str)
  if count < all_str.count(in_str):
    count = all_str.count(in_str)

max_all_str = []
for hikaku in sorted(set(all_str)):
  if (all_str.count(hikaku) == count) & (max_all_str.count(hikaku) == 0):
    print(hikaku)

Submission status: Time Limit Exceeded

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


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


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


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(sorted(rank.items(), key=lambda x: x[1])
    for i in sorted([k for k, v in rank.items() if v == max(rank.values())]):
        print(i)


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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input() for i in range(N))
set = set(S)
max = 0

for i in set:
    if S.count(i) > max:
        max = S.count(i)
        list = [i]
    elif S.count(i) == max:
        list.append(i)

list.sort()

for i in list:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

input_line=int(input())
count=0
input_list=[]
set_list=set()
while count < input_line:
  input1=input()
  input_list.append(input1)
  set_list.add(input1)
  count+=1
ans_list=[]
#list_set=set(input_list)
max_appeard=Counter(input_list).most_common(1)[0][1]
for item in set_list:
    if Counter(input_list)[item] == max_appeard:
        ans_list.append(item)
ans_list.sort()
for item in ans_list:
  print (item)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    ss = {}
    m = 0
    for i in range(N):
        s = input()
        if s not in ss.keys():
            ss[s] = 0
        else:
            ss[s] += 1
        if m < ss[s]:
            m = ss[s]
#    print(m, ss)
    ans = []
    for key in ss:
        val = ss[key]
        if val < m:
            continue
        if key not in ans:
            ans.append(key)
    count = 0
    ans.sort()
    for a in ans:
        count+=1
        if count == len(ans):
            print(a)
        else:
            print(a, ' ')
main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
s = []
for _ in range(n):
    s.append(input())
#print(s)
#s = list(itertools.chain.from_iterable(s))
#print(s)
s_u = list(set(s))
box = []
for i in range(len(s_u)):
    box.append([s_u[i],s.count(s_u[i])])
count=1
box = sorted(box,key=lambda x:x[1],reverse=True)
#print(box)
for i in range(len(s_u)-1):
    if len(box)==1:
      break
    elif box[i][1] == box[i+1][1]:
        count+=1
    elif box[i][1] > box[i+1][1]:
        break
box_p = [box[i] for i in range(count)]
#print(box_p)
ans_box = sorted(box_p)
for i in range(count):
    print(ans_box[i][0])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(input())
ss = set(s)
sd = {}
for i in ss:
    sd[i] = s.count(i)
m = max(sd.values())
r = [k for k, v in sd.items() if v == m]
r.sort()
for i in r:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

result = {}

for i in range(N):
    s = input()
    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:
N = int(input())

strList = list([])

for i in range(N):
  strList.append(str(input()))

strDict = {}

for item in strList:
  if item not in strDict.keys():
    strDict[item] = 1
  else:
    strDict[item] += 1

maxList = list([])

for strKeys in strDict.keys():
  if strDict[strKeys] == max(strDict.values()):
    maxList.append(strKeys)

for srtedItem in sorted(maxList):
  print(srtedItem)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [input() for val in range(N)]
S_setlist = list(set(S))
S_setlist.sort()
S_cnt = []
cnt = 0
for n in S_setlist:
    S_cnt.append(S.count(n))
for m in S_cnt:
    if m == max(S_cnt):
        print(S_setlist[cnt])
        cnt += 1
    else:
        cnt += 1

Submission status: Time Limit Exceeded

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

wordl = []
timesl = []

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

maxval =max(timesl) 
maxind = [j for j,val in enumerate(timesl) if val == maxval]

resultl=[]
for i in maxind:
    resultl.append(wordl[i])

resultl.sort()

for i in resultl:
    print(i)

Submission status: Time Limit Exceeded

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

result=[S.count(S[i]) for i in range(N)]
m=max(result)

for i in range(N):
    if m==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:
from operator import itemgetter

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

for i in range(n):
    s = input()
    flg = 0
    for j in range(len(sn)):
        if(sn[j][0] == s):
            sn[j][1] += 1
            flg += 1
    if(flg == 0):
        sn.append([s,1])
        
sn.sort(key=itemgetter(1))
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:
n = int(input())
dic = {}

for i in range(n):
    s = input()
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
keys = sorted([x[0] for x in dic.items() if x[1] == max(dic.values())])
print('\n'.join(keys))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=["as"]*n
for i in range(0,n):
  s[i]=input()
st=[s[0]]
count=[1]
#st.append(st[0])
#count.append(1)
for i in range(1,n):
  k=0
  for j in range(0,len(st)):
    if s[i]==st[j]:
      count[j]+=1
      break
    else:
      k+=1
  if k==len(st):
    st.append(s[i])
    count.append(1)
maxcount=0
maxs=[]
#maxn=[]
for i in range(0,len(st)):
  if count[i]>maxcount:
    #maxn=[i]
    maxs=[st[i]]
    maxcount=count[i]
    #maxn.append(i)
    #maxs.append(st[i])
  elif count[i]==maxcount:
    #maxn.append(i)
    maxs.append(st[i])
maxed=sorted(maxs)
for i in range(0,len(maxed)):
  print("%s"% maxed[i])

Submission status: Time Limit Exceeded

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

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

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

anser_list.sort()
for key in anser_list:
    print(key)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
dic={}
for i in range(n):
  a=input()
  if a not in dic.keys():dic[a]=1
  else:dic[a]+=1
dic_max=[k for k, v in dic.items() if v==max(dic.values())]
dic_s=sorted(dic_max)
[print(i) for i in dic_s]

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort_left
from sys import stdin

def main():
    input = stdin.readline
    n = int(input())
    
    d = {}
    ds = d.setdefault
    m = 1
    for i in range(n):
        s = input().rstrip()
        ds(s, 0)
        d[s] += 1
        if m < d[s]:
            m = d[s]
    
    l = []
    for i, j in d.items():
        if j == m:
            insort_left(l, i)
            
    print("\n".join(l))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import collections

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

c = collections.Counter(a)

list = []
if(len(c.most_common()) == 1):
	list.append(c.most_common()[0][0])
elif(len(c.most_common()) == N):
  list = a
else:
  for i in range(0,len(c.most_common())-1):
    if(c.most_common()[i][1] == c.most_common()[0][1]):
        list.append(c.most_common()[i][0])



list.sort()

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

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
a = []
max_list = []
max_i = 1

for i in range(n):
    a.append(str(input()))

c = collections.Counter(a)
max_i = c.most_common()[0][1]

max_list = [x for x in set(a) if a.count(x) == max_i]

max_list.sort()

for i in max_list:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
tmp = []
for _ in range(N):
    tmp.append(input())
tmp.sort()
# print(tmp)

n = []
for t in tmp:
    n.append(tmp.count(t))

# print(n)
m = max(n)
b = ""
for i in n:
    # print(i)
    if i == m:
        if b != tmp[n.index(i)]:
            print(tmp[n.index(i)])
            b = tmp[n.index(i)]
        n[n.index(i)] = -1

Submission status: Time Limit Exceeded

Solution code:
amount = int(input())
l = []
max = 1

for i in range(amount):
    a = input()
    l.append(a)

output = []

while True:
    if len(l) == 0:
        break
    else:
        check = l[0]
        many = l.count(check)
        if many == max:
            if check not in output:
                output.append(check)
        elif many > max:
            output = []
            max = many
            output.append(check)
        while check in l:
            l.remove(check)
output.sort()
for k in range(len(output)):
    print(output[k])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
for i in range(N):
  S.append(str(input()))
C = []
for i in range(N):
  C.append(S.count(S[i]))
S_new = sorted(set(S))
for s in S_new:
  if S.count(s) == max(C):
    print(s)

Submission status: Time Limit Exceeded

Solution code:
q = int(input())
a = [input() for _ in range(q)]
dic = {}

for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
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:
def main():
    N = int(input())
    ss = {}
    m = 0
    for i in range(N):
        s = input()
        if s not in ss.keys():
            ss[s] = 0
        else:
            ss[s] += 1
        if m < ss[s]:
            m = ss[s]
#    print(m, ss)
    ans = []
    for key in ss:
        val = ss[key]
        if val < m:
            continue
        if key not in ans:
            ans.append(key)
    count = 0
    for a in sorted(ans):
        count+=1
        if count == len(ans):
            print(a)
        else:
            print(a, ' ')
main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
list = []
for i in range(0,N):
    list.append(input())
counted = Counter(list)
res = [letter for letter,count in counted.most_common() if count == counted.most_common()[0][1]]
[print(i) for i in sorted(res)]

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)
    res = [[strlist.count(i),i] for i in setstrlist]
    res = sorted(res,reverse=True)
    maxtmp = res[0][0]
    res2=[]
    x = res2.append
    res2 = [i[1] for i in res if i[0] == maxtmp]
    res2.sort()
    print('\n'.join(res2))
if __name__ == '__main__':
    input = sys.stdin.readline
    main()

Submission status: Time Limit Exceeded

Solution code:
import collections
n=int(input())
s=sorted([input() for k in range(n)])
if(len(set(s))==len(s)):
    for u in range(len(s)):
        print(s[u])
    exit()
else:
    s1=[q for q in sorted(list(set(s))) if s.count(q) > 1]
c=collections.Counter(s)
p=[]
for i in s1:
    p.append(c[i])
max=max(p)
for j, x in enumerate(p):
    if(x == max):                                                                                             print(s1[j])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
tmp = []
for i in range(n):
    tmp.append(input())
tmp = sorted(tmp)
l = []
num = []
j = 0
for s in tmp:
    j += 1
    if not s in l:
        l.append(s)
for s in l:
    num.append(tmp.count(s))
ans = max(num)
for i in range(len(num)):
    if num[i] == ans:
        print(l[i])

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import heapq

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

word_count=Counter(word)

ans=[k for k, v in word_count.items() if v == max(word_count.values())]
cnt=len(ans)
heapq.heapify(ans)
for i in range(cnt):
    print(heapq.heappop(ans))

Submission status: Time Limit Exceeded

Solution code:
import collections

num = int(input())
word_list = []
for i in range(num):
    word_list.append(input())
word_dict = collections.Counter(word_list)
word_list = [k for k,v in word_dict.items() if v == word_dict.most_common()[0][1]]
word_list.sort()
for word in word_list:
    print(word)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
words = [[]]*N
for i in range(N):
  words[i] = str(input())
wlist = []
maximum = 0
for j in set(words):
  if words.count(j) > maximum:
    maximum = words.count(j)
    wlist = [j,]
  elif words.count(j) == maximum:
    wlist.append(j)
wlist.sort()
for l in range(len(wlist)):
  print(wlist[l])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = []
for i in range(n):
  li.append(input())
dic = {}
li_a = []
for x in li:
  if x not in li_a:
    dic[x] = 1
    li_a.append(x)
  else:
    dic[x] += 1
li_s = sorted(li_a)
li_ans = []
for x in li_s:
  li_ans.append(dic[x])
for i in range(len(li_ans)):
  if li_ans[i] == max(li_ans):
    print(li_s[i])

Submission status: Time Limit Exceeded

Solution code:
num = int(input())

words = []
for _ in range(num):
    words.append(input())

d = {}
for word in words:
    if word in d:
        d[word] += 1
    else:
        d[word] =1

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

for key in max_k_list:
    print(key)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls=[input() for i in range(n)]
k_ls= [ls[0]]
nk= [1]

for i in range(1,n):
    count = 0
    for k in range(len(k_ls)):
        if ls[i] == k_ls[k]:

            nk[k] += 1
            count += 1
    if count == 0:
        k_ls.append(ls[i])
        nk.append(1)
ind = [i for i, v in enumerate(nk) if v == max(nk)]
ans = []
for i in ind:
    ans.append(k_ls[i])

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
arr=[]
for i in range(N):
    arr.append(input())
s=sorted(set(arr))
max_s = max(arr.count(ele)for ele in s)
for ele in s:
    if arr.count(ele)==max_s:
        print(ele)

Submission status: Time Limit Exceeded

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

S_lst = list(set(s_lst))
tmp,ans = 0,[]
for i in S_lst:
    if s_lst.count(i) > tmp:
        ans.clear()
        ans.append(i)
        tmp = s_lst.count(i)
    elif s_lst.count(i) == tmp:
        ans.append(i)

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

Submission status: Time Limit Exceeded

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

li.sort()
B=[int(li.count(li[i])) for i in range(N)]

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()

L=len(C)

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

Submission status: Time Limit Exceeded

Solution code:
import collections
def main(N,S):
    S.sort()
    setS = set(S)
    counterS = collections.Counter(S)
    maxcount = 0
    for i in setS:
        maxcount = max(maxcount, S.count(i))
    keys = [k for k, v in counterS.items() if v == maxcount]
    keys.sort()
    for j in keys:
        print(j)

N = int(input())
S = [input() for _ in range(N)]
main(N,S)

Submission status: Time Limit Exceeded

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(input())
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
maxi=max(b)
for i in range(l):
    if(b[i]==maxi):
        d.append(c[i])
        tt=tt+1
d.sort()
for i in range(tt):
    print(d[i])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = {}
for _ in range(N):
    x = input()
    if x in D:
        D[x] = D[x] + 1
    else:
        D[x]=1
MaxDarray = [k for k, v in D.items() if v == max(D.values())]
print("\n".join(sorted(MaxDarray)))

Submission status: Time Limit Exceeded

Solution code:
n, *str_n = open(0).read().split()
n = int(n)
dic = list(set(str_n))
dic.sort()
str_n.sort()

cnt = [0] *len(dic)
j = 0
for i in range(n-1):
    if str_n[i] == str_n[i+1]:
        cnt[j] += 1
    else:
        j += 1
        
max_vote = [i for i, v in enumerate(cnt) if v == max(cnt)]
        
for i in max_vote:
    print(dic[i])