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: Accepted

Solution code:
from itertools import groupby
def main():
    n=int(input())
    ss=[]
    for _ in range(n):
        ss.append(input())
    ss=sorted(ss)
    c=0
    for k,g in groupby(ss):
        lg=len(list(g))
        if lg>c:
            c=lg
            zz=[k]
        elif lg==c:
            zz.append(k)
    for k in sorted(zz):
        print(k)
main()

Submission status: Accepted

Solution code:
#from math import sqrt
#from heapq import heappush, heappop
#from collections import deque

n = int(input())

max_v = 0

s = {}
list = [[] for _ in range(n+1)]
for _ in range(n):
    str = input()
    if str in s:
        v = s[str] + 1
    else:
        v = 1
    s[str] = v
    max_v = max(max_v, v)
    list[v].append(str)

list[max_v].sort()

for str in list[max_v]:
    print(str)

Submission status: Accepted

Solution code:
import sys
from collections import deque

n=int(input())
s=['']*n
for i in range(n):
    s[i]=sys.stdin.readline().strip()

ss=sorted(s)

cnt=0
i=0
while i<n:
    curcnt=1
    j=i+1
    while j<n:
        if ss[i]!=ss[j]:
            break
        j+=1
        curcnt+=1
    i=i+curcnt
    cnt=max(cnt,curcnt)

i=0
while i<n:
    curcnt=1
    j=i+1
    while j<n:
        if ss[i]!=ss[j]:
            break
        j+=1
        curcnt+=1
    if curcnt==cnt:
        print(ss[i])
    i=i+curcnt

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
def main():
    N=int(input())
    S=[""]*N
    result={}
    for i in range(N):
        S[i]=input().strip()
        if S[i] not in result:
            result[S[i]]=1
        else:
            result[S[i]]+=1

    result=sorted(result.items())
    result=sorted(result,key=lambda x:-x[1])

    max_num=result[0][1]
    for i in range(len(result)):
        if result[i][1]==max_num:
            print(result[i][0])
        else:
            break
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import collections

if __name__ == '__main__':
    N = int(input())
    kv = collections.defaultdict(int)
    max_cnt = 0
    res = []
    for _ in range(N):
        word = input()
        kv[word] += 1
        if kv[word] == max_cnt:
            res.append(word)
        elif kv[word] > max_cnt:
            res = [word]
            max_cnt = kv[word]
    for s in sorted(res):
        print(s)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import groupby
from operator import itemgetter

c = Counter(input() for _ in range(int(input())))
a = sorted((-c[x],x) for x in c)
for _, s in next(groupby(a, itemgetter(0)))[1]:
  print(s)

Submission status: Accepted

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

sorted_map = sorted(mymap.items(), key=lambda kv: kv[1], reverse = True )

maxi = sorted_map[0][1]
# print(maxi)

answer = []

for x in sorted_map:
	if x[1] == maxi:
		answer.append(x[0])
	else:
		break

answer.sort()

for x in answer:
	print(x)

Submission status: Accepted

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

    c = {}
    for i in range(N):
        s = S[i]
        c[s] = c[s] + 1 if (s in c)  else 1

    m = max(list(c.values()))
    ss = sorted(list(c.keys()))
    for s in ss:
        if c[s] == m:
            print(s)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
mydic = {}
mynumdic = {} 
mymax = 0

for n in range(N):
    s = input()
    if s in mydic:
        mydic[s] += 1
    else:
        mydic[s] = 1
    
    if mymax <= mydic[s]:
        mymax = mydic[s]
        
        if mydic[s] in mynumdic:
            mynumdic[mydic[s]] += [s]
        else:
            mynumdic[mydic[s]] = [s]

mylist = mynumdic[mymax]
mylist.sort()
for d in mylist:
    print(d)

Submission status: Accepted

Solution code:
N=int(input())
S=[input() for i in range(N)]
if len(set(S))==1:
  print(S[0])
else:  
  T=sorted(S)
  A=[]
  cnt=1
  for i in range(N-1):
    if T[i+1]!=T[i]:
      A.append((cnt,T[i]))
      cnt=1
    else:
      cnt+=1
  A.append((cnt,T[-1]))
  X=sorted(A)[::-1]
  x=X[0][0]
  C=[]
  for i in range(N):
    if X[i][0]==x:
      C.append(X[i][1])
    else:
      break
  for i in sorted(C):
    print(i)

Submission status: Accepted

Solution code:
import collections
n = input()
# n, k = map(int, input().split())
# p = list(map(int, input().split()))
# s = input().split()
S = [input() for i in range(int(n))]
max = 0
stri = []
c = collections.Counter(S)

for i in c.most_common():
    li = list(i)
    if int(li[1]) >= int(max):
        max = li[1]
        stri.append(li[0])
li2 = sorted(stri)

for i in li2:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())
d = {}

for i in range(N):
    s = input()
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
y = sorted(d.items(), key=lambda x: x[0])
z = sorted(y, key=lambda b: b[1], reverse=True)
m = 0
for s in z:
    if s[1] >= m:
        print(s[0])
        m = s[1]
    else:
        break

Submission status: Accepted

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

a=sorted(a)
b=[]
c=[]

tmp="."
count=0

for i in range(n):
  if tmp != a[i]:
    b.append(tmp)
    c.append(count)
    tmp=a[i]
    count=1
  else:
    count += 1
 
b.append(tmp)
c.append(count)
k=sorted(c)[-1]
for i in range(len(b)):
  if c[i]==k:
    print(b[i])

Submission status: Accepted

Solution code:
import collections
n=int(input())
s=[]
for i in range(n):
  S=input()
  s.append(S)
d=collections.Counter(s)
e=list(d.items())
e.sort(key=lambda x:-x[1])
lst=[]
for i in range(len(e)):
  if e[i][1]==e[0][1]:
    lst.append(e[i][0])
  else:
    break
lst.sort()
for j in range(len(lst)):
  print(lst[j])

Submission status: Accepted

Solution code:
N = int(input())

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

d = {}
for n in P:
    if n not in d.keys():
        d[n] = 0
    d[n] += 1


# valueでソート。降順=True
sorted_list = sorted(d.items(), key=lambda x:x[1], reverse=True)

max_num = sorted_list[0][1]

new_list = [sorted_list[0][0]]
for e in sorted_list[1:]:
    if max_num != e[1]:
        break
    new_list.append(e[0])


for r in sorted(new_list):
    print(r)

Submission status: Accepted

Solution code:
s = list(map(int, input().split()))
n=s[0]
dic={}
for i in range(n):
    s=input().split()
    s=s[0]
    if s in dic.keys():
        dic[s]+=1
    else:
        dic[s]=1
m=max(dic.values())
ans=[]
for i in dic:
    if dic[i]==m:
        ans.append(i)
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:

n = int(input())

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

x = set(s)

dic = {}
for i in x:
    dic[i] = 0


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

max_dic = max(dic.values())

ans = []
for i in x:
    if dic[i] == max_dic:
        ans.append(i)


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

Submission status: Accepted

Solution code:
n = int(input())
s = []
for _ in range(n):
    s.append(input())
s = sorted(s)
s.append('')
tmp_max = []
tmp = ''
cnt_max = 0
cnt = 0
for ss in s:
    if tmp == ss:
        cnt += 1
    else:
        if cnt > cnt_max:
            cnt_max = cnt
            tmp_max = []
        if cnt == cnt_max:
            tmp_max.append(tmp)
        tmp = ss
        cnt = 1
tmp_max = sorted(tmp_max)
for t in tmp_max:
    print(t)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d=defaultdict(int)

for ls in l:
    d[ls]+=1

fg=0
th=list(d.values())

gh=list(d.keys())

for i in range(len(th)):
    fg=max(fg,th[i])

ans=[]
for i in range(len(gh)):
    if th[i]==fg:
        ans.append(gh[i])

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

Submission status: Accepted

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

from collections import defaultdict
 
counter = defaultdict(int)
 
for x in S:
    counter[x] += 1

X = max(counter.values())
s = set(S)
ans=[]
for i in s:
    if counter[i] == X:
        ans.append(i)

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

Submission status: Accepted

Solution code:
import collections

usrCount = int(input())
usrStrList = []

mostStrList = []

for n in range(usrCount):
    usrStrList.append(input())

countObj = collections.Counter(usrStrList)
mostedList = countObj.most_common()

for n in range(len(mostedList)):
    if mostedList[0][1] == mostedList[n][1]:
        mostStrList.append(mostedList[n][0])

sortedList = sorted(mostStrList, reverse = False)

for m in range(len(sortedList)):
    print(sortedList[m])

Submission status: Accepted

Solution code:
input()
d = dict()
while True:
    try:
        s = input()
    except EOFError:
        break
    try:
        d[s] = d[s] + 1
    except KeyError:
        d[s] = 1
m = max(d.values())
d = sorted(d.items(), key=lambda x: x[1], reverse=True)
for i, item in enumerate(d):
    if item[1] < m:
        d = d[:i]
        break
d = sorted(d, key=lambda x: x[0])
for item in d:
    print(item[0])

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
import collections
from operator import itemgetter

def resolve():
    N = int(input())
    S = [input() for _ in range(N)]

    counter = collections.Counter(S)

    max_freq = max(counter.values())
    most_freq = [k for k, v in counter.items() if v==max_freq]
    for i in sorted(most_freq):
        print(i)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

S.sort()
#print(S)

max_count=0
cur_count=1
cur_str=[]
for i in range(N):
  if i==0:
    max_count=1
    cur_count=1
    cur_str=[S[0]]
  else:
    #S[i-1]
    if S[i]==S[i-1]:
      cur_count+=1
    else:
      cur_count=1
      
    if max_count<cur_count:
      max_count=cur_count
      cur_str=[S[i]]
    elif max_count==cur_count:
      cur_str+=[S[i]]
  #print(cur_str)
  #print(cur_count)
  #print(max_count)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter


def solve(N: int, S: "List[str]"):
    cnt = Counter()
    for s in S:
        cnt[s] += 1
    
    lst = []
    mx = max(cnt.values())
    for key, val in cnt.items():
        if val == mx:
            lst += [key]

    for word in sorted(lst):
        print(word)
    
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
vote_ls = {}
#vote_num = [0]*n
for i in range(n):
    aaa = input()
    if aaa in vote_ls.keys():
        vote_ls[aaa]+=1
    else:
        vote_ls[aaa] = 1
#print(vote_ls)
sub_ls = []
'''
max_vote = max(vote_)
for i in range(n):
    if vote_num[i] == max_vote:
        sub_ls.append(vote_ls[i])
sub_ls.sort()
for i in range(len(sub_ls)):
    print(sub_ls[i])
'''
sorted = sorted(vote_ls.items(), key=lambda x:x[1])
sub_ls.append(sorted[-1])
for i in range(len(sorted)-2,-1,-1):
    if sorted[i][1] == sorted[-1][1]:
        sub_ls.append(sorted[i])
    else:
        break
#print(sub_ls)
sub_ls.sort()
for i in range(len(sub_ls)):
    print(sub_ls[i][0])

Submission status: Accepted

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

S = collections.Counter(A)
T=[]
R=[]
ans=0
T=S.most_common()
T.sort(reverse=True,key=lambda x: x[1])
a=T[0][1]
for i in range(len(T)):
  if T[i][1]==a:
    R.append(T[i][0])
R.sort()
for i in R:
  print(i)

Submission status: Accepted

Solution code:
import collections

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

counter = collections.Counter(S)
maxcount = max(counter.values())

strs_max = []
for k, v in counter.items():
    if v == maxcount:
        strs_max.append(k)

ans_list = sorted(strs_max)
for a in ans_list:
    print(a)

Submission status: Accepted

Solution code:
n = int(input())
s = [str(input()) for i in range(n)]
sorted_s = sorted(s)
count = 1
max = 1
ans_list = []
prev = sorted_s[0]
for i in sorted_s[1:]:
    if i == prev:
        count += 1
    else:
        if count > max:
            ans_list = [prev]
            max = count
        elif count == max:
            ans_list.append(prev)
        prev = i
        count = 1
if count > max:
    ans_list = [prev]
elif count == max:
    ans_list.append(prev)
for i in ans_list:
    print(i)

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for _ in range(n)]
t={}
u=[]
for i in range(n):
    if s[i] not in t.keys():
        t[s[i]]=1
    else:
        t[s[i]]+=1

max=0
for i in t:
    if max<=t[i]:
        max=t[i]
for i in t:
    if max==t[i]:
        u.append(i)
u.sort()
for i in range(len(u)):
    print(u[i])

Submission status: Accepted

Solution code:
n = int(input())
sen = {}
maxsen = 0
for i in range(n):
    s = input()
    if s not in sen:
        sen[s] = 1
        maxsen = max(maxsen,sen[s])
    else:
        sen[s]+=1
        maxsen = max(maxsen,sen[s])
p = []
for key in sen:
    val = sen[key]
    if val ==  maxsen:
        p.append(key)
p = sorted(p)
for x in p:
    print(x)

Submission status: Accepted

Solution code:
import collections

N=int(input())
S=[input() for _ in range(N)]
max=0
l=[]
c=collections.Counter(S)
values=list(c.values())
key=list(c.keys())

for i in range(len(key)):
    l.append([key[i],values[i]])

x=sorted(l,key=lambda x:x[0])
x.sort(key=lambda x:x[1],reverse=True)
max=x[0][1]
i=0
#print(x)
while True:
    if (x[i][1]==max):
        print(x[i][0])
        i=i+1
        if i+1>len(x):
            break
    else:
        break

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for _ in range(n):
    s = input()
    if not s in d:
        d[s] = 1
    else:
        d[s] += 1
d_max = max(d.values())
ans = [k for k, v in d.items() if v == d_max]
for a in sorted(ans):
    print (a)

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for i in range(n):
    key = input()
    if key in d:
        d[key] += 1
    else:
        d[key] = 1
l = list(d.items())
l = sorted(l, key=lambda x: x[1], reverse=True)

tmp = l[0][1]
tmp2 = l[0][1]
i = 0
ans = []
while tmp == tmp2 and i < len(l):
    ans.append(l[i][0])
    i += 1
    if i < len(l):
        tmp2 = l[i][1]
    else:
        break

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

Submission status: Accepted

Solution code:
N = int(input())
dct = {}
for i in range(N):
    S = input()
    if dct.get(S) == None:
        dct[S] = 1
    else:
        dct[S] += 1
sortedDct = sorted(dct.items(), key=lambda x: -x[1])
L = []
maxNum = 0
for k, v in sortedDct:
    if (maxNum <= v):
        L.append(k)
        maxNum = v
L.sort()
for l in L:
    print(l)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(ss)

max_count = max(c.values())

out_k = []
for k, v in c.items():
  if v == max_count:
    out_k.append(k)
out_k.sort()
for k in out_k:
  print(k)

Submission status: Accepted

Solution code:
import collections
n = int(input())
vs = collections.Counter()
for i in range(n):
  vs[input()] += 1
j = 0
ans = []
for m in vs.most_common():
  if m[1] >= j:
    j = m[1]
    ans.append(m[0])
for a in sorted(ans):
  print(a)

Submission status: Accepted

Solution code:
from collections import defaultdict

d = defaultdict(lambda : 0)

n = int(input())
for _ in range(n):
    item = input()
    d[item] += 1

items = sorted(d.items(), key=lambda x: (x[1], x[0]), reverse=True)
c = items[0][1]
l = []
for k, v in items:
    if v < c:
        break
    l.append(k)
if len(l) == 1:
    print(l[0])
else:
    print('\n'.join(l[::-1]))

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import pdb
import sys
F = sys.stdin

N = int(F.readline().rstrip())
string_count_dict = {}
max = 1
ans = []

for i in range(N):
    s = F.readline().rstrip()
    if s in string_count_dict:
        string_count_dict[s]  += 1
        if max < string_count_dict[s]:
            max = string_count_dict[s]
        continue
    string_count_dict[s] = 1

for st in string_count_dict:
    if string_count_dict[st] == max:
        ans.append(st)

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

Submission status: Accepted

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

c = collections.Counter(S)
mc = c.most_common()
max_count = mc[0][1]

lst = []

for x, y in mc:
    if y == max_count:
       lst.append(x)
    
for z in sorted(lst):
    print(z)

Submission status: Accepted

Solution code:
# 2020/02/16
# AtCoder Beginner Contest 155 - C

from operator import itemgetter

# ans = chr(ord(a) + 1)

# Input
n = int(input())
s = list()
for i in range(n):
    s.append(input())

s.sort()

# Init
wks = s[0]
cnt = 1
strmap = list()
for i in range(1, n):
    # Different word
    if wks != s[i]:
        wklist = list()
        wklist.append(wks)
        wklist.append(cnt)
        strmap.append(wklist)

        # Init next String
        wks = s[i]
        cnt = 1
    else:
        cnt = cnt + 1

wklist = list()
wklist.append(wks)
wklist.append(cnt)
strmap.append(wklist)

strmap.sort(key=itemgetter(1), reverse=True)

# Output
for i in range(len(strmap)):
    if strmap[i][1] == strmap[0][1]:
        print(strmap[i][0])
    else:
        break

Submission status: Accepted

Solution code:
n = int(input())
dict={}
while n > 0:
    s = input()
    if s in dict.keys():
        dict[s] = dict[s] + 1
    else:
        dict[s]=1
    n = n - 1
maxnum = 0
for v in dict.values():
    if v > maxnum:
        maxnum = v
a=[]
for k,v in dict.items():
    if v == maxnum:
        a.append(k)
a.sort()
for s in a:
    print(s)

Submission status: Accepted

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

c = collections.Counter(l)
result = c.most_common()

m = 0
ans = []
for i in result:
    if i[1]<m:
        break
    else:
        ans.append(i[0])
        m = i[1]

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

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = [input() for _ in range(n)]
c = collections.Counter(a)
num = max(c.values())
keys = [k for k, v in c.items() if v == num]
keys.sort()
for i in range(len(keys)):
  print(keys[i])

Submission status: Accepted

Solution code:
n = int(input())

s = {}

for i in range(n):
    si = input()
    if si in s.keys():
        s[si] += 1
    else:
        s[si] = 1

sorted_s = sorted(s.items(), key=lambda x:x[1], reverse=True)
max_v = sorted_s[0][1]
ans = []
for i in range(len(sorted_s)):
    if max_v == sorted_s[i][1]:
        ans.append(sorted_s[i][0])
    else:
        break
ans.sort()
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
N = int(input())

d={}
maxN=0
for i in range(N):
  k = input()
  if k in d:
    d[k] += 1
  else:
    d[k]=1
  maxN = max(d[k], maxN)

s = []
for k,v in d.items():
  if maxN==v:
    s.append(k)
s=sorted(s)
for _ in s:
  print(_)

Submission status: Accepted

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

for i in range(N):
  S[i]=input()
S.sort()
A={}
B=set()
for i in range(N):
  if S[i] in B:
    A[S[i]]=A[S[i]]+1
  else:
    A[S[i]]=1
    B.add(S[i])
#print(S)
#print(A)
slist = sorted(A.items(), key=lambda x: x[1], reverse=True)
#print(slist)
flag=slist[0][1]
x=[]
for i in range(len(B)):
  if slist[i][1]<flag:
    break
  x.append(slist[i][0])
x.sort()
for i in x:
  print(i)

Submission status: Accepted

Solution code:
import collections

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

moji_count = collections.Counter(moji)
max_kv = max(moji_count.items(), key=lambda x: x[1])

max_moji = []
for i, j in moji_count.items():
    #print(i, j)
    if j==max_kv[1]:
        max_moji.append(i)
#max_moji.append(max_kv[0])
max_sort = sorted(max_moji)
for i in max_sort:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())
S = {}
for i in range(N):
  Si = input()
  if S.setdefault(Si, 0) == 0:
    S[Si] = 1
  else:
    S[Si] += 1
S_sorted = sorted(S.items(), key=lambda x:-x[1])
anslist = []
for s in S_sorted:
  if s[1] < S_sorted[0][1]:
    break
  anslist.append(s)
anslist.sort()
for s in anslist:
  print(s[0])

Submission status: Accepted

Solution code:
n = int(input())
d = dict()

maxi = 0
for _ in range(n):
    s = input()
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
    maxi = max(maxi, d[s])
    
max_k_list = [kv[0] for kv in d.items() if kv[1] == maxi]
#print(max_k_list)
# ['a', 'd']

max_k_list.sort()
for v in max_k_list:
    print(v)

Submission status: Accepted

Solution code:
import collections

n = int(input())

strs = [ input() for _ in range(n) ]

cntr = collections.Counter(strs)

maxvalue = 0
ans = []
for st, num in cntr.most_common():
    if maxvalue <= num:
        ans.append(st)
        maxvalue = num
    else:
        break

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

Submission status: Accepted

Solution code:
from itertools import takewhile
n = int(input())
d = {}
for _ in range(n):
    s = input()
    d[s] = d.get(s, 0) + 1

m = max(d.values())
ss = filter(lambda x: d[x] == m, d)
for s in sorted(ss):
    print(s)

Submission status: Accepted

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

m=max(D.values())
d=list(D.values())
k=list(D.keys())
ans=[]
for i in range(len(D)):
    if m==d[i]:
        ans.append(k[i])

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

Submission status: Accepted

Solution code:

from collections import defaultdict
def resolve():
    N = int(input())
    S = [input() for _ in range(N)]
    
    res = defaultdict(int)

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

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

    max_k_list.sort()
    for k in max_k_list:
        print(k)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
from collections import Counter
def main():
  n = int(input())
  s = [input() for _ in range(n)]
  s_c = Counter(s)
  s_c_l = [c for c in s_c.items()]
  m = max([c[1] for c in s_c_l])
  s_c_l_max = [c[0] for c in s_c_l if c[1] == m]
  s_c_l_max_s = set(s_c_l_max)
  s_c_l_max_s = sorted(s_c_l_max_s)
  for ch in s_c_l_max_s:
    print(ch)
  
main()

Submission status: Accepted

Solution code:
n=int(input())
lst=[input() for _ in range(n)]
#print(lst)
dict={}
for str in lst:
    if str in dict:
        dict[str]+=1
    else:
        dict[str]=1
#print(dict)
max_value=max(dict.values())
ans=[k for k,v in dict.items() if v==max_value]
ans.sort()
[print(ans[i]) for i in range(len(ans))]

Submission status: Accepted

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

S_ = {}
for a in S:
  if a not in S_:
    S_[a] = 1
  else:
    S_[a] += 1

S_ = sorted(S_.items(), key=lambda x:-x[1])

#print(S_)
max_ = 0
a = []
for i in range(len(S_)):
  #print(S_[i][1], )
  if S_[i][1] >= max_:
    max_ = S_[i][1]
    #print(a)
    a.append(S_[i][0])
  else:
    break
a =sorted(a)
print(*a)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
l = []
for i in range(n):
  s = input()
  l.append(s)
#print(l)
c = Counter(l)
max_n = c.most_common()[0][1]
#print(c, max_n)
out = []
for key, val in c.items():
  if val == max_n:
    out.append(key)
for o in sorted(out):
  print(o)

Submission status: Accepted

Solution code:
#N,*S=map(int,open(0).read().split())
N=int(input())
d={}
for i in range(N):
    k=input()
    d[k]= d[k]+1 if k in d else 1
dd=sorted(d.items(),key=lambda x:x[1])  
max_k=max(d,key=d.get)
max_v=d[max_k]
keys=[k for k,v in d.items() if v==max_v]
kk=sorted(keys)
for i in kk:
    print(i)

Submission status: Accepted

Solution code:
import collections
N=int(input())
S=[0 for i in range(N)]
for i in range(N):
  S[i]=str(input())
c = collections.Counter(S)
p=max(c.values())
T=[]
for i in c:
  if c[i]==p:
    T.append(i)
T=sorted(T)
for i in range(len(T)):
  print(T[i])

Submission status: Accepted

Solution code:
import collections
n = int(input())
l=[input() for i in range(n)]
ans = []
cnt=0
c = collections.Counter(l)
for i in c.most_common():
    if i[1] >= cnt:
        ans.append(i[0])
        cnt = i[1]
ans.sort()
for j in ans:
    print(j)

Submission status: Accepted

Solution code:
n=int(input())
a=[]
d={}
b=0
m=0
for i in range(n):
    s=input()
    try:
        a[d[s]][1]+=1
    except:
        d[s]=b
        a.append([s,1])
        b+=1
    m=max(m,a[d[s]][1])
a.sort()
for i in range(len(a)):
    if a[i][1]==m:
        print(a[i][0])

Submission status: Accepted

Solution code:
import collections
S=collections.Counter([input() for _ in range(int(input()))]).most_common()
m=S[0][1]
L=[]
for s in S:
  if s[1]==m:L.append(s[0])
for l in sorted(L):print(l)

Submission status: Accepted

Solution code:
import collections
# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
n=int(input())
l=[]
for i in range(n):
    l.append(str(input()))


# l = list(map(str, input().split()))
c = collections.Counter(l)
m=c.most_common()[0][1]
a=[]
values, counts=zip(*c.most_common())
for value, count in zip(values, counts):
    if count==m:
        a.append(value)
a=sorted(a)
for b in a:
    print(b)
        

# c=[i for i in value if value.count(i) == max(values)]
# c=sorted(c)
# print(c)

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest

def resolve():
    n=int(input().strip())
    ls=[]
    for i in range(n):
        ls.append(input().strip())
    
    d={}

    for s in ls:
        if s in d:
            d[s]+=1
        else:
            d[s]=1

    saidai=0
    for k in d.keys():
        if d[k] > saidai:
            saidai=d[k]

    l=[]

    for k in d.keys():
        if d[k] == saidai:
            l.append(k)

    l.sort(reverse=False)

    for p in l:
        print(p)
        
resolve()

Submission status: Accepted

Solution code:
import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
import time
# import itertools

mod = int(1e9+7)
INF = 1<<29

def main():
    n = int(input())
    s = []
    for i in range(n):
        s.append(input())
    s.sort()
    ans = []
    num = 0
    count = 1
    for i in range(1,n):
        if s[i] == s[i-1]:
            count += 1
        else:
            if count > num:
                ans = [s[i-1]]
            elif count == num:
                ans.append(s[i-1])
            num = max(num,count)
            count = 1
        if i == n - 1:
            if count > num:
                ans = [s[i]]
            elif count == num:
                ans.append(s[i])
    for a in ans:
        print(a)
    return

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from collections import Counter

TEST_INPUT = [
    """
    7
    beat
    vet
    beet
    bed
    vet
    bet
    beet
    """,
    """
    8
    buffalo
    buffalo
    buffalo
    buffalo
    buffalo
    buffalo
    buffalo
    buffalo
    """,
    """
    7
    bass
    bass
    kick
    kick
    bass
    kick
    kick
    """,
    """
    4
    ushi
    tapu
    nichia
    kun
    """
]
ANSWER = [
    "['beet', 'vet']",
    "['buffalo']",
    "['kick']",
    "['kun', 'nichia', 'tapu', 'ushi']"
]


class InputHandler:

    def __init__(self, text_lines="", is_test=False):
        self.data = list(text_lines.split("\n"))
        self.index = 0
        self.is_test = is_test

    def input(self):
        if self.is_test:
            self.index += 1
            return self.data[self.index].strip()
        else:
            return sys.stdin.readline().rstrip()


def solve(n, s_list):
    c = Counter(s_list)
    m = max(c.values())
    res_list = [k for k in c.keys() if c[k] == m]
    return list(sorted(res_list))


def input_and_solve(ih):
    n = int(ih.input())
    s_list = [ih.input() for _ in range(n)]
    res = solve(n, s_list)
    return res


def main():
    ih = InputHandler()
    res = input_and_solve(ih)
    for r in res:
        print(r)


def test():
    for test_input, ans in zip(TEST_INPUT, ANSWER):
        ih = InputHandler(test_input, True)
        res = input_and_solve(ih)
        assert str(res) == str(ans)


if __name__ == "__main__":
    test()
    main()

Submission status: Accepted

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

import collections

c = collections.Counter(S)
b = c.most_common()

ls_ans = []
ls_ans.append( b[0][0] )

a = b[0][1]

for i in range(1,len(b)):
    if b[i][1]==a:
        ls_ans.append(b[i][0])
    else:
        break
ans = sorted(ls_ans)
print("\n".join(ans))
exit()

Submission status: Accepted

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


S.sort()

maxc = -1
sol = []
prev = S[0]
count = 0
S.append("")

for i in range(N+1):
    if prev == S[i]:
        count += 1
    else:
        if maxc < count:
            sol = [prev]
            maxc = count
        elif maxc == count:
            sol.append(prev)

        count = 1
        prev = S[i]
#print sol
for i in range(len(sol)):
    print sol[i]

Submission status: Accepted

Solution code:
import numpy as np
import collections

N=int(input().split()[0])
A=[]
for i in range(N):
  A.append(input().split()[0])

C=collections.Counter(A)
c= C.most_common()
m=c[0][1]
x=[]
for c,n in c:
  if n==m:
    x.append(c)
  else:
    break
x=sorted(x)
for i in x:
  print(i)

Submission status: Accepted

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

a = sorted(d.items(), key=lambda x:x[1], reverse=True)
m = a[0][1]
l = list()
for v in a:
    if v[1] == m:
        l.append(v[0])
    else:
        break

for v in sorted(l):
    print(v)

Submission status: Accepted

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

m = {}
for s in s_list:
  if s in m:
    m[s] += 1
  else:
    m[s] = 1

ans = []
maxi = 0
for k, v in m.items():
  if v > maxi:
    ans.clear()
    maxi = v
  elif v < maxi:
    continue
  ans.append(k)

ans.sort()

for a in ans:
  print(a)