Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
inputs = sys.stdin.readlines()

n = int(inputs[1])
Y = []
for s in inputs[1:]:
    x, l = map(int, s.split())
    Y.append((x-l, x+l))
Y.sort(key=lambda x: x[0])

cnt = 1
_, r0 = Y[0]
for i in range(1, n):
    l, r = Y[i]
    if r0 <= l:
        cnt += 1
        r0 = r
    
print(cnt)

Fixed submission:
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
Y = []
for s in inputs[1:]:
    x, l = map(int, s.split())
    Y.append((x-l, x+l))
Y.sort(key=lambda x: x[1])

cnt = 1
_, r0 = Y[0]
for i in range(1, n):
    l, r = Y[i]
    if r0 <= l:
        cnt += 1
        r0 = r
    
print(cnt)

Buggy python submission (verdict: Runtime Error):
n = int(inputs[0])
Y = []
for s in inputs[1:]:
    x, l = map(int, s.split())
    Y.append((x-l+1, x+l-1))
Y.sort(key=lambda x: x[0])

cnt = 0
_, r0 = Y[0]
for i in range(1, n):
    l, r = Y[i]
    if r0 < l:
        cnt += 1
        r0 = r
print(cnt)

Fixed submission:
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
Y = []
for s in inputs[1:]:
    x, l = map(int, s.split())
    Y.append((x-l, x+l))
Y.sort(key=lambda x: x[1])

cnt = 1
_, r0 = Y[0]
for i in range(1, n):
    l, r = Y[i]
    if r0 <= l:
        cnt += 1
        r0 = r
    
print(cnt)
Buggy python submission (verdict: Runtime Error):
n, k, s = map(int, inputs[0].split())
A = [s]*k + [s-1]*(n-k)
print(*A)

Fixed submission:
n, k, s = map(int, input().split())
A = [s]*(n+1)
b = s+1 if s != 10**9 else 1
for i in range(n-k):
    A[i] = b
print(*A[:n])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
inputs = sys.stdin.readlines()

N = int(inputs[0])

s = 0
for i in range(1, N+1):
    s += i
print(s-N)

Fixed submission:
import sys
inputs = sys.stdin.readlines()

N = int(inputs[0])

print((N-1)*N // 2)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
s, t = [x.strip() for x in open(0).readlines()]
if set(t) - set(s) != set():
    print(-1)
else:
    d = defaultdict(list)
    n = len(s)
    for i, c in enumerate(s, 1):
        d[c].append(i)
    for k in d:
        d[k].append(d[k][0] + n)
    ans = 0
    d
    for c in t:
        q, r = divmod(ans, n)
        for x in d[c]:
            if r < x:
                ans = n*q + x
                break
    print(ans)

Fixed submission:
from collections import defaultdict
import bisect
s, t = [x.strip() for x in open(0).readlines()]
if set(t) - set(s) != set():
    print(-1)
else:
    d = defaultdict(list)
    n = len(s)
    for i, c in enumerate(s, 1):
        d[c].append(i)
    for k in d:
        d[k].append(d[k][0] + n)
    ans = 0
    for c in t:
        q, r = divmod(ans, n)
        x = d[c][bisect.bisect(d[c], r)]
        ans = n*q + x
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque
s, t = [x.strip() for x in open(0).readlines()]
if set(t) - set(s) != set():
    print(-1)
else:
    d = defaultdict(deque)
    n = len(s)
    for i, c in enumerate(s, 1):
        d[c].append(i)
    ans = 0
    for c in t:
        while True:
            i = d[c].popleft()
            d[c].append(i + n)
            if ans < i:
                ans = i
                break
    print(ans)

Fixed submission:
from collections import defaultdict
import bisect
s, t = [x.strip() for x in open(0).readlines()]
if set(t) - set(s) != set():
    print(-1)
else:
    d = defaultdict(list)
    n = len(s)
    for i, c in enumerate(s, 1):
        d[c].append(i)
    for k in d:
        d[k].append(d[k][0] + n)
    ans = 0
    for c in t:
        q, r = divmod(ans, n)
        x = d[c][bisect.bisect(d[c], r)]
        ans = n*q + x
    print(ans)

Buggy python submission (verdict: Runtime Error):
s, t = [x.strip() for x in open(0).readlines()]
if set(t) - set(s) != set():
    print(-1)
else:
    d = defaultdict(deque)
    n = len(s)
    for i, c in enumerate(s, 1):
        d[c].append(i)
    ans = 0
    for c in t:
        while True:
            i = d[c].popleft()
            d[c].append(i + n)
            if ans < i:
                ans = i
                break
    print(ans)

Fixed submission:
from collections import defaultdict
import bisect
s, t = [x.strip() for x in open(0).readlines()]
if set(t) - set(s) != set():
    print(-1)
else:
    d = defaultdict(list)
    n = len(s)
    for i, c in enumerate(s, 1):
        d[c].append(i)
    for k in d:
        d[k].append(d[k][0] + n)
    ans = 0
    for c in t:
        q, r = divmod(ans, n)
        x = d[c][bisect.bisect(d[c], r)]
        ans = n*q + x
    print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
S = inputs[1:]

d = defaultdict(lambda: -1)
for i in range(n):
    s = ''.join(sorted(list(S[i])))
    d[s] += 1

ans = 0
for v in d.values():
    ans += v*(v+1)//2
print(ans)

Fixed submission:
import sys
from collections import defaultdict
inputs = sys.stdin.readlines()

n = int(inputs[0])
S = inputs[1:]

d = defaultdict(lambda: -1)
for i in range(n):
    s = ''.join(sorted(list(S[i].rstrip())))
    d[s] += 1

ans = 0
for v in d.values():
    ans += v*(v+1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
S = inputs[1:]

for i in range(n):
    S[i] = ''.join(sorted(list(S[i])))
S.sort()

ans = 0
for i in range(n-1):
    query = S[i]
    for j in range(i+1, n):
        if query == S[j]:
            ans += 1
        else:
            break
print(ans)

Fixed submission:
import sys
from collections import defaultdict
inputs = sys.stdin.readlines()

n = int(inputs[0])
S = inputs[1:]

d = defaultdict(lambda: -1)
for i in range(n):
    s = ''.join(sorted(list(S[i].rstrip())))
    d[s] += 1

ans = 0
for v in d.values():
    ans += v*(v+1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
from fractions import gcd
a, b, c, d = [int(x) for x in inputs[0].split(' ')]
e = c * d // gcd(c, d) # lcm(c, d)

num_b = b - b // c - b // d + b // e
num_a = (a-1) - (a-1) // c - (a-1) // d + (a-1) // e

print(num_b - num_a)

Fixed submission:
import sys
import math
from fractions import gcd
inputs = sys.stdin.readlines()
a, b, c, d = [int(x) for x in inputs[0].split(' ')]
e = c * d // gcd(c, d) # lcm(c, d)
 
num_b = b - b // c - b // d + b // e
num_a = (a-1) - (a-1) // c - (a-1) // d + (a-1) // e
 
print(num_b - num_a)
Buggy python submission (verdict: Runtime Error):
# 3
memo=dict()
def combi_memorized(n, k):
    if k * 2 > n:
        k = n - k
    if k == 0:
        return 1
    if k == 1:
        return n
    memo_key = (n, k)
    if (n, k) not in memo:
        memo[memo_key] = combi_memorized(n-1, k) + combi_memorized(n-1, k-1)
    return memo[memo_key]

import sys
sys.setrecursionlimit(10000)
N, M = (int(x) for x in sys.stdin.readline().split(' '))
a_list = [int(x) for x in sys.stdin.readlines()]

tmp_list = []
tmp_list.append(a_list[0]-1 - 0)
for i in range(1, M):
    tmp_list.append(a_list[i] - a_list[i-1]-1)
tmp_list.append(N - a_list[-1]-1)

if 0 in tmp_list[1:]:
    print(0)
    exit()
s = 0
for v in tmp_list:
    for i in range(v):
        s += combi_memorized(v-i, i)
        if s > 1000000007:
            s -= 1000000007
print(s)

Fixed submission:
import sys
inputs = sys.stdin.readlines()

n, m = map(int, inputs[0].split())
B = set(map(int, inputs[1:]))
A = [0 if i in B else 1 for i in range(n+3)]
MOD = 10 ** 9 + 7

dp = [0]*(n+1)
dp[0], dp[1] = 1, A[1]
for i in range(1, n):
    dp[i+1] = (dp[i] + dp[i-1]) * A[i+1] % MOD
    if A[i] + A[i+1] == 0:
        break
print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
inputs = sys.stdin.readlines()

h, w = map(int, inputs[0].split())
S = [list(map(lambda x: 0 if x=='#' else 1, row)) for row in inputs[1:]]

w_costs = [[0]*w for _ in range(h)]
h_costs = [[0]*w for _ in range(h)]

def row_search(x, y):
    x_, cost = x, 0
    while x+1 < w and S[y][x+1]:
        x += 1
        cost += 1
    while x_ <= x:
        w_costs[y][x] = cost
        x -= 1
def col_search(x, y):
    y_, cost = y, 0
    while y+1 < h and S[y+1][x]:
        y += 1
        cost += 1
    while y_ <= y:
        h_costs[y][x] = cost
        y -= 1

for y in range(h):
    for x in range(w):
        if S[y][x]:
            if w_costs[y][x] == 0:
                row_search(x, y)
            if h_costs[y][x] == 0:
                col_search(x, y)

ans = 0
for y in range(h):
    for x in range(w):
        ans = max(ans, w_costs[y][x] + h_costs[y][x] + 1)
print(ans)

Fixed submission:
import sys
inputs = sys.stdin.readlines()

h, w = map(int, inputs[0].split())
S = [list(map(lambda x: 0 if x=='#' else 1, row)) for row in inputs[1:]]

w_costs = [[0]*w for _ in range(h)]
h_costs = [[0]*w for _ in range(h)]

def row_search(x, y):
    x_, cost = x, 0
    while x+1 < w and S[y][x+1]:
        x += 1
        cost += 1
    while x_ <= x:
        w_costs[y][x] = cost
        x -= 1
def col_search(x, y):
    y_, cost = y, 0
    while y+1 < h and S[y+1][x]:
        y += 1
        cost += 1
    while y_ <= y:
        h_costs[y][x] = cost
        y -= 1

for y in range(h):
    for x in range(w):
        if S[y][x]:
            if w_costs[y][x] == 0:
                row_search(x, y)
            if h_costs[y][x] == 0:
                col_search(x, y)

ans = 0
for y in range(h):
    for x in range(w):
        ans = max(ans, w_costs[y][x] + h_costs[y][x] + 1)
print(ans)
Buggy python submission (verdict: Runtime Error):
n, a, b, c, d = map(int, input().split())
a -= 1
b -= 1
c -= 1
d -= 1
S = input()

if c < d:
    while b < d:
        if S[b+1] == '.':
            b += 1
        elif b+2 <= d and S[b+2] == '.':
            b += 2
        else:
            print('No')
            exit()
    while a < c:
        if S[a+1] == '.':
            a += 1
        elif a+2 <= c and S[a+2] == '.':
            a += 2
        else:
            print('No')
            exit()
else:
    while a < c:
        if a+1 == b and S[a+2] == '.' :
            a += 2
        elif a+1 == b and S[a+3] == '.' and a+3 <= d:
            b += 2
            a += 1
        elif S[a+1] == '.' and a+1 != b:
            a += 1
        elif a+2 == b and S[a+3] == '.' and a+3 <= d:
            a += 2
            b += 1
        elif a+2 == b and S[a+4] == '.' and a+4 <= d:
            a += 2
            b += 2
        elif S[a+2] == '.' and a+2 != b:
            a += 2
        else:
            print('No')
            exit()
    while b < d:
        if S[b+1] == '.':
            b += 1
        elif b+2 <= d and S[b+2] == '.':
            b += 2
        else:
            print('No')
            exit()
print('Yes')

Fixed submission:
n, a, b, c, d = map(int, input().split())
a -= 1
b -= 1
c -= 1
d -= 1
S = input()

if c < d:
    while b < d:
        if S[b+1] == '.':
            b += 1
        elif b+2 <= d and S[b+2] == '.':
            b += 2
        else:
            print('No')
            exit()
    while a < c:
        if S[a+1] == '.':
            a += 1
        elif a+2 <= c and S[a+2] == '.':
            a += 2
        else:
            print('No')
            exit()
else:
    while a < c:
        if a+1 == b and S[a+2] == '.' :
            a += 2
        elif a+1 == b and a+3 <= d and S[a+3] == '.':
            b += 2
            a += 1
        elif S[a+1] == '.' and a+1 != b:
            a += 1
        elif a+2 == b and a+3 <= d and S[a+3] == '.':
            a += 2
            b += 1
        elif a+2 == b and a+4 <= d and S[a+4] == '.':
            a += 2
            b += 2
        elif S[a+2] == '.' and a+2 != b:
            a += 2
        else:
            print('No')
            exit()
    while b < d:
        if S[b+1] == '.':
            b += 1
        elif b+2 <= d and S[b+2] == '.':
            b += 2
        else:
            print('No')
            exit()
print('Yes')
Buggy python submission (verdict: Runtime Error):
from itertools import groupby
n, k = map(int, input().split())
S = input().strip()
L = [len(list(g)) for v, g in groupby(S)]
A = [sum(L[:2*k+1])]
for i in range(0, len(L)-2*k-1, 2):
    A += A[-1]-L[i]-L[i+1]+L[i+2*k+1]+L[i+2*k+2],
print(max(A))

Fixed submission:
from itertools import groupby
n, k = map(int, input().split())
S = input().strip()
L = [len(list(g)) for v, g in groupby(S)]
if S[0] == '0':
    L = [0] + L
if S[-1] == '0':
    L = L + [0]

A = [sum(L[:2*k+1])]
for i in range(0, len(L)-2*k-1, 2):
    A += A[-1]-L[i]-L[i+1]+L[i+2*k+1]+L[i+2*k+2],
print(max(A))
Buggy python submission (verdict: Runtime Error):
from string import ascii_lowercase
from functools import reduce
from operator import mul
n = int(input())
S = input()
mod = 10**9 + 7
print(reduce(lambda x, y: x*y % mod, S.count(c)+1 for c in ascii_lowercase))

Fixed submission:
from string import ascii_lowercase
n = int(input())
S = input()
mod = 10**9 + 7
s = 1
for c in ascii_lowercase:
  s *= S.count(c)+1
  s %= mod
print(s-1)
Buggy python submission (verdict: Runtime Error):
S = input().strip()
x = sum(c == '0' for c in S)
y = len(n) - x
print(2 * min(x, y))

Fixed submission:
S = input().strip()
x = sum(c == '0' for c in S)
y = len(S) - x
print(2 * min(x, y))
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from operator import itemgetter

n, a, b, c, *L = map(int, open(0).read().split())
L.sort()
A = [a, b, c]
dicts = [defaultdict(lambda: 10**5) for _ in range(3)]
for i in range(n-2):
    for x in combinations(enumerate(L), i+1):
        k = tuple(i for i, l in x)
        v = sum(l for i, l in x)
        for d, x in zip(dicts, A):
            d[k] = min(d[k], abs(x-v) + 10*i)
scores = [sorted(d.items(), key=itemgetter(1)) for d in dicts]

ans = 10**5
for p1, p2, p3 in permutations(range(3)):
    k1, v1 = scores[p1][0]
    k1 = set(k1)
    for k2, v2 in scores[p2]:
        k2 = set(k2)
        if len(k1 & k2) == 0:
            break
    for k3, v3 in scores[p3]:
        k3 = set(k3)
        if len(k1 & k3) + len(k2 & k3) == 0:
            break
    ans = min(ans, sum([v1, v2, v3]))
print(ans)

Fixed submission:
from collections import defaultdict
from itertools import combinations, permutations
from operator import itemgetter
n, a, b, c, *L = map(int, open(0).read().split())
L.sort()
A = [a, b, c]
dicts = [defaultdict(lambda: 10**5) for _ in range(3)]
for i in range(n-2):
    for x in combinations(enumerate(L), i+1):
        k = tuple(i for i, l in x)
        v = sum(l for i, l in x)
        for d, x in zip(dicts, A):
            d[k] = min(d[k], abs(x-v) + 10*i)
scores = [sorted(d.items(), key=itemgetter(1)) for d in dicts]

ans = 10**5
for p1, p2, p3 in permutations(range(3)):
    k1, v1 = scores[p1][0]
    k1 = set(k1)
    for k2, v2 in scores[p2]:
        k2 = set(k2)
        if len(k1 & k2) == 0:
            break
    for k3, v3 in scores[p3]:
        k3 = set(k3)
        if len(k1 & k3) + len(k2 & k3) == 0:
            break
    ans = min(ans, sum([v1, v2, v3]))
print(ans)
Buggy python submission (verdict: Runtime Error):
n, *H = map(int, open(0).read().split())

inc = True
peaks = [], []
for h0, h1 in zip(H, H[1:]):
    if inc:
        if h0 > h1:
            peaks.append(h0)
            inc = False
    else:
        if h0 < h1:
            peaks.append(-h0)
            inc = True
if inc:
    peaks.append(H[-1])
print(sum(peaks))

Fixed submission:
n, *H = map(int, open(0).read().split())

inc = True
maxes, mins = [], []
for h0, h1 in zip(H, H[1:]):
    if inc:
        if h0 > h1:
            maxes.append(h0)
            inc = False
    else:
        if h0 < h1:
            mins.append(h0)
            inc = True
if inc:
    maxes.append(H[-1])
print(sum(maxes)-sum(mins))

Buggy python submission (verdict: Runtime Error):
n, *H = map(int, open(0).read().split())

inc = True
maxes, mins = [], []
for h0, h1 in zip(H, H[1:]):
    if inc:
        if h0 > h1:
            maxes.append(h0)
            inc = False
    else:
        if h0 < h1:
            mins.append(h0)
            inc = True
if inc:
    maxes.append(h1)
print(sum(maxes)-sum(mins))

Fixed submission:
n, *H = map(int, open(0).read().split())

inc = True
maxes, mins = [], []
for h0, h1 in zip(H, H[1:]):
    if inc:
        if h0 > h1:
            maxes.append(h0)
            inc = False
    else:
        if h0 < h1:
            mins.append(h0)
            inc = True
if inc:
    maxes.append(H[-1])
print(sum(maxes)-sum(mins))
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
pairs = []
for i in [0]*M:
    inp = sorted(list(map(int,input().split())))
    if inp not in pairs:
        pairs.append(inp)
def solver(N,M,pairs):
    group_list = []
    max_len = 1
    for i in pairs:
        pair = sorted(i)
        for j in range(len(group_list)):
            if pair[1] in group_list[j]:
                break
            elif pair[0] in group_list[j]:
                group_list[j].append(pair[1])
                if max_len < len(group_list[j]):
                    max_len = len(group_list[j])
                break
        else:
            if max_len < 2:
                max_len = 2
            group_list.append(pair)
    return max_len
print(solver(N,M,pairs))


Fixed submission:
D, T, S = map(int,input().split())
if D / S <= T:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
X, K, D = map(int,input().split())
absX = abs(X)
t = abs(X // D)
remain_K = K - t
l = X % D
if remain_K < 0:
    a = abs(X - (K * D))
    b = abs(X + (K * D))
else:
    if remain_K % 2 == 0:
        a = abs(l - (D * 2))
        b = abs(l + (D * 2))
        if a < b and a < l:
            ans = a
        elif a > b and b < l:
            ans = b
        else:
            ans = l
    else:
        a = abs(l - D)
        b = abs(l + D)
        if a < b:
            ans = a
        else:
            ans = b
print(ans)


Fixed submission:
X, K, D = map(int,input().split())
absX = abs(X)
t = abs(X // D)
remain_K = K - t
l = X % D
if remain_K < 0:
    a = abs(X - (K * D))
    b = abs(X + (K * D))
    if a < b:
        ans = a
    else:
        ans = b
else:
    if remain_K % 2 == 0:
        a = abs(l - (D * 2))
        b = abs(l + (D * 2))
        if a < b and a < l:
            ans = a
        elif a > b and b < l:
            ans = b
        else:
            ans = l
    else:
        a = abs(l - D)
        b = abs(l + D)
        if a < b:
            ans = a
        else:
            ans = b
print(ans)
Buggy python submission (verdict: Runtime Error):
X, N = map(int, input().split())
p = list(map(int, input().split()))

not_in_p = list(range(1,101))
for pn in p:
    if pn in not_in_p:
        not_in_p.remove(pn)

diff_p = []
for not_in_pn in not_in_p:
    diff_p.append(abs(not_in_pn - X))
min_value_index =  [j for j, value in enumerate(diff_p) if value == min(diff_p)]

answer = 0
for index in min_value_index:
    if answer == 0:
        answer = not_in_p[index]
    elif answer > not_in_p[index]:
        answer = not_in_p[index]

print(answer)

Fixed submission:
x = list(map(int, input().split()))
print(x.index(0) + 1)
Buggy python submission (verdict: Runtime Error):
X, N = map(int, input().split())
p = list(map(int, input().split()))
not_in_p = list(range(1,101))
for pn in p:
    if pn in not_in_p:
        not_in_p.remove(pn)
diff_p=[]
for not_in_pn in not_in_p:
    diff_p.append(abs(not_in_pn - X))
index = diff_p.index(min(diff_p))
print(not_in_p[index])

Fixed submission:
X, N = map(int, input().split())
p = list(map(int, input().split()))

not_in_p = list(range(-101,102))
for pn in p:
    if pn in not_in_p:
        not_in_p.remove(pn)

diff_p = []
for not_in_pn in not_in_p:
    diff_p.append(abs(not_in_pn - X))
answer = not_in_p[diff_p.index(min(diff_p))]

print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
N = int(input())
S = {}
for i in range(N):
    value = input()
    if value in S:
        S[value] += 1
    else:
        S[value] = 1
S_sorted = sorted([k for k, v in S.items() if v == max(S.values())])
for ans in S_sorted:
    print(ans)


Fixed submission:
import collections
N = int(input())
S = {}
for i in range(N):
    value = input()
    if value not in S:
        S[value] = 1
    else:
        S[value] += 1
S_largest = max(S.values())
S_sorted = sorted(S.items(), key=lambda x:x[1], reverse=True)
ans = []
for i in range(len(S_sorted)):
    if S_sorted[i][1] == S_largest:
        ans.append(S_sorted[i][0])
    else:
        break
ans_sorted = sorted(ans)
for a in ans_sorted:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N = int(input())
S = []
for i in range(N):
    S.append(input())
S_counter = collections.Counter(S)
S_max = [Sv[0] for Sv in S_counter.items() if Sv[1] == max(S_counter.values())]
S_max_sorted = sorted(S_max)
for ans in S_max_sorted:
    print(ans)

Fixed submission:
import collections
N = int(input())
S = {}
for i in range(N):
    value = input()
    if value not in S:
        S[value] = 1
    else:
        S[value] += 1
S_largest = max(S.values())
S_sorted = sorted(S.items(), key=lambda x:x[1], reverse=True)
ans = []
for i in range(len(S_sorted)):
    if S_sorted[i][1] == S_largest:
        ans.append(S_sorted[i][0])
    else:
        break
ans_sorted = sorted(ans)
for a in ans_sorted:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N = int(input())
S = []
for i in range(N):
    S.append(input())
S_counter = collections.Counter(sorted(S))
S_max = [Sv[0] for Sv in S_counter.items() if Sv[1] == max(S_counter.values())]
S_max_sorted = sorted(S_max)
for ans in S_max_sorted:
    print(ans)


Fixed submission:
import collections
N = int(input())
S = {}
for i in range(N):
    value = input()
    if value not in S:
        S[value] = 1
    else:
        S[value] += 1
S_largest = max(S.values())
S_sorted = sorted(S.items(), key=lambda x:x[1], reverse=True)
ans = []
for i in range(len(S_sorted)):
    if S_sorted[i][1] == S_largest:
        ans.append(S_sorted[i][0])
    else:
        break
ans_sorted = sorted(ans)
for a in ans_sorted:
    print(a)
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int,input().split())
S = input()
S = "a"*10000
yosen = 0
yosen_b = 1
for i in range(N):
    if S[i] == "a" and yosen < (A + B):
            print("Yes")
            yosen += 1
    elif S[i] == "b" and yosen < (A + B) and yosen_b <= B:
            print("Yes")
            yosen += 1
            yosen_b += 1
    else:
        print("No")

Fixed submission:
N, A, B = map(int,input().split())
S = input()
yosen = 0
yosen_b = 1
for i in range(N):
    if S[i] == "a" and yosen < (A + B):
            print("Yes")
            yosen += 1
    elif S[i] == "b" and yosen < (A + B) and yosen_b <= B:
            print("Yes")
            yosen += 1
            yosen_b += 1
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
Q = int(input())
c = 0
for _ in range(Q):
  q = input()
  if (q[0] == "1"):
    c += 1
  else:
    if (q[2] == "1"):
      if (c % 2 == 0):
      	s = q[4] + s
      else:
        s = s + q[4]
    else:
      if (c % 2 == 0):
      	s = s + q[4]
      else:
        s = q[4] + s
if (c % 2 == 0):
  print(s)
else:
  print(s[::-1])

Fixed submission:
from collections import deque
s = deque(input())
Q = int(input())
c = 0
for _ in range(Q):
  q = input()
  if (q[0] == "1"):
    c += 1
  else:
    if (q[2] == "1"):
      if (c % 2 == 0):
        s.appendleft(q[4])
      else:
        s.append(q[4])
    else:
      if (c % 2 == 0):
        s.append(q[4])
      else:
        s.appendleft(q[4])
if (c % 2 == 0):
  print("".join(list(s)))
else:
  print("".join(list(s))[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
Q = int(input())
for _ in range(Q):
  q = input()
  if (q[0] == "1"):
    s = s[::-1]
  else:
    if (q[2] == "1"):
      s = q[4] + s
    else:
      s = s + q[4]
print(s)

Fixed submission:
from collections import deque
s = deque(input())
Q = int(input())
c = 0
for _ in range(Q):
  q = input()
  if (q[0] == "1"):
    c += 1
  else:
    if (q[2] == "1"):
      if (c % 2 == 0):
        s.appendleft(q[4])
      else:
        s.append(q[4])
    else:
      if (c % 2 == 0):
        s.append(q[4])
      else:
        s.appendleft(q[4])
if (c % 2 == 0):
  print("".join(list(s)))
else:
  print("".join(list(s))[::-1])