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 as cl
from operator import itemgetter, attrgetter
n = int(input())
s = []
for i in range(n):
    s.append(input())
h = cl.Counter(s)
itm = h.items()

m = max(list(h.values()))
#mlist = [i[0] for i in itm if lambda x:x[1] == m]
mfil = list(filter(lambda x:x[1]==m ,itm))
mfil = sorted(mfil,key=itemgetter(0))
for j in mfil:
    print(j[0])

Submission status: Accepted

Solution code:
from collections import defaultdict

H=int(input())
d = defaultdict(int)
for _ in range(H):
    d[input()] += 1
max_appeard=max(d.items(), key=lambda x: x[1])[1]
ans=[k for k,v in d.items() if v == max_appeard]
ans.sort()
for item in ans:
  print (item)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
arr = []
arr_max = []
for i in range(N):
    arr.append(input())
dic = Counter(arr)
inverse = [(value, key) for key, value in dic.items()]
max_s = max(inverse)[0]
for key,value in dic.items():
    if value == max_s: 
        arr_max.append(key)
    else: continue
for j in sorted(arr_max): print (j)

Submission status: Accepted

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

max_letter = []
max_count = 0
tmp_S = S[0]
count = 0

for i in range(len(S)):
  if i == 0:
    count=1
    max_letter.append(S[i])
    tmp_S = S[i]
  elif tmp_S != S[i]:
    if max_count < count:
      max_count = count
      max_letter = []
      max_letter.append(tmp_S)
    elif max_count == count:
      max_letter.append(tmp_S)
    tmp_S = S[i]
    count=1
  else:
    count+=1
if max_count < count:
  max_letter = list([tmp_S])
elif max_count == count:
  max_letter.append(tmp_S)
  
for i in range(len(max_letter)):
  print(max_letter[i])

Submission status: Accepted

Solution code:
def main():
	# n,m = map(int,input().split())
	n = int(input())
	l = [str(input()) for i in range(n)]
	
	import collections

	c = collections.Counter(l)
	lc = sorted(list(c.items()), key = lambda x:x[1] , reverse = True)
	# print(lc[0][0])
	ans = []
	checker = 0
	i = 0
	while checker == 0 and i < len(lc):
		if lc[i][1] == lc[0][1]:
			ans.append(lc[i][0])
		else:
			checker += 1
		i += 1

	# keys = [k for k, v in c.items() if v == max(c.values())]
	# print(list(c.items())[0][0])
	# checker = 0
	# while checker == 0:
	# 	if c.items() == max(c.values()):
	ans.sort()
	print('\n'.join(map(str, ans)))

	
	
 
if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import OrderedDict
N = int(input())
ans = dict()
for _ in range(N):
    k = str(input())
    if k in ans:
        ans[k]+=1
    else:
        ans.update({k:1})
groupedByValue = defaultdict(list)
for key, value in sorted(ans.items()):
    groupedByValue[value].append(key)
j = groupedByValue[max(groupedByValue)]
for i in j:
    print(i)

Submission status: Accepted

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

for i in lst :
    if i in dic.keys() :
        dic[i] += 1
    else :
        dic[i] = 1

dic = sorted(dic.items(), key=lambda x:x[1], reverse=True)
result = [dic[0][0]]
if len(dic) > 1 :
    for j in range(n-1) :
        if dic[j][1] == dic[j+1][1] :
            result += [dic[j+1][0]]
        else :
            break

result = sorted(result)
for k in result :
    print(k)

Submission status: Accepted

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

c=1
m=0
for i in range(n-1):
  if s[i]==s[i+1]:
    c+=1
  else:
    if c > m:
      ans=[s[i]]
      m=c
      c=1
    elif c==m:
      ans.append(s[i])
      c=1
    else:
      c=1
if c > m:
  ans=[s[n-1]]
elif c==m:
   ans.append(s[n-1])
for i in range(len(ans)):
  print(ans[i])

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import OrderedDict

N = int(input())
ans = dict()
for _ in range(N):
    k = str(input())
    if k in ans:
        ans[k] += 1
    else:
        ans.update({k: 1})
groupedByValue = defaultdict(list)
for key, value in sorted(ans.items()):
    groupedByValue[value].append(key)
l = groupedByValue[max(groupedByValue)]
for i in l:
    print(i)

Submission status: Accepted

Solution code:
import collections

n = input()
mylist = []
for i in range(0, int(n)):
    val = input()
    mylist.append(val)

c = collections.Counter(mylist)
ma = c.most_common()[0][1]
ans = []
for target_list in c.items():   
    if target_list[1] == ma:
        ans.append(target_list[0])

ans.sort()

for target_list in ans:
    print(target_list)

Submission status: Accepted

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

ans = [dic[0][0]]

for i in range(len(dic)-1):
    if dic[i][1] == dic[i+1][1]:
        ans.append(dic[i+1][0])
    else:
        break
        
ans = sorted(ans)

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

Submission status: Accepted

Solution code:
#C - Poll
N = int(input())
S = [str(input()) for i in range(N)]
S = sorted(S)
count = 1
tmpcount = 1
DP = [S[0]]
for i in range(1,N):
    if S[i] == S[i-1]:
        count += 1
        if tmpcount < count:
            DP.clear()
            DP.append(S[i])
            tmpcount = count
        elif tmpcount == count:
            DP.append(S[i])
        else:
            pass
    else:
        count = 1
        if tmpcount == count:
            DP.append(S[i])
        else:
            pass

for l in range(len(DP)):
     print(DP[l])

Submission status: Accepted

Solution code:
num = int(input())

from collections import defaultdict
dic = defaultdict(int)

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

k = {}
k = [key for m in [max(dic.values())] for key,val in dic.items() if val == m]
k.sort()
for i in k:
  print(i)

Submission status: Accepted

Solution code:
a=int(input())
li={}
while(a):
    a=a-1
    b=input()
    if b in li:
        li[b]+=1
    else:
        li[b]=1
m = max(li.values())
l=[]
for t in li:
    if m==li[t]:
        l.append(t)
l=sorted(l)
for y in l:
    print(y)

Submission status: Accepted

Solution code:
n = int(input())
dic = {}
max = 1
for i in range(n):
    # print(dic)
    s = input()
    if not s in dic.keys():
        dic[s] = 1
    else:
        dic[s] += 1
        if dic[s] > max:
            max = dic[s]

# print(dic)
keys = [k for k, v in dic.items() if v == max]
print(("\n").join(sorted(keys)))

Submission status: Accepted

Solution code:
n=int(input())
memo={}
for i in range(n):
  s=input()
  if s not in memo:
    memo[s]=1
  else:
    memo[s]+=1
    
a=[]
max_v = max(memo.values())
for k, v in memo.items():
  if v==max_v:
    a.append(k)
print('\n'.join(sorted(a)))

Submission status: Accepted

Solution code:
from collections import Counter


N=int(input())
l=['']*N
for i in range(N):
    l[i]=input()

l.sort()

c=1
c_crt=1
pre=""
ans=[]
for e in l+[""]:
    if e == pre:
        c_crt+=1
    else:
        if c_crt > c:
            ans=[pre]
            c=c_crt
        elif c_crt == c:
            ans.append(pre)
        c_crt=1
    pre=e
for e in ans:
    print(e)

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

dic = sorted(dic.items())
dic = sorted(dic, key=lambda x: -x[1])
dic.append(('_', 0))
for i in range(n):
    if dic[i][1] == dic[i + 1][1]:
        print(dic[i][0])
    else:
        print(dic[i][0])
        break

Submission status: Accepted

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

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

dic = sorted(S)

i = 0
while i < N-1:
    j = 0
    while i+j+1 < N and dic[i+j] == dic[i+j+1]:
        j += 1
    num[i] = j
    i += j + 1

flag = 1
for i in range(N):
    if flag == 1:
        if num[i] > 0:
            Max = num[0]
            flag = 0
    if flag == 0:
        if num[i] >= Max:
            Max = num[i]

i = 0
while i < N:
    if num[i] == Max:
        print(dic[i])
    i += num[i] + 1

Submission status: Accepted

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

P=collections.Counter(S)

y=max(P.values())
A = [k for k, v in P.items() if v == y]

A.sort()

for List in A:
    print(List)

Submission status: Accepted

Solution code:
import collections

N=int(input())
data=[input() for i in range(N)]
c = collections.Counter(data)
score=c
com=c.most_common()

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

val=score_sorted
L=len(val)
count="Yes"
ii=0
ansa=1
if L==1:
    print(val[0][0])
else:
    while count=="Yes":
        if val[ii][1]==val[ii+1][1]:
            ii+=1

            ansa+=1
            if ii == L-1:
                break
        else:
            count="No"
    data2=[]
    for i in range(ansa):
        data2.append(val[i][0])

    data2.sort()
    for i in range(ansa):
        print(data2[i])

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_k_list=[]
max_d = max(d.values())
for k,v in d.items():
    if v == max_d:
        max_k_list.append(k)
max_k_list.sort()
for i in max_k_list:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
candidates = {}
for i in range(n):
    now = input()
    if now in candidates:
        candidates[now] += 1
    else:
        candidates[now] = 1
winners = []
max_poll = 0
for key in candidates:
    if candidates[key] > max_poll:
        max_poll = candidates[key]
for key in candidates:
    if candidates[key] == max_poll:
        winners.append(key)
winners.sort()
for winner in winners:
    print(winner)

Submission status: Accepted

Solution code:
import collections
import sys
input = sys.stdin.readline
num = int(input())
word_list = []
for i in range(num):
    word_list.append(input())
word_dict = collections.Counter(word_list)
most_common = word_dict.most_common()[0][1]
word_list = [k for k,v in word_dict.items() if v == most_common]
word_list.sort()
for word in word_list:
    print(word)

Submission status: Accepted

Solution code:
import collections
N=int(input())
S=[]
for i in range(N):
  s=str(input())
  S +=[s]
T=collections.Counter(S)
answer=T.most_common()
A=[]
for i in range(len(T)):
  if answer[i][1]==answer[0][1]:
    A +=[answer[i][0]]
  else:
    break
A=sorted(A)
for a in A:
  print(a)

Submission status: Accepted

Solution code:
N = int(input())
a = [input() for i in range(N)]
a.sort()
b = [0] * N
flag = 1
cc = 0
bef = 132
c = 1
for i in range(N):
    if a[i] == bef:
        c = c + 1
    else:
        c = 1
    bef = a[i]
    b[i] = c
    if flag == 1:
        max = c
        flag = 0
    if c > max:
        max = c
        
for i in range(N):
    if b[i] == max:
        print(a[i])

Submission status: Accepted

Solution code:
n=int(input())

dic=dict()
for i in range(n):
  s=input()
  if s not in dic:
    dic[s]=1
  else:
    dic[s]+=1
a=(max(dic, key=dic.get))
b=dic[a]
keys = [k for k, v in dic.items() if v == b]
keys.sort()

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

Submission status: Accepted

Solution code:
from collections import Counter
def solve():
    n = int(input())
    c = Counter(input() for _ in range(n))
    t = c.most_common()[0][1]
    ans = []
    for a in c.most_common():
        if a[1] != t:
            break
        ans.append(a[0])
    print(*sorted(ans), sep="\n")
solve()

Submission status: Accepted

Solution code:
n = int(input())
vote = dict()
for i in range(n):
  s = input()
  if s not in vote.keys():
    vote[s] = 0
  else:
    vote[s] += 1

res = []
mx = max(vote.values())
for key, value in vote.items():
    if value== mx:
        res.append(key)

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

Submission status: Accepted

Solution code:
def poll(arr):
    ans_h = {}
    for ele in arr:
        if ele in ans_h.keys():
            ans_h[ele] += 1
        else:
            ans_h[ele] = 0
    max_v = max(ans_h.values())
    mkv = [kv for kv in ans_h.items() if kv[1] == max_v]
    for ele in sorted(mkv):
        print(ele[0])

if __name__ == "__main__":
    n = int(input())
    arr = [input() for _ in range(0, n)]
    poll(arr)

Submission status: Accepted

Solution code:
n = int(input())

d = {}
for i in range(n):
    s = input()
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
max_d = max(d.values())
max_d_list = [kv[0] for kv in d.items() if kv[1] == max_d]

ans = sorted(max_d_list)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import numpy as np

num = int(input())

words = []
for _ in range(num):
    words.append(input())

words = tuple(words)

d = {}
for word in words:
    if word in d:
        d[word] += 1
    else:
        d[word] =1


# keyをndarrayで取得
keys = np.array([a[0] for a in d.items()])

# valueをndarrayで取得
values = np.array([a[1] for a in d.items()])

# valueがmaxであるkeyを探してくる
keys_of_max_val = keys[values == values.max()]

keys_of_max_val.sort()

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

Submission status: Accepted

Solution code:
n=int(input())
import collections
d=collections.defaultdict(int)
for i in range(n):
    d[input()]+=1
m=0
ans=[]
for i,j in d.items():
    if j>m:
        ans=[i]
        m=j
    elif j==m:
        ans.append(i)
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
s = []
for _ in range(n):
    s.append(input())
import collections
s1 = collections.Counter(s)
x = max(s1.values())
key = [k for k,v in s1.items() if v == x]
s2 = sorted(key)
ans = '\n'.join(s2)
print(ans)

Submission status: Accepted

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

for _ in S:
    d[_]=0

for _ in S:
    d[_]+=1

max_ = max(d.values())

_sorted = sorted(d.items(), key=lambda x:x[0])
for _ in _sorted:
    if _[1]== max_:
        print(_[0])

Submission status: Accepted

Solution code:
n = int(input())
s_list = []
import collections

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

s_dict = collections.Counter(s_list)
maxv = max(s_dict.values())

keys = [k for k,v in s_dict.items() if v == maxv]
keys.sort()
for i in range (len(keys)):
    print(keys[i])

Submission status: Accepted

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

numbers = dict()
maxval = 1
for val in s:
    if val in numbers:
        if maxval == numbers[val]:
            maxval = maxval + 1
        numbers[val] += 1
    else:
        numbers[val] = 1

ret = [kv[0] for kv in numbers.items() if kv[1] == maxval]
for v in sorted(ret):
    print(v)

Submission status: Accepted

Solution code:
N=int(input())
a=[]
b=0
for i in range(N):
	a.append(input())
d={}
sor={}
for i in range(N):
    if a[i] in d.keys():
        d[a[i]]+=1
    else:
        d.setdefault(a[i],1)
        b+=1
sod = sorted(d.keys())
#max=sod["a[0]"]
maxval=0
for i in range(N):
    if maxval<=d[a[i]]:
        maxval=d[a[i]]
for i in range(b):
    if maxval==d[sod[i]]:
        print(sod[i])

Submission status: Accepted

Solution code:
import collections

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

for i in range(N):
  tmp = input()
  S.append(tmp)
  
c = collections.Counter(S)

d = c.most_common()

max_ = d[0][1]

for i,k in enumerate(d):
  if d[i][1] == max_:
    solution.append(d[i][0])
    
solution.sort()

for i in solution:
  print(i)

Submission status: Accepted

Solution code:
import collections as cl
ans = []
n = int(input())
list1 = []
for x in range(n): 
  list1.append(input())

clist = cl.Counter(list1)
max = max(clist.values())
citem =list(clist.items())
for y in citem:
    if y[1] == max:
      ans.append(y[0])

ans = sorted(ans)

for l in ans:
  print(l)

Submission status: Accepted

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

c = collections.Counter(S_list)

d = c.most_common() 

keys = [k for k, v in c.items() if v == d[0][1]]

keys = sorted(keys)

for i in keys:
  print(i)

Submission status: Accepted

Solution code:
import collections

n = int(input())
data_list = [input() for i in range(n)]
data_list.sort()

count_dict = collections.Counter(data_list)

max_val = max(count_dict.values())
max_keys = [key for key in count_dict if count_dict[key] == max_val]

max_keys.sort()

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

Submission status: Accepted

Solution code:
from collections import Counter

def poll(N, S):
  take = []
  counted = Counter(S)
  mode = max(counted.values())
  for i, value in counted.items():
    if value == mode:
      take.append(i)
  newtake = sorted(take)
  for i in range(len(take)):
    print(newtake[i])

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

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
S=list()
Y=list()
for i in range(N):
    S.append(input())
X=Counter(S)
F=X.most_common()[0][1]
keys = [k for k, v in X.items() if v == F]
keys.sort()
for i in range(len(keys)):
    print(keys[i])

Submission status: Accepted

Solution code:
import collections
import itertools

n = int(input())
l = [input() for _ in range(n)]
counter = collections.Counter(l)

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

l2 = list((k for k, v in it))
l2.sort()
print(*l2)

Submission status: Accepted

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

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

d = {}
for x in S:
    if x in d:
        d[x] += 1
    else:
        d.setdefault(x, 1)

d_sorted = sorted(d.items(), key=lambda x:x[1], reverse=True)
count = d_sorted[0][1]
result = []

for x in d_sorted:
    if x[1] == count:
        result.append(x[0])

result.sort()

for z in result:
    print(z)

Submission status: Accepted

Solution code:
import collections
from operator import itemgetter

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

s = collections.Counter(S)
#print(list(s.items()))
ss = list(s.items())
#s2 = collections.OrderedDict(s)
maxint = s.most_common()[0][1]
s3 = sorted(ss, key=itemgetter(0))
s4 = sorted(s3, key=itemgetter(1), reverse=True)
#print(s3,s4,sep="\n")

count = 0
for i in range(N):
    if(s4[i][1] == maxint):
        print(s4[i][0])
        count += s4[i][1]
        if(N==count):
            break
    else:
        break

Submission status: Accepted

Solution code:
n = int(input())
l=[]
for i in range(n):
    l.append(input())
from collections import Counter
S=Counter(l)#カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})

mn = max(S.values())
for letter, count in sorted(S.most_common()):
    if(count==mn):
        print(letter)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict
N, = map(int, input().split())
d = defaultdict(int)
for _ in range(N):
    s = input().strip()
    d[s] += 1
mx = 0
for k in d:
    mx = max(d[k], mx)
rs = set()
for k in d:
    if d[k] == mx:
        rs.add(k)
rs = list(rs)
rs.sort()
for r in rs:
    print(r)

Submission status: Accepted

Solution code:
n=int(input())
dic={}
for i in range(n):
  a=input()
  if a not in dic.keys():dic[a]=1
  else:dic[a]+=1
max_value=max(dic.values())
dic_max=[k for k, v in dic.items() if v==max_value]
dic_s=sorted(dic_max)
[print(i) for i in dic_s]

Submission status: Accepted

Solution code:
N = int(input())
Dict = {}
List = []

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

Max = max(list(Dict.values()))
for i in list(Dict.items()):
    if i[1]>=Max:
        List.append(i[0])
for i in sorted(List):
    print(i)

Submission status: Accepted

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

dic_={}
n = 1

for i in range(N):
    a = input()
    if a in dic_.keys():
        b = dic_.get(a) + 1
        dic_.update({a: b})
        if n < b:
            n = b
    else:
        dic_.update({a: 1})

ANS = []

for i in dic_:
    if dic_.get(i) == n:
        ANS += [i]

ANS = sorted(ANS)

for key in ANS:
        print(key)

Submission status: Accepted

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

for i in range(n):
    tmp = input()
    # print(type(tmp))
    if tmp in d :
        d[tmp] += 1
    else :
        d[tmp] = 1

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

num = 0
l =[]
for k in sd:
    if k[1] < num:
        break
    num = k[1]
    l.append(k[0])

l.sort()

for n in l:
    print(n)

Submission status: Accepted

Solution code:
n=int(input())

li={}
an=[]
ma=0

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

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

ma=li2[0][1]

for j in range(n):
    if li2[j][1]==ma:
        an.append(li2[j][0])
        
        if len(li2)==j+1:
            break
    else:
        break

an.sort()
 
for k in range(len(an)):
    print(an[k])

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = []
max_list = []
max_i = 1

a = [str(input()) for x in range(n)]

c = collections.Counter(a)
c = c.most_common()
max_i = c[0][1]

for i in range(len(c)):
    if max_i == c[i][1]:
        max_list.append(c[i][0])
    else:
        break

max_list.sort()

for i in max_list:
    print(i)

Submission status: Accepted

Solution code:
# input1 = list(map(int, (input().split())))
# input2 = list(map(int, (input().split())))
N = int(input())
input2 = []
for i in range(N):
    input2.append(input())

jisyo = {}

for a in input2:
    if a not in jisyo:
        jisyo[a] = 1
    else:
        jisyo[a] += 1

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

m = result[0][1]
liststr = []
for r in result:
    if m != r[1]:
        break
    liststr.append(r[0])

liststr.sort()

for a in liststr:
    print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
v = list(range(n))
for x in range(n):
  v[x] = input()

import collections
c = collections.Counter(v)
values, counts = zip(*c.most_common())
num = list(counts).count(max(counts))
answers = list(values[:num])
answers.sort()
for z in range(num):
  print(answers[z])

Submission status: Accepted

Solution code:
N = int(input())
S = []
for i in range(N):
    S.append(input())
S = sorted(S)
CNT = [1]
dummy = 1
for i in range(1, N):
    if(S[i] == S[i - 1]):
        dummy += 1
    else:
        dummy = 1
    CNT.append(dummy)
#print(S)
#print(CNT)        
MAX = max(CNT)
for i in range(N):
    if(CNT[i] == MAX):
        print(S[i])

Submission status: Accepted

Solution code:
n=int(raw_input())
d={}
for i in range(n):
    x=str(raw_input())
    try:
        d[x]+=1
    except:
        d[x]=0

key_max = max(d.keys(), key=(lambda k: d[k]))
x=d[key_max]
ans=[]
for i in d:
    if(d[i]==x):
        ans.append(i)
ans.sort()
for i in ans:
    print i

Submission status: Accepted

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

from collections import Counter
B = []
mycounter = Counter(S)
max_v = max(mycounter.values())
for s, v in mycounter.items():
  if v == max_v:
    B.append(s)
for a in sorted(B):
  print(a)

Submission status: Accepted

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

s.sort()

t=[]
icnt=0
t.append([1,s[0]])
for i in range(1,len(s)):
    if s[i-1]==s[i]:
        t[icnt][0]=t[icnt][0]+1
    else:
        icnt=icnt+1
        t.append([1,s[i]])
        
#print(t)
t.sort(reverse=True)
#print(t)

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

if len(u)==0:
    print(u[0])    
else:
    u.sort()
    for i in range(len(u)):
        print(u[i])

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input().rstrip())
d=dict()
for _ in range(n):
    s=input().rstrip()
    if s not in d:
      d[s]=1
    else:
      d[s]+=1
ans=Counter(d).most_common()
ans.sort(key=lambda x: (-x[1],x[0]))
m=ans[0][1]
for i in ans:
    if i[1]!=m:
        break
    print(i[0])

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(), key=lambda x: x[1], reverse=True)
a = []
count = -1
for s in sorted_S:
    if count == -1:
        a.append(s[0])
        count = s[1]
    elif count == s[1]:
        a.append(s[0])
    else:
        break
sorted_a = sorted(a)
for s in sorted_a:
    print(s)

Submission status: Accepted

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

for i in range(N):
    arg = input()
    if (arg in S):
        S[arg] = S[arg] + 1
    else:
        S[arg] = 1
valSorted = sorted(S.items(), key=lambda x:(-x[1], x[0]))
breakKey = -1
for key, value in valSorted:
    if breakKey == -1:
        breakKey = value
    if breakKey != value:
        break
    print(str(key))

Submission status: Accepted

Solution code:
import collections
N = int(input())
S = []
for i in range(N):
  S.append(str(input()))
A = collections.Counter(S)
m = max(A.values())
for s in sorted(set(S)):
  if A[s] == m:
    print(s)

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import OrderedDict

N = int(input())
ans = dict()
for _ in range(N):
    k = str(input())
    if k in ans:
        ans[k] += 1
    else:
        ans.update({k: 1})
groupedByValue = defaultdict(list)
for key, value in sorted(ans.items()):
    groupedByValue[value].append(key)
l = groupedByValue[max(groupedByValue)]
for i in l:
    print(i)

Submission status: Accepted

Solution code:
n = 0
s = [""]

def format_input(filename = None):
	global n
	global s
	if filename == None:
		n = int(input())
		s = [input() for i in range(n)]

	elif filename == '__random__':
		from random import randint as rng
		from random import choices
		n = rng(1, 2 * 10**5)
		s = [''.join(choices('abcdefghijklmnopqrstuvwxyz', k = rng(1, 10))) for i in range(n)]

def get_answer():
	poll_dict = {}
	for i in s:
		if i in poll_dict:
			poll_dict[i] += 1
		else:
			poll_dict[i] = 1
	sorted_dict = sorted(poll_dict.items(), key=lambda x:x[1], reverse=True)
	name_list = [i for i, j in sorted_dict if j == sorted_dict[0][1]]
	name_list.sort()
	answer = ""
	for i in name_list:
		answer += i
		answer += '\n'
	answer = answer[:-1]
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)

Submission status: Accepted

Solution code:
n = int(input())

s_dic = dict()
a_dic = dict()

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

# s_dic_sk = sorted(s_dic.items())
s_dic_s = sorted(s_dic.items(), key= lambda x:x[1], reverse=True)

# print(len(s_dic_s))
#print(s_dic_s)

m_count = s_dic_s[0][1]
# print(m_count)

max_n = True
j = 0

while max_n:
  if s_dic_s[j][1] == m_count:
    a_dic[s_dic_s[j][0]] = s_dic_s[j][1]
    j += 1
    if j == len(s_dic_s):
      max_n = False
  else:
    max_n = False

# print(a_dic)
a_dic_s = sorted(a_dic.items())
    
# print(a_dic_s)

for i in range(len(a_dic_s)):
  print(a_dic_s[i][0])

Submission status: Accepted

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

sorted_dic = sorted(dic.items(), key=lambda x:x[1], reverse=True)
ans = []
max = 0
for sd in sorted_dic:
    if max <= sd[1]:
        ans.append(sd[0])
        max = sd[1]
    else:
        break

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

Submission status: Accepted

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

N = int(input())
d = {}
for i in range(N):
    S = input()
    if S in d:
        cnt = d[S]
        cnt += 1
        d.update({S: cnt})
    else:
        d.update({S: 1})
list = sorted(d.items(), key=lambda x:(-x[1], x[0]))
max = list[0][1]
for v in list:
    if max == v[1]:
        print(v[0])
    else:
        break

Submission status: Accepted

Solution code:
N = int(input())
S = []
for i in range(N):
    S.append(input())
T = {}
for i in range(N):
  if S[i] in T:
    T[S[i]] += 1
  else:
    T.setdefault(S[i],1)
A = max(T.values())

keys = [k for k, v in T.items() if v == A]
U =sorted(keys)

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

Submission status: Accepted

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

max_n = max(n_dict.values())

max_s = [s for s in n_dict.keys() if n_dict[s] == max_n]

max_s.sort()

for s in max_s:
  print(s)

Submission status: Accepted

Solution code:
a = int(input())
import collections
b = [input() for i in range(a)]
clist = collections.Counter(b)
#print(clist)
V = clist.keys()
#print(V)
L = clist.most_common()[0][1]
#print(L)

d=[]
f=[]
g=[]
for i in clist.values():
    d.append(i)
for i in clist.keys():
    f.append(i)
#print(d)
for j in range(len(d)):
    if d[j] == L:
        g.append(f[j])
g.sort()
for i in range(len(g)):
    print(g[i])

Submission status: Accepted

Solution code:
import collections
N = int(input())
S = [input() for i in range(N)]
c = collections.Counter(S)
values, counts = zip(*c.most_common())
i = 0
lst = [values[i] for i in range(len(c)) if counts[0] == counts[i]]
lst.sort()
for i in lst:
    print(i)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = []
for i in range(n):
  a.append(input())
c = collections.Counter(a)
b = sorted(list(c.items()))
MAX = max(c.values())
for i in range(len(b)):
  if b[i][1]==MAX:
    print(b[i][0])

Submission status: Accepted

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

max_val = max(dic.values())
k = [key for key in dic if dic[key] == max_val]
for i in sorted(k):
    print(i)

Submission status: Accepted

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

  tmp = [input() for i in range(num)]

  tmp2 = {}
  for t in tmp:
    if len(tmp2) == 0:
      tmp2[t] = 1
    else:
      if t in tmp2:
        tmp2[t] += 1
      else:
        tmp2[t] = 1

  _tmp2 = sorted(tmp2.items(), key=lambda x:x[1])
  tmp3 = sorted(tmp2.items())
  for t in tmp3:
    if _tmp2[-1][1] == t[1]:
      print(t[0])

main()