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())
s = [input() for _ in range(n)]
d = {}
for w in s:
    if w not in d:
        d[w] = 0
    d[w] += 1
d2 = sorted(d.items(), key=lambda x:x[1], reverse=True)
maxcnts = [w[0] for w in d2 if w[1] == d2[0][1]]
maxcnts.sort()
for ans in maxcnts:
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
d = {}
for i in range(N):
  s = input()
  if s in d.keys():
    d[s] += 1
  else:
    d[s] = 1
mx = 0
for i in d.values():
  mx = max(mx, i)
for i in sorted(d.items()):
  if i[1] == mx:
    print(i[0])

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
from collections import Counter
import numpy as np
n=int(input())
S=[]
for i in range(n):
    S.append(input())
s=Counter(S)
keys, values = zip(*s.most_common())

values=np.array(values)
index=np.where(values==np.max(values))
answer=[]
for i in index[0]:
    answer.append(keys[i])
answer.sort()
for i in answer:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
d = {}
for w in s:
  if w not in d:
    d[w] = 0
  d[w] += 1
d2 = sorted(d.items(), key=lambda x:x[1], reverse=True)
maxcnts = [w[0] for w in d2 if w[1] == d2[0][1]]
maxcnts.sort()
for ans in maxcnts:
  print(ans)

Submission status: Accepted

Solution code:
#from collections import Counter
n = int(input())
d = {}
for i in range(n):
  s = input()
  if s in d:
    d[s] += 1
  else:
    d[s] = 1

ds = sorted(d.items(), key=lambda t:(-t[1],t[0]))

m = ds[0][1]
#print(m)
ans = []
for k, v in ds:
  if v != m:
    break
  print(k)

Submission status: Accepted

Solution code:
N=int(input())
votes = dict()
for _ in range(N):
    S = input()
    if votes.get(S):
        votes[S] += 1
    else:
        votes[S] = 1
max = 0
for k in votes:
    if votes[k] > max:
        max = votes[k]
keys = []
for k in votes:
    if votes[k] == max:
        keys.append(k)
keys.sort()
for k in keys:
    print(k)

Submission status: Accepted

Solution code:
N = int(input())
d = dict()
for i in range(N):
  let = input()
  if let in d:
    d[let] += 1
  else:
    d[let] = 0
max = 0
res = []
for i in d:
  if d[i]  > max:
    max = d[i]
    res =[i]
  elif d[i] == max:
    res.append(i)
for i in sorted(res):
  print(i)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

sys.setrecursionlimit(1000000)
dire, dire8 = [[1, 0], [0, 1], [-1, 0], [0, -1]], [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets, ALPHABETS = "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD, INF = 1000000007, float("inf")

def main():
    N = I()
    S = R(N)
    c = Counter(S)
    [common] = c.most_common(1)
    for k, v in sorted(c.items(), key=lambda x: (-x[1], x[0])):
        if common[1] != v:
            break
        print(k)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
d={}
m=1
for i in range(n):
    s=input()
    if s in d:
        d[s]+=1
        m=max(m,d[s])
    else:
        d[s]=1
se=set()
for i in d:
    if d[i]==m:
        se.add(i)
se=list(se)
se.sort()
print(*se)

Submission status: Accepted

Solution code:
import collections
import itertools
N = int(input())
P = [input() for i in range(N)]
ans =[]

counter = collections.Counter(P)
mode_v = counter.most_common()[0][-1]
it = list(itertools.takewhile(lambda kv: kv[-1] == mode_v, counter.most_common()))
for i in range(len(it)):
    ans.append(it[i][0])
s_ans = sorted(ans)
for i in range(len(s_ans)):
    print(s_ans[i])

Submission status: Accepted

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

max = max(num.values())
keys = []
for k, v in num.items():
    if v == max:
        keys.append(k)
keys.sort()

for key in keys:
    print(key)

Submission status: Accepted

Solution code:
import collections

N = int(input())
L = [input() for i in range(N)]
c = collections.Counter(L)

max_L = max(list(c.values()))

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

for key in keys:
    print(key)

Submission status: Accepted

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

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

abc155c_poll()

Submission status: Accepted

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

maxS=max(S.values())
S=[k for k,v in S.items() if v==maxS]
print('\n'.join(sorted(S)))

Submission status: Accepted

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

maxS=max(S.values())
S={k:v for k, v in S.items() if v==maxS}
S=sorted(S.items(), key=lambda x:(-x[1],x[0]))
for k,cnt in S:
  print(k)

Submission status: Accepted

Solution code:
N=int(input())
S={}
for n in range(N):
  s=input()
  S[s]=S.get(s,0)+1
  
S=sorted(S.items(), key=lambda x:(-x[1],x[0]))
maxS=S[0][1]
for s, cnt in S:
  if cnt!=maxS:
    break
  print(s)

Submission status: Accepted

Solution code:
N = int(input())
D = {}
for i in range(N):
	S = input()
	M = D.get(S)
	if M == None:
		D.update([(S, 1)])
	else:
		D.update([(S, M+1)])
E = list(D.keys())
F = list(D.values())
MA = max(F)
I = [i for i,x in enumerate(F) if x == MA]
ans =[]
for i in I:
	ans.append(E[i])
ans = sorted(ans)
print('\n'.join(ans))

Submission status: Accepted

Solution code:
n = int(input())
dic1 = {}
for i in range(n):
    s = input()
    if s not in dic1.keys():
        dic1[s] = 1
    else:
        dic1[s] += 1
dic2 = sorted(dic1.items(), key=lambda j: j[1], reverse=True)

ans_ls = []
for k in range(len(dic2)):
    if dic2[k][1] != dic2[0][1]:
        break
    ans_ls.append(dic2[k][0])
ans_ls.sort()
for _ in ans_ls:
  	print(_)

Submission status: Accepted

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

ans = []

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

ans = sorted(ans)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
N = int(input())
d = {}
for _ in range(N):
    s = input().replace('\n', '')
    d[s] = d.get(s, 0) + 1
max_count = 0
for count in d.values():
    max_count = max(max_count, count)

ans = sorted([k for k, v in d.items() if v == max_count])
print('\n'.join(ans))

Submission status: Accepted

Solution code:
N=int(input())

ls={}
max_ch=0
for i in range(N):
    ch=input()
    if not ch in ls:
        ls[ch]=1
    else:
        ls[ch]+=1
    if max_ch<ls[ch]:
        max_ch=ls[ch]

S=[]
for j in ls:
    if max_ch==ls[j]:
        S.append(j)

S=sorted(S)

for i in S:
    print(i)

Submission status: Accepted

Solution code:
count = {}
for i in range(int(input())):
    S = input()
    if S in count:
        count[S] += 1
    else:
        count[S] = 1
ans = max(count.values())
print(*sorted([A[0] for A in count.items() if A[1] == ans]))

Submission status: Accepted

Solution code:
import collections
n=int(input())
s=[]
for i in range(n):
  c=input()
  s.append(c)
a=collections.Counter(s)
d=sorted(a.items(), key=lambda x:x[1])
e=max(a.values())
l=[]
for i in a:
  if a[i]==e:
    l.append(i)
l.sort()
for i in l:
  print(i)

Submission status: Accepted

Solution code:
N=int(input())
kouholist=[]
worddict=dict()
maxvalue=0
for i in range(N):
    S=input()
    if S in worddict.keys():
        worddict[S]+=1
    else:
        worddict[S]=1
    maxvalue=max(maxvalue,worddict[S])
#print("ここから")
#print(worddict)
for k in worddict.keys():
    if worddict[k]==maxvalue:
        kouholist.append(k)
kouholist=sorted(kouholist)
for h in range(len(kouholist)):
    print(kouholist[h])

Submission status: Accepted

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

N = int(input())

for _ in range(N):
    Poll_Dict[str(input())] += 1

Max_Number = max(Poll_Dict.values())    
Max_List = sorted([k[0] for k in Poll_Dict.items() if k[1] == Max_Number])

for i in Max_List:
    print(i)

Submission status: Accepted

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

maxcount = max(x.values())
ans = []
for s, count in x.items():
    if count == maxcount:
        ans.append(s)
ans.sort()
for a in ans:
    print(a)

Submission status: Accepted

Solution code:


num_of_votes = int(input())

poll = {}

for i in range(num_of_votes):
    entry = input()
    
    if (poll.get(entry) == None):
        poll[entry] = 0
    
    poll[entry] += 1

max_votes = 0
most_voted_entries = []

for key in poll:
    num_of_votes = poll[key]

    if num_of_votes > max_votes:
        most_voted_entries = [ key ]
        max_votes = num_of_votes
    elif num_of_votes == max_votes:
        most_voted_entries.append(key)

for entry in sorted(most_voted_entries):
    print(entry)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
ss = sorted(s)
t = ss
x = 0
maxx = 0
for i in range(n-1):
    if ss[i] == ss[i+1]:
        x += 1
        if x == maxx:
            maxx = x
            t.append(ss[i])
        elif x > maxx:
            maxx = x
            t = [ss[i]]
    else:
        x = 0
for j in t:
    print(j)