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 collections

n = int(input())
s = [input() for _ in range(n)]
cnt = collections.Counter(s)

values, cnts = zip(*cnt.most_common())
maxCnt = cnts[0]
maxStr = []
for i in range(len(cnts)):
    if cnts[i] == maxCnt:
        maxStr.append(values[i])
maxStr.sort()
for i in maxStr:
    print(i)

Submission status: Accepted

Solution code:
import collections

n = int(input())
s = []
for i in range(n):
    si = input()
    s.append(si)
    
s.sort()
counted = collections.Counter(s)
M = max(counted.values())

ms = [k for k, v in counted.items() if v == M]
ms.sort()

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

Submission status: Accepted

Solution code:
N = input()
N = int(N)
S = {}
for n in range(N):
  word = input()
  if word in S.keys():
    S[word] += 1
  else:
    S[word] = 1
max_value = max(S.values())
keys = sorted(list(S.keys()))
for word in keys:
  if S[word] == max_value:
    print(word)

Submission status: Accepted

Solution code:
import sys
import itertools

N = int(input())
S = sys.stdin.read().split()

max_len = 0
for key, group in itertools.groupby(sorted(S)):
	length = len(list(group))
	if length > max_len:
		max_len = length
		ans = []
	
	if max_len == length:
		ans.append(key)

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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
S = [str(input()) for i in range(N)]
X = Counter(S)
ans = X.most_common()
p = ans[0][1]

A = [i[0] for i in X.items() if i[1] == p]
A.sort()

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

Submission status: Accepted

Solution code:
n = int(input())
s = [None] *n
countdict = {}
for i in range(n):
    s[i] = str(input())
for moji in s:
    if moji in countdict.keys():
        countdict[moji] += 1
    else:
        countdict[moji] = 0
ma = max(countdict.values())
ma_lis = []
for ke in countdict.keys():
    if countdict[ke] == ma:
        ma_lis.append(ke)
ma_lis.sort()
for name in ma_lis:
    print(name)

Submission status: Accepted

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

maxCnt = 0
cnt = 0
result = []
str = ''
for S in Sj:
	if S == str:
		cnt += 1
	else:
		str = S
		cnt = 1
	if cnt > maxCnt:
		maxCnt = cnt
		result = [S]
	elif cnt == maxCnt:
		result.append(S)
for rStr in result:
	print(rStr)

Submission status: Accepted

Solution code:
n = int(input())
s = {}
count = 0
while n > count:
    st = input()
    if st not in s:
        s[st] = 1
        count += 1
    else:
        s[st] += 1
        count += 1

sorteditems = sorted(s.items(), key = lambda x : x[1], reverse= True)
max = 0
ans = []
for a, b in sorteditems:
    if max == 0:
        ans.append(a)
        max = b
    elif max == b:
        ans.append(a)
for i in sorted(ans):
    print(i)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
s = [input() for _ in range(N)]
#a = list(map(int, input().split()))

c = Counter(s)


imax = len

values, counts = zip(*c.most_common())

for i in range(len(counts)):
    if counts[0]==counts[i]:
        imax = i

value = [values[i] for i in range(imax+1)]
value.sort()
print(*value, sep='\n')

Submission status: Accepted

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

    count = dict()
    for i in range(N):
        s = input()
        try:
            count[s] += 1
        except:
            count[s] = 1
    
    sort_ = sorted(count.items(), key=lambda x:x[1], reverse=True)

    max_value = sort_[0][1]
    item = []
    for key,value in sort_:
        if value == max_value:
            item.append(key)
        else:
            break
    
    item.sort()
    for ans in item:
        print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
S=[input() for _ in range(N)]
S.sort()
cnt=1
sheet=[[],[]]

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

cmax=max(sheet[1])
for j in range(len(sheet[1])):
    if sheet[1][j]==cmax:
        print(sheet[0][j])

Submission status: Accepted

Solution code:
n = int(input())


s_count ={}

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


max_val = max(s_count.values())
max_s_list = [key for key in s_count if s_count[key] == max_val]
result = sorted(max_s_list)

for k in result:
    print(k)

Submission status: Accepted

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

s.sort()
s0 = [s[0]]
s0n = [0]
cnt = 0
for i in range(1, n):
    if s[i] == s0[cnt]:
        s0n[cnt] += 1
    else:
        s0.append(s[i])
        s0n.append(0)
        cnt += 1

#print(s0)
#print(s0n)
max_s0n = max(s0n)
for i in range(cnt+1):
    if s0n[i] == max_s0n:
        print(s0[i])

Submission status: Accepted

Solution code:
import collections

N = int(input())
A = [0] * N

for i in range(N):
    A[i] = input()
B = collections.Counter(A)    
C = B.most_common()
Max = B.most_common()[0]

Ans =[]
for i in C:
    if Max[1] == i[1]:
        Ans.append(i[0])
    else:
        break
Ans = sorted(Ans)
for i in Ans:
    print(i)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import takewhile
n=int(input())
s=[input() for _ in range(n)]
count=Counter(s)
v=count.most_common()[0][-1]
it=takewhile(lambda kv: kv[-1]==v,count.most_common())
for t in sorted(list(it)):
    print(t[0])

Submission status: Accepted

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

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

#print(ab)
c = collections.Counter(ab)
#print(c)
score_sorted = sorted(c.items(), key=lambda x:-x[1])
value = 0
count = 0
res = []
for k, i in score_sorted:
    if count == 0:
        res.append(k)
        count += 1
        value = i
    else:
        if value == i:
            res.append(k)
res.sort()
for i in res:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())

S = {}
for i in range(N):
    s = input()
    if s not in S.keys():
        S[s] = 0
    S[s] += 1

m = 0
ans = []
for s, c in S.items():
    if c > m:
        ans = []
        ans.append(s)
        m = c
    elif c == m:
        ans.append(s)


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

Submission status: Accepted

Solution code:
import math
import itertools
#n = int(input())
#n, d = list(input().split())
#n, l = list(map(int, input().split()))
N = int(input())
#A = list(map(int, input().split()))
S = []
count = [0]*N
for i in range(N):
    S.append(input())

S.sort()

point = 0
for i in range(N-1):
    if S[i]==S[i+1]:
       point+=1
       if i==N-2:
           point+=1
           count[i]=point
    else:
        point+=1
        count[i]=point
        point = 0
        if i==N-2:
            count[i+1]=1

m = max(count)

#print("SSSSSSSSSSSSS")
for i in range(N):
    if m==count[i]:
        print(S[i])

#print(S)
#print(count)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = []
for i in range(n):
    s.append(input())
counter = Counter(s)
maxnum = max(counter.values())
keys = [k for k, v in counter.items() if v == maxnum]
keys.sort()
for ans in keys:
    print(ans)

Submission status: Accepted

Solution code:
import collections

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

#print(N,S)
#print("------------")
c = collections.Counter(S)
#print(c.most_common())
temp = c.most_common()
max_count = temp[0][1]

T = []
for i in range(N):
    if len(temp) > 1:
        if temp[i][1] == max_count:
            T.append(temp[i][0])
        else:
            break
    else:
        T.append(temp[0][0])
        break

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = Counter(list(input() for _ in range(N)))

#%%
max_v = max(S.values())
words = []
for k, v in S.most_common():
    if v == max_v:
        words.append(k)
    else:
        break

words.sort()
for w in words:
    print(w)

Submission status: Accepted

Solution code:
import collections
N = int(input())
S = [input() for i in range(N)]
c = collections.Counter(S)
max_count = c.most_common()[0][1]
max_k_list = [kv[0] for kv in c.items() if kv[1] == max_count]
max_k_list.sort()
for max_k in max_k_list:
    print(max_k)

Submission status: Accepted

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

c = Counter(s)
m = max(c.values())
l = sorted(list(c.items()))

for i in range(len(c)):
  if l[i][1] == m:
    print(l[i][0])

Submission status: Accepted

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

c = collections.Counter(S)
d = c.most_common()
values, counts = zip(*d)
M = max(counts)

M_counts = counts.count(M)
ans = []
for i in range(M_counts):
    ans.append(values[i])

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

Submission status: Accepted

Solution code:
from collections import Counter

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

s = s.most_common()

k = s[0][1]
lst = []
for i in range(len(s)):
    if k == s[i][1]:
        lst.append(s[i][0])
    else:
        break

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

Submission status: Accepted

Solution code:
N = int(input())
S = {}
for i in range(N):
  s = input()
  if s in S: S[s] += 1
  else: S[s] = 1  
sorted_S = sorted(S.items(), reverse = True, key=lambda x: x[1]) 
ans = []
for word, value in sorted_S:
  if value == sorted_S[0][1]: ans.append(word)
ans.sort()
for i in ans:
  print(i)

Submission status: Accepted

Solution code:
import collections
N = int(input())
s = [0] * N
for i in range(N):
  s[i] = str(input())
  
#print(s)
t = collections.Counter(s)
u = list(t.items())
#print(u)
x = max(list(t.values()))
ans = []
#print(x)
#print(u)
for i in range(len(u)):
  #print(u[i][1], x)
  if u[i][1] == x:
    ans.append(u[i][0])
    
    
ans = sorted(ans)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import collections
from collections import Counter

n = int(input())
s = []
for i in range(n):
    s.append(str(input()))
"""
s.sort()
count = 1
max_ = 0
ans = []
for i in range(n - 1):
    if s[i] == s[i + 1]:
        count += 1
    elif s[i] != s[i + 1]:
        if max_ <= count:
            max_ = count
            ans.append(s[i])
            count = 1

for i in range(len(ans)):
    print(ans[i], end = '')
"""

count = Counter(s)
max_number = 0
ans = []
for i in count.most_common():
    ans.append(list(i))
len_ans = len(ans)
ans.sort(key = lambda x : x[1])
tmp = ans[len_ans - 1][1]
ans.sort()
for i in range(len_ans):
    if ans[i][1] == tmp:
        print(ans[i][0])

Submission status: Accepted

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

b = sorted(a)

word = b[0]
word_idx = 0
w = []
for i in range(n):
  if word == b[i]:
    word_idx += 1
  else:
    w.append((word,word_idx))
    word_idx = 1
    word = b[i]
    
w.append((word,word_idx))
#print(w)
n_max = max(w, key=lambda x:x[1])[1]

for i in range(len(w)):
  if w[i][1] == n_max:
    print(w[i][0])

Submission status: Accepted

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

vdic={}
for a in range(n):
    if s[a] in vdic:
        vdic[s[a]]=vdic[s[a]]+1
    else:
        vdic[s[a]]=1

max=0
for a in vdic:
    if vdic[a]>=max:
        max=vdic[a]

maxname=[]
for a in vdic:
    if vdic[a]==max:
        maxname.append(a)

maxname=sorted(maxname)

for a in maxname:
    print(a)

Submission status: Accepted

Solution code:
import collections

n = int(input())
l = []
for i in range(n):
  l.append( input() )
  
c = collections.Counter(l).most_common()
mn = c[0][1]

res = []
for cc in c:
  if cc[1]==mn:
    res.append(cc[0])
  else:
    break

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

Submission status: Accepted

Solution code:
import collections

num = int(input())
votes = []
for i in range(num):
  votes.append(input())
  
c = collections.Counter(votes)

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

words = []
for word, freq in c.items():
  if freq == max_freq:
    words.append(word)

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

Submission status: Accepted

Solution code:
n=int(input())
a={}
for i in range(n):
    tmp=input()
    if not tmp in a:
        a[tmp] = 1
    else:
        a[tmp] += 1
M=max(a.values())
ans=[]
for k, v in a.items():
    if v == M:
        ans.append(k)
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
import collections
import itertools
s=int(input())
l=[input() for i in range(s)]
counter = collections.Counter(l)

mode_v = counter.most_common()[0][-1]
it = itertools.takewhile(
    lambda kv: kv[-1] == mode_v, counter.most_common()
)
u=[]
for k, v in it:
  u.append(k)
  
u.sort()
for i in range(len(u)):
  print(u[i])

Submission status: Accepted

Solution code:
from itertools import groupby
from operator import itemgetter

a = sorted(input() for _ in range(int(input())))
a = sorted((-len(list(g)), s) for s, g in groupby(a))
for _, s in next(groupby(a, itemgetter(0)))[1]:
  print(s)

Submission status: Accepted

Solution code:
n = int(input())

word = {}
x = set()
for i in range(n):
    s = str(input())
    x.add(s)
    if not s in word :
        word[s] = 1
    else:
        word[s] = int(word[s]) + 1

m = sorted(word.values(),reverse=True)
items_sorted = sorted(word.items())

for i in range(len(x)):
    if items_sorted[i][1] == m[0]:
        print(items_sorted[i][0])

Submission status: Accepted

Solution code:
n = int(input())
dictionary = {}
for i in range(n) :
    new_word = input()
    if new_word in dictionary.keys() :
        dictionary[new_word] += 1
    else :
        dictionary[new_word] = 1

max_val = max(dictionary.values())
keys_of_max_val = [key for key in dictionary if dictionary[key] == max_val]

keys_of_max_val.sort()

for word in keys_of_max_val :
    print(word)

Submission status: Accepted

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

max_cnt = max(cnt_list.values())
res_list = []

for a in cnt_list.items():
  if a[1] == max_cnt:
    res_list.append(a[0])

res_list.sort()

for res in res_list:
  print(res)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = [input() for i in range(n)]
c = Counter(s)
# print(max(c.values()))
ans = []
w = max(c.values())
for k, v in sorted(c.items()):
    if v == w:
        ans += [k]
# print(ans)
# print(sorted(ans))
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
dics = {}
for i in range(n):
    try:
        s = input()
        dics[s] += 1
    except KeyError:
        dics[s] = 1
max_v = max(dics.values())

max_k_list = [kv[0] for kv in dics.items() if kv[1] == max_v]
max_k_list.sort()
for i in max_k_list:
    print(i)

Submission status: Accepted

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

import collections
s_counter = collections.Counter(s_list)

import sys
max_count = s_counter.most_common()[0][1]

s_list_keys = list(s_counter.keys())
s_list_values = list(s_counter.values())

list_ans = []

for i in range(len(s_list_keys)):
    if s_list_values[i] == max_count:
        list_ans.append(s_list_keys[i])

list_ans.sort()

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

Submission status: Accepted

Solution code:
import collections
z = int(input())
a = [input() for i in range(z)]
a = collections.Counter(a).most_common()
a.sort(key = lambda x:x[1],reverse = True)
c = a[0][1]
ans = []
for i in a:
  if i[1] == c:
    ans.append(i[0])
  else:
    break
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
num = int(input())
i = [input() for _ in range(num)]
 
count_dict = {}
for ele in i:
  if ele not in count_dict:
    count_dict[ele] = 1
  else:
    count_dict[ele] += 1
 
max_count = max(count_dict.values())
max_str = [a for a in count_dict if count_dict[a] == max_count]
for string in sorted(max_str):
  print(string)

Submission status: Accepted

Solution code:
from collections import Counter

a = int(input())
a_list = []
ans_list = []

for i in range(a):
  a_list.append(input())

a_counter = Counter(a_list)

_v = 0
for k, v in a_counter.most_common():
    if _v == 0 or _v == v:
      _v = v
      ans_list.append(k)
    elif _v > v:
      break

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

Submission status: Accepted

Solution code:
#coding:utf-8
import collections

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

c = collections.Counter(s)
count_max = max(c.values())
for key, num in c.items():
    if num == count_max:
        ans.append(key)

ans = sorted(ans)

for i in ans:
    print(i)

Submission status: Accepted

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

c = Counter(S)
max_value = max(list(c.values()))
ans_list = sorted(list(c.items()))

for i in range(len(ans_list)):
  if ans_list[i][1] == max_value:
    print(ans_list[i][0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

li = {}
key = []
for _ in range(n):
    tmp = input()
    if tmp in li.keys():
        li[tmp] += 1

    else:
        li[tmp] = 1
        key.append(tmp)

mord = max(li.values())

ans = []
for i in key:
    if li[i] == mord:
        ans.append(i)

ans.sort()

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import collections
n=int(input())
lst=[]
for i in range(n):
    lst.append(input())
cnt=collections.Counter(lst)
ma=0
for val in cnt.values():
    val=int(val)
    if(val>ma):
        ma=val
li=[]
for key,val in cnt.items():
    val=int(val)
    if(val==ma):
        li.append(key)
li.sort()
for i in li:
    print(i)

Submission status: Accepted

Solution code:
import collections

N = int(input())
L = [input() for _ in range(N)]
result = []
c = collections.Counter(L)
mostC =  c.most_common()[0][1]

for k,v in c.items():
    if v == mostC:
        result.append(k)

result.sort()

for name in result:
    print(name)

Submission status: Accepted

Solution code:
from collections import Counter

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

polls = Counter(s)
max_count = max(polls.values())

l = list(map(lambda t: t[0], filter(lambda item: item[1] == max_count , polls.items())))
l.sort()
print(*l, sep="\n")

Submission status: Accepted

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

sorted_S = sorted(S)
count = [0]*N

index_str = sorted_S[0]
index_num = 0

for i in range(N):
    if sorted_S[i] == index_str:
        count[index_num] += 1
    else:
        index_str = sorted_S[i]
        index_num = i

        count[i] += 1

max_num = max(count)

tousen = list()
for i in range(N):
    if count[i] == max_num:
        tousen.append(sorted_S[i])

sorted_tousen = sorted(tousen)
num_of_tousen = len(sorted_tousen)

for i in range(num_of_tousen):
    print(sorted_tousen[i])

Submission status: Accepted

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

d = {}
cnt = 0
for i in range(n):
	if s[i] in d: d[s[i]] += 1
	else: d[s[i]] = 1
	cnt = max(cnt, d[s[i]])

l = []
for i in range(n):
	if d[s[i]] == cnt:
		l.append(s[i])

l = list(set(l))
l.sort()
for i in range(len(l)):
	print(l[i])

Submission status: Accepted

Solution code:
N = int(input())

existed_dict = {}
max_count = 0
max_text_list = []
for _ in range(N):
    text = input()
    if existed_dict.get(text):  # ここか
        existed_dict[text] += 1
    else:
        existed_dict[text] = 1
    if existed_dict[text] == max_count:
        max_count = existed_dict[text]
        max_text_list.append(text)
    elif existed_dict[text] > max_count:
        max_count = existed_dict[text]
        max_text_list = []
        max_text_list.append(text)
    else:
        pass

for text in sorted(max_text_list):  # ここ
    print(text)

Submission status: Accepted

Solution code:
from collections import Counter

def main():
    n = int(input())
    sn = []
    for _ in range(n):
        sn.append(input())

    sn_counter = Counter(sn)
    ans = sn_counter.most_common()
    max_num = sn_counter.most_common()[0][1]
    
    cut_num = 0
    for it in range(len(ans)):
        if ans[it][1] == max_num:
            cut_num += 1
        else:
            break
    
    ans = ans[:cut_num]
    ans.sort()

    for s in ans:
        print(s[0])

if __name__ == "__main__":
    main()

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

max_v=max(d.values())
ans=list(filter(lambda x: x[1] == max_v, d.items()))
[print(i[0]) for i in sorted(ans)]

Submission status: Accepted

Solution code:
from collections import defaultdict

N=int(input())
cnt=defaultdict(int)
for i in range(N):
    ai=input()
    cnt[ai]+=1
count=0
ans=[]
for idx, val in cnt.items():
    if count<val:
        count=val
        ans=[]
        ans.append(idx)
    elif count==val:
        ans.append(idx)
ans = sorted(ans)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())

a = {}
l = []

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

num = max(a.values())

for i in a:
  if a[i] == num:
    l.append(i)

l.sort()

for j in l:
  print(j)

Submission status: Accepted

Solution code:
n = int(input())

d = {}
for i in range(n): 
    s = input()
    if(d.get(s) is None):
        d[s] = 1
    else:
        d[s] = d[s] + 1

l = list(d.items())

l.sort(key=lambda x: (-x[1], x[0])) 

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N = int(input())

m = {}
for i in range(0,N):
    S = input()
    if S in m:
        m[S] = m[S] + 1
    else:
        m[S] = 1

top = 0
r = list()
for k,v in sorted(m.items(), key=lambda x: -x[1]):
    if top == 0:
        top = v
    if top != v:
        break
    r.append(k)

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

Submission status: Accepted

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

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

mx = 0
ans = []

for itm in d.items():
  if itm[1] == mx:
    ans.append(itm[0])
  elif itm[1] > mx:
    ans = [itm[0]]
    mx = itm[1]
  else:
    continue

ans.sort()

for x in ans:
  print(x)

Submission status: Accepted

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

def solve(N: int, S: "List[str]"):
    d = defaultdict(int)
    for s in S:
        d[s]+=1
    dd = []
    for key in d.keys():
        dd.append((-d[key],key))
    sd = sorted(dd)
    n = sd[0][0]
    for sdd in sd:
        if sdd[0] != n:
            break
        print(sdd[1])
    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:
#!/usr/bin/env python3
n = int(input())
s = [input() for _ in range(n)]
s.sort()
#print(s)
max_cnt = 0
dup_str = 1
cnt = 1
ans = [""] * n
for i in range(n-1):
    if s[i+1] == s[i]: cnt +=1
    else:
        if cnt > max_cnt:
            #print(i,s[i])
            max_cnt = cnt
            ans[0] = s[i] 
            dup_str = 1
        elif cnt == max_cnt:
            ans[dup_str] = s[i]
            dup_str += 1
        cnt = 1
    if i == n-2:
        if cnt > max_cnt:
            max_cnt = cnt
            ans[0] = s[i] 
        elif cnt == max_cnt:
            ans[dup_str] = s[i]
            dup_str += 1
        if max_cnt == 1 and cnt == 1:
            ans[n-1] = s[n-1]
            dup_str = n
#print(ans)
for i in range(dup_str):
    print(ans[i])

Submission status: Accepted

Solution code:
import collections
import sys
input = sys.stdin.readline
n = int(input())
s = []
for i in range(n):
  s.append(input())
#print(s)
c = collections.Counter(s)
#print(c.most_common())
x = c.most_common()
m = x[0][1]
l = len(x)
ans = []
for i in range(l):
  if x[i][1] == m:
    ans.append(x[i][0])
  else:
    break
ans0 = sorted(ans)
for i in range(len(ans0)):
  print(ans0[i],end="")

Submission status: Accepted

Solution code:
N = int(input())
count_dict = {}
answer = []
for i in range(N):
  key = input()
  if key in count_dict.keys():
    count_dict[key] += 1
  else:
    count_dict[key] = 1
sorted_dict = sorted(count_dict.items(), key=lambda x:x[1], reverse=True)
max_count = sorted_dict[0][1]
answer.append(sorted_dict[0][0])

for i in range(1, len(sorted_dict)):
  if sorted_dict[i][1] == max_count:
    answer.append(sorted_dict[i][0])
  else:
    break

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

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input()) #1行目のNを取得する
S=[input() for i in range(N)] #複数行の数値の入力を取得

most_common_list=Counter(S).most_common()

common_s=[]

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

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

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
import numpy as np
import collections
from collections import deque
import queue
import copy

# 最大公約数
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" #探索した場所は探索できないようにする
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      #print(q)
  return mlength

def brick(a,n,m,N):#ABC 148
  #n番目以降にmがあるか調べる
  if not m in a[n:]:
    print(N-(m-1))
  else:
    #b = copy.deepcopy(a)
    brick(a,a[n:].index(m),m+1,N)

#X = str(input()).split()
#a = [int(x) for x in input().split()]

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

c = collections.Counter(S)
a = c.most_common()


B.append(a[0][0])

for i in range(len(a)-1):
    if(a[i][1]==a[i+1][1]):
        B.append(a[i+1][0])
    else:
        break
B.sort()

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

Submission status: Accepted

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

S_sorted = sorted(S)
dupulication = [0 for i in range(N)]
dupMax = 0
output=""

for i in range(N-1):
    if(S_sorted[i+1] == S_sorted[i]):
        dupulication[i+1] = dupulication[i] + 1
        if (dupulication[i+1] >= dupMax):
            dupMax = dupulication[i+1]

for i in range(N):
    if dupulication[i]==dupMax:
        output += S_sorted[i]+"\n"

###########　出力
print(output)

Submission status: Accepted

Solution code:

import collections

n = int(input())

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


c = collections.Counter(s)


max_c = max(c.values())


keys = [k for k, v in c.items() if v == max_c]
keys.sort()

for k in keys:
    print(k)

Submission status: Accepted

Solution code:
n = int(input())
S = [input() for _ in range(n)]
d = {}
m = 0
for s in S:
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
    m = max(m, d[s])

sd = sorted(d.items(), key=lambda x: x[1], reverse=True)
ans = []
for k, v in sd:
    if v != m:
        break
    ans.append(k)

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

Submission status: Accepted

Solution code:
N = int(input().rstrip())
d = {}
for _ in range(N):
    string = input().rstrip()
    if string in d.keys():
        d[string] += 1
    else:
        d[string] = 1
d = sorted(d.items(), key=lambda x: x[1], reverse=True)
# print(d)
rets = []
max = -1
for string, val in d:
    if max == -1:
        max = val
    elif max != val:
        break
    rets.append(string)

for a in sorted(rets):
    print(a)

Submission status: Accepted

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

mx = max(list(hist.values()))
ans = []
for x in hist.keys():
    if hist[x] == mx:
        ans.append(x)
ans = sorted(ans)
for x in ans:
    print(x)

Submission status: Accepted

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

words = set()
cnt = dict()
for i in range(n):
  if s[i] not in words:
    words.add(s[i])
    cnt[s[i]] = 1
  else:
    cnt[s[i]] += 1

top_words = []
max_val = 0
for k, v in cnt.items():
  if v > max_val:
    max_val = v
    top_words = [k]
  elif v == max_val:
    top_words.append(k)

top_words =sorted(top_words)
for i in range(len(top_words)):
  print(top_words[i])

Submission status: Accepted

Solution code:
input_num = int(input())
dic = {}
strlist = []
strlist2 = []
maxi = 1
for i in range(input_num):
  strlist.append(input())
for i in range(input_num):
  if dic.setdefault(strlist[i],0) != 0:
    dic[strlist[i]] += 1
    if dic[strlist[i]] > maxi:
      maxi = dic[strlist[i]]
  else:
    dic[strlist[i]] = 1
    strlist2.append(strlist[i])
strlist2.sort()
for i in range(len(strlist2)):
  if dic[strlist2[i]] == maxi:
    print(strlist2[i])