Problem:


Score: 300 points

Problem Statement

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

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

Constraints

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

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

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

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

Print all strings in question in lexicographical order.

Sample Input 1

7
beat
vet
beet
bed
vet
bet
beet

Sample Output 1

beet
vet

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

Sample Input 2

8
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo

Sample Output 2

buffalo

Sample Input 3

7
bass
bass
kick
kick
bass
kick
kick

Sample Output 3

kick

Sample Input 4

4
ushi
tapu
nichia
kun

Sample Output 4

kun
nichia
tapu
ushi



Sample input:
7
beat
vet
beet
bed
vet
bet
beet


Sample output:
beet
vet

Submission status: Accepted

Solution code:
N = int(input())
dic = {}
maxi = 0
res = []
for _ in range(N):
    s = input()
    if s in dic.keys():
        dic[s] += 1
    else:
        dic[s] = 1
    if dic[s] > maxi:
        maxi = dic[s]
for key in dic.keys():
    if dic[key] == maxi:
        res.append(key)

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

Submission status: Accepted

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

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

m = 0
for k in dict:
  m = max(dict[k], m)

arr = []

for k in dict:
  if dict[k] == m:
    arr.append(k)

arr.sort()

for k in arr:
  print(k)

Submission status: Accepted

Solution code:
import collections
L = [input() for x in range(int(input()))]
L = collections.Counter(L)
LMC = L.most_common()
max_N = L.most_common()[0][1]
R = []
for x in LMC:
    if x[1] == max_N:
        R.append(x[0])
R.sort()
print("\n".join(R))

Submission status: Accepted

Solution code:
N=int(input())
d={}
cnt=0
for i in range(N):
  s=input()
  if s not in d:
    d[s]=1
  else:
    d[s]+=1
  if cnt<d[s]:
    cnt=d[s]
ans=[]
for k in d:
  if d[k]==cnt:
    ans.append(k)
ans=sorted(ans)
for i in ans:
  print(i)

Submission status: Accepted

Solution code:
import collections

n = int(input())

s = []

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

c = collections.Counter(s)
cc = c.most_common()
mx = cc[0][1]
cc.sort(key = lambda x:x[0])

for i in range(len(cc)):
    if cc[i][1] == mx:
        print(cc[i][0])

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
s=[input() for i in range(n)]
d=dict()
for i in range(n):
  if s[i] not in d:
    d[s[i]]=1
  else:
    d[s[i]]+=1
d=list(d.items())
d.sort()
d.sort(key=itemgetter(1),reverse=True)
maxi=d[0][1]
for i in range(len(d)):
  if d[i][1]==maxi:
    print(d[i][0])
  else:
    exit()

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
S = [input() for _ in range(N)]
d = defaultdict(int)
maxn = 0

for i in range(N):
    d[S[i]] += 1
    maxn = max(maxn, d[S[i]])

ans = []
for k, v in d.items():
    if v == maxn:
        ans.append(k)
ans.sort()
for s in ans:
    print(s)

Submission status: Accepted

Solution code:


#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = 'APPROVED'
no = 'DENIED'

def main():
    n = ii()
    s = []
    for i in range(n):
        tmp = input()
        s.append(tmp)
    
    s = sorted(s)

    anslist = []

    cnt = 0
    cntmax = 0
    tmp = ""
    for i in range(n):
        if cntmax == 0:
            anslist.append(s[i])
        if s[i] == tmp:
            cnt+=1
            if cntmax == cnt:
                anslist.append(s[i])
            if cntmax < cnt:
                cntmax = cnt
                anslist = [s[i]]
        else:
            cnt = 0
            tmp = s[i]
    for i in range(len(anslist)):
        print(anslist[i])



main()

Submission status: Accepted

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

from collections import Counter

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

C = Counter(S)

lst = [[] for _ in range(N + 1)]

saidai = 0
for c in C:
    lst[C[c]].append(c)
    saidai = max(saidai, C[c])

ans = lst[saidai]
ans.sort()
# print (ans)
for tmp in ans:
    print (tmp, end = '')

Submission status: Accepted

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

M = []
C = collections.Counter(S)
max = C.most_common()[0][1]
for c in C.most_common():
    if c[1] == max:
        M.append(c[0])
M.sort()
for m in M:
    print(m)

Submission status: Accepted

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

import sys
import math
import itertools

def main():
    n = int(sys.stdin.readline())
    ss = [sys.stdin.readline().strip() for _ in range(n)]

    ss.sort()
    votes = [(-sum(1 for _ in g), k) for k, g in itertools.groupby(ss)]
    votes.sort()

    for v, k in votes:
        if v != votes[0][0]:
            break
        print(k)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
words = []
for _ in range(N):
    words.append(input())
count_table = {}
for w in words:
    if w in count_table:
        count_table[w] += 1
    else:
        count_table[w] = 0
best_count = 0
best_words = []
for w in count_table:
    if best_count < count_table[w]:
        best_count = count_table[w]
        best_words = [w]
    elif best_count == count_table[w]:
        best_words.append(w)
for w in sorted(best_words):
    print(w)

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())

dic = defaultdict(lambda :0)

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

m = max(dic.values())

D = [k for k, v in dic.items() if v == m]
D.sort()
for s in D:
    print(s)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

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

d = defaultdict(int)
for i in range(N):
    d[S[i]] += 1

k = 0
ans = []
for x in d.items():
    if x[1] > k:
        k = x[1]
        ans = [x[0]]
    elif x[1] == k:
        ans.append(x[0])
    else:
        pass

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

    max_d = max(d.values())
    ans = []
    for key, value in d.items():
        if value == max_d:
            ans.append(key)
    ans.sort()
    for a in ans:
        print(a)
    
    



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
dic = {}
for i in range(n):
    word = input()
    if word in dic:
        dic[word] += 1
    else:
        dic[word] = 1
answer = []
max_dic = 0
for word, cnt in dic.items():
    if cnt > max_dic:
        max_dic = cnt
for word, cnt in dic.items():
    if cnt == max_dic:
        answer.append(word)
answer.sort()
for ans in answer:
    print(ans)

Submission status: Accepted

Solution code:
import collections

N = int(input())
S = [input() for _ in range(N)]
S_count = collections.Counter(S)
S_count_sort = sorted(S_count.items(), key=lambda x: x[1], reverse=True)

ans_list = []
for i, k in enumerate(S_count_sort):
    if i == 0:
        before_v = k[1]
        ans_list.append(k[0])
    else:
        if k[1] != before_v:
            break
        else:
            ans_list.append(k[0])
ans_list.sort()
for ans in ans_list:
    print(ans)

Submission status: Accepted

Solution code:
import collections 

N = int(input())
string = [""] * N

for i in range(N):
  s = input()
  string[i] = s

freq = collections.Counter(string)
mfreq = freq.most_common()
mtime = mfreq[0][1]

mosts = sorted([mfreq[i][0] for i in range(len(mfreq)) if mfreq[i][1] == mtime])

for s in mosts:
  print(s)

Submission status: Accepted

Solution code:
n = int(input())
sub = dict()
ans = 0
for i in range(n):
  key = input()
  if key in sub:
    sub[key] = sub[key] + 1
    if ans < sub[key]:
      ans = sub[key]
  else:
    sub[key] = 1
    if ans < sub[key]:
      ans = sub[key]
      
sub = sorted(sub.items())

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
MOD = 10**9+7
 

def main():
    n = int(input())
    d = dict()
    for _ in range(n):
        s = input()
        d.setdefault(s, 0)
        d[s] += 1
    d = sorted(d.items(), key=lambda x: (-x[1], x[0]))
    maxc = d[0][1]
    for row in d:
        if row[1]<maxc:
            exit()
        print(row[0])
 
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
result = dict()

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

result = sorted(result.items(), key = lambda x:x[1])[::-1]
output, i, highest = [result[0][0]], 1, result[0][1]

if len(result) != 1:
    while result[i][1] == highest:
        output.append(result[i][0])
        i += 1
        if i == N:
            break

for name in sorted(output):
    print(name)

Submission status: Accepted

Solution code:
N = int(input())
S = [0]*N

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

S = sorted(S)
S.append(-1)

#print(S)

counta = []

times = 1
for i in range(1, N+1):
    if S[i-1] == S[i]:
        times += 1
    else:
        counta.append((times, i-1))
        times = 1

#print(counta)

M = max(counta, key=lambda x: x[0])[0]

#print(M)

for i in range(len(counta)):
    if counta[i][0] == M:
        print(S[counta[i][1]])

Submission status: Accepted

Solution code:
N = int(input())
d = {}
for _ in range(N):
  s = input()
  if not s in d:
    d[s] = 1
  else:
    d[s] += 1
x = sorted(list(d.items()), key=lambda x:x[1], reverse=True)
n = 0
l = []
for k, v in x:
  if v >= n:
    n = v
    l.append(k)
for y in sorted(l):
  print(y)

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
    #sorted_count_dict = sorted(count_dict.items(), key=lambda x: x[1], reverse=True)

    largest = heapq.nlargest(1, [y for x, y in count_dict.items()])[0]
    list = []
    for k, v in count_dict.items():
        if v == largest:
            list.append(k)
    answer_list = sorted(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 defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	D = defaultdict(int)
	for i in range(N):
		S = input()
		D[S] += 1

	L = []
	for i in D:
		L.append([D[i], i])
	L = sorted(L)
	X = len(L)
	c = L[-1][0]
	ans = []
	for i in range(X):
		if L[-1 - i][0] == c:
			ans.append(L[-1 - i][1])
		else:
			break

	M = len(ans)
	for i in range(M):
		print(ans[-1 - i])


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
#map(int,input().split())
n=int(input())
s=[]
for i in range(n):
    s.append(input())
s.sort()
g=[]
buf=s[0]
count=0
for i in range(n):
    if buf==s[i]:
        count+=1
    else:
        g.append((count,buf))
        buf=s[i]
        count=1
g.append((count,buf))
g.sort(reverse=True)
idx=g[0][0]
h=[]
import sys
for i,j in g:
    if i==idx:
        h.append(j)
h.sort()
for j in h:
    print(j)

Submission status: Accepted

Solution code:
N = int(input())
S = {}
for _ in range(N):
    s = input()
    if s in S.keys():
        S[s] += 1
    else:
        S[s] = 1
S = sorted(S.items(), key=lambda x:x[1])
maxi = S[-1][1]
ans = []
for s in reversed(S):
    if s[1] == maxi:
        ans.append(s[0])
ans.sort()
for a in ans:
    print(a)

Submission status: Accepted

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

C = collections.Counter(S)
max_c=C.most_common()[0][1]

values, counts = zip(*C.most_common())
min_i=len(counts)
for i in range(len(counts)):
    if counts[i]<max_c:
        min_i = i
        break
ans = sorted(list(values)[:min_i])

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

Submission status: Accepted

Solution code:
n=int(input())
#A,B,C=map(int,input().split())
S=[]
C={}
for a in range(n):
    s=input()
    if not s in C:
        C[s]=1
    else:
        C[s]+=1
A=[]
for a,b in C.items():
    A.append([b,a])
A.sort(key=lambda x:(-x[0],x[1]))
max_=A[0][0]
for a in A:
    if(a[0]!=max_):break
    print(a[1])

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

n = int(input())
l = [input() for _ in range(n)]
d = defaultdict(int)
for i in range(len(l)):
    d[l[i]] += 1
d = sorted(d.items(), key=lambda x:-x[1])
ans = []
num = d[0][1]
for i in range(len(d)):
    if d[i][1] != num:
        break
    ans.append(d[i][0])
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
n = int(input())
s = {}
max = 1

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

result = []
for k, v in s.items():
    if v == max:
        result.append(k)
result.sort()
for v in result:
    print(v)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(S)

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

ans_list = []

for item in c.most_common():
    if target == item[1]:
        ans_list.append(item[0])
    else:
        break

ans_list.sort()

for s in ans_list:
    print(s)

Submission status: Accepted

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

for c in range(n):
    s = input()
    if s not in s_count:
        s_count[s] = 0
    s_count[s] += 1

# print(s_count)

max_count = 0

for word, count in s_count.items():
    max_count = max(count, max_count)

# print(max_count)
res = []
for word, count in s_count.items():
    if count == max_count:
        res.append(word)
# print(word)
for word in sorted(res):
    print(word)

Submission status: Accepted

Solution code:
n=int(input())
l=[input() for i in range(n)]
from collections import Counter as co
k=co(l).most_common()
d=k[0][1]
print(*sorted([a for a,s in k if s==d]),sep="\n")

Submission status: Accepted

Solution code:
from collections import Counter

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

C = Counter(S)

max_v = max(v for k, v in C.items())

ans = []
for k, v in C.items():
  if v == max_v:
    ans.append(k)

ans.sort()

for a in ans:
  print(a)

Submission status: Accepted

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

    # print(voted)

    max_count = 0
    max_list = []
    for k, v in voted.items():
        if max_count == v:
            max_list.append(k)
        elif max_count < v:
            max_list = [k]
            max_count = v

    # print(max_list, max_count)

    for j in sorted(max_list):
        print(j)

Submission status: Accepted

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

for i in range(n):
    ss = input()

    if ss in s:
        s[ss] += 1
    else:
        s[ss] = 1

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

s2.reverse()

max_value = s2[0][1]
ret = []

for sss in s2:
    if sss[1] == max_value:
        ret.append(sss[0])
    else:
        break

ret2 = sorted(ret)
for r in ret2:
    print(r)

Submission status: Accepted

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

B = [(a, A[a]) for a in A]
# print(B)
B.sort(reverse=True, key=lambda x: x[1])
# print(B)
count = B[0][1]
ans = []
for b in B:
    if b[1] == count:
        ans.append(b[0])

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

Submission status: Accepted

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

from collections import Counter
c = Counter()

for si in S:
    c[si] += 1

a = []

for k, v in c.items():
    a.append([v, k])

from operator import itemgetter
a.sort(key=itemgetter(1))
a.sort(key=itemgetter(0), reverse=True)


for ai in a:
    if ai[0] == a[0][0]:
        print(ai[1])

Submission status: Accepted

Solution code:
n = int(input())
ss = [input() for i in range(n)]
dd = {}
for s in ss:
    dd[s] = dd.get(s, 0) + 1
#print('dd=', dd)
mm = sorted(dd, key=lambda s: -dd[s])
#print('mm=', mm)
ll = [mm[0]]
i = 1
while i < len(mm) and dd[mm[0]] == dd[mm[i]]:
    ll.append(mm[i])
    i += 1
ll.sort()
for l in ll:
    print(l)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    nums = defaultdict(int)
    for _ in range(N):
        s = input()
        nums[s] += 1
    mmax = max(nums.values())
    nums = dict(nums)
    keys = sorted(nums.keys())
    for s in keys:
        if mmax == nums[s]:
            print(s)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
S=[input() for i in range(N)]
S.sort()
M=[]
c=1
m=0
s=S[0]
for i in range(1,N):
    if S[i]==s:
        c+=1
    else:
        if c>m:
            M=[s]
            m=c
        elif c==m:
            M.append(s)
        c=1
        s=S[i]
if c>m:
    M=[s]
elif c==m:
    M.append(s)
print(*M,sep="\n")

Submission status: Accepted

Solution code:
N = int(input())
d = dict()
for _ in range(N):
    s = input()
    if not s in d:
        d[s] = 1
    else:
        d[s] += 1

d_sorted = sorted(d.items(), key=lambda x: x[1], reverse=True)
maxNum = d_sorted[0][1]
ans = [] 
for i in d_sorted:
    if i[1] == maxNum:
        ans.append(i[0])
    else:
        break
ans.sort()
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
N = int(input())

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

dictlist = []
for key, value in dic.items():
    temp = [key,value]
    dictlist.append(temp)
dictlist.sort(key=lambda x:(-x[1], x[0]))

top = dictlist[0][1]
for i in range(len(dictlist)):
    if dictlist[i][1] == top:
        print(dictlist[i][0])

Submission status: Accepted

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

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

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

for w in dic_sorted:
    if w[1] == max_cnt:
        print(w[0])
    else:
        break

Submission status: Accepted

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

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

c = Counter(l)
maxcnt = c.most_common()[0][1]

l1 = []
for e,n in c.most_common():
    if n == maxcnt:
        l1.append(e)
l1.sort()
for w in l1:
    print(w)

Submission status: Accepted

Solution code:
n=int(input())
l=[input() for _ in range(n)]
from collections import Counter as co
d=co(l)
k=max(d.values())
x=[]
for i,j in d.items():
  if j==k:
    x.append(i)
x.sort()
for i in x:
  print(i)

Submission status: Accepted

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

A=[]
for v,m in S.items():
    A.append((m,v))

A=sorted(A)[::-1]
num=A[0][0]

B=[]
for i in A:
    if i[0]==num:
        B.append(i[1])
    else:break

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

Submission status: Accepted

Solution code:
import collections

n = int(input())

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

c = collections.Counter(ss)

mc = c.most_common()
max_cnt = max([x[1] for x in mc])
ans = [x[0] for x in mc if x[1] == max_cnt]

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

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter, namedtuple, deque
from bisect import bisect_left
from functools import reduce
import math

NN = 2020202
MOD = 10**9+7
INF = float("inf")

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

count = Counter(A)
count2 = [(c, s) for s, c in count.items()]
count2.sort(key=lambda x: (-x[0], x[1]))
# print(count2)

for elem in count2:
    if elem[0] == count2[0][0]:
        print(elem[1])
    else:
        break

Submission status: Accepted

Solution code:
n = int(input())
w_dict = {}
max_c = 1
for i in range(n):
  w = input()
  if w in w_dict.keys():
    count = w_dict[w] + 1
    w_dict[w] = count
    if count > max_c:
      max_c = count
  else:
    w_dict[w] = 1

print_list = []
for k,v in w_dict.items():
  if v == max_c:
    print_list.append(k)
    
for p in sorted(print_list):
  print(p)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
from collections import deque
sys.setrecursionlimit(10 ** 7)

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

cnt = defaultdict(int)

for s in SS:
    cnt[s] += 1

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

ans = deque([])
mx = -1
for i, x in cnt:
    if mx == -1:
        mx = x
    elif mx != x:
        break
    ans.appendleft(i)

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = [input() for i in range(N)]
S.sort()
c = Counter(S)
m = 0
for word,num in c.items():
    m = max(m, num)
W = []
for word, num in c.items():
    if num == m:
        W.append(word)
W.sort()
print(*W, sep="\n")

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
#print(dic)
max = 0
maxs = []
for i in dic.keys():
    if dic[i] > max:
        max = dic[i]
        maxs = [i]
    elif dic[i] == max:
        maxs.append(i)
maxs.sort()
for i in maxs:
    print(i)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from collections import Counter

def main():
    n = int(input().strip())
    v = []
    for i in range(n):
        v.append(input().strip())
    v2 = dict(Counter(v))
    q = []
    for k, w in v2.items():
        q.append([k, w])
    q = sorted(q, key=itemgetter(1), reverse=True)
    # print(q)
    ans = []
    ans.append(q[0][0])
    prev = q[0][1]
    for t in q[1:]:
        if t[1] == prev:
            ans.append(t[0])
    ans = sorted(ans)
    for a in ans:
        print(a)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

# print(S)
maxCnt = 0
for key in list(S.keys()):
    cnt = S[key]
    if cnt > maxCnt:
        ans = [key]
        maxCnt = cnt
    elif cnt == maxCnt:
        ans.append(key)

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

Submission status: Accepted

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

num_max = 0
words = []
for k in dic.keys():
    num = dic[k]
    if num_max == num:
        words.append(k)
    elif num_max < num:
        words = [k]
        num_max = num
    

words = sorted(words)
for w in words:
    print(w)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
counter = Counter()
for i in range(N):
    s = input()
    counter[s] += 1
most_common = counter.most_common(1)
most_count = most_common[0][1]
for k, v in sorted(counter.items(), key=lambda x: x[0]):
    if v == most_count:
        print(k)

Submission status: Accepted

Solution code:
N = int(input())
P = {}
for _ in range(N):
    s = input()
    if s not in P.keys():
        P[s] = 1
    else:
        P[s] += 1

P = sorted(P.items(), key=lambda x: [-x[1], x[0]])
max_n = P[0][1]
for p in P:
    if p[1] == max_n:
        print(p[0])

Submission status: Accepted

Solution code:
from collections import Counter

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

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

o = []
for k,v in c.most_common():
    if v != P:
        break
    o.append(k)

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

Submission status: Accepted

Solution code:
n=int(input())
vote={}
for i in range(n):
    si=input()
    vi=vote.get(si, 0)
    vote[si]=vi+1

max_v=max(vote.values())

ans=[]
for k,v in vote.items():
    if(v==max_v):
        ans.append(k)
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
import sys
from collections import Counter

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
S = [sr() for _ in range(N)]
c = Counter(S)
l = c.most_common()
max = l[0][1]
answer = []
for k, v in l:
    if v == max:
        answer.append(k)

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

Submission status: Accepted

Solution code:
n = int(input())
h = {}
max_num = 0
for _ in range(n):
    s = input()
    if s not in h:
        h[s] = 0
    h[s] += 1
    if h[s] > max_num:
        max_num = h[s]

answer = []
for k in h.keys():
    if h[k] == max_num:
        answer.append(k)

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

Submission status: Accepted

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

dict = {}
for s in S:
    dict[s] = dict.get(s, 0)+1
max_val = max(dict.values())
keys_of_max_val = [key for key in dict if dict[key] == max_val]
keys_of_max_val.sort()
for k in keys_of_max_val:
    print(k)

Submission status: Accepted

Solution code:
n = int(input())
ans = {}
li = []
for _ in range(n):
    li.append(input())

ma = 0

for i in li:
    if i in ans:
        ans[i] += 1
    else:
        ans[i] = 1
    if ma < ans[i]:
        ma = ans[i]

ans = [i for i, j in ans.items() if j==ma]
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

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

s_dict = dict()
s_max = 0

for i in s:
    if i not in s_dict:
        s_dict[i] = 1
        s_max = max(s_max, s_dict[i])
    else:
        s_dict[i] += 1
        s_max = max(s_max, s_dict[i])

ans = list()
for k, v in s_dict.items():
    if v == s_max:
        ans.append(k)

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

from collections import defaultdict
# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

def main():
	n=int(input())
	
	d=defaultdict(int)
	
	li=[]
	
	for i in range(n):
		s=input().rstrip().decode('utf-8')
		d[s]+=1
	for k,v in d.items():
		li.append((v,k))
	li.sort(reverse=True)
	
	cnt=li[0][0]
	
	li2=[]
	
	for v,k in li:
		if v==cnt:
			li2.append(k)
	li2.sort()
	
	for i in li2:
		print(i)
	
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 無限 #####
# inf = float('inf')

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')

def main():
	N = inputInt()
	S = {}
	for i in range(N):
		inp = input()
		inp = inp[:-1]
		if inp in S:
			S[inp] += 1
		else:
			S[inp] = 1

	score_sorted = sorted(S.items(), key=lambda x:-x[1])
	ans = []
	mx = 0
	for i in score_sorted:
		str,inin = i
		if mx == 0:
			mx = inin
		if mx != inin:
			break
		ans.append(str)

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

	#print(score_sorted)

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import copy
n=int(input())
s=[]
for i in range(n):
    s.append(input())
t=copy.deepcopy(s)
s=list(set(s))
s.sort()
t.sort()
#print(s,t)
ans=[0]*len(s)
cnt=0
c=0
for i in range(n):
    if i==0:
        cnt+=1
        continue
    if t[i]!=t[i-1]:
        ans[c]=cnt
        cnt=1
        c+=1
    else:
        cnt+=1
if c!=len(s)-1:
    c+=1
    ans[c]=cnt
elif ans[len(s)-1]==0:
    ans[c]=cnt
#print(ans)
ma=max(ans)
for i in range(len(s)):
    if ans[i]==ma:
        print(s[i])