Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

S = input().strip()
Q = int(input())
cnt = 0
for _ in range(Q):
    q = list(input().split())
    if int(q[0])==1:
        cnt += 1
    else:
        if cnt%2==0:
            if int(q[1])==1:
                S = q[2]+S
            else:
                S = S+q[2]
        else:
            if int(q[1])==1:
                S = S+q[2]
            else:
                S = q[2]+S
if cnt%2==0:
    print(S)
else:
    S = S[::-1]
    print(S)

### FIXED CODE ###

from collections import deque
S = deque(list(input().strip()))
Q = int(input())
cnt = 0
for _ in range(Q):
    q = list(input().split())
    if int(q[0])==1:
        cnt += 1
    else:
        if cnt%2==0:
            if int(q[1])==1:
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if int(q[1])==1:
                S.append(q[2])
            else:
                S.appendleft(q[2])
if cnt%2==0:
    print("".join(S))
else:
    S.reverse()
    print("".join(S))
### BUGGY CODE ###

import math

N = int(input())
lis_all = []
lis_pat = []
lis_num = []

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

count = 0
for i in range(N):
    lis_S = list(str(input()))
    lis_S.sort()
    if lis_S not in lis_all:
        lis_pat.append(lis_S)
    lis_all.append(lis_S)

ans = 0
for i in lis_pat:
    if lis_all.count(i) != 1:
        ans += comb(lis_all.count(i),2)
   
print(ans)
    

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
N=int(input())
dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)
### BUGGY CODE ###

s = input()
n = int(input())
now: bool = True

for i in range(n):
    q = list(input().split())
    if q[0] == '1':
        now = not now
    else:
        if (q[1] == '1' and now == True) or (q[1] == '2' and now == False):
            s = q[2]+s
        elif (q[1] == '1' and now == False) or (q[1] == '2' and now == True):
            s = s+q[2]
if now == True:
    print(s)
else:
    print(s[::-1])


### FIXED CODE ###

from collections import deque
s = deque(input())
n = int(input())
now: bool = True

for i in range(n):
    q = list(input().split())
    if q[0] == '1':
        now = not now
    else:
        if (q[1] == '1' and now == True) or (q[1] == '2' and now == False):
            s.appendleft(q[2])
        elif (q[1] == '1' and now == False) or (q[1] == '2' and now == True):
            s.append(q[2])
if now == True:
    print(''.join(s))
else:
    print(''.join(reversed(s)))
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    from collections import defaultdict
    S = input().rstrip()
    counter = defaultdict(int)
    mod = 2019
    counter[0] += 1
    num = 0
    for i, c in enumerate(S[::-1]):
        num += int(c) * (10**(i)%mod)
        num %= mod
        counter[num] += 1
    ans = 0
    for v in counter.values():
        ans += (v * (v-1)) // 2
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    from collections import defaultdict
    S = input().rstrip()
    counter = defaultdict(int)
    mod = 2019
    counter[0] += 1
    num = 0
    d = 1
    for c in S[::-1]:
        num += int(c) * d
        num %= mod
        counter[num] += 1
        d *= 10
        d %= mod
    ans = 0
    for v in counter.values():
        ans += (v * (v-1)) // 2
    print(ans)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
A = map(int, input().split())

import functools

r = functools.reduce(lambda x, y: x * y, A, 1)
print(-1 if r > 10 ** 18 else r)


### FIXED CODE ###

def main():
  N = int(input())
  A = list(map(int,input(). split ()))

  if 0 in A:
    print(0)
    return

  prod = 1
  for a in A:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      return
  print(prod)

main ()
### BUGGY CODE ###

#import time

nk = [int(x) for x in raw_input().strip().split()]
d = []
for i in range(nk[0]):
    d_tmp = raw_input().strip().split()
    d.append([int(d_tmp[0]), int(d_tmp[1]), int(d_tmp[2] == 'B')])

n1 = nk[0]
k1 = nk[1]
k2 = k1 * 2

d = tuple(d)
n = 0
#t = time.clock()
for i in range(k1):
    for j in range(k1):
        n_tmp = [0, 0]
        for k in range(n1):
            x = (d[k][0] - i) // k1 % 2
            y = (d[k][1] - j) // k1 % 2
            if x == y:
                n_tmp[1 - d[k][2]] += 1
            else:
                n_tmp[d[k][2]] += 1
        if n_tmp[0] > n:
            n = n_tmp[0]
        if n_tmp[1] > n:
            n = n_tmp[1]
#print time.clock() - t
print n


### FIXED CODE ###

import numpy as np

def getBoundary(p, k, k2):
    if p - k + 1 >= 0:
        return [(p - k + 1, p + 1)]
    else:
        return [(0, p + 1), ((p - k + 1) % k2, k2)]

n, k = map(int, input().strip().split())
k2 = k * 2
b = [[0 for i in range(k2 + 1)] for j in range(k2 + 1)]

for i in range(n):
    x_str, y_str, c_str = input().strip().split()
    x = int(x_str) % k2
    y = (int(y_str) + (c_str == 'B') * k) % k2
    for xb, xe in getBoundary(x % k2, k, k2):
        for yb, ye in getBoundary(y % k2, k, k2):
            b[xb][yb] += 1
            b[xb][ye] -= 1
            b[xe][yb] -= 1
            b[xe][ye] += 1
    for xb, xe in getBoundary((x + k) % k2, k, k2):
        for yb, ye in getBoundary((y + k) % k2, k, k2):
            b[xb][yb] += 1
            b[xb][ye] -= 1
            b[xe][yb] -= 1
            b[xe][ye] += 1

arr_b = np.array(b)
for i in range(k2):
    arr_b[i + 1] += arr_b[i]
for j in range(k2):
    arr_b[:, j + 1] += arr_b[:, j]
print(arr_b.max())
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
p = max(A)
q = p//2
r = p//2
while True:
    if q in A and p != q:
        print(p,q)
        exit(0)
    elif r in A and p != r:
        print(p,r)
        exit(0)
    else:
        q+=1
        r-=1

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
p = max(A)
q = p//2
r = 10**9+7
ans = 0
for k in range(N):
    if abs(A[k]-q) < r and A[k] != p:
        r = abs(A[k]-q)
        ans = A[k]

print(p,ans)
### BUGGY CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def solve():
    n = I()
    edge = [[] for _ in range(n)]
    for v in range(1,n):
        u = I()-1
        edge[u].append(v)

    dp = [None]*n
    def dfs(s):
        if dp[s] != None:
            return dp[s]
        if edge[s] == []:
            dp[s] = 0
            return 0
        tmp = []
        for v in edge[s]:
            tmp.append(dfs(v))
        tmp.sort(reverse=True)
        m = 0
        for i,j in enumerate(tmp):
            m = max(m,(i+1)+j)
        dp[s] = m
        return m
    dfs(0)
    print(dp[0])

if __name__=='__main__':
    solve()



### FIXED CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n = I()
edge = [[] for _ in range(n)]
for v in range(1,n):
    u = I()-1
    edge[u].append(v)

dp = [None]*n
def dfs(s):
    if dp[s] != None:
        return dp[s]
    if edge[s] == []:
        dp[s] = 0
        return 0
    tmp = []
    for v in edge[s]:
        tmp.append(dfs(v))
    tmp.sort(reverse=True)
    m = 0
    for i,j in enumerate(tmp):
        m = max(m,(i+1)+j)
    dp[s] = m
    return m

dfs(0)
print(dp[0])
### BUGGY CODE ###

import numpy as np
N=int(input())
H=np.array(list(map(int, input().split())))

output='Yes'
for i in range(N-1):
  if H[i]-np.min(H[i+1:])>1:
    output='No'
    
print(output)

### FIXED CODE ###

N=int(input())
h=list(map(int, input().split()))

index=N-1
output='Yes'
while index>0:
  if h[index-1]-h[index]>1:
    output='No'
    break
  elif h[index-1]-h[index]==1:
    h[index-1]-=1
  else:
    pass
  index-=1
  
print(output)
### BUGGY CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

a,b,k = na()
f = [i for i in range(a,b+1)]
if (b-a+1) // 2 >= k:
    ans = list(range(a,a+k)) + list(range(b-k+1,b+1))
else:
    ans = list(range(a,b+1))
for i in ans:
    print(i)


### FIXED CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

a,b,k = na()
if (b-a+1) // 2 >= k:
    ans = list(range(a,a+k)) + list(range(b-k+1,b+1))
else:
    ans = list(range(a,b+1))
for i in ans:
    print(i)
### BUGGY CODE ###

from collections import deque

N,M = map(int,input().split())
C = [[] for _ in range(N+1)]
for _ in range(M):
    tmp = list(map(int,input().split()))
    C[tmp[0]].append(tmp[1])
    C[tmp[1]].append(tmp[0])
d = [1000000000]*(N+1)
d[1] = 0
visited = [False]*(N+1)
q = deque()
q.append(1)

while q:
    node = q.popleft()
    visited[node] = True
    for adj in C[node]:
        if visited[adj] == False:
            d[adj] = min(d[node]+1,d[adj])
            q.append(adj)

sirube = [0]*(N+1)
for i in range(2,N+1):
    min_d = 10000000000
    for adj in C[i]:
        if d[adj] < min_d:
            sirube[i] = adj
            min_d = d[adj]


print("Yes")
for i in range(2,N+1):
    print(sirube[i])



### FIXED CODE ###

from collections import deque

N,M = map(int,input().split())
C = [[] for _ in range(N+1)]
for _ in range(M):
    tmp = list(map(int,input().split()))
    C[tmp[0]].append(tmp[1])
    C[tmp[1]].append(tmp[0])
d = [1000000000]*(N+1)
d[1] = 0
visited = [False]*(N+1)
q = deque()
q.append(1)

sirube = [0]*(N+1)
while q:
    node = q.popleft()
    for adj in C[node]:
        if visited[adj] == False:
            sirube[adj] = node
            q.append(adj)
            visited[adj] = True



print("Yes")
for i in range(2,N+1):
    print(sirube[i])
### BUGGY CODE ###

from collections import Counter
import numpy as np
n,k,q=map(int,input().split())
a=[]
for i in range(q):
  a_=int(input())
  a.append(a_)


listn_=[]
for i in range(n):
  listn_.append(k)
listn=np.array(listn_)

s=Counter(a)
for i in s.keys():
  lists_=[-1*s[i]]*n
  lists_[i-1]=0
  lists=np.array(lists_)
  listn=listn+lists

#print(listn)
for i in listn:
  if i>0:
    print('Yes')
    
  else:
    print('No')
  


  

### FIXED CODE ###

from collections import Counter
import numpy as np
n,k,q=map(int,input().split())
a=[]
for i in range(q):
  a_=int(input())
  a.append(a_)
 
 
listn_=[]
for i in range(n):
  listn_.append(k)
listn=np.array(listn_)
listn=listn-q
s=Counter(a)
for i in s.keys():
  listn[i-1]+=s[i]
 
#print(listn)
for i in listn:
  if i>0:
    print('Yes')
    
  else:
    print('No')
### BUGGY CODE ###

import math
n=int(input())
a=[]
c=0.0
for i in range(n):
  a.append(input())
cnt=0
b=[int(i) for i in a]
for i in range(n):
    if b[i]==2:
      cnt+=1
    for j in range(2,b[i]):
      if b[i]%j==0:
        break
      if b[i]-j==1:
        cnt+=1
print(cnt)       
      


### FIXED CODE ###

import math
n=int(input())
a=[]

for i in range(n):
  a.append(input())
cnt=0
b=[int(i) for i in a]

for i in range(n):
    c=math.sqrt(b[i])
    c=int(c)
    if b[i]==2:
      cnt+=1
    for j in range(2,b[i]):
      if b[i]%j==0:
        break
      if math.sqrt(b[i])<j:
        cnt+=1
        break
print(cnt)
### BUGGY CODE ###

from math import gcd
n=int(input())
RGB = str(input())

ans = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if RGB[i]!=RGB[j] and RGB[i]!=RGB[k] and RGB[j]!=RGB[k] and j-i != k-j:
                ans += 1

print(ans)    

### FIXED CODE ###

n = int(input())
s = input()

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

ans = r_cnt * g_cnt * b_cnt

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1

print(ans)
### BUGGY CODE ###

import collections
n = int(input())
S = [input() for _ in range(n)]
ans = 0
c = []

for s in S:
    c.append(collections.Counter(s))

for i in range(n-1):
    for j in range(i+1, n):
        if c[i] == c[j]:
            ans += 1

print(ans)

### FIXED CODE ###

n = int(input())
S = [input() for _ in range(n)]
ans = 0
c = {}

for s in S:
    s = "".join(sorted(s))
    if s not in c.keys():
        c[s] = 1
    else:
        ans += c[s]
        c[s] += 1


print(ans)
### BUGGY CODE ###

from math import ceil
A,B,C,D,E,F = map(int,input().split())
am,bm,cm,dm=ceil(31/A),ceil(31/B),ceil(E*30/C)+1,ceil(E*30/D)+1
temp = []
for a in range(am):
    for b in range(bm):
        for c in range(cm):
            for d in range(dm):
                w = 100*a*A+100*b*B
                s = c*C+d*D
                if w + s > F:
                    break
                else:
                    if w / 100 * E >= s:
                        temp.append([w+s,s])
print(*sorted(temp, key=lambda x: (100*x[1] / x[0] if x[0] else 0))[-1])

### FIXED CODE ###

from math import ceil
A,B,C,D,E,F = map(int,input().split())
am,bm,cm,dm=ceil(31/A),ceil(31/B),ceil(F*E/(100+E)/C)+1,ceil(F*E/(100+E)/D)+1
temp = []
for a in range(am):
    for b in range(bm):
        for c in range(cm):
            for d in range(dm):
                w = 100*a*A+100*b*B
                s = c*C+d*D
                if w + s > F:
                    break
                else:
                    if w / 100 * E >= s:
                        temp.append([w+s,s])
print(*sorted(temp, key=lambda x: (100*x[1] / x[0] if x[0] else 0))[-1])
### BUGGY CODE ###

#
import sys
import math
import numpy as np
import itertools

# いくつか入力
h,w = (int(i) for i in input().split())  

# 2次元配列
grid = []
for i in range(h):
    array = list(input())
    grid.append(array)

a = np.zeros((h,w), dtype=np.int)
#print(yoko)
b = np.zeros((h,w), dtype=np.int)
for i in range(h):
    for j in range(w):
        if grid[i][j]=='#':
            b[i][j] = 1
        else:
            b[i][j] = 0

for i in range(h):
    temp = 0
    for j in range(w):
        if b[i][j]==1:
            temp=0
        else:
            temp += 1
            a[i][j] += temp

for i in range(h):
    temp = 0
    for j in range(w-1,-1,-1):
        if b[i][j]==1:
            temp=0
        else:
            temp += 1
            a[i][j] += temp
#print(a)
for j in range(w):
    temp = 0
    for i in range(h):
        if b[i][j]==1:
            temp=0
        else:
            temp += 1
            a[i][j] += temp

for j in range(w):
    temp = 0
    for i in range(h-1,-1,-1):
        if b[i][j]==1:
            temp=0
        else:
            temp += 1
            a[i][j] += temp
answer=3
for i in range(h):
    for j in range(w):
        answer=max(a[i][j],answer)
#print(a)
print(answer-3)



### FIXED CODE ###

#
import sys
import math
import numpy as np
import itertools

# いくつか入力
h,w = (int(i) for i in input().split())  

# 2次元配列
grid = []
for i in range(h):
    array = list(input())
    grid.append(array)
b = np.array(grid)
b = np.where(b == ".", 1, 0)

a1 = np.zeros((h,w), dtype=np.int)
a2 = np.zeros((h,w), dtype=np.int)
a3 = np.zeros((h,w), dtype=np.int)
a4 = np.zeros((h,w), dtype=np.int)
#print(b)

for i in range(1,h):
    a1[i] += (a1[i-1]+1)*b[i-1]

for i in range(h-2,-1,-1):
    a2[i] += (a2[i+1]+1)*b[i+1]

for i in range(1,w):
    a3[:, i] += (a3[:, i-1]+1)*b[:, i-1]

for i in range(w-2,-1,-1):
    a4[:, i] += (a4[:, i+1]+1)*b[:, i+1]

#print(a1,a2,a3,a4)

answer = ( (a1+a2+a3+a4)*b ).max()

print(answer+1)
### BUGGY CODE ###

from bisect import bisect,bisect_left
n,q=map(int,input().split())
xst=[]
for i in range(n):
    s,t,x=map(int,input().split())
    xst.append([x,s,t])
xst.sort()
d=[]
for i in range(q):
    D=int(input())
    d.append([D,i])
ans=[-1]*q
for u in xst:
    x,s,t=u
    left=s-x
    right=t-x-1
    a=bisect(d,[left])
    b=bisect(d,[right,q+1])
    for u in d[a:b]:
        ans[u[1]]=x
    d=d[:a]+d[b:]
for u in ans:
    print(u)

### FIXED CODE ###

from bisect import bisect,bisect_left
import sys
input=sys.stdin.readline

def main():
    n,q=map(int,input().split())
    xst=[]
    for i in range(n):
        s,t,x=map(int,input().split())
        xst.append([x,s-x,t-x])
    xst.sort()
    d=[None]*q
    for i in range(q):
        d[i]=int(input())
    ans=[-1]*q
    skip=[-1]*q
    for u in xst:
        x ,left ,right = u
        a=bisect_left(d,left)
        b=bisect_left(d,right)
        while a < b:
            if skip[a] == -1:
                ans[a]=x
                skip[a]=b
                a+=1
            else:
                a=skip[a]
    for u in ans:
        print(u)

if __name__=="__main__":
    main()
### BUGGY CODE ###

ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import itertools
import random
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        cnt =0
        while n % b == 0:
            n //= b
            cnt +=1
        if cnt >=1:
            fct.append((b,cnt))
        b = b + 1
    if n > 1:
        fct.append((n,1))
    return fct
def solve():
    random.seed(0)
    n = ni()
    A = lma()
    d=collections.Counter()
    r = random.random()
    if n==10**6:
        if r<0.25:
            print("setwise coprime")
            exit()
        elif 0.25<r<0.5:
            print("pairwise coprime")
            exit()
    for i in range(n):
        a = A[i]
        fct = factorize(a)
        for fc,cnt in fct:
            d[fc]+=1
            if d[fc]==n:
                break

    f1=True # pp or sp
    f2=True # sp or other
    for num,cnt in d.items():
        if cnt==n:
            f2=False #other
            break
        else:
            if cnt==1:
                pass
            else:
                f1=False
    if f2==False:
        print("not coprime")
        exit()
    elif f1 and f2:
        print("pairwise coprime")
    elif f1==False:
        print("setwise coprime")
solve()


### FIXED CODE ###

ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
gcd=math.gcd

def is_primes(n):
    primes = [1]*n
    primes[0] =0
    primes[1] =0
    for i in range(2,int(n**0.5)+2):
        if primes[i] ==1:
            for j in range(2*i,n,i):
                primes[j] = 0
    return primes
def factorize(n,primes):
    fct = [(1,1)]
    for b in primes:#primes ::sorted
        if b**2 > n:
            break
        cnt =0
        while n % b == 0:
            n //= b
            cnt +=1
        if cnt >=1:
            fct.append((b,cnt))
    if n > 1:
        fct.append((n,1))
    return fct

n =ni()
A = lma()
mx= 10**6+10
prms = is_primes(mx)
prms2=[i for i in range(mx) if prms[i]]
#print(prms2)
d=collections.Counter()
for a in A:
    fct = factorize(a,prms2)
    #print(fct)
    for fc,cnt in fct:
        if fc==1:continue
        d[fc]+=1

f1=True # pp or sp
f2=True # sp or not p
for num,cnt in d.items():
    if cnt==n:
        f2=False #numが全体で共通の約数になる not coprime
        break
    else:
        if cnt==1:## 素
            pass
        else:
            f1=False

if f2==False:
    print("not coprime")
elif f1:
    print("pairwise coprime")
else:
    print("setwise coprime")
### BUGGY CODE ###

n=int(input())
count_=0
while(n!=0):
    count_+=n%10
    n=n//10
    
if count_%9==0:
    print("Yes")
else:
    print("No")



### FIXED CODE ###

n=int(input())
if n%9==0:
  print("Yes")
else:
  print("No")
### BUGGY CODE ###

h = int(input())
ans = 1
ls = []
i = 1
while True:
    #print(ans)
    h //= 2
    ans += 2*i
    i += 1+(i-1)
    if h == 1:
        break
        
print(ans)

### FIXED CODE ###

h = int(input())
ans = 1
i = 1
if h == 1:
    print(1)
else:
    while True:
        h //= 2
        ans += 2*i
        i += 1+(i-1)
        if h == 1:
            break

    print(ans)
### BUGGY CODE ###

def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    for _ in range(q):
        b, c = map(int, input().split())
        ichi = [x for x, i in enumerate(a) if i == b]
        for ie in ichi:
            a[ie] = c
        print(sum(a))

if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import Counter
from collections import defaultdict
def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    asum = sum(a)
    ac = Counter(a)
    acl = defaultdict(int)
    for ae in ac:
        acl[ae] = ac[ae]

    for _ in range(q):
        b, c = map(int, input().split())
        rmed = acl[b]
        acl[c] += rmed
        acl[b] = 0
        asum -= b * rmed
        asum += c * rmed
        print(asum)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

n = int(input())


s_count ={}

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



max_s_list = [kv[0] for kv in s_count.items() if kv[1] == max(s_count.values())]

result = sorted(max_s_list)

for k in result:
    print(k)

### FIXED CODE ###

n = int(input())


s_count ={}

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


max_val = max(s_count.values())
max_s_list = [key for key in s_count if s_count[key] == max_val]
result = sorted(max_s_list)

for k in result:
    print(k)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
j = True
count = 0
while True:
     for i in A:
             if i % 2 == 0:
                     A[A.index(i)] = i / 2
             else:
                     j = False
             if j != True:
              	break
                     
     count += 1
print(count)


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
j = True
count = 0
while j :
     for i in A:
             if i % 2 == 0 or i == 0:
                     A[A.index(i)] = i / 2
             else:
                     j = False
     if j == True:             
     	count += 1
print(count)