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:
N = int(input())
S = [input() for _ in range(N)]

cnt = {}
for Si in S:
    cnt[Si] = cnt.setdefault(Si, 0) + 1

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

ans_list = []
for i, (key, value) in enumerate(result):
    if i == 0:
        ans_cnt = value
    #
    if value >= ans_cnt:
        ans_list.append(key)
    else:
        break

for key in sorted(ans_list):
    print(key)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
s=[input().strip() for _ in range(n)]
from collections import Counter
s=Counter(s).most_common()
a=s[0][1]
ans=[]
for w,k in s:
    if k==a:
        ans.append(w)
ans.sort()
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
s = [input() for _ in range(N)]
d = defaultdict(int)
for i in s:
    d[i] += 1

dsort = sorted(d.items(), key=lambda x : x[1], reverse=True)
ans = []
tmp = dsort[0][1]
for i, v in dsort:
    if tmp == v:
        ans.append(i)

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

Submission status: Accepted

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

ans=[]
for s in dic:
    if dic[s]==m: ans.append(s)
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

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

from collections import Counter

ctr = Counter(s)
sorted(ctr.most_common(), key=lambda x: x[1], reverse=True)
mx = sorted(ctr.most_common(), key=lambda x: x[1], reverse=True)[0][1]
li = []
for k, v in sorted(ctr.most_common(), key=lambda x: x[1], reverse=True):
    if v == mx:
        li.append(k)

li.sort()
for val in li:
    print(val)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

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

c = collections.Counter(S)

max_c = -1
anss = []
for key, count in c.most_common():
    if max_c <= count:
        max_c = count
    else:
        break
    anss.append(key)
anss.sort()
for ans in anss:
    print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=[]
for i in range(0,N):
    S.append(input())
d={}
for s in S:
    if s not in d:
        d[s]=1
    else:
        d[s]+=1
A=[]
B=[]
for k in d:
    A.append([d[k], k])
    B.append(d[k])
A.sort(reverse=True)
B.sort(reverse=True)
M=B[0]
C=[]
for a in A:
    if a[0]==M:
        C.append(a[1])
C.sort()
for c in C:
    print(c)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = []
for n in range(N):
    S.append(input())
c = Counter(S)
num = c.most_common()[0][1]
ans = []
for x in c:
    if c[x] == num:
        ans.append(x)
for x in sorted(ans):
    print(x)

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

maxkey = max([dic[i] for i in dic])

anslist = []

for i in dic:
    if dic[i] == maxkey:
        anslist.append(i)
anslist.sort()

for i in anslist:
    print(i)

Submission status: Accepted

Solution code:
from bisect import bisect_right, bisect_left
from collections import Counter, deque
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import groupby, permutations, combinations, product
from sys import stdin, stderr


# 最大公約数（ユークリッドの互除法）
# Python3.5 で math.gcd()が追加され、
# AtCoder環境と最新環境でパッケージが分かれてしまったので、自分で書いておく
def gcd(x, y):
    return x if y == 0 else gcd(y, x % y)


# 拡張ユークリッド互除法
# 正整数x, y について、a*x + b*y == gcd(x,y)なるa,bを返す。
# 特に、互いに素なるx, yについては a*x + b*y == 1 となる a, b。
def exgcd(x, y):
    if y == 0:
        return 1, 0
    a, b = exgcd(y, x % y)
    return b, a - (x // y) * b


# 最小公倍数
def lcm(x, y):
    m = gcd(x, y)
    return (x // m) * (y // m)


def main():
    n = int(input())
    ss = {}
    m = 0
    for i in range(n):
        s = input()
        if s not in ss:
            ss[s] = 0
        ss[s] += 1
        m = max(m, ss[s])
    ret = []
    for s in ss.keys():
        if ss[s] == m:
            ret.append(s)
    ret = sorted(ret)
    return "\n".join(ret)


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

Submission status: Accepted

Solution code:
import collections
n=int(input())
a=[]
for i in range(n):
    a.append(input())
a=list(collections.Counter(a).most_common())
b=a[0][1]
c=[]
for i in range(len(a)):
    c.append(a[i][0])
    if i+1==len(a):
        break
    if a[i+1][1]!=b:
        break
c=sorted(c)
for i in range(len(c)):
    print(c[i])

Submission status: Accepted

Solution code:
def solve():
    import itertools
    from operator import itemgetter

    N = int(input())
    B = [input() for _ in range(N)]
    B.sort()

    l = []
    gr = itertools.groupby(B)
    max_key = 0
    for key, group in gr:
        length = len(list(group))
        l.append((length, key))
        if length > max_key:
            max_key = length

    l.sort(key = itemgetter(0), reverse=True)

    key = l[0][0]
    for k, v in l:
        if key == k:
            print(v)
        else:
            break

solve()

Submission status: Accepted

Solution code:

N = int(input())
S = [input() for _ in range(N)]
#%%
mydic = {}
for s in S:
    mydic[s] = 0

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

MIN = -1
for s in S:
    MIN = max(MIN, mydic[s])

ans = []
for s in S:
    if mydic[s] == MIN:
        ans.append(s)

ans.sort()
print(ans[0])
for i in range(1,len(ans)):
    if ans[i] == ans[i-1]:
        continue
    else:
        print(ans[i])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
d = {}
for i in range(n):
    s = input()
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
l = [[-d[key], key] for key in d]
l.sort()

m = l[0][0]
for v, k in l:
    if v == m:
        print(k.rstrip("\n"))

Submission status: Accepted

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

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

s = collections.Counter(S)

mv = s.most_common()[0][1]
ans = []
for k,v in s.items():
    if v == mv:
        ans.append(k)
ans = sorted(ans)
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
import collections
n=int(input())
slist=[input() for i in range(n)]
c = collections.Counter(slist)
most = c.most_common()
num = most[0][1]
most = [i[0] for i in most if i[1]==num]
most.sort()
for s in most:
  print(s)

Submission status: Accepted

Solution code:
from collections import Counter
c = Counter()
n = int(input())
for _ in range(n):
    c[input()] += 1

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

ans = []
for x, y in c.most_common():
    if y == m:
        ans.append(x)
    else:
        break

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

Submission status: Accepted

Solution code:
n = int(input())

s_dict = {}
max_count = 0
max_words = []

for _ in range(n):
    s = input()
    if s in s_dict:
        s_dict[s] += 1
        count = s_dict[s] + 1
    else:
        s_dict[s] = 1
        count = 1
    if count == max_count:
        max_words.append(s)
    elif count > max_count:
        max_words = [s]
    max_count = max(max_count,count)

max_words.sort()
for word in max_words:
    print(word)

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

mm = 0
li = []

for i in dic:
    if dic[i] > mm:
        li = [i]
        mm = dic[i]
    elif dic[i] == mm:
        li.append(i)

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

Submission status: Accepted

Solution code:
#def main(S, b):

if __name__ == '__main__':
    N = int(input())

    emp_dict = {}

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

    a = max(list(emp_dict.values()))

    A = []

    for k in emp_dict.keys():
        if emp_dict[k] == a:
            A.append(k)

    A.sort()
    for a in A:

        print(a)

Submission status: Accepted

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

c = Counter(l)

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

ans = []
for k,v in c.items():
    if v < d:
        pass
    else:
       ans.append(k)
       
       
ans = sorted(ans)

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

Submission status: Accepted

Solution code:
n = int(input())
s = []
for i in range(n):
    s0 = input()
    s.append(s0)
l = []
s.sort()
count = 0
for i in range(n-1):
    count += 1
    if s[i] == s[i+1]:
        continue
    else:
        l.append([s[i],count])
        count = 0
count += 1
l.append([s[n-1],count])
l.sort(key=lambda x:x[1],reverse=True)
m = len(l)
a = l[0][1]
for i in range(m):
    if l[i][1] == a:
        print(l[i][0])
    else:
        break

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    N = int(input())
    d = Counter()
    l = 0
    for _ in range(N):
        s = input()
        if s not in d:
            d[s] = 1
        else:
            d[s] += 1
        l = max(d[s], l)
    d2 = []
    for i in d:
        if d[i] == l:
            d2.append(i)
    d2.sort()
    for j in d2:
        print(j)
main()

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 = []
for k in c.keys():
    if c[k] == m:
        ans.append(k)
for a in sorted(ans):
    print(a)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(S).most_common()
m = c[0][1]
print("\n".join(sorted(s[0] for s in c if s[1] == m)))

Submission status: Accepted

Solution code:
from collections import defaultdict

N=int(input())
S=[input() for _ in range(N)]
d=defaultdict(int)
maxV=0
for s in S:
    d[s]+=1
    maxV=max(maxV, d[s])
ans=[]
for key, value in d.items():
    if value==maxV:
        ans.append(key)
ans.sort()
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
#[int(i) for i in input().split()]
n = int(input())
s = {}
for i in range(n):
    tmp = input()
    try:
        s[tmp] += 1
    except:
        s[tmp] = 1
smax = max(s.values())
ls = []
for i in s.keys():
    if s[i] == smax:
        ls.append(i)
ls.sort()
for i in ls:
    print(i)

Submission status: Accepted

Solution code:
from collections import Counter

def main():
    n = int(input().strip())
    cnt = Counter()
    for _ in range(n):
        cnt[input().strip()] += 1
    
    maxval = max(cnt.values())
    for s in sorted(k for k, v in cnt.items() if v == maxval):
        print(s)


main()

Submission status: Accepted

Solution code:
n = int(input())

num_of_votes = {}

for _ in range(n):
  s = input()
  if num_of_votes.get(s) == None:
    num_of_votes[s] = 0
  num_of_votes[s] += 1

ans = []
max_v = 0
for k, v in num_of_votes.items():
  if max_v < v:
    ans = [k]
    max_v = v
  elif max_v == v:
    ans.append(k)
  else:
    pass

print("\n".join(sorted(ans)))

Submission status: Accepted

Solution code:
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    c = collections.Counter()
    for i in range(N):
        S = input().strip()
        c[S] += 1

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

    ans = []
    for v in c.most_common():
        if v[1] == ma:
            ans.append(v[0])
        else:
            break
    ans.sort()

    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections
n=int(input())
S=[]
for i in range(n):
    S.append(input())
SS=collections.Counter(S).most_common()
s,ct=SS[0]
Ans=[]
for s,c in SS:
    if c==ct:
        Ans.append(s)
Ans.sort()
for ans in Ans:
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())

S = list(input() for _ in range(n))
from collections import Counter

c = Counter(S).most_common()

max_cnt = c[0][1]
lst = []

for i in c:
  if i[1] != max_cnt:
    break
  else:
    lst.append(i[0])
    

for node in sorted(lst):
  print(node)

Submission status: Accepted

Solution code:
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_left # bisect_left(list, value)
#from fractions import gcd

sys.setrecursionlimit(10**7)
N = int(input())
S = [input() for _ in range(N)]

d = defaultdict(int)
for s in S:
    d[s] += 1

maxn = max(list(d.values()))

for s in sorted(d.items()):
    if s[1] == maxn:
        print(s[0])

Submission status: Accepted

Solution code:
from collections import defaultdict
n=int(input())
d=defaultdict(int)
for _ in range(n):
    d[input()]+=1
d=sorted(d.items(),key=lambda x:x[1],reverse=True)
m=d[0][1]
ans=[]
for k,v in d:
    if v==m:
        ans.append(k)
ans=sorted(ans)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

n=int(input())
s=[input() for i in range(n)]
c=dict(Counter(s))
lst=[]
cnt=0
for i in c.items():
    if i[1]>cnt:
        lst=[i[0]]
        cnt=i[1]
    elif i[1]==cnt:
        lst.append(i[0])

lst.sort()
# print(lst)
for i in range(len(lst)):
    print(lst[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).most_common()
ans = []
for i in range(len(c)):
    if c[0][1] == c[i][1]:
        ans.append(c[i][0])
    else:
        break
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

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

N = int(input())
Ss = Counter([input().rstrip() for _ in range(N)])
m = max(Ss.values())
ans = []
for k, v in Ss.items():
    if v == m:
        ans.append(k)
ans.sort()
print(*ans, sep="\n")

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
d = {}
for i in range(N):
    s = input()
    if s not in d.keys():
        d[s] = 1
    else:
        d[s] += 1
ans = []
v = max(d.values())
for k in d.keys():
    if d[k] == v:
        ans.append(k)
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
n = int(input())
#n,m = map(int,input().split())
#lst1 = list(map(int,input().split()))
dic1 = dict()
for i in range(n):
    s = input()
    if s in dic1:
        dic1[s] += 1
    else:
        dic1[s] = 1

ma = max(dic1.values())
lst1 = []
for i in dic1:
    if dic1[i] == ma:
        lst1.append(i)

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
S = read().decode().split()

dicts = Counter(S)
max_cnt = 0
ans_list = []
for v in dicts.values():
    max_cnt = max(max_cnt, v)
for k, v in dicts.items():
    if v == max_cnt:
        ans_list.append(k)

ans_list = sorted(ans_list)

for key in ans_list:
    print(key)

Submission status: Accepted

Solution code:
n=int(input())
lists=[]
for i in range(n):
    a=input()
    lists.append(a)
import collections 
D=dict(collections.Counter(lists))
K=0
for some in D.values():
    K=max(K,some)
P=[]
for some in D.keys():
    if D[some]==K:
        P.append(some)
P=sorted(P)
for some in P:
    print(some)

Submission status: Accepted

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

import collections
c = collections.Counter(s)
ans=[]
first=c.most_common()[0][1]
for tup in c.most_common():
    if tup[1] != first:
        break
    ans.append(tup[0])
ans.sort()

for i in ans:
    print(i)

Submission status: Accepted

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

N = int(input())
S = []
S2 = []

for _ in range(N):
    S.append(input().strip())

count = Counter(S)
most = max(count.values())
for key, value in count.items():
    if value == most:
        S2.append([key, value])

S2.sort(key=lambda x:x[0])
for value in S2:
    print(value[0])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def solve():
    d = dict()
    for _ in range(int(input())):
        s = input()
        d[s] = d.get(s,0)+1
    m = max(d.values())
    return '\n'.join(sorted([k for k,v in d.items() if v == m]))

if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
import sys, math
from collections import Counter

def input():
    return sys.stdin.readline()[:-1]

def main():
    N = int(input())
    S = [input() for k in range(N)]
    C = Counter(S)
    t = 0
    for e in C.values():
        t = max(e,t)
    ans = []
    for e in C:
        if C[e] == t:
            ans.append(e)
    print(*sorted(ans),sep="\n")

if __name__ == '__main__':
    main()

Submission status: Accepted

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

B = c.Counter(A)

M = max(list(B.values()))

ans = []

for s,cnt in B.items():
	if cnt == M:
		ans.append(s)

ans.sort()

for a in ans:
	print(a)

Submission status: Accepted

Solution code:
from collections import Counter

n=int(input())
s=[input() for _ in range(n)]
c=Counter(s)
mx=c.most_common()[0][1]
ans=[]
for e in c.most_common():
    if mx==e[1]:
        ans.append(e[0])
ans.sort()
print(*ans,sep='\n')

Submission status: Accepted

Solution code:
n = int(input())
d = dict()
for i in range(n):
    s= input()
    d.setdefault(s, 0)
    d[s] += 1
d = sorted([[x, y] for x, y in d.items()], key=lambda x:x[1], reverse=True)
now = 0
ans = set()
for x, y in d:
    if y >= now:
        ans.add(x)
        now = y
    else:
        break
for x in sorted(ans):
    print(x)

Submission status: Accepted

Solution code:
d=dict()
n=int(input())
for i in range(n):
    s=input()
    if s in d:
        d[s]+=1
    else:
        d[s]=1
d=list(d.items())
d.sort(key=lambda x:x[0])
d.sort(key=lambda x:x[1],reverse=True)
#print(d)
m=len(d)
for i in range(m):
    if d[i][1]==d[0][1]:
        print(d[i][0])
    else:
        break

Submission status: Accepted

Solution code:
n = int(input())
log = {}
for _ in range(n):
  s = input()
  if s in log:
    log[s] += 1
  else:
    log[s] = 1
    
dic2 = sorted(log.items(), key=lambda x:x[1])
max_s = []
m = dic2[-1][1]
for i in dic2[::-1]:
  if i[1] == m:
    max_s.append(i[0])
  else:
    break
max_s.sort()
for s in max_s:
  print(s)

Submission status: Accepted

Solution code:
N = int(input())
S = []
for _ in range(N):
    S.append(input())
from collections import defaultdict as ddict
cnt = ddict(int)
max_cnt = 0
for s in S:
    cnt[s] += 1
    max_cnt = max(max_cnt,cnt[s])
ans = []
for key in cnt.keys():
    if max_cnt == cnt[key]:
        ans.append(key)
for a in sorted(ans):
    print(a)

Submission status: Accepted

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

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = [input() for i in range(N)]

C = Counter(A)
mx = max(C.values())
ans = []
for k, v in C.items():
    if v == mx:
        ans.append(k)
ans.sort()
[print(s) for s in ans]

Submission status: Accepted

Solution code:
N = int(input())
words = {}
max_count = 1
for i in range(N):
    new = input()
    if new in words:
        words[new] += 1
        if words[new] > max_count:
            max_count = words[new]
    else:
        words[new] = 1
ans = []
for word in words:
    if words[word] == max_count:
        ans.append(word)
        
ans.sort()

for elem in ans:
    print(elem)

Submission status: Accepted

Solution code:
n = int(input())

from collections import defaultdict

d = defaultdict(int)

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

a = list(d.keys())
b = list(d.values())

l = len(a)
val = max(b)

ans = []

for i in range(l):
    if b[i] == val:
        ans.append(a[i])

ans = sorted(ans)
l = len(ans)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
Ss = [input() for _ in range(N) ]
di  ={}
for s in Ss:
    if s not in di:
        di[s] = 1
    else:
        di[s] += 1

di = sorted(di.items(),key= lambda x:(-x[1],x[0]) )
# print(di)
key = di[0][1]
for temp in di:
    k,v = temp
    if key == v:
        print(k)

Submission status: Accepted

Solution code:
n = int(input())
from collections import defaultdict
dic = defaultdict(int)

for _ in range(n):
    s = input()
    dic[s] += 1

k = max(dic.values())

ansl = []
for s in dic:
    if dic[s] == k:
        ansl.append(s)

ansl = sorted(ansl)

for s in ansl:
    print(s)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
P = defaultdict(int)
for i in range(N):
  P[input()] += 1
m = max(P.values())
E = []
for k, v in P.items():
  if v == m:
    E.append(k)
E.sort()
for e in E:
  print(e)

Submission status: Accepted

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

for _ in range(N):
    s = input()
    if s not in S:
        S[s] = 1
    else:
        S[s] += 1

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

flag = True
k = 0
l = []
for key, val in S:
    if flag:
        l.append(key)
        k = val
        flag = False
    else:
        if k == val:
            l.append(key)
        else:
            break

l.sort()
for ll in l:
    print(ll)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
cs = Counter(s)
freq = Counter(cs).most_common()
cnt = Counter(cs).most_common()[0][1]
ans = []
for i, c in freq:
  if c == cnt:
    ans.append(i)
    
ans.sort()

for i in ans:
  print(i)

Submission status: Accepted

Solution code:
N = int(input())

d = {}
for _ in range(N):
    s = input()
    if s not in d:
        d[s] = 0
    d[s] += 1

max_val = max(d.values())
keys = [k for k, v in d.items() if v == max_val]
for k in sorted(keys):
    print(k)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(S)

max_cnt = 0
words = []
for s_i, cnt in sorted(c.items(), key=lambda x: x[1], reverse=True):
    if max_cnt <= cnt:
        max_cnt = cnt
        words.append(s_i)
    else:
        break

for word in sorted(words):
    print(word)

Submission status: Accepted

Solution code:
n = int(input())
s = {}
for i in range(n):
    temp = input()
    s.setdefault(temp, 0)
    s[temp] += 1
num = max(s.values())
s2 = list(s.items())
s3 = [s2[i][0] for i in range(len(s)) if s2[i][1] == num]
s3.sort()
for i in s3:
    print(i)

Submission status: Accepted

Solution code:
from collections import Counter


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

C = Counter(S)

max = -1
ans = []

for k, v in C.most_common():
    if max == -1:
        max = v
    elif max > v:
        break
    ans.append(k)

ans = sorted(ans)

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
d = defaultdict(int)
for i in range(N):
    s = input().strip()
    d[s] += 1

L = sorted(d.items(), key=lambda x: -x[1])
MX = L[0][1]

L2 = [l[0] for l in L if l[1] == MX]
L2.sort()

for l in L2:
    print(l)

Submission status: Accepted

Solution code:
n = int(input().strip())
s = [input().strip() for _ in range(n)]
dic = {}

for e in s:
    if e in dic:
        dic[e] += 1
    else:
        dic[e] = 1

ans = []
m = max(dic.values())
for k, v in dic.items():
    if v == m:
        ans.append(k)
ans.sort()
for e in ans:
    print(e)

Submission status: Accepted

Solution code:
from collections import deque, Counter
from itertools import chain, combinations
import json
import numpy as np


def main():
    N = int(input())
    S = [input() for _ in range(N)]
    # A = [int(a) for a in input().split()]
    c = Counter(S)
    vs = c.most_common(N)

    v = sorted([a[0] for a in vs if vs[0][1] == a[1]])
    for a in v:
        print(a)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from collections import defaultdict
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


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

    votes = defaultdict(int)

    m = 0
    top = []
    for _ in range(n):
        s = input()
        votes[s] += 1

        if votes[s] > m:
            m = votes[s]
            top = []

        if votes[s] == m:
            top.append(s)

    print(*sorted(top), sep='\n')


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = []
for i in range(n):
    s.append(input())
s = collections.Counter(s)
ans = []
k = list(s.most_common())
k_len = k[0][1]
for i in k:
    word, count = i
    if count == k_len:
        ans.append(word)
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N = int(input())
d = defaultdict(int)
max_n= 0
for n in range(N):
    s = input().strip()
    d[s] += 1
    if d[s] > max_n:
        max_n = d[s]

for s in sorted(d.keys()):
    if d[s] == max_n:
        print(s)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = [str(input()) for _ in range(N)]
hoge = Counter(S)
hoge = sorted(hoge.items(), key=lambda x: (-x[1], x[0]))
now = hoge[0][1]
for k, v in hoge:
    if now == v:
        print(k)
    else:
        break