Problem:


Score: 300 points

Problem Statement

We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it.

Print all strings that are written on the most number of votes, in lexicographical order.

Constraints

1 \leq N \leq 2 \times 10^5

S_i (1 \leq i \leq N) are strings consisting of lowercase English letters.

The length of S_i (1 \leq i \leq N) is between 1 and 10 (inclusive).

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

Print all strings in question in lexicographical order.

Sample Input 1

7
beat
vet
beet
bed
vet
bet
beet

Sample Output 1

beet
vet

beet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.

Sample Input 2

8
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo

Sample Output 2

buffalo

Sample Input 3

7
bass
bass
kick
kick
bass
kick
kick

Sample Output 3

kick

Sample Input 4

4
ushi
tapu
nichia
kun

Sample Output 4

kun
nichia
tapu
ushi



Sample input:
7
beat
vet
beet
bed
vet
bet
beet


Sample output:
beet
vet

Submission status: Accepted

Solution code:
import sys
import itertools
import collections
t = sys.stdin.read()
a = t.split("\n")[1:-1]
counter = collections.Counter(a)

for s in sorted([x[0]  for x in list(itertools.groupby(counter.most_common(), lambda x: x[1]).next()[1])]):
    print s

Submission status: Accepted

Solution code:
N = int(input())
S_dir = {}
max_count = 1
for _ in range(N):
    S = input()
    if S in S_dir:
        S_dir[S] += 1
        max_count = max(max_count, S_dir[S])
    else:
        S_dir[S] = 1

for s in sorted([k for k, v in S_dir.items() if v == max_count]):
    print(s)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
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 LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	d = {}
	ansl=[]
	max_c = 0
	for _ in range(N):
		s = IS()
		if not s in d:
			d[s]=1
		else:
			d[s]+=1

		if(d[s]>max_c):
				max_c=d[s]
				ansl=[]
				ansl.append(s)
		elif(d[s]==max_c):
			ansl.append(s)
	ansl.sort()
	printV(ansl)


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda x: [ns() for _ in range(x)]
nas = lambda: stdin.readline().split()

from collections import defaultdict

n = ni()
ss = nsn(n)

d = defaultdict(int)
for i in range(n):
    d[ss[i]] += 1

mx = max(d.values())
ans = []
for i, j in d.items():
    if mx == j:
        ans.append(i)

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

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())

d = defaultdict(int)

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

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

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

Submission status: Accepted

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

count = Counter(stri)
max_val = max(count.values())
sortedcount = sorted(count.items(), key=lambda x:x[0])
for s, cnt in sortedcount:
    if cnt == max_val:
        print(s)

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    N = int(input())

    c = Counter()
    M = 0
    for i in range(N):
        s = input()
        n = c[s] + 1
        c[s] = n
        M = max(M, n)

    for s in sorted((s for s, c in c.items() if c == M)):
        print(s)
main()

Submission status: Accepted

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

max_vote_count = max(polls.values())

results = []

for poll in polls:
  if polls[poll] == max_vote_count:
    results.append(poll)

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

Submission status: Accepted

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

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

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

mx = dic[0][1]
for i in dic:
    if i[1]==mx: print(i[0])
    else: break

Submission status: Accepted

Solution code:
N=int(input())
D={}
for i in range(N):
    s=input()
    if s not in D:
        D[s]=1
    else:
        D[s]+=1
#print(D)
L=list(D.items())
#print(L)
ANS=[]
NUM=0
for i in range(len(L)):
    if L[i][1]<NUM:
        continue
    elif L[i][1]==NUM:
        ANS.append(L[i][0])
    elif L[i][1]>NUM:
        ANS=[L[i][0]]
        NUM=L[i][1]
ANS.sort()
for i in ANS:
    print(i)

Submission status: Accepted

Solution code:
# ABC155 C
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))
from collections import defaultdict as dd
from operator import itemgetter
n=ni()
d=dd(int)
# s=[si() for i in range(n)]
for i in range(n):
    s=input()
    d[s]+=1

mv=0
for k,v in d.items():
    mv=max(mv,v)
ans=set()
for k,v in d.items():
    if mv==v:
        ans.add(k)
ans=list(ans)
ans.sort()
for aaa in ans:
    print(aaa)

Submission status: Accepted

Solution code:
n=int(input())
s=[]
for i in range(n):
    s.append(input())
s2=sorted(s)
now=s2[0]
ren=1
kind=[]
for i in range(1,n):
    if now!=s2[i]:
        kind.append([ren,now])
        now=s2[i]
        ren=1
    else:
        ren+=1
kind.append([ren,now])
kind2=sorted(kind,reverse=True)
max_=kind2[0][0]
ans=[]
ans.append(kind2[0][1])
for i in range(1,len(kind2)):
    if max_==kind2[i][0]:
        ans.append(kind2[i][1])
    else:
        break
#print(kind2)
ans2=sorted(ans)
for i in range(len(ans2)):
    print(ans2[i])

Submission status: Accepted

Solution code:
from collections import defaultdict


def resolve():
    n = int(input())
    d = defaultdict(int)
    for _ in range(n):
        d[input()] += 1
    m = max(d.values())
    l = sorted(x[0] for x in d.items() if x[1] == m)
    for i in l:
        print(i)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
from collections import Counter

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

counter = Counter(S)
counts = counter.most_common()
maxcnt = counts[0][1]
ans = []
for count in counts:
    if count[1] != maxcnt:
        break
    else:
        ans.append(count[0])
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)]

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

cnt = list(cnt.items())
cnt.sort(key = lambda x: x[0])
cnt.sort(key = lambda x: -x[1])

tmp = cnt[0][1]
for c in cnt:
    if tmp == c[1]:
        print(c[0])

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
S = [0]*N
ht = Counter()
for i in range(N):
    S[i] = input()
    ht[S[i]] += 1
l = []
bc = -1
for kw, count in ht.most_common():
    if (bc != -1)and(bc != count):
        break
    l.append(kw)
    bc = count

l.sort()

for i in l:
    print(i)

Submission status: Accepted

Solution code:
from math import factorial
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


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


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def MS(): return map(str, input().split())


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = False
show_flg = True


def main():
    N = I()
    s = [None] * N
    m = {}

    for i in range(N):
        s[i] = S()
        m[s[i]] = 0

    for i in range(N):
        m[s[i]] += 1

    arr = []
    for (key, v) in m.items():
        arr.append((v, key))

    arr.sort(reverse=True)

    m = arr[0][0]
    ans = []
    for i in range(len(arr)):
        if m == arr[i][0]:
            ans.append(arr[i][1])

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
scnt = Counter([input() for _ in range(n)])
x = scnt.most_common(1)[0][1]

ans = sorted([k for k, v in scnt.most_common() if v == x])
for s in ans:
    print(s)

Submission status: Accepted

Solution code:
n=int(input())
mx = 0
t=[]
d={}
for i in range(n):
	s=input()
	t+=[s]
	d[s] = d.get(s,0)+1
	mx = max(mx,d[s])
	
v=[]
d2={}
for s in t:
	if(d[s]==mx and d2.get(s,0)==0):
		v+=[s]
		d2[s] = d2.get(s,0)+1
	
v.sort()
for s in v:
	print(s)

Submission status: Accepted

Solution code:
N=int(input())
S=[input() for _ in range(N)]
import collections
C=collections.Counter(S)
Ca=list(sorted(C.items(), key=lambda x:x[1], reverse=True))
ca=Ca[0][1]
ans=[]
for c in Ca:
    if c[1]==ca: ans.append(c[0])
    else: break
ans.sort()
for a in ans:
    print(a)

Submission status: Accepted

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

for _ in range(N):
    s = input()
    if s not in dic:
        dic[s] = 0
    dic[s]+=1
    if dic[s]>m:
        m = dic[s]

re = {}
for key in dic:
    if dic[key] not in re:
        re[dic[key]] = []
    re[dic[key]].append(key)
    
for one in sorted(re[m]):
    print(one)

Submission status: Accepted

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

N = int(input())
for n in range(N):
  string = input()
  count[string] += 1
sore = sorted(count.items(), key=lambda x: x[1], reverse=True)
item = []
max = 0
max = sore[0][1]
for s in sore:
  if s[1] != max:
    break
  item.append(s[0])

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

Submission status: Accepted

Solution code:
from collections import Counter
n,*s = open(0).read().split()
s_count = Counter(s).most_common()
long_word=[]
max_count = s_count[0][1]
for word,count in s_count:
    if count < max_count: break
    long_word.append(word)

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

Submission status: Accepted

Solution code:
import collections
N = int(input())
S = [input() for _ in range(N)]
C = collections.Counter(S)
now = -1
ans = []
for v, i in C.most_common():
    if now == -1:
        now = i
    if now != i:
        break
    ans += [v]
print(*sorted(ans), sep='\n')

Submission status: Accepted

Solution code:
N = int(input())

S = dict()
for i in range(N):
    tmp = input()
    if tmp in S:
        S[tmp] += 1
    else:
        S[tmp] = 1

max_v = 0
for k, v in S.items():
    if max_v < v:
        max_v = v

S = sorted(S.items(), key=lambda x:x[0])
        
for k, v in S:
    if v == max_v:
        print(k)

Submission status: Accepted

Solution code:
n = int(input())
raw = []
for _ in range(n):
  raw.append(input())
raw.sort()
raw2 = [[-1,raw[0]]]
for i in range(1,n):
  if raw[i] == raw[i-1]:
    raw2[-1][0] -= 1
  else:
    raw2.append([-1,raw[i]])
raw2.sort()
maxi = raw2[0][0]
for x in raw2:
  if x[0] == maxi:
    print(x[1])
  else:
    break

Submission status: Accepted

Solution code:
n=int(input())
d={}
for i in range(n):
    s=input()
    try:
        if d[s]>0:
            d[s]+=1
    except:
        d[s]=1
l=[]
maxi=-1
for i in d:
    if d[i]>maxi:
        maxi=d[i]
for i in d:
    if d[i]==maxi:
        l.append(i)
l.sort()
for i in l:
    print(i)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    strings = {}
    for _ in range(N):
        s = input()
        if s in strings.keys():
            strings[s] += 1
        else:
            strings[s] = 1
    strings = sorted(strings.items(), key=lambda x: x[1], reverse=True)
    maximum = strings[0][1]
    answer = []
    for s in strings:
        if s[1] == maximum:
            answer.append(s[0])
    answer.sort()
    for ans in answer:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
'''
n = int(input())
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [int(input()) for i in range n]
p = [list(map(int, input().split()))]

a = input()
a, b = input().split()
a = [input() for i in range n]
'''
n = int(input())
a = [input() for i in range(n)]

ans = []

import collections
counter = collections.Counter(a)

max_h = max(counter.values())


for i in counter.items():
    #print(i)
    if i[1] == max_h:
        ans.append(i[0])
    else:
        pass

ans.sort()

[print(i) for i in ans]

Submission status: Accepted

Solution code:
n = int(input())
vote = {}
v_max = 0
for i in range(n):
    s = input()
    if s not in vote:
        vote[s] = 1
    else:
        vote[s] += 1
    
    if(v_max<vote[s]): v_max = vote[s]

res = []
for k in vote:
    if vote[k]==v_max: res.append(k)

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

Submission status: Accepted

Solution code:
from collections import *
n = int(input())
s = Counter(input() for _ in range(n))

l = sorted((-i, k) for k, i in  s.items())

m = l[0][0]
for i, k in l:
  if i != m:
    break
  print(k)

Submission status: Accepted

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

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

maximum = 0
for v in count.values():
    maximum = max(v, maximum)

ans = []

for k, v in count.items():
    if v == maximum:
        ans.append(k)

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

Submission status: Accepted

Solution code:
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)
from collections import defaultdict
n = inn()
h = defaultdict(int)
for i in range(n):
    s = ins()
    h[s] += 1
mx = max(list(h.values()))
ss = []
for s in h:
    if h[s]==mx:
        ss.append(s)
ss.sort()
for s in ss:
    print(s)

Submission status: Accepted

Solution code:
#counter 2次元リスト
def counter_list(A):
 def counter_dic(A): #counter 辞書
  dic = {}
  for a in A:
   dic[a] = dic.get(a,0) + 1
  return dic

 dic_ = counter_dic(A)
 B = []
 for k in dic_:
  B.append([dic_[k], k])
 B.sort(reverse=True) 
 return B

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

for i in range(N):
 s = input()
 S.append(s)
  
ans = []
cnt = counter_list(S)
for i in range(len(cnt)):
  if(cnt[i][0] == cnt[0][0]):
    ans.append(cnt[i][1])
  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())
l = []
for i in range(n):
    l.append(input())

c = Counter(l)
common = c.most_common()
max_count = common[0][1]
tmp = []
for s, num in common:
    if num == max_count:
        tmp.append(s)
    else:
        break

for item in sorted(tmp):
    print(item)

Submission status: Accepted

Solution code:
N = int(input())
S = ['0'] * N
for i in range(N):
    S[i] = input()
import collections
c = collections.Counter(S)
li = list(c.values())
ca = list(c.keys())
li.sort()
max = li[-1]
lia = []
for i in ca:
    if c[i] == max:
        lia.append(i)
lia.sort()
n = len(lia)
for i in range(n):
    print(lia[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

dic = {}
maxn = 1
for _ in range(n):
    s = input()
    if s in dic:
        dic[s] += 1
        maxn = max(maxn, dic[s])
    else:
        dic[s] = 1

dic = sorted(dic.items(), key=lambda x: x[0])
# print(dic)

for k, v in dic:
    if v == maxn:
        print(k)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(N)]
s_dict = {}
ans = ['{'] * N

for i in S:
    if i in s_dict:
        s_dict[i] += 1
    else:
        s_dict[i] = 1

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


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

ans.sort()
for i in ans:
    if i == '{':
        break
    else:
        print(i)

Submission status: Accepted

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

m = 0
for i in dic:
    m = max(dic[i],m)
    
lis = []
for i in dic:
    if dic[i] == m:
        lis.append(i)
        
lis.sort()
for i in lis:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
l = [input() for _ in range(n)]
d = {}
for w in l:
  d[w] = d.get(w,0)+1
m = max(d.values())
lt = sorted(d.items(),key=lambda k:-k[1])
ans = sorted([k for k,v in lt if v==m])
print(*ans,sep='\n')

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(a)
d = c.most_common()
e = d[0][1]
f = []
for i, j in d:
    if e == j:
        f.append(i)
f.sort()

for i in f:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())

d1 = {}
for _ in range(N):
    S = input()
    if S in d1:
        d1[S] += 1
    else:
        d1[S] = 1

d2 = {}
for key in d1:
    value = d1[key]
    if value in d2:
        d2[value].append(key)
    else:
        d2[value] = [key]

key = sorted(d2.keys(), reverse=True)[0]
for s in sorted(d2[key]):
    print(s)

Submission status: Accepted

Solution code:
from collections import defaultdict as d

n = int(input())
dico = d(int)
for i in range(n):
	s = input()
	dico[s] += 1
x = 0
tab = []
for k in dico.keys():
	if dico[k] > x:
		tab = [k]
		x = dico[k]
	elif dico[k] == x:
		tab.append(k)
tab.sort()
for i in tab:
	print(i)

Submission status: Accepted

Solution code:
N = int(input())
words = {}
ans = []
for i in range(N):
  w = input()
  words.setdefault(w, 0)
  words[w] += 1
m = max(list(words.values()))
for k, v in words.items():
  if v == m:
    ans.append(k)
ans.sort()
for w in ans:
  print(w)

Submission status: Accepted

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

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

max_s=0
for s in sdic:
  if sdic[s]>max_s:
    max_s=sdic[s]
    
#print(max_s)
slist=[]
for s in sdic:
  if sdic[s]==max_s:
    slist.append(s)
    
slist.sort()
#print(slist)
for s in slist:
  print(s)

Submission status: Accepted

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

_max = 0
_list = sorted(dic.items(), key=lambda x:x[0])
for s, num in sorted(_list, key=lambda x:x[1], reverse=True):
    if num < _max:
        break
    else:
        _max = num
        print(s)

Submission status: Accepted

Solution code:
N = int(input())

d = {}
maxval=0
for i in range(N):
    tmp = input()
    if tmp in d.keys():
        d[tmp] +=1
        maxval = max(d[tmp], maxval)
    else:
        d[tmp] = 1
        maxval = max(d[tmp], maxval)

        
ans = []
for istr in  d.keys():
    if d[istr] == maxval:
        ans += [istr]
ans.sort()
        
for istr in ans:
    print(istr)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(S)
mc = c.most_common()
L = []
for p in mc:
    if p[1] < mc[0][1]:
        break
    L.append(p[0])
L.sort()
for l in L:
    print(l)

Submission status: Accepted

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

cnt=list(cnt.items())
cnt=sorted(cnt,reverse=True,key=lambda x: x[1])
maxim=cnt[0][1]
ans=[]
for i in range(len(cnt)):
    if cnt[i][1]==maxim:
        ans+=[cnt[i][0]]
ans=sorted(ans)
print(*ans,sep='\n')

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
S = ['_']*n
for i in range(n):
    S[i] = input()
cS = Counter(S).most_common()
mx = cS[0][1]
ans = []
for i in range(len(cS)):
    if cS[i][1]==mx:
        ans.append(cS[i][0])
    else:
        break
ans = sorted(ans)
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)]
d = sorted(list(Counter(s).items()), key=lambda x:x[1], reverse=True)
MAX = d[0][1]
ans = []
for S,i in d:
  if i == MAX:
    ans.append(S)
  else:
    break
ans.sort()
for i in ans:
  print(i)

Submission status: Accepted

Solution code:
N = int(input())
d = {}
m = 1
for i in range(N):
    s = input()
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
        m = max(m, d[s])

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=lst(n)

b = Counter(arr)
ak=list(b.keys())
av=list(b.values())

am=max(av)
ans=[]
for i in range(len(ak)):
    if av[i]==am:
      ans.append(ak[i])
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7
    from collections import defaultdict
    
    N = II()
    countS = defaultdict(int)
    max_count = 0
    max_words = []
    for _ in range(N):
        s = input()
        countS[s] += 1
        if countS[s] > max_count:
            max_words = [s]
            max_count = countS[s]
        elif countS[s] == max_count:
            max_words.append(s)
    
    max_words.sort()
    for w in max_words:
        print(w)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
import math
import sys
from collections import Counter

n = int(input())
s = [input() for i in range(n)]
s_cnt = Counter(s).most_common()
# print(s_cnt)
cnt = s_cnt[0][1]
# print(cnt)
ans = []
for i in s_cnt:
    if i[1] == cnt:
        ans.append(i[0])
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from collections import deque, defaultdict

def comb(a, b):
    result = 1
    for i in range(b):
        result *= (a - i) / (i + 1)
    return result


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

    counter = defaultdict(int)

    max_value = 0
    for i in range(N):
        S = input().strip()
        counter[S] += 1

        if max_value < counter[S]:
            max_value = counter[S]

    most_freq_string = []
    for S in counter:
        if counter[S] == max_value:
            most_freq_string.append(S)

    most_freq_string = sorted(most_freq_string)
    for S in most_freq_string:
        print(S)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
max_num = 0
word_dict = {}
for i in range(n):
    w = input()
    temp = word_dict.get(w, 0) + 1
    word_dict[w] = temp
    if temp > max_num:
        max_num = temp

ans_list = []
for w in word_dict:
    if word_dict[w] == max_num:
        ans_list.append(w)

ans_list.sort()

for w in ans_list:
    print(w)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(S)
max_count = max(c.values())
word = [k  for k,v in c.items() if v == max_count]

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

Submission status: Accepted

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

    t = Counter(s)
    T = t.most_common()

    m = T[0][1]
    c = []
    for w, n in T:
        if n == m:
            c.append(w)
        else:
            break

    c.sort()
    print("\n".join(c))



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
d = dict()
m = 0
for i in range(n):
    s = input()
    d[s] = d.get(s, 0) + 1
    m = max(m, d[s])
res = list()
for k, v in d.items():
    if v == m:
        res.append(k)
res.sort()
for r in res:
    print(r)

Submission status: Accepted

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


c = collections.Counter(v)
x = 0
u = []
for t in c.most_common():
    if x>0 and t[1] != x:
        break
    else:
        x = t[1]
        u.append(t[0])

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

Submission status: Accepted

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

S.sort()
count = 0
hoge = ""
ans = [""]
ansnum = -1
for c in S:
    if hoge == c:
        count += 1
    else:
        count = 1
        hoge = c
    if count > ansnum:
        ans = [c]
        ansnum = count
    elif count == ansnum:
        ans.append(c)

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)


#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
愚直に操作を実装する
"""
#solution:
N=int(input())
S=[input() for i in range(N)]
import collections as cl
#print(S)
a=cl.Counter(S)
b=(a.most_common())
#print(b)
maxvalue=b[0][1]
ans=[]
for i in range(len(b)):
    if b[i][1] == maxvalue:
        ans.append(b[i][0])
for w in sorted(ans):
    print(w)
#print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])

Submission status: Accepted

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

def main():
    N = int(input())
    S = defaultdict(int)
    for _ in range(N):
        S[input().rstrip("\n")] += 1
    S = sorted(S.items(), key=lambda x:x[1])

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
s=[0]*n
for i in range(n):
    s[i] = input()
    
lis = set(s)
dic = {ss:0 for ss in lis }
for ss in s:
    dic[ss]+=1
    
ma = max(dic.values())
ans = [k for k,v in dic.items() if v==ma]
ans.sort()
print("\n".join(ans) )

Submission status: Accepted

Solution code:
from collections import defaultdict
a, *D,  = [s.split()[0] for s in open(0)] 
d = defaultdict(int)

for w in D:
    d[w] += 1 

d = sorted(d.items(),key = lambda x:(-x[1], x[0]))
max_v = d[0][1]
for v in d:
    if v[1] == max_v:
        print(v[0])

Submission status: Accepted

Solution code:
N = int(input())
count = {}
for _ in range(N):
    s = input()
    if s in count:
        count[s] += 1
    else:
        count[s] = 1
res = sorted(count.items(), key=lambda x: (-x[1], x[0]))
max_count = res[0][1]
res = [x[0] for x in res if x[1] == max_count]
print(*res, sep='\n')

Submission status: Accepted

Solution code:
from collections import Counter


n = int(input())
S = list()
for i in range(n):
    S.append(input())

count = Counter(S)
v_max = max(count.values())
keys = list()
for key, value in count.items():
    if value == v_max:
        keys.append(key)

keys = sorted(keys)
for key in keys:
    print(key)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
C = Counter(s)
L = C.most_common()
x = 0
ans = []
for i, l in enumerate(L):
    if i == 0:
        x = l[1]
        ans.append(l[0])
    elif x == l[1]:
        ans.append(l[0])
    else:
        break
ans.sort()
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
n = int(input())

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

MAX = 0
ans = []
for k, v in d.items():
    if v > MAX:
        ans = [k]
        MAX = v
    elif v == MAX:
        ans.append(k)


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

Submission status: Accepted

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

maxx = 0
for i in d:
    if d[i] > maxx:
        maxx = d[i]
ans = []
for i in d:
    if d[i] == maxx:
        ans.append(i)
for i in sorted(ans):
    print(i)