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())
L=[input() for i in range(n)]
LC=Counter(L)
m=max(LC.values())
R=[]
for k,v in LC.items():
    if v==m:
        R.append(k)
RS=sorted(R)
for s in RS:
    print(s)

Submission status: Accepted

Solution code:
import collections
n=int(input())
cnts=collections.Counter(input() for _ in range(n))
sort=sorted(cnts.items(),key=lambda x:(-x[1],x[0]))
most=sort[0][1]
for word,time in sort:
  if time==most:
    print(word)

Submission status: Accepted

Solution code:
n = int(input())

dic = {}

for i in range(n):
  s = input()
  tmp = dic.get(s, 0)
  dic[s] = tmp + 1
  
max_num = max(dic.values())

array = []

for key in dic.keys():
  if max_num == dic.get(key):
    array.append(key)
    
for s in sorted(array):
  print(s)

Submission status: Accepted

Solution code:
N = int(input())
# dicts = { 'aaa': 3, 'bbb': 2,,, }
dicts = {}
max_count = 0
max_strings = []

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

    if dicts[Si] == max_count:
        max_strings.append(Si)
    if dicts[Si] > max_count:
        max_count = dicts[Si]
        max_strings = [Si]

max_strings.sort()
for str in max_strings:
    print(str)

Submission status: Accepted

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

n = int(input())
A = {}

for i in range(n):
    x = input()
    A.update({x: A.setdefault(x, 0) + 1})

B = []
m = 0
for j in A:
    y = A.get(j)
    if y > m:
        m = y

for k in A:
    h = A.get(k)
    if h == m:
        B.append(k)

B.sort()

for t in B:
    print(t)

Submission status: Accepted

Solution code:
N = int(input())

dic = dict()
for n in range(N):
  key = input()
  dic[key] = dic.get(key, 0) + 1

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

for k in sorted(keys):
  print(k)

Submission status: Accepted

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

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

values, counts = zip(*c.most_common())
ans = []
for i in range(len(counts)):
    if counts[i] == MAX:
        ans.append(values[i])
ans.sort()

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

Submission status: Accepted

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

max = 1
for i in range(N):
    s = input()
    if s in d.keys():
        d[s] += 1
        if max < d[s]:
            max = d[s]
    else:
        d[s] = 1

r = []
for k,v in d.items():
    if v == max:
        r.append(k)

r.sort()
for p in r:
    print(p)

Submission status: Accepted

Solution code:
dic={}

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

#print(dic)

maxa=0
for val in dic:
    maxa=max(dic[val],maxa)
ans=[]
for val in dic:
    if dic[val]==maxa:
        ans.append(val)
print("\n".join(sorted(ans)))

Submission status: Accepted

Solution code:
n = int(input())
dicts = {}
for i in range(n):
    k = input()
    try:dicts[k] += 1
    except:dicts.setdefault(k, 1)
s = sorted(dicts.values(), reverse=True)
m = 0
for i in dicts:m = max(m, dicts[i])

ans = []
for i in dicts:
    if(dicts[i] == m):ans.append(i)

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

Submission status: Accepted

Solution code:
from collections import defaultdict


def solve():
    N = int(input())
    S_dict = defaultdict(int)
    S = ['' for _ in range(N)]
    for i in range(N):
        si = input()
        S[i] = si
        S_dict[si] += 1
    
    max_v = max(S_dict.values())
    tmp = [s for s in S if S_dict[s] == max_v]
    tmp.sort()
    p_ans = ''
    for ans in tmp:
        if p_ans != ans:
            print(ans)
            p_ans = ans


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from collections import Counter

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

C = Counter(Sn)
most = C.most_common()
max = most[0][1]
ans = []
for i in most:
    if max == i[1]:
        ans.append(i[0])
    else:
        break

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

Submission status: Accepted

Solution code:
dic={}
n=int(input())
for i in range(n):
    s=input()
    if s not in dic:
        dic[s]=1
    else:
        dic[s]+=1
m=max(dic.values())
ans=[i for i,v in dic.items() if v==m]
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())

ls = []
for _ in range(n):
  ls.append(input())
ls = sorted(ls)


ans =[ [ls[0],1] ]
tmp = ls[0]
for i in range(1,n):
  if ls[i] == tmp:
    ans[-1][1] += 1
  else:
    ans.append( [ls[i],1] )
    tmp = ls[i]
ans = sorted(ans, key = lambda x: (-1*x[1],x[0]))

m = ans[0][1]
for i in range(len(ans)):
  if ans[i][1] == m:
    print(ans[i][0])
  else:
    break

Submission status: Accepted

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

N = int(input())
S_count = {}
for n in range(N):
    s = input()
    if s not in S_count:
        S_count[s] = 0
    S_count[s] += 1

max_count = 0
max_strings = []
for k, v in S_count.items():
    if v > max_count:
        max_strings = []
        max_strings.append(k)
        max_count = v
    elif v == max_count:
        max_strings.append(k)

#print(max_strings)

# 辞書順に並び替え
sorted_strings = sorted(max_strings)

#print(sorted_strings)
for s in sorted_strings:
    print(s)

Submission status: Accepted

Solution code:
import sys
import math
import collections
n = int(input())
#a, b, c = map(int, input().split())
#s = input()
#a = list(map(int, input().split()))

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

c = collections.Counter(l)
x = c.most_common()
y = x[0][1]
ans = []
for i in range(len(x)):
  if x[i][1] != y:
    break

  ans.append(x[i][0])


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

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())

from collections import defaultdict
d = defaultdict(int)
maxnum = 0
maxli = []

for _ in range(n):
    s = input()
    d[s] += 1
    if d[s] > maxnum:
        maxnum += 1
        maxli = [s]
    elif d[s] == maxnum:
        maxli.append(s)
    
maxli.sort()

for l in maxli:
    print(l)

Submission status: Accepted

Solution code:
dic = {}
N = int(input())
for _ in range(N):
  s = input()
  if s not in dic:
    dic[s] = 0
  else:
    dic[s] += 1
max_val = max(dic.values())
keys_of_max_val = [key for key in dic if dic[key] == max_val]
keys_of_max_val.sort()
for item in keys_of_max_val:
  print(item)

Submission status: Accepted

Solution code:
import collections


def main():
    n = int(input())
    s = collections.defaultdict(int)
    m = -1
    for i in range(n):
        t = input()
        s[t] += 1
        if m < s[t]:
            m = s[t]

    f = sorted(filter(lambda x: s[x] == m, s.keys()))
    for e in f:
        print(e)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    N = int(input())
    S = [input().strip() for _ in range(N)]
    c = collections.Counter(S)
    l = c.most_common()

    ans = []
    tmp = 0

    for i, x in enumerate(l):
        if i == 0:
            tmp = x[1]

        if x[1] == tmp:
            ans.append(x[0])
        else:
            break
    
    ans.sort()

    for x in ans:
        print(x)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import collections

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

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

d=collections.Counter(s).most_common()

ans=[]
past=d[0][1]

for i,m in d:
    if past==m:
        ans.append(i)
        past=m
    else:
        break

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

Submission status: Accepted

Solution code:
n=int(input())
dic={}
maxx=-1
for _ in range(n):
    s=input()
    if s in dic:
        dic[s]+=1
        
    else:
        dic[s]=1
    maxx=max(maxx,dic[s])
for i in sorted(dic.keys()):
    if dic[i]==maxx:
        print(i)

Submission status: Accepted

Solution code:
read = input 
rn = lambda :list(map(int, read().split()))
d = {}
n, = rn()
for i in range(n):
    s = read()
#     print(s)
    if s not in d: d[s] = 0
    d[s] += 1
max_cnt = sorted(d.items(), key=lambda tp:tp[1])[-1][1] # max cnt
a1 = filter(lambda tp:tp[1] == max_cnt, d.items())
a2 = map(lambda tp:tp[0], a1)
for s in sorted(a2):
    print(s)

Submission status: Accepted

Solution code:
def num():
    return int(input())
def nums():
    return list(map(int,input().split()))

N = num()
used = {}
for _  in range(N):
    si = input()
    if si in used.keys():
        used[si] += 1
    else:
        used[si] = 0
l = sorted(used.items(),key=lambda x: x[1],reverse=True)
maxl = max([i[1] for i in l])
ans = []
for _,e in l:
    if e == maxl:
        ans.append(_)
    else:
        break
ans.sort()
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n = int(input())

s = [0] * n
for i in range(n):
    s[i] = input().strip()

import collections

counter = collections.Counter(s).most_common()

first = counter.pop(0)
answers = [first[0]]
value = first[1]

for c in counter:
    if c[1] != value:
        break
    answers.append(c[0])

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

Submission status: Accepted

Solution code:
from sys import stdin

if __name__ == '__main__':
    N = int(stdin.readline().rstrip())
    d = {}
    for i in range(N):
        poll = stdin.readline().rstrip()
        if not poll in d:
            d[poll] = 1
        else:
            d[poll] += 1
    maxv = max(d.values())
    max_k_list = [kv[0] for kv in d.items() if kv[1] == maxv]
    for key in sorted(max_k_list):
        print(key)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

n = int(input())
s = [sys.stdin.readline().strip() for _ in range(n)]

c = Counter(s)
kaisuu = c.most_common(1)[0][1]
kosuu = Counter([x[1] for x in c.most_common()])[kaisuu]

for label in sorted([x[0] for x in c.most_common(kosuu)]):
  print(label)

Submission status: Accepted

Solution code:
n = int(input())
# S = [None] * n
d = {}
m = 0
T = []
for i in range(n):
    s = input()
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
    m = max(m, d[s])

for key in d:
    if d[key] == m:
        T.append(key)

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

Submission status: Accepted

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

c = collections.Counter(s)
arr=c.most_common()
num=arr[0][1]
tmp=[]
for i in arr:
  if i[1]==num:
    tmp+=[i[0]]

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

Submission status: Accepted

Solution code:
N = int(input())

dic = {}

print()

for i in range(N):
    S = input()

    if S in dic:
        dic[S] += 1
    else:
        dic[S] = 1

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

max_num = dic2[0][1]

l = [p[0] for p in dic2 if p[1] == max_num]

l2 = sorted(l)

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

Submission status: Accepted

Solution code:
N = int(input())
d = {}
for i in range(N):
    S = input()
    if S in d:
        d[S] += 1
    else:
        d[S] = 1
M = max(d.values())
keys = [k for k, v in d.items() if v == M]
keys.sort()
for key in keys:
    print(key)

Submission status: Accepted

Solution code:
N = int(input())
C = {}
for _ in range(N):
    s = input().strip()
    if s not in C:
        C[s] = 0
    C[s] += 1
C = sorted(list(C.items()),key=lambda x:x[0])
C = sorted(C,key=lambda x:x[1],reverse=True)
k = C[0][1]
for i in range(len(C)):
    if C[i][1]==k:
        print(C[i][0])
    else:break

Submission status: Accepted

Solution code:
n = int(input())
a = {}
for i in range(n):
    s = input()
    if s not in a.keys():
        a[s] = 1
    else:
        a[s] += 1
mx = 0
for i in a.keys():
    if a[i] >= mx:
        mx = a[i]

l = []
for i in a.keys():
    if a[i] == mx :
        l.append(i)
l = sorted(l)
for i in l:
    print(i)



    

# h = sorted(h,reverse = True)
# print(sum(h[k:]))zz

# s,t= map(str, input().split())
# a,b= map(int, input().split())
# u = input()
# print("x"*len(u))

# if(u == s):
#     print(a-1,b)
# else:
#     print(a,b-1)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
l = []
for i in range(n):
    l.append(input())
c = Counter(l)
cm = c.most_common()
m = cm[0][1]
r = [x for x,i in cm if i==m]
r.sort()
for x in r:
    print(x)

Submission status: Accepted

Solution code:
#from fractions import gcd
#mod = 10 ** 9 + 7
#N = int(input())
#a = list(map(int,input().split()))
#a,b,c = map(int,input().split())
#ans = [0] * N
#math.ceilで切り上げ
#dp = [[0] * 4 for i in range(3)] #2次元配列初期化
#dp = [[[0] * 2 for i in range(3)] for j in range(5)]
#(ord('A'))でASCII出力 Aは65
import math
import string

def intinput():
    return int(input())

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

def splitintinput():
    return map(int,input().split())

N = intinput()
A = {}

for i in range(N):
    s = input()
    if s in A:
        A[s] += 1
    else:
        A[s] = 1
        
j = max(A.values())

maxalist = [kv[0] for kv in A.items() if kv[1] == j]
maxalist.sort()
for i in maxalist:
    print(i)

Submission status: Accepted

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

sc = Counter(s).most_common()

ans = [sc[0]]

if len(sc) == 1:
    pass
else:
    for i in range(1, n):
        if sc[i][1] == sc[0][1]:
            ans.append(sc[i])
        else:
            break

ans.sort()
for x in ans:
    print(x[0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
N = int(input())
S = []
for i in range(N):
    S.append(input())
s = Counter(S).most_common()
maximum = s[0][1]
tmp = []
for i in s:
    if i[1] == maximum:
        tmp.append(i[0])
    else:
        break
for i in sorted(tmp):
    print(i)

Submission status: Accepted

Solution code:
import collections
import itertools

n = int(input())
s = [0] * n
for i in range(n):
    s[i] = input()
c = collections.Counter(s)
cc = c.most_common()

ans = []

num = cc[0][1]
for i in cc:
    if i[1] == num:
        ans.append(i[0])

ans = sorted(ans)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

def solve(n, s):
    s_sorted = sorted(s.items(), key=lambda x: -x[1])
    pre = s_sorted[0][1]
    ans = []
    for word, count in s_sorted:
        if count != pre:
             break
        ans.append(word)
    for a in sorted(ans):
        print(a)
        

if __name__ == "__main__":
    n = int(sys.stdin.readline().strip())
    s = defaultdict(int)
    for _ in range(n):
        s_i = sys.stdin.readline().strip()
        s[s_i] += 1
    solve(n, s)

Submission status: Accepted

Solution code:

def main():
    d = dict()
    mx = 0
    n = int(input())
    for _ in range(n):
        s = input()
        if not s in d:
            d[s] = 1
        else:
            d[s] += 1

        if d[s] > mx:
            mx = d[s]
    lst = [s for s in d.keys() if d[s] == mx]
    lst.sort()
    for s in lst:
        print(s)



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
l = sorted(d.items(), key=lambda x:x[1], reverse=True)
n=l[0][1]
s_list=[]
for c in l:
  if c[1] != n:
    break
  s_list.append(c[0])
s_list.sort()
for s in s_list:
  print(s)

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
m = 0
d = defaultdict(int)
for i in range(N):
    S = input()
    d[S] += 1
    m = max(m, d[S])

X = []
for s in d:
    if d[s] == m:
        X.append(s)
X.sort()
for s in X:
    print(s)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n = int(input())
    s = {}
    o = []
    for i in range(n):
        tmp = input()
        if tmp not in s.keys():
            s[tmp] = 1
        else:
            s[tmp] += 1
    s_sorted = sorted(s.items(), key=lambda x:x[1], reverse = True)
    
    l = s_sorted[0][1]
    for i in s_sorted:
        if i[1] == l:
            o.append(i[0])
        else:
            break
    
    for i in sorted(o):
        print(i)

Submission status: Accepted

Solution code:
n = int(input())

import collections

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

sc = collections.Counter(s)
m = sc.most_common()

cc = m[0][1]
r = []
for v, c in m:
  if c != cc:
    continue
  r.append(v)
  
for v in sorted(r):
  print(v)

Submission status: Accepted

Solution code:
def A():
    A, B, C = map(int, input().split())
    if A == B or B == C or A == C:
        if (A+B+C) != A*3:
            print('Yes')
            return
    print('No')

def B():
    N = int(input())
    A = [int(i) for i in input().split()]
    for i in A:
        if i%2==0 and not (i%3==0 or i%5==0):
            print('DENIED')
            return
    print('APPROVED')

from collections import Counter
from itertools import takewhile
def C():
    N = int(input())
    lst = []
    for i in range(N):
        lst.append(input())

    c = Counter(lst)
    m = max(c.values())
    r = [x for x, _ in takewhile(lambda x: x[1]==m, c.most_common())] 
    for s in sorted(r):
        print(s)
C()

Submission status: Accepted

Solution code:
N = int(input())
s_list = {}
already = set()
for _ in range(N):
    s = input()
    if s in already:
        s_list[s] += 1
    else:
        s_list[s] = 0
    already.add(s)

max_value = max(s_list.values())
max_kv_list = [kv for kv in s_list.items() if kv[1] == max_value]
kv_list = []
for kv in max_kv_list:
    kv_list.append(kv[0])
kv_list.sort()
for kv in kv_list:
    print(kv)

Submission status: Accepted

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

s.sort()
ac = 0
ans = []
i = 0
while i < n:
  temp = s[i]
  j = i + 1
  while j < n:
    if s[j] == temp:
      j += 1
    else:
      j -= 1
      break
  if j == n:
    j -= 1
  c = j - i + 1
  if c > ac:
    ans = [temp]
    ac = c
  elif c == ac:
    ans.append(temp)
  i = j + 1

for x in ans:
  print(x)

Submission status: Accepted

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

for i in range(N):
  tmp = input()
  
  d[tmp] = d.get(tmp,0) + 1
  
m = max(d[i] for i in d)
max_list = [i for i in d if d[i] == m]

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

Submission status: Accepted

Solution code:
N = input()
Ws = {}
for i in range(int(N)):
  a = input()
  if a in Ws.keys():
    Ws[a] += 1
  else:
    Ws[a] = 0
m = max(Ws.values())
for i in sorted([k for k, v in Ws.items() if v == m]):
  print(i)

Submission status: Accepted

Solution code:
import collections

n = int(input())
s = list(input() for i in range(n))


c = collections.Counter(s)

cm = c.most_common()

ans = []


max_num = cm[0][1]
for string, num in cm:
    if max_num == num:
        ans.append(string)

ans.sort()

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

Submission status: Accepted

Solution code:
n = int(input())
l = []
ll = [0] * n

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

l.sort()

i = 0

while i < n:
    cnt = 1

    while i + cnt < n and l[i] == l[i + cnt]:
        cnt += 1

    ll[i] = cnt
    i += cnt

m = max(ll)

for x in range(n):
    if ll[x] == m:
        print(l[x])

Submission status: Accepted

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

for i in range(N):
  if S[i] not in str_dict.keys():
    str_dict[S[i]] = 1
  else:
    str_dict[S[i]] += 1
else:
  max_val = max(str_dict.values())
  for i in str_dict:
    if str_dict[i] == max_val:
      answer.append(i)
  else:
    answer.sort()
    for i in range(len(answer)):
      print(answer[i])

Submission status: Accepted

Solution code:

n = int(input())
s = [ str(input()) for _ in range(n)]
d = {}
for i in range(n):
      if s[i] in d:
            d[s[i]] +=1
      else:
            d[s[i]] = 1
d = sorted(d.items(),key=lambda x: x[1],reverse=True)
m = d[0][1]
ans = []
for i in range(len(d)):
      if d[i][1]==m:
            ans.append(d[i][0])
      else:
            break
ans.sort()
for i in range(len(ans)):
      print(ans[i])

Submission status: Accepted

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

N = int(input())

X = {}
M = 0

for i in range(N):
    S = input()
    if not (S in X):
        X[S] = 0

    X[S] += 1
    M = max(M, X[S])

Y = sorted(map(lambda item:item[0],
               filter(lambda item:item[1] == M, X.items())))

for y in Y:
    print(y)

Submission status: Accepted

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

from collections import Counter

def main():
  n = int(input())
  Ss = [input().strip() for _ in range(n)]
  counts = sorted(Counter(Ss).items(), key=lambda x:x[1], reverse=True)
  max = counts[0][1]
  Ss_max = []
  for S, count in counts:
    if count != max:
      break
    Ss_max.append(S)
  print('\n'.join(sorted(Ss_max)))



if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for _ in range(N)]
from itertools import groupby
S = sorted(S)
g = groupby(S)
ans = []
j = 0
for key,group in g:
  i = len(list(group))
  if i>j:
    ans = [key]
    j = i
  elif i==j:
    ans.append(key)
  else:
    continue

for a in ans:
  print(a)

Submission status: Accepted

Solution code:
from collections import Counter

def readlines(n):
    for _ in range(n):
        yield input()

def main():
    N = int(input())
    c = Counter(readlines(N))
    maxi = max(c.values())
    for k, v in sorted(c.items(), key=lambda x: x[0]):
        if v == maxi:
            print(k)




main()

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = [input() for _ in range(n)]
c = collections.Counter(s)
a = c.most_common()
max = a[0][1]
a.sort(key=lambda x: x[0])
for i in range(len(a)):
    if a[i][1]==max:
        print(a[i][0])

Submission status: Accepted

Solution code:
import collections

n=int(input())

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

scount=collections.Counter(s)
#print(scount[1][1])
maxc=scount.most_common()[0][1]
#print(maxc)
ans=[]
for k, v in scount.items():
    if v==maxc:
        ans.append(k)


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

Submission status: Accepted

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

for _ in range(N):
    S = input()
    cnt.setdefault(S, 0)
    cnt[S] += 1

mx = max(cnt.values())
ans = sorted([v for v,c in cnt.items() if mx == c])
for v in ans:
    print(v)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import sys
import math
import numpy as np
from collections import deque
from itertools import combinations
from functools import lru_cache
sys.setrecursionlimit(10**9)

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

    dic = {}
    for s in S:
        if not(s in dic.keys()):
            dic[s] = 1
        else:
            dic[s] += 1

    max = 0
    ans = []
    for s, count in dic.items():
        if count > max:
            ans = [s]
            max = count
        elif count == max:
            ans.append(s)

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



if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    S = args[1:]
    D = {}
    for s in S:
        if s not in D:
            D[s] = 1
        else:
            D[s] += 1
    m = max(D.values())
    A = [a[0] for a in sorted(D.items(), key=lambda x: (
        -x[1], x[0])) if a[1] == m]

    return '\n'.join(A)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

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

result = []
for k, v in D.items():
    if v == max_num:
        result.append(k)

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

Submission status: Accepted

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

c = collections.Counter(s)

ans = []
most = c.most_common()
max_size = most[0][1]
for i in range(len(most)):
    if max_size != most[i][1]:
        break
    else:
        ans.append(most[i][0])

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
from collections import defaultdict

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n = ni()
d = defaultdict(int)
for _ in range(n):
    s = ns()
    d[s] += 1
d = sorted(d.items(), key = lambda x:x[1], reverse=True)
ki, vi = d[0]
k = [ki]
for ki, v in d[1:]:
    if v == vi:
        k.append(ki)
k.sort()
for ki in k:
    print(ki)

Submission status: Accepted

Solution code:
from collections import Counter


N = int(input())

str_list = []

ctr_list = Counter()

for i in range(N):
    ctr_list[input()] += 1

sort_list = []
max_value = 0
for each_str in ctr_list.most_common():
    if max_value <= each_str[1]:
        max_value = each_str[1]
        sort_list.append(each_str[0])

for each_str in sorted(sort_list):
    print(each_str)

Submission status: Accepted

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

N = int(input().split()[0])
c_list = []
c_dict = {}
cc_dict = {}
max_v = -float("inf")

for _ in range(N):
    c = input()
    c_list.append(c)
    if c in c_dict:
        v = c_dict[c] + 1
        c_dict[c] = v
    else:
        v = 0
        c_dict[c] = 0
        # cc_dict[0] = c
    if v in cc_dict:
        cc_dict[v].append(c)
    else:
        cc_dict[v] = [c]

    if max_v < v:
        max_v = v

k_list = cc_dict[max_v]
k_list = list(sorted(k_list))
ans = "\n".join(k_list)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = {}
for i in range(N):
    new_input = input()
    if new_input not in S:
        S[new_input] = 0
    S[new_input] += 1

result = []
max_num = max(S.values())
for item in S:
    if S[item] == max_num:
        result.append(item)

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

Submission status: Accepted

Solution code:
N = int(input())

dict = dict()

written_max = 0

for i in range(N):
	s = input()
	if s in dict:
		dict[s] += 1
	else:
		dict[s] = 1
	written_max = max(written_max,dict[s])

dict_sorted = sorted(dict.items(), key=lambda x:x[0])

for item in dict_sorted:
	if item[1] == written_max:
		print(item[0])

Submission status: Accepted

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

def solve(N: int, S: "List[str]"):
    count_dict = collections.defaultdict(int)
    for s in S:
        count_dict[s] += 1
    
    largest = heapq.nlargest(1, [y for x, y in count_dict.items()])[0]
    answer_list = []
    for k, v in count_dict.items():
        if v == largest:
            answer_list.append(k)
    answer_list = sorted(answer_list)
    for ans in answer_list:
        print(ans)
    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:
from collections import Counter

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

counter = Counter(s)
index = 0
ans = []
for k, v in counter.most_common():
    if index == 0:
        max_v = v
        ans.append(k)
    else:
        if v == max_v:
            ans.append(k)
        else:
            break
    index += 1
ans = sorted(ans)
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
counts = defaultdict(int)

for _ in range(n):
    counts[input().strip()] += 1

vec = sorted([(value, key) for key, value in counts.items()])
best = vec[-1][0]
keys = sorted([key for value, key in vec if value == best])
for key in keys:
    print(key)

Submission status: Accepted

Solution code:
n = int(input().rstrip())

current_max = 0
current = []
table = {}

for i in range(n):
    s = input().rstrip()
    table[s] = table[s] + 1 if table.get(s) is not None else 0
    if table[s] > current_max:
        current = [s]
        current_max = table[s]
    elif table[s] == current_max:
        current.append(s)
    else:
        continue

current.sort()

for word in current:
    print(word)

Submission status: Accepted

Solution code:
import collections

n = int(input())
lst = []
for _ in range(n):
    lst.append(input())
ans = []

cnt = collections.Counter(lst).most_common()

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

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
p=[]
for i in range(n):
	s=input().rstrip()
	p.append(s)
p.sort()
ans=0
cnt=1
for i in range(n-1):
	if p[i]==p[i+1]:
		cnt+=1
	else:
		ans=max(ans,cnt)
		cnt=1
ans=max(ans,cnt)
q=[]
for i in range(n-ans+1):
	if p[i]==p[i+ans-1]:
		q.append(p[i])
q.sort()
for i in range(len(q)):
	print(q[i])

Submission status: Accepted

Solution code:
n=int(input())

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

c=collections.Counter(sl)
# print(c)
d=(c.most_common())

e=[d[0][0]]
tmp=d[0][1]
for i,j in d:
    if tmp==j:
        e.append(i)
    else:
        break
e=list(set(e))
e.sort()
for i in e:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())

S = {}

for i in range(N):
    s = input()
    S[s] = S.get(s, 0) + 1

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

t = []
max_v = 0
for k, v in SS:
    if v < max_v:
        break

    t.append(k)
    max_v = v 

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

Submission status: Accepted

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

li = []
a = L[0][1]
for i in range(len(L)):
    if L[i][1] == a:
        li.append(L[i][0])
li.sort()
for i in range(len(li)):
    print(li[i])