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:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    c = collections.Counter([S() for _ in range(n)])
    mv = max(c.values())

    return JA(sorted([k for k,v in c.items() if v == mv]), "\n")


print(main())

Submission status: Accepted

Solution code:
N = int(input())
d = {}
for i in range(N):
  s = input()
  d[s] = d.get(s, 0) + 1
base = sorted(d.items(), key=lambda x: x[1], reverse=True)[0][1]
items = [k for k, v in d.items() if v==base]
for item in sorted(items):
  print(item)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
S = [input() for _ in range(n)]
c = Counter(S)
max = 0
for s in set(S):
  if max < c[s]:
    max_words = [s]
    max = c[s]
  elif max == c[s]:
    max_words.append(s)
max_words.sort()
print("\n".join(max_words))

Submission status: Accepted

Solution code:
N = int(input())
S = []
for num in range(N):
    S.append(input())
dic = {}
max=1

for name in S:
    if name in dic.keys():
        dic[name] += 1
        if dic[name] > max:
            max = dic[name]
    else:
        dic[name] = 1

keys = [k for k, v in dic.items() if v == max]
keys.sort()

for key in keys:
    print(key)

Submission status: Accepted

Solution code:
from collections import Counter

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

# ansの初期化
ans = []
ans.append(s[0][0])
cnt = s[0][1]

if (len(s) != 1):
  for i in range(1, n):
    if (s[i][1] < cnt):
      break
    else:
      ans.append(s[i][0])

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

Submission status: Accepted

Solution code:
n=int(input())
L={}
c=0
for i in range (n):
    s=input()
    if s in L:
        L[s]+=1
    else:
        L.update({s:1})
        c+=1
M=list(L.values())
C=list(L.keys())
b=max(M)
F=[]
for i in range(c):
    if M[i]==b:
        F+=[C[i]]
F.sort()
for i in F:
    print(i)

Submission status: Accepted

Solution code:
import math
from collections import Counter


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

for _ in range(n):
    votes.append(input())

counter = Counter(votes).most_common()
max_votes = counter[0][1]

candidates = [cand for cand in counter if cand[1] == max_votes]

for candidate in sorted(candidates):
    print(candidate[0])

Submission status: Accepted

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

for _ in range(N):
    S = input()
    if S in dic.keys():
        dic[S] += 1
    else:
        dic[S] = 1

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

v = dic[-1][1]
ans = []

for d in dic:
    if d[1] == v:
        ans.append(d[0])

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import collections
a = int(input())
li1 = []
 
for i in range(a):
    li1.append(str(input()))
 
c = collections.Counter(li1)
 
sorted_items = sorted(
  c.most_common(),
  key = lambda x:(x[1],x[0]), reverse=True)
 
key, value = zip(*sorted_items)
li2 = []
li2.append(key[0])
for i in range(1,len(key)):
    if(value[0] == value[i]):
        li2.append(key[i])
    else:
        break;

list.sort(li2)

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

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
S = [input() for _ in range(N)]
D = defaultdict(int)

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

saidai = max(D.values())
ans = [k for k, v in D.items() if v == saidai]
for x in sorted(ans):
  print(x)

Submission status: Accepted

Solution code:
n=int(input())
mp={}
for i in range(n):
    s=input()
    if s in mp:
        mp[s]+=1
    else:
        mp[s]=1
_max=0
for x,y in mp.items():
    _max=max(_max,y)
ans=[]
for x,y in mp.items():
    if y==_max:
        ans.append(x)
ans.sort()
for x in ans:
    print(x)

Submission status: Accepted

Solution code:
import collections
n = int(input())
si = []

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

ss = collections.Counter(si)
n_ma = max(ss.values())

ans = []
for i in ss.keys():
    if ss[i] == n_ma:
        ans.append(i)

ans.sort()

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque
import sys
input = sys.stdin.readline

N = int(input())
count = defaultdict(int)
for _ in range(N):
    S = input().rstrip()
    count[S] += 1
ans = []
for k, v in count.items():
    ans.append((v, k))
ans.sort(key=lambda x: (-x[0], x[1]))
ans = deque(ans)
m = ans[0][0]
while ans:
    v, k = ans.popleft()
    if v == m:
        print(k)
    else:
        break

Submission status: Accepted

Solution code:
from collections import Counter

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

dic = Counter(S)

tmp = max(dic.values()) # ここ重要！
ans = [key for key, value in dic.items() if value == tmp]

# もうちょいかっこいい書き方があるはず。リストを1行1str出力 and 最後に改行しないように
"""
for key in sorted(ans):
    print(key, end="")
    print("")
"""


ans.sort()
print(*ans, sep="\n")


# print(*ans, sep="\n") かっこいい書き方

Submission status: Accepted

Solution code:
from collections import Counter

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

dic = Counter(S)

tmp = max(dic.values())
ans = [key for key, value in dic.items() if value == tmp]

# もうちょいかっこいい書き方があるはず。リストを1行1str出力 and 最後に改行しないように
for key in sorted(ans):
    print(key, end="")
    print("")

Submission status: Accepted

Solution code:
def maximum_values(d):
    retval = []
    maxval = max(d.values())

    for k, v in d.items():
        if v == maxval:
            retval.append(k)

    return retval

num = int(input())
strings = {}

for i in range(num):
    string = input()
    if string in strings.keys():
        strings[string] += 1
    else:
        strings[string] = 1

maximums = maximum_values(strings)
maximums = sorted(maximums)
print("\n".join(maximums))

Submission status: Accepted

Solution code:
n = int(input())
ma = 0
str1 = {}
ans=[]
for i in range(n):
	s = str(input())
	try:
		str1[s]+=1
	except:
		str1[s]=1
	if ma < str1[s]:
		ma=str1[s]
sorted(str1.items(),key=lambda x: x[1],reverse=True)
for item,val in str1.items():
	if ma==val:
		ans.append(item)
for i in sorted(ans):
	print(i)

Submission status: Accepted

Solution code:
from collections import Counter
def solve(n, s):
    D = Counter(s)
    best = max(D.values())
    S = filter(lambda k: D[k] == best, D.keys())
    return "\n".join(sorted(list(S)))

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
input_list = [input() for i in range(n)]
cnt = Counter()
for word in input_list:
  cnt[word] += 1
max_value = max(cnt.values())
answer = [i for i, j in cnt.items() if j == max_value]
answer.sort()
for i in answer:
  print(i)

Submission status: Accepted

Solution code:
from collections import Counter
import sys
n = int(sys.stdin.readline())
sn = sys.stdin.read().split()
c = Counter(sn)
c = sorted(c.items(), key=lambda x: (-x[1], x[0]))
num = c[0][1]
for i, j in c:
  if j == num:
    print(i)
  else:
    quit()

Submission status: Accepted

Solution code:
import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint=====================================
N, K = map(int, input().split())
N, M = map(int, input().split())
A, B = map(int, input().split())

H, W = map(int, input().split())

L, R = map(int, input().split())

1行のstring=================================
S, T = input().split()

1行の整数配列================================
P = list(map(int,input().split()))

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
D = list(map(int,input().split()))

L = list(map(int,input().split()))
R = list(map(int,input().split()))

T = list(map(int,input().split()))

改行あり整数==================================
X = []
Y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    X.append(x1)
    Y.append(y1)

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

Pair = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    Pair.append((x1, y1))
    
2次元整数配列=====================================
A = []
for i in range(N):
    tmp = list(map(int,input().split()))
    A.append(tmp)


N行M列の初期化====================================
dp = [[VAL] * RETU for i in range(GYO)]

'''


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

S.sort()

count = collections.Counter(S)

most = count.most_common()[0][1]

ans = []

for c in count.most_common():
    if c[1] == most:
        ans.append(c[0])

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

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
d = defaultdict(int)
t = 0
for _ in range(n):
    s = input()
    d[s] += 1
    t = max(t, d[s])
res = []
for i in d:
    if d[i] == t:
        res.append(i)
res.sort()
for i in res:
    print(i)

Submission status: Accepted

Solution code:
n=int(input())
a=[]
import collections as cc
a=[input() for i  in range(n)]
f=cc.Counter(a)
ch=max(f.values())
ans=[]
for i in a:
    if f[i]==ch:
        ans.append(i)
ans=list(set(ans))
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
li = []
for i in range(n):
  li.append(input())
from collections import Counter
s = Counter(li)
a = list(s.values())
b = list(s.keys())
ans = []
m = 0
for x in a:
  m = max(m, x)
for i in range(len(a)):
  if a[i] == m:
    ans.append(b[i])
ans_a = sorted(ans)
ans_b = "\n".join(ans_a)
print(ans_b)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = [input() for x in range(N)]
cnt = Counter(A)
mx = max(cnt.values())
s = [s for s, v in cnt.items() if v == mx]
s.sort()
print('\n'.join(s))

Submission status: Accepted

Solution code:
n =int(input())

s = []

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

dictionary = {}

for i in s:
    if i in dictionary:
        dictionary[i] += 1
    else:
        dictionary[i] = 0

max_val = max(dictionary.values())
keys_of_max_val = []

for key in dictionary:
    if dictionary[key] == max_val:
        keys_of_max_val.append(key)

keys_of_max_val.sort()

for ans in keys_of_max_val:
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())

d = {}

for _ in range(n):
    tmp = input()
    if tmp not in d.keys():
        d[tmp] = 1
    else:
        d[tmp] += 1

max_value = max(d.values())

ans = []

for k in d.keys():
    if d[k] == max_value:
        ans.append(k)

ans.sort()

for a in ans:
    print(a)

Submission status: Accepted

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

maxim = max(m.values())
mySet = set(key for key, value in m.items() if value == maxim)
for i in sorted(mySet):
    print(i)

Submission status: Accepted

Solution code:
import collections
def main():
    N = int(input())
    s = [input() for i in range(N)]
    ss = collections.Counter(s).most_common()
    #maxcount = ss[0][1]
    sss = sorted([ss[i][0] for i in range(len(ss)) if ss[i][1] == ss[0][1]])
    for i in range(len(sss)):
        print(sss[i])
main()

Submission status: Accepted

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


def solve(N: int, S: "List[str]"):
    c = Counter(S)
    words = []
    w, m = c.most_common()[0]
    words.append(w)
    for _w, _c in c.most_common()[1:]:
        if _c==m:
            words.append(_w)
        else:
            break
    print('\n'.join(sorted(words)))
    # 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 = input()
d = dict()
M = 1
for i in range(n):
  w = raw_input()
  if w in d:
    d[w] += 1
    M = max(d[w], M)
  else:
    d[w] = 1
l = []
for k in d:
  if d[k] == M:
    l.append(k)
l = sorted(l)
for one in l:
  print (one)

Submission status: Accepted

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

for i in L:
    if i in D:
        V = D.get(i) + 1
    else:
        V = 1
    D[i] = V

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

Ans = []

Ans.append(D[0][0])

for i in range(len(D)-1):
    if D[i][1] == D[i+1][1]:
        Ans.append(D[i+1][0])
    else:
        break

Ans = sorted(Ans)

for i in Ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
s = []
for _ in range(n):
    s.append(input())
set_s = set(s)
dict_s = {}
for si in set_s:
    dict_s[si] = 0
for si in s:
    dict_s[si] += 1
sorted_ds = sorted(dict_s.items(), key=lambda x: x[1], reverse=True)
f = True
for str_, c in sorted_ds:
    if f:
        list_ = [str_]
        p = c
        f = False
    else:
        if c == p:
            list_.append(str_)
list_ = sorted(list_)
for si in list_:
    print(si)

Submission status: Accepted

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

max_num = max(cnt.values())

ans_list = []

for i in cnt.items():
    if i[1] == max_num:
        ans_list.append(i[0])
    else:
        pass

ans_list.sort()

for i in ans_list:
    print(i)

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for _ in range(n):
    s = input()
    d[s] += 1
t = max([i for i in d.values()])
res = []
for i in d:
    if d[i] == t:
        res.append(i)
res.sort()
for i in res:
    print(i)

Submission status: Accepted

Solution code:
# coding: utf-8
from collections import Counter


def main():
    n = int(input())
    polls_list = []
    for _ in range(n):
        polls_list.append(input())
    polls_dict = Counter(polls_list)
    max_poll = max(polls_dict.values())

    polls_set = set()
    for key, value in polls_dict.items():
        if value == max_poll:
            polls_set.add(key)

    polls_set = sorted(polls_set)
    for poll in polls_set:
        print(poll)

    return 0


if __name__ == '__main__':
    main()

Submission status: Accepted

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

C=collections.Counter(S)
C_S=C.most_common()
m=C.most_common()[0][1]
ans=[]

for i in range(len(C_S)):
    if C_S[i][1]!=m:
        break
    else:
        ans.append(C_S[i][0])

ans.sort()

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
N = int(input())
S = (str(x) for x in sys.stdin.read().split())
cnt = Counter(s for s in S)
max_cnt = max(cnt.values())
keys = [k for k, v in cnt.items() if v == max_cnt]
print("\n".join(sorted(keys)))

Submission status: Accepted

Solution code:
from collections import defaultdict
def solve():
    N = int(input())
    d = defaultdict(int)

    for _ in range(N):
        S = input()
        d[S] += 1

    items = list(d.items())
    items.sort(key=lambda x:x[1], reverse=True)
    mx = items[0][1]
    cand = []
    for item in items:
        if item[1] == mx:
            cand.append(item[0])
        else:
            break
    
    ans = sorted(cand)
    print(*ans, sep='\n')
    
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
#python3
from collections import Counter
from operator import itemgetter
def main():
    n = int(input())
    s = [(x, -y) for x, y in Counter([input() for i in range(n)]).items()]
    s.sort(key=itemgetter(1,0))
    MAX = s[0][1]
    for i in range(len(s)):
        if s[i][1] == MAX:
            print(s[i][0])
        else:
            break

main()

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    dict = {}

    for _ in range(N):
        S = input()
        if S in dict:
            dict[S] += 1
        else:
            dict[S] = 1
    sorted_dict = list(sorted(dict.items(), key=lambda x:x[1], reverse=True))
    mx = sorted_dict[0][1]
    cand = []
    for d in sorted_dict:
        if d[1] == mx:
            cand.append(d[0])
        else:
            break
    print(*sorted(cand), sep='\n')
    
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(l)

col_tuple_list = c.most_common()

a = []

most_num = col_tuple_list[0][1]
for word_tuple in col_tuple_list:
    if most_num == word_tuple[1]:
        a.append(word_tuple[0])
    else:
        break
a = sorted(a)
for i in a:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())

ans = {}
M = 1
for _ in range(N):
    word = input()
    tmp = ans.get(word)
    if tmp == None:
        ans[word] = 1
    else:
        ans[word] = tmp + 1
        if tmp + 1 > M:
            M = tmp + 1

tmp = sorted(list(ans.keys()))
for t in tmp:
    if M == ans.get(t):
        print(t)

Submission status: Accepted

Solution code:
from collections import *
N = int(input())
count = Counter([ input() for _ in range(N)])

m = max(count.values())

ans = [a for a,b in count.items() if b == m]
ans.sort()
for S in ans:
    print(S)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = [input() for _ in range(N)]
    dict = {}
    for i in range(N):
        if S[i] not in dict:
            dict[S[i]] = 1
        else:
            dict[S[i]] += 1
    ans = {}
    p = 0
    for i ,j in dict.items():
        if p < j : p = j

        if j not in ans:
            ans[j] = [i]
        else:
            ans[j].append(i)
    ans[p].sort()
    for i in range(len(ans[p])):
        print(ans[p][i])
if __name__ == '__main__':
    main()

Submission status: Accepted

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

max_cnt = max(str_cnt.values())
res_list = []

for item in str_cnt.items():
  if item[1] == max_cnt:
    res_list.append(item[0])

res_list.sort()

for res in res_list:
  print(res)

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())
ans = []

for k, v in d.items():
  if v == m:
    ans.append(k)
ans.sort()
print(*ans, sep = "\n")

Submission status: Accepted

Solution code:
from collections import Counter
def main():
  _, *A = open(0).read().split()
  c = Counter(A)
  maxc = max(c.values())
  print(*sorted([i[0] for i in c.items() if i[1] == maxc]))

if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
table={}
import sys
input=sys.stdin.readline
n=int(input())
ss=[]
for i in range(n):
	s=input().rstrip()
	if s in table:
		table[s]+=1
	else:
		table[s]=1
		ss.append(s)
ans=[]
saidai=max(table.values())
for i in range(len(ss)):
	if table[ss[i]]==saidai:
		ans.append(ss[i])
ans.sort()
for x in ans:
	print(x)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
s=[input() for _ in range(n)]
d=Counter(s)
m=max(d.values())
keys = [k for k,v in d.items() if v==m]
print("\n".join(sorted(keys)))

Submission status: Accepted

Solution code:
n = int(input())
arr = {}

for i in range(n):
    s = input()
    if not s in arr:
        arr[s] = 1
    else:
        arr[s] += 1

max_count = max(arr.values())
dic = [key[0] for key in arr.items() if key[1] == max_count]

out_sort = sorted(dic)
print("\n".join(out_sort))

Submission status: Accepted

Solution code:
n = int(input())
arr = {}

for i in range(n):
    s = input()
    if not s in arr:
        arr[s] = 1
    else:
        arr[s] += 1

max_count = max(arr.values())
dic = [key[0] for key in arr.items() if key[1] == max_count]

out_sort = sorted(dic)
for i in out_sort:
    print(i)

Submission status: Accepted

Solution code:
n=int(input())
d=dict()
for _ in range(n):
    a=input()
    if a in d:
        d[a]+=1
    else:
        d[a]=1
m=max(d.values())
keys = [k for k,v in d.items() if v==m]
print("\n".join(sorted(keys)))

Submission status: Accepted

Solution code:
N = int(input())

hash = {}
for i in range(N):
	key = input()
	if key in hash:
		hash[key] += 1
	else:
		hash[key] = 1
        
max = 0
results = []
for i, v in hash.items():
	if max == v:
		results.append(i)
	elif max < v:
		results = [i]
		max = v

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

Submission status: Accepted

Solution code:
N = int(input())
d = dict()
m = 0
for i in range(N):
    w = input()
    if w in d:
        d[w] += 1
        m = max(d[w], m)
    else:
        d[w] = 1
        m = max(d[w], m)
res_list = []

for w, n in d.items():
    if (n == m):
        res_list.append(w)

for w in sorted(res_list):
    print(w)

Submission status: Accepted

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

for i in range(N):
    if not (S[i] in dict1.keys()):
        names.append(S[i])
        dict1.update({S[i]:1})
    else:
        dict1[S[i]] +=1
maxv = 0
for i in range(len(names)):
    if maxv < dict1[names[i]]:
        maxv = dict1[names[i]]

winners = []

for i in range(len(names)):
    if dict1[names[i]] == maxv:
        winners.append(names[i])

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

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
u = set(s)
dic = dict(zip(u, [0]*len(u)))
for i in range(n):
    dic[s[i]] += 1
m = max(dic.values())
res = []
for k, v in dic.items():
    if v == m:
        res.append(k)
res.sort()
print(*res, sep="\n")

Submission status: Accepted

Solution code:
import collections
s = collections.Counter([input() for s in range(int(input()))])
m = max(s.values())
 
a = []
for d in s.items():
  if d[1] == m:
    a.append(d[0])
print("\n".join(sorted(a)))

Submission status: Accepted

Solution code:
from collections import Counter

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

counter = Counter(s)
count = counter.most_common()
most = count[0][1]

c = []

for i in range(len(count)):
    if most == count[i][1]:
        c.append(count[i][0])

c.sort()
print(*c, sep='\n')

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = [input() for i in range(n)]
c = Counter(s)
m = 0
for i in c.values():
    m = max(m, i)
res = []
for k, v in c.items():
    if v == m:
        res.append(k)
res.sort()
print('\n'.join(res))

Submission status: Accepted

Solution code:
import sys
import collections
n = int(sys.stdin.readline())
a = []
for _ in range(n):
  a.append(sys.stdin.readline().strip())
c = collections.Counter(a)
maxc = max(c.values())
print(*sorted([i[0] for i in c.items() if i[1] == maxc]))

Submission status: Accepted

Solution code:

import collections as co
n = int(input())
s = []
for i in range(n):
    s.append(input())
SS = co.Counter(s)
ma = max(SS.values())

ans = []
for i in SS.keys():
    if SS[i] == ma:
        ans.append(i)

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

Submission status: Accepted

Solution code:
from collections import Counter

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S = read().split()

res = []
c = Counter(S)
max_num = c.most_common(1)[0][1]
for i, j in list(c.items()):
    if j == max_num:
        res.append(i)
        
res.sort()

        
print('\n'.join(list(map(lambda x:x.decode(), res))))

Submission status: Accepted

Solution code:
import collections

N = int(input())
L = []
O = []

for i in range(N):
    s = input()
    L.append(s)

c = collections.Counter(L)
M = max(c.values())

for k in c.keys():
    if c[k] == M:
        O.append(k)

O.sort()

for j in O:
    print(j)

Submission status: Accepted

Solution code:
n=int(input())
dic={}

for i in range(n):
    s=input()
    count=dic.get(s,0)
    count+=1
    dic[s]=count
mx=1
for v in dic.values():
    mx=max(v,mx)
ans=[]
for k,v in dic.items():
    if v==mx:
        ans.append(k)
ans.sort()
#print("---")
for st in ans:
    print(st)

Submission status: Accepted

Solution code:
from collections import Counter
def solve():
  n = int(input())
  a = [input() for _ in range(n)]
  c = Counter(a)
  values, counts = zip(*c.most_common())
  maxc = max(counts)
  array = []
  for i in range(len(values)):
    if counts[i] == maxc:
      array.append(values[i])
    else:
      break
  array.sort()
  for i in array:
    print(i)
solve()

Submission status: Accepted

Solution code:
n = int(input())

dic = {}
for i in range(n):
  s = input()
  if s in dic:
    dic[s] += 1
  else:
    dic[s] = 1

_max = 0
for v in dic.values():
  if _max < v:
    _max = v
dic2 = sorted(dic.items())

for (k,v) in dic2:
  if v == _max:
    print(k)

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(n):
	l.append(input())
dct={}
for i in range(n):
	if l[i] in dct:
		dct[l[i]]+=1
	else:
		dct[l[i]]=1
m=max(dct.values())
ans=[]
for i in dct:
	if dct[i]==m:
		ans.append(i)
ans.sort()
for i in ans:
	print(i)

Submission status: Accepted

Solution code:
n = int(input())

#sを辞書に入れてカウントする
d = {}
for _ in range(n):
    s = input()
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

#valueが最大であるkeyを辞書順にプリントする
m = max(d.values())
for s in sorted(k for k in d if d[k] == m):
    print(s)

Submission status: Accepted

Solution code:
n = int(input())
res = []
d = dict()
for _ in range(n):
    s = input()
    if s not in d:
        d[s] = 0
    d[s] +=1
mm = -1
for k,v in d.items():
    if v > mm:
        mm = v

for k,v in d.items():
    if v == mm:
        res.append(k)

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

Submission status: Accepted

Solution code:

N = int(input())
C = dict()


for i in range(N):
    a = input()
    if(a not in C.keys()):
        C[a] = 1
    else:
        val = C[a]
        C[a] = val + 1

m=0
for i in C.values():
    if(i > m):
        m=i

ans = sorted(C.items())
for i  in ans:
    if(m==i[1]):
        print(i[0])

Submission status: Accepted

Solution code:
import collections
n=int(input())
A=[]
for i in range(n):
  A.append(input())
c=collections.Counter(A)
B=c.most_common()
C=[]
i=0
while B[i][1]==B[0][1]:
  C.append(B[i][0])
  i=i+1
  if i==len(B):
    break
C=sorted(C)
for i in range(len(C)):
  print(C[i])

Submission status: Accepted

Solution code:
import collections as col

n = int(input())
L_W = []
for i in range(0,n):
    L_W.append(input())
 
dic = col.Counter(L_W)

dic_values_max = max(list(dic.values()))
 
max_key = [i for i, j in dic.items() if j == dic_values_max]
 
max_key.sort()
 
for k in max_key:
    print(k)

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

DD = sorted(D.items(), key=lambda x:x[1])

sn=DD[-1][1]
ans=[]
for i in DD:
    if i[1]==sn:
        ans.append(i[0])
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
from collections import Counter


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

c = Counter(S)
c_sorted = sorted(c.items(), key=lambda x: x[1], reverse=True)
j = -1
for i in range(len(c_sorted)):
    if i == len(c_sorted) - 1:
        break
    if c_sorted[i + 1][1] < c_sorted[i][1]:
        break

c_sorted_best = c_sorted[:i + 1]
c_sorted_best_dicOrder = sorted(c_sorted_best, key=lambda x: x[0])
print('\n'.join([x[0] for x in c_sorted_best_dicOrder]))

Submission status: Accepted

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

c=collections.Counter(S)
most=c.most_common()
m_cnt=most[0][1]

dicts=[]

for i in most:
    if i[1]==m_cnt:
        dicts.append(i[0])
    else:
        break
dicts.sort()
for i in dicts:
    print(i)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]
c = Counter(S)
m = max(c.values())
ans = sorted([k for k,v in c.items() if m==v])
[print(k) for k in ans]

Submission status: Accepted

Solution code:
from collections import Counter

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

c=Counter(S)
m=max(c.values())
ans = sorted(k for k,v in c.items() if v == m)
print("\n".join(ans))

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]
c = Counter(S)
m = max(c.values())
ans = sorted([(k,v) for k,v in c.items() if m==v], key=lambda x: (-x[1], x[0]))
[print(k[0])for k in ans]

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = [input() for i in range(n)]
l = []
d = defaultdict(int)
ss = set()
for i,j in enumerate(s):
    d[j] += 1
for jj in list(d):
    l.append([jj,d[jj]])
l.sort()
l.sort(key=lambda x:x[1],reverse = True)
max = l[0][1]
# print(l,max)
for i,j in enumerate(l):
    if j[1] == max:
        print(j[0])
    else:
        break