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

S = input()
Q = int(input())

reverse = 1 #reverse == 1 -> 正常, reverse == -1 -> 逆から
for i in range(Q):
    Query_tmp = list(map(str, input().split()))
    
    if Query_tmp[0] == "1":
        reverse *= -1
        # S = S[::-1]
    else:
        Ci = Query_tmp[2]

        if Query_tmp[1] == "1":
            if reverse == 1:
                S = Ci + S
            else:
                rev_Ci = Ci[::-1]
                S = S + rev_Ci
        else:
            if reverse == 1:
                S = S + Ci
            else:
                rev_Ci = Ci[::-1]
                S = rev_Ci + S
    
    # if reverse == 1:
    #     print(S)
    # else:
    #     print(S[::-1])

if reverse == 1:
    print(S)
else:
    print(S[::-1])

### FIXED CODE ###

from collections import deque

S = input()
Q = int(input())

reverse = 1 #reverse == 1 -> 正常, reverse == -1 -> 逆から

d = deque(S)

for i in range(Q):
    Query_tmp = list(map(str, input().split()))
    
    if Query_tmp[0] == "1":
        reverse *= -1
        # S = S[::-1]
    else:
        Ci = Query_tmp[2]

        if Query_tmp[1] == "1":
            if reverse == 1:
                d.appendleft(Ci)
            else:
                rev_Ci = Ci[::-1]
                d.append(rev_Ci)
        else:
            if reverse == 1:
                d.append(Ci)
            else:
                rev_Ci = Ci[::-1]
                d.appendleft(rev_Ci)
    
    # if reverse == 1:
    #     print(S)
    # else:
    #     print(S[::-1])

if reverse == -1:
    d.reverse()

print("".join(d))
### BUGGY CODE ###

h,w=map(int,input().split())
data=[list(input()) for i in range(h)]
map1=[[0]*w for i in range(h)]
map2=[[0]*w for i in range(h)]
for i in range(h):
  count=0
  for j in range(w):
    if data[i][j]=="#":
      count=0
    else:
      count+=1
      map1[i][j]=count
  count=0
  for j in range(w):
    if map1[i][-1-j]==0:
      count=0
    else:
      count=max(map1[i][-1-j],count)
      map1[i][-1-j]=count
for i in range(w):
  count=0
  for j in range(h):
    if data[j][i]=="#":
      count=0
    else:
      count+=1
      map2[j][i]=count
  count=0
  for j in range(h):
    if map2[-j-1][i]==0:
      count=0
    else:
      count=max(map2[-j-1][i],count)
      map2[-j-1][i]=count
ans=0
for i in range(h):
  for j in range(w):
    tmp=map1[i][j]+map2[i][j]
    ans=max(ans,tmp)
print(ans-1)

### FIXED CODE ###

h,w=map(int,input().split())
s=[list(input())for _ in range(h)]
score=[[0]*w for _ in range(h)]
ans=0
range_w=range(w)
range_h=range(h)
for i in range_h:
  tmp_1=0
  tmp_2=0
  for j in range_w:
    if s[i][j]=="#":
      tmp_1=0
    else:
      tmp_1+=1
    score[i][j]+=tmp_1
    
    if s[i][-j-1]=="#":
      tmp_2=0
    else:
      tmp_2+=1
    score[i][-j-1]+=tmp_2
    
for j in range_w:
  tmp_3=0
  tmp_4=0
  for i in range_h:
    if s[i][j]=="#":
      tmp_3=0
    else:
      tmp_3+=1
    score[i][j]+=tmp_3
    
    if s[-i-1][j]=="#":
      tmp_4=0
    else:
      tmp_4+=1
    score[-i-1][j]+=tmp_4-3
for i in range(h):
  for j in range(w):
    ans=max(ans,score[i][j])
print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
A = [int(a) for a in input().split()]
tot1 = 1
tot2 = 1

for i in range(K):
  tot1 *= A[i]

for j in range(N - K):
  tot2 = tot1 * A[j + K] // A[j] 
  if tot2 > tot1:
    print('Yes')
  else:
    print('No')
  tot1 = tot2

### FIXED CODE ###

N, K = map(int, input().split())
A = [int(a) for a in input().split()]


for i in range(N - K):
  if A[i] < A[K + i]:
    print('Yes')
  else:
    print('No')
### BUGGY CODE ###

import math
n=int(input())

for p in range(1, n+1):
  right=math.floor(math.sqrt(p))+1
  cnt=0
  for i in range(1, right):
    for j in range(1, i+1):
      for k in range(1, j+1):
        if (i+j+k)**2-i*j-j*k-k*i==p:
          if i==j and j==k:
            cnt+=1
          elif i==j and j!=k:
            cnt+=3
          elif j==k and k!=i:
            cnt+=3
          elif k==i and i!=j:
            cnt+=3
          elif i!=j and j!=k and k!=i:
            cnt+=6
  print(cnt)

### FIXED CODE ###

n=int(input())
lst=[0]*10000000
for i in range(1, 101):
  for j in range(1, i+1):
    for k in range(1, j+1):
      temp=i**2+j**2+k**2+i*j+j*k+k*i
      if i==j and j==k:
        lst[temp+1]+=1
      elif i==j and j!=k:
         lst[temp+1]+=3
      elif j==k and k!=i:
         lst[temp+1]+=3
      elif k==i and i!=j:
         lst[temp+1]+=3
      elif i!=j and j!=k and k!=i:
         lst[temp+1]+=6
for p in range(1, n+1):
  print(lst[p+1])
### BUGGY CODE ###

def main():
  M=10**9+7
  n,k,*a=map(int,open(0).read().split())
  b=[1]+[0]*k
  for i in a:
    t,d=0,[]
    for w,v in zip([0]*-~i+b,b):
      t+=v-w
      t%=M
      d+=t,
    b=d
  print(t)
main()

### FIXED CODE ###

def main():
  e,M=enumerate,10**9+7
  n,k,*a=map(int,open(0).read().split())
  dp=[[0]*(k+1)for _ in range(n+1)]
  dp[0][0]=1
  for i,(b,d,a)in e(zip(dp,dp[1:],a),1):
    t=0
    for j,v in e(b):
      t+=v
      if j>a:t-=b[~a+j]
      t%=M
      d[j]=t
  print(t)
main()
### BUGGY CODE ###

import numpy as np
MOD = 1000000007
s = (list(input()))
s = s[::-1]
dp = np.full((len(s), 13), 0, dtype="int64")

if s[0] == "?":
    dp[0][0:10] = 1
else:
    dp[0][int(s[0])] = 1

for index in range(1, len(s)):
    if not s[index] == "?":
        value = int(s[index])
        for old_amari in range(13):
            new_amari = (value * pow(10, index) + old_amari) % 13
            dp[index][new_amari] += dp[index-1][old_amari]
    else:
        for value in range(10):
            for old_amari in range(13):
                new_amari = (value * pow(10, index) + old_amari) % 13
                dp[index][new_amari] += dp[index - 1][old_amari]
    dp[index] = dp[index] % MOD

print(dp[len(s)-1][5])

### FIXED CODE ###

MOD = 1000000007
s = [int(x) if x!="?" else -1 for x in input()]
dp = [[0] *  13 for _ in range(len(s))] 

if s[0] == -1:
    for i in range(10):
        dp[0][i] = 1
else:
    dp[0][int(s[0])] = 1
 
table = [ s % 13 for s in range(130)]
for index in range(1, len(s)):
    if not s[index] == -1:
        value = int(s[index])
 
        for old_amari in range(13):
            new_amari = (table[old_amari * 10] + value) % 13
            dp[index][new_amari] += dp[index-1][old_amari]
    else:
        for value in range(10):
            for old_amari in range(13):
                new_amari = (table[old_amari * 10] + value) % 13
                dp[index][new_amari] += dp[index - 1][old_amari]
 
    for i in range(len(dp[index])):
        dp[index][i] %= MOD

print(dp[len(s)-1][5])
### BUGGY CODE ###

H,W,D = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(H)]
Q = int(input())
LR = [list(map(int,input().split())) for i in range(Q)]
mat = [0 for i in range(H*W)]
for h in range(H):
    for w in range(W):
        mat[A[h][w]-1] = [h,w]
for l,r in LR:
    dis = 0
    now = mat[l-1]
    for i in range(l-1,r,D):
        dis += abs(mat[i][0]-now[0])+abs(mat[i][1]-now[1])
        now = mat[i]
    print(dis)
    

### FIXED CODE ###

H,W,D = list(map(int,input().split()))
mat = [0 for i in range(H*W)]
A = []
for h in range(H):
    a = list(map(int,input().split()))
    A.append(a)
    for w in range(W):
        mat[a[w]-1] = [h,w]
Q = int(input())
LR = [list(map(int,input().split())) for i in range(Q)]
dlist = [0 for i in range(H*W)]
for i in range(H*W):
    if i+1 > D:
        dlist[i] = abs(mat[i][0]-mat[i-D][0]) + abs(mat[i][1]-mat[i-D][1]) +dlist[i-D]
for l,r in LR:
    print(dlist[r-1]-dlist[l-1])
### BUGGY CODE ###

import itertools

N, K = map(int, input().split())
H = [int(input()) for i in range(N)]

ans = float("inf")

for s in itertools.permutations(H, K):
  s = list(s)
  s.sort()
  ans = min(ans, s[K-1] - s[0])
  
print(ans)

### FIXED CODE ###

# ans

N, K = map(int, input().split())
H = [int(input()) for i in range(N)]
H.sort()

print(min(H[i+K-1] - H[i] for i in range(N-K+1)))
### BUGGY CODE ###

dx = [-1,-1,-1,0,0,1,1,1,0]
dy = [-1,0,1,-1,1,-1,0,1,0]
H,W,N = map(int,input().split())
s = []
d = {}
for i in range(N):
    a,b = map(int,input().split())
    for j in range(9):
        A = a + dy[j]
        B = b + dx[j]
        if A <= 1:
            continue
        if A >= H:
            continue
        if B <= 1:
            continue
        if B >= W:
            continue
        if (A,B) not in s:
            d[(A,B)] = 0
            s.append((A,B))
        d[(A,B)] += 1
ans = [(H-2)*(W-2)-len(s),0,0,0,0,0,0,0,0,0]
for (x,y) in s:
    ans[d[(x,y)]] += 1
for i in range(10):
    print(ans[i])

### FIXED CODE ###

dx = [-1,-1,-1,0,0,1,1,1,0]
dy = [-1,0,1,-1,1,-1,0,1,0]
H,W,N = map(int,input().split())
from collections import defaultdict, Counter
d = defaultdict(int)
for i in range(N):
    a,b = map(int,input().split())
    for j in range(9):
        A = a + dy[j]
        B = b + dx[j]
        f = 0
        if 2 <= A <= H-1:
            if 2 <= B <= W-1:
                f = 1
        if f == 1:
            d[(A,B)] += 1
s = 0
c = Counter(d.values())
for i in range(1,10):
    s += c[i]
c[0] = (H-2)*(W-2) - s
for i in range(10):
    print(c[i])
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
from fractions import gcd
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x
b=lcm(a)
c=0
for i in range(n):
    c+=(b//a[i])%(10**9+7)
print(c%(10**9+7))

### FIXED CODE ###

import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
n=int(input())
a=list(map(int,input().split()))
b=0
l=lcm_list(a)
for i in range(n):
    b+=l//a[i]
print(b%(10**9+7))
### BUGGY CODE ###

b=[]
num=int(input())
a=input().split()

for i in range(num):
    
    b.append(a[i])
    b.reverse()


for i in range(num):
    print(b[i],end=" ")

print("")


### FIXED CODE ###


b=[]
num=int(input())
a=input().split()


if num%2==0:
    for i in range(num-1,0,-2):
        print(a[i],end=" ")
    for i in range(0,num,2):
        print(a[i],end=" ")
else:
    for i in range(num-1,0,-2):
        print(a[i],end=" ")
    print(a[0],end=" ")
    for i in range(1,num,2):
        print(a[i],end=" ")
    


print("")
### BUGGY CODE ###

# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [[0] * (wlimit + 1) for _ in range(n + 1)]
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        for w in range(wlimit + 1):
            w_ = w - wi
            v_ = dp[i - 1][w] if w_ < 0 else dp[i - 1][w_] + vi
            dp[i][w] = max(dp[i - 1][w], v_)
    return(dp[i][-1])

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))


### FIXED CODE ###

# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [-1] * (wlimit + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        dp_ = list(dp)
        for w in range(wlimit + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= wlimit and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))
### BUGGY CODE ###

A, B = map(int, input().split())
a , b = 0, 0
ans = 0

for i in range(1, 100000):
  a = A * i
  if ans != 0:
    print(ans)
    break
  for j in range(1, 100000):
    b = B * j
    if a == b:
      ans = a
    elif b < a:
      continue
    else:
      break

### FIXED CODE ###

A, B = map(int, input().split())
a , c = 0, 0
ans = 0

if B > A:
  c = B
  B = A
  A = c
 
for i in range(1, B+1):
  a = A * i
  if ans != 0:
    break
  if a % B == 0:
    ans = a
    break
print(ans)
### BUGGY CODE ###

rows, columns = map(int, input().split(' '))

result = 0
for row in range(rows):
    for column in range(columns):
        target_time = 0

        inc_column = column + 1 < columns
        dec_column = 0 <= column - 1
        inc_row = row + 1 < rows
        dec_row = 0 <= row - 1

        if inc_column:
            if inc_row:
                target_time += 1
            if dec_row:
                target_time += 1
        if dec_column:
            if inc_row:
                target_time += 1
            if dec_row:
                target_time += 1

        if dec_column:
            target_time += 1
        if inc_column:
            target_time += 1
        if inc_row:
            target_time += 1
        if dec_row:
            target_time += 1

        if target_time % 2 == 0:
            result += 1

print(result)

### FIXED CODE ###

rows, columns = map(int, input().split(' '))

if rows == 1 and columns == 1:
    print(1)
    exit()

if rows == 1:
    print(columns - 2)
    exit()

if columns == 1:
    print(rows - 2)
    exit()

print(rows * columns - 2 * rows - 2 * columns + 4)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))

for i in range(n - 1):
    for j in range(i + 1, n):
        if a[i] == a[j]:
            print('NO')
            exit()
print('YES')

### FIXED CODE ###

n = int(input())
a = sorted(list(map(int, input().split())))

for i in range(n - 1):
    if a[i] == a[i + 1]:
        print('NO')
        exit()
print('YES')
### BUGGY CODE ###

#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))
    count=0

    for idx,data in enumerate(numbers):
        if idx == 0:
            count+=1
        elif min(numbers[0:idx+1])==data:
            count+=1
        else:
            continue
    print(count)

if __name__=="__main__":
    main()

### FIXED CODE ###

#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))
    small=0
    dp=[]

    for idx,data in enumerate(numbers):
        if idx == 0:
            small=data
            dp.append(data)
        elif data < small:
            small=data
            dp.append(data)
        else:
            continue
    print(len(dp))

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

# D TLE
import itertools
import bisect

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

L.sort()
value = 0

for i, j in itertools.combinations(range(len(L)-1), 2):
    index = bisect.bisect_left(L[j+1:], L[i]+L[j])
    value+=index

print(value)

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
l.sort()
 
from bisect import bisect_left
ans = 0
for i in range(n):
  for j in range(i+1, n):
    t = l[i]+l[j]
    idx = bisect_left(l, t)
    ans += max(0, idx-j-1)
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**8)
n1,k=map(int,input().split())
l=list(map(int,input().split()))
inf=10**9
dp=[-1 for i in range(n1)]
dp[0]=0
def dp1(n):
  if n==0:
    return 0
  elif dp[n]!=-1:
    return dp[n]
  elif 1<=n and n<=k-1:
    num=n
    min=inf
    for i in range(num):
      num1=dp1(i)
      high=abs(l[i]-l[n])
      if min>num1+high:
        min=num1+high
    dp[n]=min
    return min
  else:
    min=inf
    for i in range(1,1+k):
      num1=dp1(n-i)
      high=abs(l[n-i]-l[n])
      if min>num1+high:
        min=num1+high
    dp[n]=min
    return min
print(dp1(n1-1))
      

### FIXED CODE ###

n,k=map(int,input().split())
l=tuple(map(int,input().split()))
dp=[-1]*(n+1)
dp[1]=0
for i in range(2,min(n,k)+1):
  dp[i]=abs(l[i-1]-l[0])
if k>=n:
  print(dp[n])
else:
  dp[k+1]=abs(l[0]-l[k])
  for i in range(k+2,n+1):
    min=10**10
    for j in range(i-k,i):
      if min>dp[j]+abs(l[j-1]-l[i-1]):
        min=dp[j]+abs(l[j-1]-l[i-1])
    dp[i]=min
  print(dp[n])
### BUGGY CODE ###

n = int(input())
lst = []
for i in range(0,n):
  lst.append(int(input()))
  
ans = []
for i in range(0,len(lst)):
  sort_lst = lst[:]
  sort_lst.pop(i)
  sort_lst.sort(reverse=True)
  ans.append(sort_lst[0])
 
for d in ans:
  print(d)

### FIXED CODE ###

n=int(input())
a=[int(input())for _ in range(n)]
b=sorted(a) # sortする降順に

for a in a:print(b[(a<b[-1])-2])
### BUGGY CODE ###

N, W = map(int, input().split())
w = [0 for _ in range(N)]
v = [0 for _ in range(N)]
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

for i in range(N):
    for sum_w in range(1, W+1):
        if sum_w - w[i] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i])
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])

print(dp[N][W])


### FIXED CODE ###

N, W = map(int, input().split())
w = [0 for _ in range(N)]
v = [0 for _ in range(N)]
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

for i in range(N):
    for sum_w in range(1, W+1):
        if sum_w - w[i] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i])
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])

print(dp[N][W])
### BUGGY CODE ###

from collections import Counter
n = int(input())
a_input = list(map(int,input().split()))

a_count = Counter(a_input)
for i in range(n):
    li = [(v-1)*(v-2)//2 if k==a_input[i] else v*(v-1)//2 for k,v in a_count.items()]
    print(sum(li))  

### FIXED CODE ###

from collections import Counter
n = int(input())
a_input = list(map(int,input().split()))

a_count = Counter(a_input)

score_dic={}
exclude_dic={}

for k,v in a_count.items():
    score_dic[k]=v*(v-1)//2
    exclude_dic[k]=(v-1)*(v-2)//2

score_sum = sum(score_dic.values())

for i in range(n):
    print(score_sum-score_dic[a_input[i]]+exclude_dic[a_input[i]])
### BUGGY CODE ###

#import itertools

x,y,z,k=(int(i) for i in input().split())
#print(x,y,z,k)
a=list(int(i) for i in input().split())
a.sort(reverse=True)
b=list(int(i) for i in input().split())
b.sort(reverse=True)
c=list(int(i) for i in input().split())
c.sort(reverse=True)
#print(a,b,c)

#k=3000
#a=[int(i) for i in range(1000)]
#b=[int(i) for i in range(1000)]
#c=[int(i) for i in range(1000)]
x=[]
for h in range(len(a)):
    for i in range(len(b)):
        if (h+1)*(i+1) <=k:
            for j in range(len(c)):
                if (h+1)*(i+1)*(j+1) <=k:
                    x.append(a[h]+b[i]+c[j])

x.sort(reverse=True)
for i in range(k):
  print(x[i])
  


### FIXED CODE ###

#import itertools

x,y,z,k=(int(i) for i in input().split())
#print(x,y,z,k)
a=list(int(i) for i in input().split())
a.sort(reverse=True)
b=list(int(i) for i in input().split())
b.sort(reverse=True)
c=list(int(i) for i in input().split())
c.sort(reverse=True)
#print(a,b,c)

#k=3000
#a=[int(i) for i in range(1000)]
#b=[int(i) for i in range(1000)]
#c=[int(i) for i in range(1000)]
x=[]
for h in range(len(a)):
    for i in range(len(b)):
        if (h+1)*(i+1) <=k:
            for j in range(len(c)):
                if (h+1)*(i+1)*(j+1) <=k:
                    x.append(a[h]+b[i]+c[j])

x.sort(reverse=True)
for i in range(k):
  print(x[i])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))


def main():
    n, m = map(int, input().split())
    edges = [[] for _ in range(n)]
    for _ in range(m):
        s, t = map(int, input().split())
        edges[s-1].append(t-1)
    
    ans = n + 1
    for i in range(n - 1):
        # 頂点 i からの辺を消す
        dp = [0 for _ in range(n)]

        for j in range(n - 2, -1, -1):
            totale, maxe = 0, 0
            for e in edges[j]:
                totale += dp[e]
                maxe = max(maxe, dp[e])
        
            if i == j and len(edges[j]) > 1:
                dp[j] = (totale - maxe) / (len(edges[j]) - 1) + 1
            else:
                dp[j] = totale / len(edges[j]) + 1
        
        ans = min(ans, dp[0])
    
    print("%.10f" % ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))


def main():
    n, m = map(int, input().split())
    edges = [[] for _ in range(n)]
    for _ in range(m):
        s, t = map(int, input().split())
        edges[s-1].append(t-1)
    
    ans = n + 1
    for i in range(n - 1):
        # 頂点 i からの辺を消す
        dp = [0 for _ in range(n)]

        for j in range(n - 2, -1, -1):
            totale, maxe = 0, 0
            for e in edges[j]:
                totale += dp[e]
                maxe = max(maxe, dp[e])
        
            if i == j and len(edges[j]) > 1:
                dp[j] = (totale - maxe) / (len(edges[j]) - 1) + 1
            else:
                dp[j] = totale / len(edges[j]) + 1
        
        ans = min(ans, dp[0])
    
    print("%.10f" % ans)


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

N = int(input())
S = [input() for i in range(N)]
S_set = sorted(list(set(S)))
#print(S_set)
cnt = [0 for i in range(len(S_set))]
word_buf = []
mmax = -1

for i in range(len(S_set)) :
    cnt[i] = S.count(S_set[i])
    if i == 0 :
        word_buf.append(S_set[i])
    else :
        if cnt[i] < mmax :
            pass
        elif cnt[i] == mmax :
            word_buf.append(S_set[i])
        elif cnt[i] > mmax :
            word_buf.clear()
            word_buf.append(S_set[i])
    mmax = max(mmax,cnt[i]) # 現時点での最大値
#print("--")
for i in range(len(word_buf)) :
    print(word_buf[i])

### FIXED CODE ###

from collections import Counter
N = int(input())
S = [''] * N
for i in range(N) :
    S[i] = input()
S = Counter(S).most_common()
c = S[0][1]

print(*sorted([a for a,s in S if s==c]),sep="\n")
### BUGGY CODE ###

def main():
    n = 13
    mod = 1000000007
    r = 5

    s_list = list(reversed(input()))

    #amari_list = amari(n)

    amari_list = []
    tmp = amari(n)
    for i in range(len(tmp)):
        amari_list.append([j * tmp[i % len(tmp)] % n for j in range(10)])

    ans_list = initial(s_list[0], n)

    for i, s in enumerate(s_list):
        if i == 0:
            continue
        if s == "?":
            tmp_list, ans_list = ans_list, [0]*n
            for j in range(10):
                #t = j * amari_list[i % len(amari_list)] % n
                t = amari_list[i % len(tmp)][j]
                ans_list = add(ans_list, shift(t, tmp_list))
        else:
            #t = int(s) * amari_list[i % len(amari_list)] % n
            t = amari_list[i % len(tmp)][int(s)]
            ans_list = shift(t, ans_list)

        ans_list = list(map(lambda x: x % mod, ans_list))

    print(ans_list[r] % mod)


def shift(r, ans_list):
    l = len(ans_list)
    return [ans_list[(i + l - r) % l] for i in range(l)]


def add(list1, list2):
    return list(map(sum, zip(list1, list2)))


def initial(s, n):
    if s == "?":
        return [1 if i < 10 else 0 for i in range(n)]
    else:
        return [1 if i == int(s) else 0 for i in range(n)]


def amari(n):
    ret = []
    for i in range(n+1):
        r = (10**i) % n
        if r in ret:
            return ret
        else:
            ret.append(r)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import numpy as np


def main():
    n = 13
    mod = 1000000007
    r = 5
    in_str = input()

    amari_l = amari_list(n)
    amari_m = amari_matrix(n, amari_l)

    ans_list = initial(in_str[-1:], n)

    for i, s in enumerate(reversed(in_str)):
        if i == 0:
            continue
        if s == "?":
            ans_list = np.dot(ans_list, amari_m[i % len(amari_m)]) % mod
        else:
            t = int(s) * amari_l[i % len(amari_l)] % n
            ans_list = np.roll(ans_list, t)

    print(int(ans_list[r] % mod))


def initial(s, n):
    if s == "?":
        return np.array([1 if i < 10 else 0 for i in range(n)], dtype='int64')
    else:
        return np.array([1 if i == int(s) else 0 for i in range(n)], dtype='int64')


def shift(n, r):
    return np.array([[1 if (i - j + r) % n == 0 else 0 for j in range(n)] for i in range(n)])


def amari_list(n):
    ret = []
    for i in range(n + 1):
        r = 10**i % n
        if r in ret:
            return ret
        else:
            ret.append(r)


def amari_matrix(n, amari_list):
    ret = np.zeros((len(amari_list), n, n))
    for i, j in enumerate(amari_list):
        tmp = np.zeros((n, n))
        for k in range(10):
            tmp += shift(n, j * k % n)
        ret[i] = tmp
    return ret


if __name__ == '__main__':
    main()