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())

d = dict()
m = 0
for i in range(N):
    s = input()
    if s not in d:
        d[s] = 0
    d[s] += 1
    if m < d[s]:
        m = d[s]

result = list()
for x in d:
    if d[x] == m:
        result.append(x)

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

Submission status: Accepted

Solution code:
n = int(input())
s = []
for _ in range(n):
    s.append(input())
d = {}
name = set(s)
for a in name:
    d.update({a:0})
for x in s:
    d[x] += 1
ds = sorted(d.items(), key=lambda x:x[1])
max = ds[-1][1]
ans = []
for x in reversed(ds):
    if x[1]==max:
        ans.append(x[0])
    else:
        break
ans.sort()
for x in ans:
    print(x)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N = int(input().strip())
S = [input().strip() for _ in range(N)]

poll = dict()

for key in S:
    poll[key] = poll.get(key, 0) + 1

max_num = max(poll.values())
results = [key for key in poll if poll[key] == max_num]
results.sort()

for s in results:
    print(s)

Submission status: Accepted

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

m = 0
for key,value in s.items():
    if value > m:
        m = value
        ans = [key]
    elif value == m:
        ans.append(key)
ans.sort()
print(*ans,sep='\n')

Submission status: Accepted

Solution code:
from collections import Counter

# print('input >>')

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

Ss_cnt = Counter(Ss)
common = Ss_cnt.most_common()
most = common[0][1]
cand = []
for e in common:
    if e[1] == most:
        cand.append(e[0])
    else:
        break

cand.sort()

# print('-----output-----')
for c in cand:
    print(c)

Submission status: Accepted

Solution code:

def main():
    from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #n = int(stdin.readline()[:-1])   
    #r = stdin.readline()[:-1]
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]
    #n = int(r)
    #a = r.split()
    #a,b,c = r.split()
    #a = list(map(int, r.split()))
    #a,b,c,d = map(int, r.split())
    #a = list(map(int, r.split()))
    #a = [int(s[i]) for i in range(1, n+1)]
    #a = [list(map(int, r.split())) for i in range(1,n+1)]
    #a = [list(map(int, input().split())) for i in range(1,n+1)]
    #res = 0

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

    from collections import Counter
    S=Counter(a)
    b = sorted(S.items(), key=lambda x:(-x[1],x[0])) 
    m = b[0][1]
    for i in b:
        if i[1] == m:
            print(i[0])
        else:
            break

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
N = int(input())
input = sys.stdin.readline

c = defaultdict(int)

maxC = 0

for _ in range(N):
    s = input().strip()
    c[s] += 1
    tmp = c[s]
    if tmp > maxC:
        maxC = tmp

ans = []

for k in c:
    if c[k] == maxC:
        ans.append(k)

ans.sort()

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
N = int(input())

count = dict()
for _ in range(N):
    x = input()
    count[x] = count.get(x, 0) + 1

max_val = -float("infinity")
for k, v in sorted(count.items(), key=lambda x: (-x[1], x[0])):
    max_val = max(v, max_val)
    if v == max_val:
        print(k)
    else:
        break

Submission status: Accepted

Solution code:
import collections

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

counter =  collections.Counter(arr).most_common()

res = []
temp = 0
for x, y in counter:
    if y < temp:
        break
    temp = y
    res.append(x)

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

Submission status: Accepted

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

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

dd.sort()
for dv in dd:
  print(dv)

Submission status: Accepted

Solution code:
n=int(input())
dic={}
m=0
li=[]

for _ in range(n):
    w=input()
    dic[w]=dic.get(w, 0)+1
    if dic[w]==m:
        li.append(w)
    elif dic[w]>m:
        li=[w]
        m+=1

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

Submission status: Accepted

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

s.sort()
#print(s)
l = []
ans_count = 0
count = 1
S = s[0]
for i in range(1,n):
    if S == s[i]:
        count += 1
        if i == n-1:
            l.append([S,count])
            ans_count = max(ans_count,count)
    else:
        l.append([S,count])
        S = s[i]
        ans_count = max(ans_count,count)
        count = 1
        if i == n-1:
            l.append([S,count])
            ans_count = max(ans_count,count)
#print(l)
#print(ans_count)
ans = []
for i in l:
    if i[1] == ans_count:
        ans.append(i[0])
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())

from collections import defaultdict
d = defaultdict(int)

for i in range(n):
  k = input()
  d[k] += 1

m = max(d.values())
ans = []
for k,v in d.items():
  if v == m:
    ans.append(k)
for i in sorted(ans):
  print(i)

Submission status: Accepted

Solution code:
n = int(input())
dic = {}
for _ in range(n):
  s = input()
  if s in dic.keys():
    dic[s] += 1
  else:
    dic[s] = 1
    
dic = [[k,v] for (k, v) in dic.items()]
dic.sort(key=lambda x:x[1], reverse=True)

n = dic[0][1]
dic = [k for (k,v) in dic if v == n]
dic.sort()
for s in dic:
  print(s)

Submission status: Accepted

Solution code:
from collections import Counter
def solve(N, S):
    c = Counter(S)
    m = max(c.values())
    ans = []
    for x, y in c.items():
        if y == m:
            ans.append(x)
    ans.sort()
    for i in ans:
        print(i)


def main():
    N = int(input())
    S = [input() for _ in range(N)]
    solve(N, S)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

li = []
ma = 0

for s in d:
  if ma == d[s]:
    li.append(s)
    ma = d[s]
    
  if ma < d[s]:
    li = []
    li.append(s)
    ma = d[s]

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

Submission status: Accepted

Solution code:
n=int(input())
dic={}
for _ in range(n):
  inp=input()
  dic.setdefault(inp,0)
  dic[inp]+=1
maxval=0
maxkey=[]
for key,val in dic.items():
  if maxval==val:
    maxkey.append(key)
  elif val>maxval:
    maxkey=[key]
    maxval=val
maxkey.sort()
for i in maxkey:
  print(i)

Submission status: Accepted

Solution code:
# python3
# -*- coding: utf-8 -*-
import sys
import math
#from math import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint

INF = float('inf')

ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
sys.setrecursionlimit(1000000000)


def lcm(a, b):
    return (a * b) // gcd(a, b)


# main
N = ii()
slist = {}
maxvalue = 0

for _ in range(N):
    S = input()
    try:
        slist[S] += 1
    except KeyError:
        slist[S] = 1

    if maxvalue < slist[S]:
        maxvalue = slist[S]

maxs = []
for s in slist:
    if slist[s] == maxvalue:
        maxs.append(s)


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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]
c = Counter(S)
ma = 0
ans = []
for k, v in c.most_common():
    if v >= ma:
        ma = v
        ans.append(k)
    else:
        break
ans.sort()
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
import collections

n = int(input())


d = collections.defaultdict(lambda:0)

for i in range(n):
    s = input()
    d[s] += 1

d = dict(d)

a = collections.Counter(d).most_common()

most = a[0][1]
ans = []

for k, v in a:
    if v == most:
        ans.append(k)
    else:
        break

ans.sort()

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
  si = str(input())
  a.append(si)
a.sort()
mx = 1
w = []
j = 1
for i in range(1,n):
  if a[i] == a[i-1]:
    j += 1
  else:
    if j > mx:
      w = [a[i-1]]
      mx = j
    elif j == mx:
      w.append(a[i-1])
    j = 1
if j > mx:
  w = [a[n-1]]
elif j == mx:
  w.append(a[n-1])
for wi in w:
  print(wi)

Submission status: Accepted

Solution code:
N = int(input())
D = {}
ans = []
ansval = 0
for _ in range(N):
    s = input()
    if s not in D:
        D[s] = 1
    else:
        D[s] += 1
    if ansval == D[s]:
        ans.append(s)
    elif ansval < D[s]:
        ans = [s]
        ansval = D[s]
ans.sort()
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
N = int(input())

lst = [input() for i in range(N)]

import collections

c = dict(collections.Counter(lst))
c_s = sorted(c.items(), key=lambda x:-x[1])
ma = c_s[0][1]
ans = []
for i in c_s:
  if (i[1] == ma):
    ans.append(i[0])
s_ans = sorted(ans)
for i in s_ans:
  print(i)

Submission status: Accepted

Solution code:
n = int(input())
L = []
anslist = []
for i in range(n):
  s = input()
  L.append(s)
L.sort()
L.append('zzzzzzzzzzzzz')
cntmax = 1
cur = L[0]
temp = 1
for i in range(1,n+1):
  if L[i] == cur:
    temp += 1
  else:
    cur = L[i]
    cntmax = max(cntmax,temp)
    temp = 1
cur = L[0]
temp = 1
for i in range(1,n+1):
  if L[i] == cur:
    temp += 1
  else:
    cur = L[i]
    if temp == cntmax:
      anslist.append(L[i-1])
    temp = 1
anslist.sort()
for i in range(len(anslist)):
  if anslist[i] != 'zzzzzzzzzzzzz':
    print(anslist[i])

Submission status: Accepted

Solution code:
import collections
n = int(input())
dd = collections.defaultdict(int)
for _ in range(n):
    dd[input()] += 1
ans = []
for key in dd.keys():
    ans.append((dd[key], key))
ans.sort(reverse=True)
ans2 = [ans[0][1]]
for i in range(1, len(ans)):
    if ans[i - 1][0] != ans[i][0]:
        break
    ans2.append(ans[i][1])
ans2.sort()
print(*ans2, sep='\n')

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
S=sorted([input() for _ in range(N)])
S=Counter(S).most_common()
m=S[0][1]

ans=[]
for i in S:
  if i[1]==m:
    ans.append(i[0])
  else:
    break

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

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

m = {}
for s in sss:
    if s in m:
        m[s] += 1
    else:
        m[s] = 1

items = m.items()
items = list(sorted(items, key=lambda i:i[0]))
items = list(sorted(items, key=lambda i: i[1], reverse=True))

max_ = items[0][1]
i = 0
while i<len(items) and items[i][1] == max_:
    print(items[i][0])
    i+=1

Submission status: Accepted

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

for row in r:
  max = row
  break
for row in r:
  if r[row] > r[max]:
    max = row

ans = []
for row in r:
  if r[row] == r[max]:
    ans.append(row)
A = sorted(ans)
for a in A:
  print(a)

Submission status: Accepted

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

dic = Counter(strs)
max_count = max(dic.values())

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

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
S_array = [list(read_str().split())[0] for _ in range(N)]

dic = defaultdict(lambda: int())
def solve():
    ans = 0
    res = []
    for s in S_array:
        dic[s] += 1
    for _, v in dic.items():
        ans = max(ans, v)
    for k, v in dic.items():
        if v == ans:
            res.append(k)
    res.sort()
    for r in res:
        print(r)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import collections

N = int(raw_input())

l = []

for i in range(N):
    l.append(raw_input())

c = collections.Counter(l)

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

num_max = counts[0]
index_list = []

for i in range(len(counts)):
    if counts[i] == num_max:
        index_list.append(i)

ans_list = []
for item in index_list:
    ans_list.append(values[item])

for item in sorted(ans_list):
    print item

Submission status: Accepted

Solution code:
import collections

n = int(input())

s=[]
for i in range(n):
    s.append(input())
    
c = collections.Counter(s)
c = sorted(c.items())
c_sorted = sorted(c, key=lambda x:x[1],reverse=True)

num=c_sorted[0][1]
for i in c_sorted:
    if num==i[1]:
        print(i[0])
    else:
        break

Submission status: Accepted

Solution code:
n=int(input())
d=dict()
for _ in range(n):
    s=input()
    if s in d:
        d[s]+=1
    else:
        d[s]=1
keys=d.keys()
values=d.values()
m=max(values)
ans=[]
for k,v in zip(keys,values):
    if v==m:
        ans.append(k)
ans.sort()
for a in ans:
    print(a)

Submission status: Accepted

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

n = int(input())
maximum = 0
for _ in range(n):
    s = input()
    d[s] += 1
    maximum = max(maximum, d[s])
    
sorted_d = sorted(d.items())
for k, v in sorted_d:
    if v == maximum:
        print(k)

Submission status: Accepted

Solution code:
import collections as c
import sys
input = sys.stdin.readline
ip = lambda : map(int, input().split())
mod = 10**9+7
# ##############
N = int(input())
dic = {}
for i in range(N):
    s = input()
    s = s[:-1]
    dic[s] = dic.get(s,0) + 1
m = max(dic.values())
ans = []
for i in dic:
    if dic[i]==m:
        ans.append(i)
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

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

a.sort()

ans = []
count = 1
for i in range(n-1):
    if a[i] != a[i+1]:
        ans.append((-count, a[i]))
        count = 1
    else:
        count += 1

ans.append((-count, a[-1]))

ans.sort()
mx, _ = ans[0]
for c, s in ans:
    if c == mx:
        print(s)
    else:
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())

S_dict = {}
max_num = 0
for i in range(N):
    S = str(input())
    now_num = S_dict.get(S, 0) + 1
    S_dict[S] = now_num
    max_num = max(max_num, now_num)

ans_list = [k for k, v in S_dict.items() if v == max_num]
ans_list.sort()

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

Submission status: Accepted

Solution code:
n = int(input())
mx = 1
d = {}
for i in range(n):
    s = input()
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
    mx = max(mx, d[s])
spis = []
for k, z in d.items():
    if z == mx:
        spis.append(k)
spis.sort()
for a in spis:
    print(a)

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
st = [stdin.readline().rstrip() for _ in range(n)]
dic = {}
for s in st:
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1

dic = sorted(dic.items(), key=lambda x: -x[1])
vmax = 0
res = []
for k, v in dic:
    vmax = max(vmax, v)
    if vmax == v:
        res.append(k)
    else:
        break
for s in sorted(res):
    print(s)

Submission status: Accepted

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

from collections import Counter
def main():
    n = ii()
    S = []
    for _ in range(n):
        S.append(input())
    c = Counter(S)
    d = c.most_common()
    ans = []
    mm = 0
    for i in range(len(c)):
        if mm > d[i][1]:
            break
        ans.append(d[i][0])
        mm = d[i][1]
    ans.sort()
    for i in range(len(ans)):
        print(ans[i])

main()

Submission status: Accepted

Solution code:
N = int(input())
S = dict()
for i in range(N):
    s = input()
    if s not in S:
        S[s] = 1
    else:
        S[s] += 1
S = sorted(S.items(), key=lambda x:(x[1],x[0]))
m = S[-1][1]
for i in range(len(S)):
    s = S[i][0]
    if S[i][1] == m:
        print(s)

Submission status: Accepted

Solution code:
N = int(input())

d = dict()

for i in range(N):
    s = input()
    try:
        d[s] += 1
    except KeyError:
        d[s] = 1

max_value = max(d.values())


res_ls = []

for k, v in d.items():
    if v == max_value:
        res_ls.append(k)
        
for r in sorted(res_ls):
    print(r)

Submission status: Accepted

Solution code:
import collections

n = int(input())

res = []

for _ in range(n):
  res.append(input())

c = collections.Counter(res)
aa = c.most_common()

ss = aa[0][1]
res2 = []

aa.sort()
for i in aa:
  if i[1] == ss:
    res2.append(i[0])

for i in res2:
  print(i)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
from collections import Counter

N = int(readline())
S = [readline().rstrip() for i in range(N)]

c = Counter(S)

maxc = max(c.values())

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

a.sort()

for s in a:
    print(s)

Submission status: Accepted

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

c = collections.Counter(l)
cc = c.most_common()
cc.sort(key=lambda x: x[1],reverse=True)
ll = []
m = 0
for k,v in cc:
    if v >= m:
        m = v
        ll.append((k))
ll = sorted(ll)
for a in ll:
    print(a)

Submission status: Accepted

Solution code:
import sys #sys.stdin.readline()
import heapq #heap
from collections import defaultdict
fastinp = lambda: sys.stdin.readline().split(' ')[0].split('\n')
inp = lambda: input().split(' ')
ml = lambda x, y=int: list(map(y, x))
debug = lambda *args: print(*args, sep=' | ')
n = int(fastinp()[0])
hmap = defaultdict(int)
for i in range(n):
    hmap[fastinp()[0]] += 1
m = 0
for k, v in hmap.items():
    m = max(m, v)
list = []
for k, v in hmap.items():
    if v == m:
        list.append(k)
print(*sorted(list), sep='\n')

Submission status: Accepted

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

m = max(d.values())

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

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
import sys
inputs = sys.stdin.readlines()
from collections import Counter

n = int(inputs[0])
S = [s.strip() for s in inputs[1:]]
counter = Counter(S)
m = max(counter.values())
print(*sorted([k for k, v in counter.items() if v == m]), sep='\n')

Submission status: Accepted

Solution code:
from itertools import groupby

N=int(input())
S=['a' for i in range(0,N)]
for i in range(0,N):
    S[i]=input()
S.sort()
X=groupby(S)
data=[]
for key,group in X:
    g=len(list(group))
    data.append([g,key])
data.sort()
m=data[len(data)-1][0]
for i in range(0,len(data)):
    if data[i][0]==m:
        print(data[i][1])

Submission status: Accepted

Solution code:
n= int(input())
s = [input() for _ in range(n)]
r = {}
g=0
for c in s:
    r[c] = r.get(c,0) + 1
    g = max(g,r[c])
word = []
for c in r.keys():
    if r[c]==g:word.append(c)
word.sort()
for c in word:print(c)

Submission status: Accepted

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

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

m = c[0][1]
ans = []
for a, b in c:
    if b == m:
        ans.append(a)

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = [input() for _ in [0] * n]
s = Counter(s)
a = max(s.values())
b = s.most_common()[:list(s.values()).count(a)]
b = sorted(b, key=lambda x: x[0])
for i in b:
    print(i[0])

Submission status: Accepted

Solution code:
import collections
n=int(input())
a=list(input() for i in range(n))

a = collections.Counter(a)
a= a.most_common()
b=[]
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:
def main():
    n = int(input())
    table = {}
    m = 0
    for i in range(n):
        s = input()
        if s not in table:
            table[s] = 0
        table[s] += 1
        m = max(m, table[s])

    table = dict(filter(lambda x: x[1] == m, table.items()))
    table = sorted(table.items(), key=lambda x: x[0])

    for t in table:
        print(t[0])


main()

Submission status: Accepted

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(input())
s.sort()
s.append('#')
x = 1
ls = []
for i in range(n):
    if s[i] == s[i+1]:
        x += 1
    else:
        ls.append((x,s[i]))
        x = 1
ls.sort()
ls.reverse()
ls.append((0,'#'))
ans = []
ans.append(ls[0][1])
for i in range(1,n):
    if ls[i-1][0] == ls[i][0]:
        ans.append(ls[i][1])
    else:
        break
ans.sort()
for x in ans:
    print(x)

Submission status: Accepted

Solution code:
def get_keys_from_value(d_, val_):
    return [k for k, v in d_.items() if v == val_]
import collections

n = int(input())
s = []

for i in range(n):
    s.append(input())
c = collections.Counter(s)

max_val = max(c.values())
ans = sorted(get_keys_from_value(c, max_val))

for i in ans:
    print(i)

Submission status: Accepted

Solution code:


n=int(input())

s={}
cnt=0
result=[]

for _ in range(n):
    temp = input()
    if temp in s:
        s[temp]+=1
        if s[temp]>cnt:
            cnt=s[temp]
            result=[temp]
        elif s[temp]==cnt:
            result.append(temp)
    else:
        s[temp]=1
        if s[temp]>cnt:
            cnt=s[temp]
            result=[temp]
        elif s[temp]==cnt:
            result.append(temp)
result.sort()
for item in result:
    print(item)

Submission status: Accepted

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

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

l_ = []
max_ = max(d.values())
#print(max_)
for k, v in d.items():
    if v == max_:
        l_.append(k)

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
cnt = Counter(SR(n))
L = [(k, v) for k, v in cnt.items()]
L.sort()
L.sort(key=lambda x:x[1], reverse=True)
pre_v = L[0][1]
for k, v in L:
    if v != pre_v:
        break
    print(k)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
Sl = [input() for _ in range(N)]
cSl = Counter(Sl).most_common()
pre = ""
maxl = []
for k, v in cSl:
    if pre != "" and pre != v:
        break
    maxl.append(k)
    pre = v
for e in sorted(maxl):
    print(e)

Submission status: Accepted

Solution code:
import collections

N = int(input())
table = []
ans = []

for i in range(N):
    s = input()
    table.append(s)

c = collections.Counter(table).most_common()

pre_x = c[0][1]
for s,x in c:
    if pre_x != x:
        break
    ans.append(s)
    pre_x = x

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = list()
for i in range(n):
    s.append(input())
l = collections.Counter(s)
count = list(l.items())
count.sort(key=lambda x: x[1], reverse=True)
ind, x = 0, count[0][1]
for i in range(len(count)):
    if count[i][1] != x:
        ind = i-1
        break
    else:
        ind = i
x = count[:ind+1]
x.sort()
for i in range(ind+1):
    print(x[i][0])

Submission status: Accepted

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

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

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

maxV = 0
maxK = []

for key, val in nums.items():
    maxV = max(maxV, val)

for key, val in nums.items():
    if val == maxV:
        maxK.append(key)

# print(nums)
# print(maxK)

maxK.sort()

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

Submission status: Accepted

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

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

dic = defaultdict(int)

for x in S:
	dic[x] += 1

ma = max(dic.values())

a = []
for i in dic.items():
	if i[1] == ma:
		a.append(i[0])

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

Submission status: Accepted

Solution code:
import collections

n = int(input())
s = [input() for i in range(n)]
c = collections.Counter(s)
z = c.most_common()[0][1]
ans = []
for i in c.most_common():
    if i[1] == z:
        ans.append(i[0])
    else:
        break
ans.sort()
for j in ans:
    print(j)

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = []
for i in range(n):
    S = str(input())
    s.append(S)
c = collections.Counter(s)
jud = c.most_common()[0][1]
set_s = set(s)
lists = []
for i in set_s:
    if jud == int(c[i]):
        lists.append(i)
lists.sort()
for i in range(len(lists)):
    print(lists[i])

Submission status: Accepted

Solution code:
n = int(input())
dic = {}
for i in range(n):
	s = input()
	if s in dic:
		dic[s] += 1
	else:
		dic[s] = 1
dic2 = sorted(dic.items(), key=lambda x:x[1],reverse=True)
x = dic2[0][1]
b = []

for i in dic2:
	if i[1] == x:
		b.append(i[0])
b.sort()
for i in b:
	print (i)

Submission status: Accepted

Solution code:
N = int(input())

S_dic = {}
maximum = 0
for n in range(N):
    S = input()
    if S not in S_dic:
        S_dic[S] = 1
    else:
        S_dic[S] += 1
    if maximum < S_dic[S]:
        maximum = S_dic[S]


for key, value in sorted(S_dic.items(), key=lambda x: x[0]):
    if value == maximum:
        print(key)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(N)]
d = dict()
for s in S:
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
l = sorted(d.items(), key=lambda x: x[1], reverse=True)
maxv = l[0][1]
res = []
for x in l:
    if x[1] == maxv:
        res.append(x[0])
for x in sorted(res):
    print(x)

Submission status: Accepted

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

maxw = max(d.values())

ans = [k for k, v in d.items() if v == maxw]
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
from collections import Counter

n=int(input())
l=[]
for i in range(n):
    l.append(input())
l=Counter(l).most_common()
Max=l[0][1]
ans=[]
for i,j in l:
    if j==Max:
        ans.append(i)
for i in sorted(ans):
    print(i)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    d = {}
    max = 1


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

    dict2 = sorted(d.items())
    for i in dict2:
        if i[1] == max:
            print(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()

ans_list=[]
maxi=d[0][-1]
for i,item in enumerate(d):
  if d[i][-1] == maxi:
    ans_list.append(item[0])
    
ans_list.sort()
for item2 in ans_list:
  print(item2)

Submission status: Accepted

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

m = max(d.values())
lst = []
for key in d:
    if d[key] == m:
        lst.append(key)

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = Counter(input() for _ in range(N))
S = S.most_common()
most_count = S[0][1]
S.sort()
for i in range(len(S)):
    if S[i][1] == most_count:
        print(S[i][0])

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
c = Counter()
for i in range(n):
  s = input()
  c[s] += 1

_, maxi = c.most_common()[0]
ans = []
for s, i in c.most_common():
  if i != maxi:
    break
  ans.append(s)
  
for s in sorted(ans):
  print(s)

Submission status: Accepted

Solution code:
from collections import Counter


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

c = Counter(S)

max_ = 0

x = []
for k, v in c.items():
    max_ = max(max_, v)
    x.append([k, v])

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


for k, v in x:
    if v == max_:
        print(k)

    if v != max_:
        exit()