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 collections import Counter

n = int(input())
s = [input() for i in range(n)]
c = Counter(s).most_common()
m = c[0][1]
a = []
for i in c:
    s, k = i
    if k != m:
        break
    a.append(s)

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    S=[input() for i in range(N)]
    c=Counter(S)
    mc=c.most_common()
    num=mc[0][1]
    ans=[]
    for t in mc:
        if t[1]==num:
            ans.append(t[0])
        else:
            break
    ans.sort()
    for a in ans:
        print(a)
        
    
        

if __name__ == '__main__':
    main()

Submission status: Accepted

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

from collections import Counter
c = Counter(S)

max = None
ans = []
for k, v in sorted(c.items(), key=lambda x: -x[1]):
    if max is None:
        max = v
    if v == max:
        ans.append(k)
    else:
        break

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

Submission status: Accepted

Solution code:
N = int(input())
from collections import Counter
s = [input() for i in range(N)]
c = Counter(s)

i = c.most_common(1)[0][1]
ans = []
for a, b in c.most_common():
    if i != b:
        break
    ans.append(a)

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
#a = list(map(int,input().split()))
w = [input() for _ in range(n)]
c = collections.Counter(w)
k = c.most_common()
cnt = k[0][1]

ans = []
for i,j in k:
    if j == cnt:
        ans.append(i)
ans.sort()

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    ss=[SI() for _ in range(n)]
    cnt=Counter(ss)
    pv=-1
    for s,v in sorted(cnt.items(),key=lambda x:(-x[1],x[0])):
        if v!=pv and pv!=-1:break
        print(s)
        pv=v

main()

Submission status: Accepted

Solution code:
n = int(input())
count_dict = dict()
for i in range(n):
    x = input()
    if x in count_dict:
        count_dict[x] += 1
    else:
        count_dict[x] = 1
max_count = 0
for i in count_dict:
    if count_dict[i] > max_count:
        max_count = count_dict[i]
ans = []
for i in count_dict:
    if count_dict[i] == max_count:
        ans.append(i)
ans = sorted(ans)
for i in ans:
    print(i)

Submission status: Accepted

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

mx = 0

for key in mp.keys():
    if mx < mp[key]:
        mx = mp[key]

ans_list = []

for key in mp.keys():
    if mp[key] == mx:
        ans_list.append(key)

ans_list = sorted(ans_list)

for ans in ans_list:
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

ans = []
max_v = S.most_common()[0][1]
for key, v in S.most_common():
    if v != max_v:
        break
    ans.append(key)
for s in sorted(ans):
    print(s)

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

cnt = 0
for i, j in dic.items():
    cnt = max(cnt, j)
ans = []
for i, j in dic.items():
    if cnt == j:
        ans.append(i)
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = [input() for i in range(N)]
    from collections import Counter
    c = Counter(S)
    cnt = c.most_common()[0][1]
    ans = []
    for s in c.most_common():
        # print(s)
        if s[1] == cnt:
            ans.append(s[0])
    ans.sort()
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

ctr = Counter(S)
cnt_max =  max(ctr.values())

for s, c in sorted(ctr.items(), key=lambda x: (-x[1], x[0])):
    if c == cnt_max:
        print(s)

Submission status: Accepted

Solution code:
# ABC155c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    n = int(input())
    s = [input()[:-1] for _ in range(n)]
    from collections import Counter
    ma = 0
    ans = []
    for st, cou in Counter(s).most_common():
        ma = max(ma, cou)
        if cou == ma:
            ans.append(st)
        else:
            break
    ans.sort()
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def c_poll():
    from collections import Counter
    N = int(input())
    S = [input() for _ in range(N)]

    vote = Counter(S)
    most = (vote.most_common(1))[0][1]
    ans = [k for k, v in vote.items() if v == most]
    return '\n'.join(map(str, sorted(ans)))

print(c_poll())

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
strings = Counter([input() for _ in range(N)])
lst = sorted(list(strings.items()), key=lambda x: (-x[1], x[0]))
num = lst[0][1]
for l in lst:
    if l[1] != num: break
    print(l[0])

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(n):
    l.append(input())
l.sort()
l.append('1')
f=1
m=1
for i in range(n):
    if l[i]==l[i+1]:
        f+=1
    else:
        m=max(m,f)
        f=1
ans=[]
for i in range(n):
    if l[i]==l[i+1]:
        f+=1
    else:
        if f==m:
            ans.append(l[i])
        f=1
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
from collections import defaultdict
D = defaultdict(int)
N = int(input())
M = 0
for i in range(N):
    s = input()
    D[s] += 1
    M = max(M,D[s])
ans = []
for i in D:
    if D[i] == M:
        ans.append(i)
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
a = dict()
for i in range(n):
    x = input()
    if x not in a:
        a[x] = 1
    else:
        a[x] += 1

maxer = 0
for i in a:
    if a[i] > maxer:
        maxer = a[i]

out = []
for i in a:
    if a[i] == maxer:
        out.append(i)

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

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(S)
c_most_num = c.most_common()[0][1]
ans = []
for ci in c.most_common():
    if ci[1] == c_most_num:
        ans.append(ci[0])
ans.sort()

for a in ans:
    print(a)

Submission status: Accepted

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

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

c = Counter(ss)

ma = max(c.values())
d = dict(filter(lambda x : x[1] == ma, c.items()))
s = sorted(d.keys())

for e in s:
  print(e)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict
def main():
    N = int( input())
    S = [ input().strip() for _ in range(N)]
    d = defaultdict( int)
    for s in S:
        d[s] += 1
    m = 0
    for _, v in d.items():
        if v > m:
            m = v
    ANS = []
    for w, v in d.items():
        if v == m:
            ANS.append(w)
    ANS.sort()
    print("\n".join(ANS))
if __name__ == '__main__':
    main()

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[i] for i in D)
L = []
for i in D:
  if D[i] == M:
    L.append(i)
L.sort()
for i in range(len(L)):
  print(L[i])

Submission status: Accepted

Solution code:
n = int(input())

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

import collections
import itertools

counter = collections.Counter(A)
mode_v = counter.most_common()[0][-1]
it = itertools.takewhile(
    lambda kv: kv[-1] == mode_v, counter.most_common()
)

# print(*(k for k, v in it))
B = []
for k, v in it:
    B.append(k)
B = sorted(B)
for i in B:
    print(i)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
c = Counter(S)
max_num = 0
for i, v in c.items():
    max_num = max(max_num, v)

ret_list = []
for i, v in c.items():
    if v == max_num:
        ret_list.append(i)
ret_list.sort()
for i in ret_list:
    print(i)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = Counter([input() for i in range(N)])
k = max(S.values())
A = []
for s in S:
    if S[s]==k:
        A.append(s)
A.sort()
for a in A: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()
ans = []

for s in C:
    if s[1] == C[0][1]:
        ans.append(s[0])

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

Submission status: Accepted

Solution code:
N = int(input())
sdict = {}
mf = 0
for _ in range(N):
    s = input()
    if not s in sdict:
        sdict[s] = 1
        if mf == 0:
            mf = 1
    else:
        sdict[s] += 1
        if mf < sdict[s]:
            mf = sdict[s]

out = []
for k, f in sdict.items():
    if f == mf:
        out.append(k)
out.sort()
for o in out:
    print(o)

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

n = list(d.values())
n.sort()
max_n = n[-1]
ans = []
for k in d:
  if d[k] == max_n:
    ans.append(k)

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

Submission status: Accepted

Solution code:
import collections
n=int(input())
s=[input() for i in range(n)]
c=collections.Counter(s)
l=(c.most_common())
x=l[0][1]
ans=[]
for i in range(len(l)):
  if l[i][1]==x:
    ans.append(l[i][0])
  else:
    break
ans.sort()
for i in range(len(ans)):
  print(ans[i])

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
S = [input() for i in range(N)]
Sc = Counter(S)
Sc1 = Sc.most_common()
#print(Sc1)
m = Sc1[0][1]
ans = []
for s in Sc1:
    if s[1] == m:
        ans.append(s[0])
ans.sort()
for a in ans:
    print(a)

Submission status: Accepted

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

maxkey = None
result = []
for (val, key) in Counter(S).most_common():
  if maxkey == None:
    maxkey = key
    result.append(val)
  else:
    if maxkey == key:
      result.append(val)
    else:
      break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

s = list(Counter(S).most_common())
n = s[0][1]
ans = []

for i, j in s:
    if j == n:
        ans.append(i)

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

Submission status: Accepted

Solution code:
N = int(input())

table = {}

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

data = []
for S, count in table.items():
	data.append((-count, S))

data.sort()

i = 0
while True:
	print(data[i][1])
	i += 1
	if i >= len(data) or data[i][0] != data[0][0]:
		break

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
smap = {}
for i in range(n):
    smap[s[i]] = smap.get(s[i], 0) + 1
maxs = []
maxsmap = max(list(smap.values()))
for si in smap:
    if maxsmap == smap[si]:
        maxs.append(si)
maxs.sort()
for i in range(len(maxs)):
    print(maxs[i])

Submission status: Accepted

Solution code:

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

s2 = Counter(s)
mx = 0
for k in s2:
    mx = max(mx,s2[k])
ans = []
for k in s2:
    if s2[k]==mx:
        ans.append(k)
ans.sort()
for st in ans:
    print(st)

Submission status: Accepted

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

n = int(input())
s = [str(input().rstrip()) for _ in range(n)]
c = Counter(s)
d_sorted = sorted(c.items(), key=lambda x:x[1], reverse=True)

m = d_sorted[0][1]
ans = []
for key, v in d_sorted:
    if v == m:
        ans.append(key)
ans.sort()
print("\n".join(ans))

Submission status: Accepted

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

import collections
d=collections.defaultdict(int)
maxi=0
for i in a:
    d[i]+=1
    maxi=max(d[i],maxi)
b=[]
for word,cnt in d.items():
    if cnt==maxi:
        b.append(word)
b=sorted(b)
for i in b:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
vote=dict()
for i in range(n):
    try:
        vote[s[i]]+=1
    except:
        vote[s[i]]=1

ans=list()
mx=0
for s,c in vote.items():
    if mx<c:
        ans=list()
        ans.append(s)
        mx=c
    elif mx==c:
        ans.append(s)

ans.sort()

for s in ans:
    print(s)

Submission status: Accepted

Solution code:
from collections import Counter


def main():
    N = int(input())
    S = [input() for _ in range(N)]
    cnt = list(Counter(S).items())
    cnt.sort(reverse=True, key=lambda x: x[1])
    ans = list(filter(lambda x: x[1] == cnt[0][1], cnt))
    ans.sort()
    for s, c in ans:
        print(s)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

d = {}

m = 0
for i in range(N):
    S = input()
    if S in d:
        d[S] += 1
    else:
        d[S] = 1
    if d[S] > m: m = d[S]

ans_l = []

for k, v in d.items():
    if v==m: ans_l.append(k)

ans_l = sorted(ans_l)

for ans in ans_l:
    print(ans)

Submission status: Accepted

Solution code:
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

sys.setrecursionlimit(10**9)
mod = 10**7+9
inf = 10**20

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

n = I()
di = collections.defaultdict(int)

for i in range(n):
    s = S()
    di[s]+=1

mx = 0
l = []
for i in di:
    if mx<di[i]:
        l = [i]
        mx = di[i]
    elif mx==di[i]:
        l.append(i)
l.sort()
for v in l:
    print(v)

Submission status: Accepted

Solution code:
n=int(input())
c={}
for i in range(n):
    t=input()
    if t in c:
        c[t]+=1
    else:
        c[t]=1
c=sorted(c.items(),key=lambda x:(-x[1],x[0]))
p=c[0][1]
for i,j in c:
    if j==p:
        print(i)
    else:
        break

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
S = [input() for i in range(n)]
S = Counter(S).most_common()
max_v = S[0][1]
ans = []
for k ,v in S:
    if v == max_v:
        ans.append(k)
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


n = onem()

a = []

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

aa = s(a)

aa.sort(key = lambda x:x[1],reverse = True)

for i in range(len(aa)):
    if i == 0:
        co = aa[i][1]
        print(aa[i][0],end = "")
    else:
        if aa[i][1] == co:
            print(aa[i][0],end = "")
        else:
            break

Submission status: Accepted

Solution code:
from collections import Counter

input = raw_input
n = int(input())
s_list = [input() for _ in range(n)]
counter = Counter(s_list)

max_val = max(counter.values())
outs = sorted([key for key, val in counter.items() if val == max_val])

for out in outs:
    print(out)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    m = {}
    for i in range(N):
        S = input()
        m.setdefault(S, 0)
        m[S] += 1
    L = list(m.items())
    L.sort(key=lambda x: x[1])
    max_freq = L[-1][1]
    I = []
    for k, v in m.items():
        if v == max_freq:
            I.append(k)
    I.sort()
    print('\n'.join(I))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
import sys


def read() -> str:
    return sys.stdin.readline().rstrip()


def main():
    n = int(read())
    s = [read() for _ in range(n)]
    counter = Counter(s).most_common()
    c = counter[0][1]
    print(*sorted(ci[0] for ci in counter if ci[1] == c), sep="\n")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math
import bisect


def main():
    d = dict()
    for _ in range(int(input())):
        s = input()
        if s not in d:
            d[s] = 0
        d[s] += 1
    max_val = max(list(d.values()))
    '''
    print(d)
    print(max_val)
    '''
    A = []
    for a in d:
        if d[a] == max_val:
            A.append(a)
    A.sort()
    for a in A:
        print(a)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

s = [input() for i in range(n)]
c = Counter(s)
ans = []
cnt = 0
for k in sorted(c.keys()):
    if c[k] > cnt:
        ans = [k]
        cnt = c[k]
    elif c[k] == cnt:
        ans.append(k)
[print(i) for i in ans]

Submission status: Accepted

Solution code:
n=int(input())
dic={}
cnt=1
s=[input() for i in range(n)]
for i in s:
    if i in dic:
        dic[i]+=1
        cnt=max(cnt,dic[i])
    else:
        dic[i]=1
ans=[]
for i in s:
    if dic[i]==cnt:
        ans.append(i)
ans=list(set(ans))
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(N)]
from collections import Counter
ctr = Counter(S)
n = ctr.most_common()[0][1]

cands = []
for k in ctr.keys():
    if ctr[k] == n:
        cands.append(k)
cands.sort()
print(*cands, sep='\n')

Submission status: Accepted

Solution code:
n = int(input())
import collections
dat = []
for _ in range(n):
    dat.append(input())
c = collections.Counter(dat)
mcc = c.most_common(1)[0][1]
#print(mcc)
res = []
for k in c:
    if c[k] == mcc:
        res.append(k)
res.sort()
for i in range(len(res)):
    print(res[i])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, S: "List[str]"):
    from collections import Counter
    c = Counter(S)
    ans = []
    t = c.most_common()[0][1]
    # print(t)
    for k,v in c.most_common():
        if v == t:
            ans.append(k)

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



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())
s = [str(input()) for _ in range(n)]
s.sort()
t = list(set(s))
t.sort()
u = []
i = 0
j = 0
tmp = 0
while i < n:
    if s[i] == t[j]:
        tmp += 1
    else:
        u.append(tmp)
        tmp = 0
        j += 1
        i -= 1
    i += 1
u.append(tmp)
a = max(u)
for i in range(len(t)):
    if u[i] == a:
        print(t[i])

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    words = {}
    for i in range(n):
        s = input()
        if s not in words.keys():
            words[s] = 0

        words[s] += 1

    counts = []
    for i in words.keys():
        counts.append((words[i],i))

    counts.sort()
    highest = []
    max_count = counts[-1][0]
    while counts and counts[-1][0] == max_count:
        highest.append(counts.pop()[1])

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

main()

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(N)]
ans = {}
for s in S:
  ans[s] = ans.get(s, 0) + 1

m = max(ans.items(), key=lambda x: x[1])[1]
a = [s[0] for s in ans.items() if s[1] == m]
print(*sorted(a), sep="\n")

Submission status: Accepted

Solution code:
from collections import defaultdict
dd = defaultdict(int)

ma=0

N=int(input())
for i in range(N):
    S=input()
    dd[S]+=1
    if dd[S]>ma:
        ma=dd[S]
       
    
ans=[]   
for k,v in dd.items():
    if v==ma:
        ans.append(k)
        
ans.sort()

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int, S: "List[str]"):
    c = {}
    for s in S:
        if not s in c:
            c[s] = 0
        c[s] += 1
    tmp =list( c.items())
    tmp.sort(key = lambda x: (-x[1], x[0]))
    ret = [tmp[0][0]]
    for i in range(1, len(tmp)):
        if tmp[i][1] == tmp[0][1]:
            ret.append(tmp[i][0])
        else:
            break
    for r in ret:
        print(r)
    return

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:
def main():
    from collections import defaultdict
    N = int(input())
    count = defaultdict(int)
    maxcnt = 0
    for _ in range(N):
        s = input()
        count[s] += 1
        maxcnt = max(maxcnt, count[s])
    ss = [s for (s, n) in count.items() if n==maxcnt]
    for s in sorted(ss):
        print(s)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = int(input())
vote_dict = {}
for i in range(a):
    s = input()
    if s in vote_dict:
        vote_dict[s] += 1
    else:
        vote_dict[s] = 1
dic2 = sorted(vote_dict.items(), key=lambda x:x[1])
max_count = dic2[-1][1]
choose_list = []
for candidate in dic2:
    if(max_count == candidate[1]):
        choose_list.append(candidate[0])
print("\n".join(str(e) for e in sorted(choose_list)))

Submission status: Accepted

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

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

ans = []
for x in c:
    if x[1] == m:
        ans.append(x[0])
ans = sorted(ans)
for x in ans:
    print(x)

Submission status: Accepted

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

m = max(dic.values())
ls = sorted([k for k in dic if dic[k] == m])
for s in ls:
    print(s)

Submission status: Accepted

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

from collections import Counter

s = Counter(S)

k = s.most_common()

maxc = k[0][1]

l = []
for i in k:
    if i[1]<maxc:
        break
    else:
        l.append(i[0])

print(*sorted(l), sep="\n")

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
c = Counter(S)
max_times = max(c.values())
keys = [key for key, value in c.items() if value == max_times]
# print('keys', keys)
keys = sorted(keys)
print('\n'.join(keys))

Submission status: Accepted

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

d = defaultdict(int)

for word in words:
    d[word] += 1

m = max(d.values())

tmp = [word for word, freq in d.items() if freq == m]
for word in sorted(tmp):
    print(word)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = {}
    for _ in range(N):
        s = input()
        if s not in S:
            S[s] = 0
        S[s] += 1
    maxCount = max(S.values())
    res = [s for s, ct in S.items() if ct == maxCount]
    res = sorted(res)
    for s in res:
        print(s)


    

main()

Submission status: Accepted

Solution code:
N=int(input())

from collections import defaultdict
cnt=defaultdict(int)
maxcnt=0
for i in range(N):
  S=input()
  cnt[S]+=1
  if maxcnt<cnt[S]:
    maxcnt=cnt[S]

out=[]
keys=cnt.keys()
for k in keys:
  if cnt[k]==maxcnt:
    out.append(k)
    
out.sort()
n=len(out)
for i in range(n):
  print(out[i])

Submission status: Accepted

Solution code:
N = int(input())
dic = dict()
m = 0

for _ in range(N):
	S = str(input())
	if S in dic:
		dic[S] += 1
	else:
		dic[S] = 1
	m = max(m, dic[S])
		
a = list(dic.keys())
a.sort()

for t in a:
	if dic[t] == m:
		print(t)

Submission status: Accepted

Solution code:
from collections import Counter

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

C = Counter(S).most_common()
ans = []
m = C[0][1]
for i in range(len(C)):
    if C[i][1]==m:
        ans.append(C[i][0])
    else:
        break
ans.sort()
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    d = defaultdict(int)
    for _ in range(n):
        d[input()] += 1
    max_v = max(d.values())
    d_sorted = sorted(d)

    for word in d_sorted:
        if d[word] == max_v:
            print(word)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, S):
    c = Counter(S)
    m = -1
    ans = []
    for s, n in c.most_common(n=N):
        if m == -1:
            m = n
            ans.append(s)
        else:
            if n == m:
                ans.append(s)
            else:
                break
    return '\n'.join(sorted(ans))


def main():
    N = read_int()
    S = [read_str() for _ in range(N)]
    print(slv(N, S))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

c = list(c.items())
c.sort(reverse=True, key=lambda x: x[1])
mx = c[0][1]

ans = []
for k, v in c:
    if v == mx:
        ans.append(k)
    else:
        break

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

Submission status: Accepted

Solution code:
n = int(input())
S_dict = {}
for i in range(n):
    s = str(input())
    if s in S_dict.keys():
        S_dict[s] += 1
    else:
        new = {s:1}
        S_dict.update(new)

Ans = []
count = 0
for j in S_dict.values():
    count = max(j, count)

for key, value in S_dict.items():
    if value == count:
        Ans.append(key)

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

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    N = int(input())
    S = [input() for _ in range(N)]
    s = list(set(S))
    c = Counter(S)
    maxc = max(c.values())
    ans = []
    for i in range(len(s)):
        if c[s[i]] == maxc:
            ans.append(s[i])
    ans.sort()
    for i in range(len(ans)):
        print(ans[i])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = [S() for i in range(N)]
s = {}

tmp = 0
for i in range(N):
  if a[i] in s:
    s[a[i]] += 1
  else:
    s[a[i]] = 0
  tmp = max(tmp, s[a[i]])

ans = []
for i in range(N):
  if s[a[i]] == tmp:
    ans.append(a[i])
ans = list(set(ans))
ans.sort()
for i in ans:
  print(i)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
names = dict()
for _ in range(n):
    s = input().rstrip()
    if s not in names:
        names[s] = 1
    else:
        names[s] += 1

max_val = 0
for key in names.keys():
    if names[key] > max_val:
        max_val = names[key]
        ans = [key]
    elif names[key] == max_val:
        ans.append(key)

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