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:
from collections import Counter
def solve():
  N = int(input())
  S = [input() for _ in range(N)]
  c = Counter(S)
  M = max(c.values())
  ans = []
  for k,v in c.items():
    if v==M:
      ans.append(k)
  ans.sort()
  return ans
print(*solve(),sep='\n')

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
C = Counter([input() for _ in range(N)])
# print(f'{list(C)=}')

max_value = max([value for value in C.values()])
# print(f'{max_value=}')

S = [key for key, value in zip(C.keys(), C.values()) if value == max_value]
# print(f'{S=}')

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = Counter([input() for _ in range(n)])
before = 0
ans = []
s = s.most_common()
for i in range(len(s)):
    if before == 0: before = s[i][1]
    elif before != s[i][1]: break
    ans.append(s[i][0])
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)]
l = Counter(S)
MAXNUM = max(l.values())

for s in sorted(list(set(S))):
    if l[s] == MAXNUM:
        print(s)

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=[SI() for i in range(n)]
c=Counter(lis)
mx=0
for x in c.keys():
    if c[x]>mx:
        mx=c[x]
answers=[]
for x in c.keys():
    if c[x]==mx:
        answers.append(x)
answers.sort()
for x in answers:
    print(x)

Submission status: Accepted

Solution code:
N = int(input())
C = {}
for _ in range(N):
    s = input().strip()
    if s not in C:
        C[s]=0
    C[s] += 1
cmax = 0
for s in C:
    cmax = max(cmax,C[s])
A = []
for s in C:
    if C[s]==cmax:
        A.append(s)
A = sorted(A)
for i in range(len(A)):
    print(A[i])

Submission status: Accepted

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


t = []
for k,v in d.items():
    t.append((v,k))

t.sort()
num = t[0][0]
for v,s in t:
    if v == num:
        print(s)

Submission status: Accepted

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

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

MAX = max(dic.values())
ans = []
for x in dic.keys():
  if dic[x] == MAX:
    ans.append(x)
ans.sort()
print(*ans,sep="\n")

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]
cnt = Counter(S)
M = max(list(cnt.values()))
ans = []

for k, v in cnt.items():
    if v==M:
        ans.append(k)

ans.sort()

for ans_i in ans:
    print(ans_i)

Submission status: Accepted

Solution code:
n = int(input())
dic = {}
for i in range(n):
    s = str(input())
    if s in dic.keys():
        dic[s] += 1
    else:
        dic.setdefault(s,1)
max_v = max(dic.values())
ans = []
for j in dic.items():
    if j[1] == max_v:
        ans.append(j[0])
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def solve(N: int, S: "List[str]"):
    c = collections.Counter(S).most_common()
    return "\n".join(sorted([i[0] for i in c if i[1] == c[0][1]]))


def main():

    sys.setrecursionlimit(10 ** 6)

    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]"
    print(f'{solve(N, S)}')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
d = {}
for _ in range(int(input())):
    s = input().replace("\n", "")
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

x = max(d.values())
l = sorted(s for (s, i) in d.items() if i == x)
print(*l, sep="\n")

Submission status: Accepted

Solution code:
from collections import  Counter
n = int(input())
lst = []
for _ in range(n):
    lst.append(input())

C = Counter(lst)
x = max(C.values())
anslst = []
for k,v in C.items():
    if v == x:
        anslst.append(k)
anslst.sort()
for v in anslst:
    print(v)

Submission status: Accepted

Solution code:
N = int(input())
count = {}
max_count = 0
for _ in range(N):
  s = input()
  if s not in count:
    count[s] = 0
  count[s] += 1
  max_count = max(max_count, count[s])

longest = []
for s, c in count.items():
  if c == max_count:
    longest.append(s)

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

Submission status: Accepted

Solution code:
import collections

N = int(input())
S = [input() for _ in range(N)]
S.sort()
#print(S)
ans = collections.Counter(S)
values, cnt = zip(*ans.most_common())
#print(values)
#print(cnt)
max_count = cnt[0]
for i in range(len(cnt)):
    if max_count > cnt[i]:
        break
    print(values[i])

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter

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

a = Counter(lis)

tmp = 0
for key, value in a.items():
    tmp = max(value, tmp)

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

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

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()

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

m = max(d.values())
for s in sorted(filter(lambda x: d[x] == m,d)):
    print(s)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
s = sorted(inplL(n))

tmp = ''
ans = []
anscnt = -1
for i in range(n):
    if tmp == s[i]:
        ans[anscnt][1] += 1
    else:
        ans.append([s[i],1])
        anscnt += 1
    tmp = s[i]

ans.sort(key=lambda x: x[1],reverse=True)

tmp = 0
ret = []
for i in range(len(ans)):
    if i == 0 or tmp == ans[i][1]:
        ret.append(''.join(ans[i][0]))
        tmp = ans[i][1]
    elif tmp != ans[i][1] :
        break

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

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
S = defaultdict(int)
for i in range(N):
    S[input()] += 1
m = max(S.values())
for s in sorted(filter(lambda x: S[x] == m, S)):
    print(s)

Submission status: Accepted

Solution code:
n=int(input())
a=[]
b=[[] for _ in range(n)]
for i in range(n):
    s=input()
    a.append(s)
a=sorted(a)
d=0
b[0].append(a[0])
for i in range(1,n):
    if a[i]!=a[i-1]:
        d+=1
    b[d].append(a[i])
x=max(len(b[i]) for i in range(n))
for i in range(n):
    if len(b[i])==x:
        print(b[i][0])

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = Counter([input() for i in range(n)])
max_s = max(s.values()) 
print(*sorted(k for k, v in s.items() if v == max_s), sep='\n')

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = Counter([input() for i in range(n)])
max_s = max(s.values()) 
print(*sorted([k for k, v in s.items() if v == max_s]), sep='\n')

Submission status: Accepted

Solution code:
n = int(input())
c = {}
for i in range(n):
    s = input()
    if s in c:
        c[s] += 1
    else:
        c[s] = 1
max = 0
for k in c.keys():
    if c[k] > max:
        max = c[k]
hit = [k for k in c.keys() if c[k] == max]
hit.sort()
for i in range(len(hit)):
    print(hit[i])

Submission status: Accepted

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

num = 0
for key in dic:
    num = max(num, dic[key])

ans = []
for key in dic:
    if dic[key] == num:
        ans.append(key)

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

Submission status: Accepted

Solution code:
n=int(input())
dic=dict()
for i in range(n):
    s=input()
    if s in dic:
        dic[s]+=1
    else:
        dic[s]=1
ans=[]
val=max(dic.values())
for kv in dic.items():
    if kv[1]==val:
        ans.append(kv[0])
ans=sorted(ans)
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(words)

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

nums = counts.count(max(counts))
xs = (list(values))[:nums]
xs.sort()

for x in xs:
    print(x)

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    n = int(input())
    s = [input() for _ in range(n)]
    s_c = Counter(s)
    s_c_max = s_c.most_common()[0][1]
    keys =[k for k, v in s_c.items() if v == s_c_max]
    keys_s = sorted(keys)
    print(*keys_s, sep='\n')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
Row = int(input())
dictA= {}
a = ""
mid = 0
for i in range (Row):
  a = input()
  dictA.setdefault(a,0) 
  dictA[a] += 1
  mid = max(mid, dictA[a])
sDict = sorted(dictA.items())
for i in range(len(dictA)):
  if sDict[i][1]== mid:
    print(sDict[i][0])

Submission status: Accepted

Solution code:
n = int(input())
dic = dict()

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

ans = []
val = max(dic.values())
for kv in dic.items():
    if kv[1] == val:
        ans.append(kv[0])

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

Submission status: Accepted

Solution code:
n = int(input())
dic = {}
for _ in range(n):
    s = input()
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
mv = max(dic.values())
for s, v in sorted(dic.items()):
    if v == mv:
        print(s)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
xc = Counter()
for _ in range(n):
    xc[input()] += 1

mx = xc.most_common(1)[0][1]
ans = []
for k, v in xc.items():
    if v == mx:
        ans.append(k)
ans.sort()
print(*ans, sep="\n")

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
xc = Counter()
for _ in range(n):
    xc[input()] += 1

mx = xc.most_common(1)[0][1]
ans = []
for v in xc.items():
    if v[1] == mx:
        ans.append(v[0])
ans.sort()
print(*ans, sep="\n")

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    n = int(input())
    S = [input() for _ in range(n)]
    c = Counter(S).most_common()
    V = c[0][1]
    ans = [k for k, v in c if v == V]
    [print(a) for a in sorted(ans)]

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
dic = {}
for _ in range(N):
    s = input()
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
ma = max(dic.values())
for i,j in sorted(dic.items()):
    if j == ma:
        print(i)

Submission status: Accepted

Solution code:
import collections
N = int(input())
S = [input() for _ in range(N)]
c = collections.Counter(S)
d = c.most_common()
cnt = 0
for i in range(len(c)-1):
    if d[i][1] == d[i+1][1]:
        cnt += 1
    else:
        break
e = []
for j in range(cnt+1):
    e.append(d[j][0])
e.sort()
for k in range(len(e)):
    print(e[k])

Submission status: Accepted

Solution code:
def readinput():
    n=int(input())
    sList=[]
    for _ in range(n):
        sList.append(input())
    return n,sList

def main(n,sList):
    hist={}
    for s in sList:
        if s in hist.keys():
            hist[s]+=1
        else:
            hist[s]=1
    hList=sorted(list(hist.items()), key=lambda x:x[1], reverse=True)
    #print(hList)
    hvalue=hList[0][1]
    ss=[]
    i=0
    while(i<len(hList) and hList[i][1]==hvalue):
        ss.append(hList[i][0])
        i+=1
    ss.sort()
    for s in ss:
        print(s)    

if __name__=='__main__':
    n,sList=readinput()
    main(n,sList)

Submission status: Accepted

Solution code:
N = int(input())

S = []

import collections

for i in range (0, N):
	S.append(str(input()))

S = sorted(S)
cnt = collections.Counter()

for word in S:
	cnt[word] += 1
    
mostCommon = cnt.most_common()

D = mostCommon[0][1]
print(mostCommon[0][0])
for i in range(1, len(set(S))):
	if mostCommon[i][1] == D:
		print(mostCommon[i][0])
	else:
		exit()

Submission status: Accepted

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(input())
s.sort()
# print(s)
m = 1
cnt = [1]
ans = []
for i in range(1,n):
    if s[i] == s[i-1]:
        cnt[-1] += 1
    else:
        if cnt[-1] > m:
            ans = [s[i-1]]
        elif cnt[-1] == m:
            ans.append(s[i-1])
        m = max(m, cnt[-1])
        cnt.append(1)
    if i == n-1 and cnt[-1] > m:
        ans = [s[i]]
    elif i == n-1 and cnt[-1] == m:
        ans.append(s[i])
print('\n'.join(ans))

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(S)

max_num = max(c.values())

l = []
for item in c.items():
    k = item[0]
    v = item[1]
    if v == max_num:
        l.append(k)

l.sort()

for li in l:
    print(li)

Submission status: Accepted

Solution code:
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    S = [readline().rstrip() for _ in range(n)]
    c = collections.Counter(S)
    keys = sorted(c.keys())
    maxS = c.most_common()[0][1]
    for key in keys:
        if c[key] == maxS:
            print(key)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# abc155_c.py
# https://atcoder.jp/contests/abc155/tasks/abc155_c

# C - Poll /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点: 300点

# 問題文
# N枚の投票用紙があり、i (1≤i≤N) 枚目には文字列 Siが書かれています。
# 書かれた回数が最も多い文字列を全て、辞書順で小さい順に出力してください。

# 制約
#     1≤N≤2×105
#     Siは英小文字のみからなる文字列 (1≤i≤N)
#     Siの長さは 1 以上 10 以下 (1≤i≤N)

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# S1
# :
# SN

# 出力
# あてはまる文字列を全て辞書順で小さい順に、改行区切りで出力せよ。

# 入力例 1
# 7
# beat
# vet
# beet
# bed
# vet
# bet
# beet

# 出力例 1
# beet
# vet

# 書かれた回数は beet と vet が 2回、beat と bed と bet が 1 回です。したがって、2回書かれた beet と vet を出力します。

# 入力例 2
# 8
# buffalo
# buffalo
# buffalo
# buffalo
# buffalo
# buffalo
# buffalo
# buffalo

# 出力例 2
# buffalo

# 入力例 3
# 7
# bass
# bass
# kick
# kick
# bass
# kick
# kick

# 出力例 3
# kick

# 入力例 4
# 4
# ushi
# tapu
# nichia
# kun

# 出力例 4
# kun
# nichia
# tapu
# ushi


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    values = list()
    for i in range(N):
        values.append(lines[i+1])
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    dic = dict()
    for value in values:
        if value in dic:
            dic[value] += 1
        else:
            dic[value] = 1

    tmp = list()
    for key in dic:
        tmp.append(dic[key])
    ma = max(tmp)

    results = list()
    for key in dic:
        if dic[key] == ma:
            results.append(key)

    results.sort()

    return results


# 引数を取得
def get_input_lines():
    line = input()
    N = int(line)
    lines = list()
    lines.append(line)
    for _ in range(N):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['7', 'beat', 'vet', 'beet', 'bed', 'vet', 'bet', 'beet']
        lines_export = ['beet', 'vet']
    if pattern == 2:
        lines_input = ['8', 'buffalo', 'buffalo', 'buffalo', 'buffalo', 'buffalo', 'buffalo', 'buffalo', 'buffalo']
        lines_export = ['buffalo']
    if pattern == 3:
        lines_input = ['7', 'bass', 'bass', 'kick', 'kick', 'bass', 'kick', 'kick']
        lines_export = ['kick']
    if pattern == 4:
        lines_input = ['4', 'ushi', 'tapu', 'nichia', 'kun']
        lines_export = ['kun', 'nichia', 'tapu', 'ushi']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections

def poll():
    # 入力
    N = int(input())
    S = list()
    for _ in range(N):
        S.append(input())
    # 各文字列の出現回数をカウント
    count_list = collections.Counter(S)
    # 最大の出現回数のvalueのみ抽出
    max_count = max(count_list.values())
    max_count_str = list()
    for key, value in count_list.items():
        if value == max_count:
            max_count_str.append(key)
    # ソート
    return sorted(max_count_str)
           
result = poll()
for string in result:
    print(string)

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
l = defaultdict(int)
m = 0
for _ in range(n):
    s = input()
    l[s] += 1
    m = max(m, l[s])

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = [input() for l in range(n)]
word = collections.Counter(s)
ma = max(word.values())
z = [kv for kv in word.items() if kv[1] == ma]
z = sorted(z)
for c in z:
  print(c[0])

Submission status: Accepted

Solution code:
N = int(input())
a = []
for i in range(N):
  a.append(input())
a = sorted(a)
count = 0
count_list=[]
b = []
for i,k in enumerate(a):
  if i == 0:
    continue
  if k == a[i-1]:
    count+=1
  else:
    count_list.append(count)
    b.append(a[i-1])
    count = 0
  if i==N-1:
    count_list.append(count)
    b.append(a[i])
maxi = 0
maxi_list =[]
for i,k in enumerate(count_list):
  if maxi <k:
    maxi_list.clear()
    maxi_list.append(b[i])
    maxi = k
  elif maxi == k:
    maxi_list.append(b[i])
  else:
    continue
for i in maxi_list:
  print(i)

Submission status: Accepted

Solution code:
n = int(input())

dic = {}
ma = 1

for i in range(n):
    wo = input()
    if(wo in dic):
        dic[wo] += 1
        if(dic[wo] > ma):
            ma = dic[wo]
    else:
        dic.update({wo:1})


ans = []
for i in dic.keys():
    if(dic[i] == ma):
        ans.append(i)
ans.sort()
for j in ans:
    print(j)

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for _ in range(n):
  s = input()
  if s in d: d[s] += 1
  else: d[s] = 1
  
t = max(d.values())
for x,y in sorted(d.items()):
  if y == t: print(x)

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import itertools

n = int(stdin.readline().rstrip())

d = {}
for i in range(n):
    s = stdin.readline().rstrip()

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

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

m = d[0][1]
a = []
i = 0
for i in range(len(d)):
    if d[i][1] == m:
        a.append(d[i][0])
    else:
        break

a.sort()

for aa in a:
    print(aa)

Submission status: Accepted

Solution code:
N = int(input())

d = dict()

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

d = sorted(d.items(), key=lambda x:-x[1])
i=0
ans=[]
while i<len(d):
  ans.append(d[i][0])
  if i<len(d)-1 and d[i+1][1]==d[i][1]:
      i+=1
  else:
    break

ans = sorted(ans)

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

Submission status: Accepted

Solution code:
from collections import defaultdict
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  dic = defaultdict(int)
  for i in range(N):
    dic[input()[:-1]] += 1

  max_ = max(dic.values())
  out = []
  for key, val in dic.items():
    if val == max_:
      out.append(key)

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


if(__name__ == '__main__'):
  main()

Submission status: Accepted

Solution code:
N = int(input())
S = sorted([input() for x in range(N)])
word = [S[0]]+[""]*(N-1)    #単語のリスト
kaisuu = [0]*N              #単語の出た回数のリスト
k = 0                       #今wordリストのどこを使っているか

for p in range(N):  #wordとkaisuuのリスト作成

    if word[k] != S[p]:
        k += 1
        word[k] = S[p]
        kaisuu[k] += 1
    
    else:
        kaisuu[k] += 1

m = max(kaisuu)     #m:出た回数が最大のもの
ansnum = []         #出た回数が最大のもののwordリストでの位置
for q in range(N):      
    if kaisuu[q] == m:
        ansnum += [q]

for r in range(len(ansnum)):
    print(word[ansnum[r]])

Submission status: Accepted

Solution code:
from collections import Counter


def main():
    n = int(input())
    S = [input() for _ in range(n)]
    S_c = Counter(S)
    num = list(S_c.values()).count(max(list(S_c.values())))
    anss = S_c.most_common()[:num]
    for ans in sorted(anss):
        print(ans[0])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
dict={}
xs=[]
for i in range(n):
  s=input()
  xs+=[s]
  if s not in dict:
    dict[s]=1
  else:
    dict[s]+=1
pin=0
xs=list(set(xs))
for i in xs:
  pin=max(pin,dict[i])
ans=[]
for i in xs:
  if dict[i]==pin:
    ans+=[i]
ans.sort()
for i in ans:
  print(i)

Submission status: Accepted

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

count = collections.Counter(ls)
maxval = max(count.values())
K = [k for k, v in count.items() if v == maxval]
L = sorted(K)
for i in L:
    print(i)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())

A = []
for _ in range(N):
    A.append(input().strip())

dic = Counter(A)

B = []
for a, c in dic.items():
    B.append((a,c))

B.sort(key=lambda x:x[0])
B.sort(key=lambda x:x[1],reverse=True)

r = B[0][1]
for b in B:
    p, q = b
    if q < r:
        exit()
    print(p)

Submission status: Accepted

Solution code:
n = int(input())

memo = {}

for _ in range(n):
    s = input()
    try:
        memo[s] += 1
    except KeyError:
        memo[s] = 1

m = max(memo.values())

print(*sorted([ i for i, j in memo.items() if j == m]), sep='\n')

Submission status: Accepted

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

s_sort = sorted(s)

s_num = [1]*n

for i in range(1,n):
    if s_sort[i] == s_sort[i-1]:
        s_num[i] += s_num[i-1]

Maxnum = max(s_num)

index_num = [n for n, v in enumerate(s_num) if v == Maxnum]

[print(s_sort[i]) for i in index_num]

Submission status: Accepted

Solution code:
import collections
n=int(input())
data=[""]*n
for i in range(n):
    data[i]=input()
data=sorted(data)
count=collections.Counter(data)
num=max(count.values())
for v,k in count.items():
    if k==num:
        print(v)

Submission status: Accepted

Solution code:
import collections
n = int(input())
c = collections.Counter([ input() for i in range(n) ])
ma = max(c.values())
print(*sorted([ i for i, j in c.items() if j == ma ]), sep='\n')

Submission status: Accepted

Solution code:
from collections import Counter

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

counter = Counter(S)
maxv = max(counter.values())
ans = []
for k, v in counter.items():
    if v == maxv:
        ans.append(k)

ans.sort()

for s in ans:
    print(s)

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)
n = int(input())
for _ in range(n): d[input()] += 1
s = sorted(d.items(), key=lambda x: (-x[1], x[0]))
nmax = s[0][1]
for i in s:
  if i[1] != nmax: break
  print(i[0])

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

def solve():
    input = sys.stdin.readline
    N = int(input())
    sDict = defaultdict(int)
    maxCount = 0
    for i in range(N):
        s = input().strip("\n")
        sDict[s] += 1
        maxCount = max(maxCount, sDict[s])
    maxS = []
    for key in sDict:
        if sDict[key] == maxCount:
            maxS.append(key)
    maxS.sort()
    print(*maxS, sep="\n")

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = [input() for _ in range(n)]
cnt = Counter(s)
li = sorted(cnt.items(), key=lambda x: (-x[1], x[0]))
m = li[0][1]
for i in range(len(li)):
    if li[i][1] < m:
        break
    print(li[i][0])

Submission status: Accepted

Solution code:
n,*s=map(str,open(0).read().split())
mydict={}
for i in set(s):
    mydict[i]=1
for i in s:
    mydict[i]+=1
    """
    if s[i] in mydict:
        mydict[s[i]]+=1
    else:
        mydict[s[i]]=1
    """
v_max=max(mydict.values())
for i in sorted([kv[0] for kv in mydict.items() if kv[1]==v_max]):
    print(i)

Submission status: Accepted

Solution code:
N=int(input())
L=list(input() for i in range(N))
L=sorted(L)
X=L[0]
c=0
d=0
e=[]
for i in range(N):
  if L[i]==X:
    c+=1
    if i==N-1 and c>d:
      e=[X]
    elif i==N-1 and c==d:
      e.append(X)
  elif L[i]!=X and d<c:
    d=c
    c=0
    e=[]
    e.append(X)
    X=L[i]
    c+=1
  elif L[i]!=X and d==c:
    c=1
    e.append(X)
    X=L[i]
    if i==N-1:
      e.append(X)
  elif L[i]!=X and d>c:
    c=0
    X=L[i]
    c+=1
for i in e:
  print(i)

Submission status: Accepted

Solution code:
n=int(input())
d={}
for x in range(n):
  key=input()
  if key not in d:
    d[key]=0
  d[key]+=1
  
values=d.values()
a=max(values)
b=[]
for y in d:
  if d[y]==a:
    b.append(y)
    
b=sorted(b)
for r in b:
  print(r)

Submission status: Accepted

Solution code:
N=int(input())
d={}
ans=[]
num=0
for x in range(N):
  S=input()
  if S not in d:
    d[S]=1
  else:
    d[S] += 1
  if d[S]>num:
    num=d[S]
    ans=[]
    ans.append(S)
  elif d[S]==num:
    ans.append(S)
ans.sort()
for i in range(len(ans)):
  print(ans[i])

Submission status: Accepted

Solution code:
N = int(input())

d = {}

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

m = max(d.values())

for s in sorted(k for k in d if d[k] == m):
  print(s)

Submission status: Accepted

Solution code:
# import itertools
# import math
# import sys
# import numpy as np

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, K = map(int, input().split())
# A = list(map(int, input().split()))
# Q = list(map(int, input().split()))
# S = input()

d = {}
for i in range(N):
    S = input()
    d.setdefault(S, 0)
    d[S] += 1

cnt_max = max(d.values())
d = sorted(d.items(), key=lambda x:x[0]) # keyでsort

for k, v in d:
    if cnt_max == v:
        print(k)

Submission status: Accepted

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

c = collections.Counter(s)
max_cnt = max(c.values())

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

Submission status: Accepted

Solution code:
import collections
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    S = [input() for _ in range(n)]
    word = collections.Counter(S).most_common()
    maxi = word[0][1]
    ans = []
    for w in word:
        if w[1] == maxi:
            ans.append(w[0])
        else:
            break
    ans.sort()
    a = "\n".join(ans)
    print(a)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
dict={}
for _ in range(int(input())):
  s=input()
  if s not in dict:
    dict[s] = 1
  else:
    dict[s] += 1
dict=sorted(dict.items(),key=lambda x:-x[1])
print(*sorted([dict[i][0] for i in range(len(dict)) if dict[0][1]==dict[i][1]]),sep='\n')