Harryxun/stf_run huggingface dataset:
S = str(input())
Q = int(input())
querry = [list(map(str, input().split())) for i in range(Q)]
for i in range(Q):
    if querry[i][0] == '1':
        S = S[::-1]
    elif querry[i][0] == '2':
        if querry[i][1] == '1':
            A_S += querry[i][2] 
        elif querry[i][1] == '2':
            S_A += querry[i][2]

print(A_S + S + S_A)

### FIXED CODE ###

from collections import deque
S = deque(input())
Q = int(input())
querry = [list(map(str, input().split())) for i in range(Q)]
reverse = False
for i in range(Q):
    if querry[i][0] == '1':
        reverse = not reverse
    elif querry[i][0] == '2':
        if querry[i][1] == '1':
            if reverse:
                S.append(querry[i][2])
            else:
                S.appendleft(querry[i][2])
        elif querry[i][1] == '2':
            if reverse:
                S.appendleft(querry[i][2])
            else:
                S.append(querry[i][2])

ans=list(S)

if reverse:
    print("".join(reversed(ans)))
else:
    print("".join(ans))
# encoding utf-8

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

x = list(int(i) for i in input().split())


for i in range(N):
    if 0 <= x[i]:
        border = i
        break

len_run = 100000

if border == 0:
    len_run = min(abs(x[K-1]), len_run)

if border == N-1:
    len_run = min(abs(x[N-K]), len_run)

for i in range(K):
    if border-K+i >= 0 and border+i <= N:
        len_run = min(abs(2*x[border-K+i])+abs(x[border+i-1]), len_run)
        len_run = min(abs(x[border-K+i])+abs(2*x[border+i-1]), len_run)

print(len_run)













# #最終的に右に進む
# def right(K):
#     runlen = 0
#     y = x_pos
#     for i in range(len(x_neg)):
#         y.append(x_neg[i]*(-2))
#     y.sort()
#     max = y[K-1]
#     if max in x_pos:
#         runlen += max
#         y_neg = [i for i in x_neg if i >= (-max)/2]
#         runlen += y_neg[-1]*-2
#     else:
#         runlen += max/2
#         y_pos = [i for i in x_pos if i <= max]
#         runlen += y_pos[-1]
#     return runlen
#
#
# def left(K):
#     runlen = 0
#     z = []
#     for j in range(len(x_neg)):
#         z.append(x_neg[j]*-1)
#     for i in range(len(x_pos)):
#         z.append(x_pos[i]*(2))
#     z.sort()
#     max = -z[K-1]
#     if max in x_neg:
#         runlen -= max
#         z_pos = [i for i in x_pos if i <= (-max)/2]
#         runlen += z_pos[-1]*2
#     else:
#         runlen -= max/2
#         z_neg = [i for i in x_neg if i <= -max]
#         runlen += z_neg[-1]
#     return runlen
#
# if len(x_neg) == 0:
#     runlen = x[K-1]
# elif len(x_pos) == 0:
#     x.sort().reverse()
#     runlen = x[K-1]
# else:
#     runlen = min(right(K),left(K))
#     print(right(K),left(K))
#
# print(runlen)


### FIXED CODE ###

#encoding utf 8

n, k = map(int, input().split())

pos = list(int(i) for i in input().split())

ans = abs(pos[0])+abs(pos[0]-pos[k-1])

for i in range(n-k+1):
    val = 0
    val += abs(pos[i] - pos[i+k-1])
    val += min(abs(pos[i]), abs(pos[i+k-1]))

    if val < ans:
        ans = val
print(ans)
import re;print(int(re.sub('¥D',"",__file__))/2)

### FIXED CODE ###

_=int(input());c=0
for i in 'i¥½ÃÉ':
  if (_ < ord(i)):
    print(c)
    break
  c+=1
N, M=map(int, input().split())
a=[int(input()) for _ in range(M)]
tmp=[1,1,2]
for i in range(N):
    tmp.append(tmp[-1]+tmp[-2])
def func(x):
    if x==-1:
        return 0
    else:
        return tmp[x]

s=func(a[0]-1)
for i in range(0, M-1):
    s*=func(a[i+1]-a[i]-2)
s*=func(N-a[M-1]-1)
print(s%1000000007)
         
    


### FIXED CODE ###

N, M=map(int, input().split())
a=[int(input()) for _ in range(M)]
tmp=[1,1,2]
for i in range(N):
    tmp.append(tmp[-1]+tmp[-2])
def func(x):
    if x==-1:
        return 0
    elif x==-2:
        return 1
    else:
        return tmp[x]

if M==0:
    print(func(N)%1000000007)
    exit(0)
s=func(a[0]-1)
for i in range(0, M-1):
    s*=func(a[i+1]-a[i]-2)
s*=func(N-a[M-1]-1)
print(s%1000000007)
import sys
N,M = map(int,input().split())
cc = [list(map(int, input().split())) for i in range(M)]
if [0,1] in cc:
  if N!= 1:
    print(-1)
    sys.exit()
a,b = [0]*N,['v']*N
for [i,j] in cc:
  a[i-1] = j
  if b[i-1] != 'v' or b[i-1] != j:
    print(-1)
    sys.exit
  b[i-1] = j
if a[0] = 0:
  a[0] = 1
c = ''
for i in a:
  c = c + str(i)
print(c)
  
  
    

### FIXED CODE ###

import sys
N,M = map(int,input().split())
cc = [list(map(int, input().split())) for i in range(M)]
if [1,0] in cc:
  if N!= 1:
    print(-1)
    sys.exit()
a,b = [0]*N,['v']*N
for [i,j] in cc:
  a[i-1] = j
  if b[i-1] != 'v' and b[i-1] != j:
    print(-1)
    sys.exit()
  b[i-1] = j
if a[0] == 0:
  if N != 1:
    a[0] = 1
c = ''
for i in a:
  c = c + str(i)
print(c)
N = int(input())
s = 0
for i in range(1,N,2):
	t = 0
    for j in range(1,N,2):
		if not N%n:
			t+=1
    if t==8:
		s+=1

print(s)



### FIXED CODE ###

N = int(input())
s = 0
for i in range(1,N+1,2):
  t = 0
  for j in range(1,i+1,2):
    if not i%j:
      t+=1
  if t==8:
    s+=1

print(s)
N = int(input())
A = list(map(int, input().split()))
count = [0] * N
last = [0] * N
used = [0] * N

for i in range(3 * N):
  now = A[i] - 1
  count[now] += 1
  if count[now] == 3:
    last[now] = i
  #print(now)  
#print(count, last)    

score = 0
now = [A[0], A[1], A[2], A[3], A[4]]
for i in range(N - 1):
  L = [0] * 5
  for j in range(5):
    L[j] = [last[now[j] - 1], j]
  L = sorted(L)
  #print(L)
  if L[1][0] == L[2][0]:
    if L[0][0] == L[1][0]:
      score += 1
      one, two = L[3][1], L[4][1]
    elif L[2][0] == L[3][0]:
      score += 1
      one, two = L[0][1], L[4][1]
    else:
      one, two = L[0][1], L[1][1]
  elif L[2][0] == L[3][0] and L[3][0] == L[4][0]:
    score += 1
    one, two = L[0][1], L[1][1]
  else:
    one, two = L[0][1], L[1][1]
    
  if i != N - 2:
    now = [A[one], A[two], A[5 + 3 * i], A[6 + 3 * i], A[7 + 3 * i]]
  else:
    now = [A[one], A[two], A[-1]]
  
if now[0] == now[1] and now[1] == now[2]:
  score += 1
    
print(score)  
      
      
  
  
  
  
  
  
  
  
  
  
  
  





### FIXED CODE ###

#ABC176 #F 問題 (Question F) #解説方針 #提出参考
N = int(input())
A = list(map(int, input().split()))

#DP(動的計画法)用配列
ans = [[-N] * (N+1) for _ in range(N+1)]
#初期化 (Initialization)
a0, a1 = A[:2]
ans[a0][a1] = 0
ans[a1][a0] = 0

##最大値の管理
#ans[i] の最大値を集めた配列 (0 <= i <= N)
ma = [-N] * (N+1) 
#ans の初期化に合わせて初期化
ma[a0] = 0
ma[a1] = 0
#ansの全要素の最大値、0で初期化
all_max = 0

#3, 4, 5番目の数が等しいときに加算するための変数
add = 0

#DP部分 多分 O(N ** 2)
for i in range(N - 1): 
    #3, 4, 5番目の数を a, b, c とする
    a, b, c = A[3 * i + 2], A[3 * i + 3], A[3 * i + 4]
    #3つとも等しいとき、最後の三枚を消す
    if a == b == c:
        add += 1
        continue
    Q = []
    for _ in range(3):
        a, b, c = b, c, a
        # a, b, c から残す数を2つ選ぶ
        # ans[c][c] + 1 は [c,c,a,b,c]を想定
        # all_max は DP[i][k][l]の最大値で最大化するときに対応
        Q.append((a, b, max(all_max, ans[c][c] + 1)))
        
        # a, b, c から残す数を1つ選ぶ
        for j in range(1, N + 1):
            #これまでのDP[i][k][l] (k, lのうち片方の変数として見たとき) の最大値
            val = ma[j]
            #2つの数が等しいとき
            if b == c:
                val = max(val, ans[b][j] + 1)
            Q.append((a, j, val))
            
        #配列を使いまわしているので、DP[i + 1][k][l] を DP[i][k][l]で最大化し直す必要なし
        #もしDP[i][k][l]が最大なら、maxを取る過程でこれが残る
    for i, j, val in Q:
        #DP配列の更新
        ans[i][j] = max(ans[i][j], val)
        ans[j][i] = max(ans[j][i], val)
        #最大値の管理
        ma[i] = max(ma[i], val)
        ma[j] = max(ma[j], val)
        all_max = max(all_max, val)
        
#ans の中から最大の値を見つけ出す。O(N ** 2)        
answer = 0
for i in range(1, N + 1):
    for j in range(1, N + 1):
        #最後に残った3枚が同じならもう1点加算
        if i == j == A[-1]:
            answer = max(answer, ans[i][j] + 1)
        else:
            answer = max(answer, ans[i][j])
            
print(answer + add)
def total(x):
    x=[abs(i) for i in x]
    return sum(x)

N,M=map(int,input().split())
x=[0 for i in range(N)]
y=[0 for i in range(N)]
z=[0 for i in range(N)]
for i in range(N):
    x[i],y[i],z[i]=map(int,input().split())
dp=[[[0,0,0] for i in range(M+1)] for j in range(N+1)]
for i in range(N):
    for j in range(M):
        if i>j:
            D=dp[i][j]
            XYZ=[D[0]+x[i],D[1]+y[i],D[2]+z[i]]
            if total(XYZ)>=total(dp[i][j+1]):
                dp[i+1][j+1]=[X,Y,Z]
            else:
                dp[i+1][j+1]=dp[i][j+1]
        elif i==j:
            dp[i+1][j+1]=[a+b for a,b in zip(dp[i][j],[x[i],y[i],z[i]])]
print(total(dp[N][M]))



### FIXED CODE ###

import numpy as np
N,M=map(int,input().split())
x=[0 for i in range(N)]
y=[0 for i in range(N)]
z=[0 for i in range(N)]
for i in range(N):
    x[i],y[i],z[i]=map(int,input().split())
x=np.array(x)
y=np.array(y)
z=np.array(z)
xyz=np.array([x,y,z])
d=[]
for i in range(8):
    buf=np.zeros(N)
    for j in range(3):
        if i & (1<<j):
            buf=buf+-1*xyz[j]
            continue
        buf=buf+xyz[j]
    buf.sort()
    d.append(sum(buf[N-M:]))
print(int(max(d)))
s=int(input())
mod=10**9+7
dp=[0]*s
dp[0]=1

for i in range(0,s+1):
	dp[i]=dp[i-1]+dp[i-3]
	dp[i]%=mod

print(dp[s])



### FIXED CODE ###

s=int(input())
mod=10**9+7
dp=[0]*(s+1)
dp[0]=1

for i in range(1,s+1):
	for j in range(0,(i-3)+1):
		dp[i]+=dp[j]
		dp[i]%=mod
print(dp[s])
#21:30
n = int(input())
peer = [[] for _ in range(n)]
for _ in range(n-1):
  a,b,x = map(int,input().split())
  a -= 1
  b -= 1
  peer[a].append([b,x])
  peer[b].append([a,x])
ans = [-1 for _ in range(n)]
now = [0]
while now != []:
  last = now
  now = []
  for x in last:
    for yz in peer[x]:
      y = yz[0]
      z = yz[1]
      if ans[y] == -1:
        ans[y] = (ans[x] + z) % 2
        now.append(y)
  #print(now)
for i in range(n):
  print(now[i])

### FIXED CODE ###

#21:30
n = int(input())
peer = [[] for _ in range(n)]
for _ in range(n-1):
  a,b,x = map(int,input().split())
  a -= 1
  b -= 1
  peer[a].append([b,x])
  peer[b].append([a,x])
ans = [-1 for _ in range(n)]
now = [0]
while now != []:
  last = now
  now = []
  for x in last:
    for yz in peer[x]:
      y = yz[0]
      z = yz[1]
      if ans[y] == -1:
        ans[y] = (ans[x] + z) % 2
        now.append(y)
  #print(now)
for i in range(n):
  print(ans[i])
n=int(input())
d=[int(i) for i  in input().split()]
from operator import mul
from functools import reduce

def cmb(n,r,mod):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under % mod

c=[d.count(i) for i in set(d)]
m=998244353
ans=1
if d[0]!=0:
    print(0)
else:
    for i in range(1,len(c)):
        ans=ans*cmb(c[i-1]*2,c[i],m) % m
    print(ans)

### FIXED CODE ###

#b
n=int(input())
d=[int(i) for i in input().split()]

import collections
c = collections.Counter(d)

m=998244353
ans=1
if d[0]!=0 or set(d)!=set(range(len(set(d)))) or 0 in d[1:]:
    print(0)
else:
    for i in range(1,len(c)):
        ans = (ans* c[i-1]**c[i]) %m
    print(ans)
args = raw_input().split()
sarr = []
for i in range(int(args[0])):
        sarr.append(raw_input().split())

counter = 0
lim = int(args[1])

for i in sarr:
    counter += int(i[1])
    if(counter >= lim):
        print(int(i[0]))
        exit()


### FIXED CODE ###

x = raw_input().split(" ")
num_operations = int(x[0])
kth_integer = int(x[1])
field = {}
for p in range(0, num_operations):
 line = raw_input().split(" ")
 a = int(line[0])
 b = int(line[1])
 if a in field:
  field[a] += b
 else:
  field[a] = b
ks = field.keys()
ks.sort()
out = field.keys()[-1]
for k in ks:
 kth_integer -= field[k]
 if (kth_integer <= 0):
  out = k
  break
print (out)
N, M = list(map(int, input().split()))
D = list(map(int, input().split()))
UB = [list(map(int, input().split())) for _ in range(M)]

R = {}
for i in range(M):
  a, b = UB[i]
  a -= 1
  b -= 1
  if a not in R: R[a] = [[b, i]]
  else: R[a].append([b, i])
  if b not in R: R[b] = [[a, i]]
  else: R[b].append([a, i])

DD = [[0] * 2 for _ in range(N)]
for i in range(N):
  DD[i][0] = D[i]
  DD[i][1] = i
DD.sort()
L = [0] * N
H = [0] * M
LL = [-1] * N
for i in range(N):
  h, x = DD[i]
  if L[x] == 0:
    if LL[x] == -1:
      for n, m in R[x]:
        LL[n] = x
        if D[n] == D[x] or L[n] != 0:
          H[m] = h
          if L[n] == 1:
            L[n] = 1
            L[x] = 2
          else:
            L[n] = 2
            L[x] = 1
          break
      else:
        print(-1)
        exit()
    else:
      if LL[x] not in R:
        break
      n, m = R[x][LL[x]]
      H[m] = h
      if L[n] == 1:
        L[n] = 1
        L[x] = 2
      else:
        L[n] = 2
        L[x] = 1

print(LL)
t = ""
for i in range(N):
  if L[i] == 1:
    t += "B"
  else:
    t += "W"
print(t)
for i in range(M):
  if H[i] == 0:
    print(10 ** 9)
  else:
    print(H[i])


### FIXED CODE ###

import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
D = list(map(int, input().split()))
UB = [list(map(int, input().split())) for _ in range(M)]

LL = [[-1] * 2 for _ in range(N)]
for i in range(M):
  a, b = UB[i]
  a -= 1
  b -= 1
  if D[a] < D[b]:
    LL[b] = [a, i]
  elif D[a] > D[b]:
    LL[a] = [b, i]
  else:
    LL[a] = [b, i]
    LL[b] = [a, i]

DD = [[0] * 2 for _ in range(N)]
for i in range(N):
  DD[i][0] = D[i]
  DD[i][1] = i
DD.sort()
L = [0] * N
H = [0] * M

for i in range(N):
  h, x = DD[i]
  if L[x] == 0:
    if LL[x][0] == -1:
      print(-1)
      exit()
    else:
      n, m = LL[x]
      H[m] = h
      if L[n] == 1:
        L[n] = 1
        L[x] = 2
      else:
        L[n] = 2
        L[x] = 1

for i in range(N):
  if L[i] == 1:
    L[i] = "B"
  else:
    L[i] = "W"
print("".join(list(map(str, L))))
for i in range(M):
  if H[i] == 0:
    print(10 ** 9)
  else:
    print(H[i])
def price():
    ramen_price = 700
    sa, st, sn = input().split() 
    if sa == 'o':
        ramen_price +=100
    if st == 'o':
        ramen_price +=100
    if sn == 'o':    
        ramen_price +=100
    print(ramen_price)

price()


### FIXED CODE ###

s = input()
t = 0
for i in range(3):
    if s[i] == 'o':
        t+=1

print(700 + t * 100)
from math import factorial
from scipy.special import comb
x,y = map(int, input().split())

if (x + y) % 3 != 0:
    print(0)
else:
    n = (2*y-x)//3
    m = (2*x-y)//3
    c = comb(n+m, n, exact=True)
    print(c % (10**9+7))


### FIXED CODE ###

x,y = map(int, input().split())

mod = 10**9+7
def inv(x):
        return pow(x, mod-2, mod)
def fact(x):
        f = 1 
        for i in range(1, x + 1): 
                f *= i
                f %= mod    
        return f
def comb(n, r): 
        return (fact(n) * inv(fact(n-r)) * inv(fact(r))) % mod 

if (x + y) % 3 != 0 or y / x < 1/2 or y/x > 2:
    print(0)
else:
    n = (2*y-x)//3
    m = (2*x-y)//3
    res = comb(n+m, m)
    print(res)
a,b,c=map(input().split())
if b=="+":
  print(a+b)
else:
  print(a-b)

### FIXED CODE ###

a,op,b=map(str,input().split())
a=int(a)
b=int(b)
if op=="+":
  print(a+b)
else:
  print(a-b)
n=input()
n=n.remove(1)
n=list(n)
print(len(n))

### FIXED CODE ###

n=int(input())
print(len(list(set([int(input()) for x in range(n)]))))
A,B = map(int, raw_input().split())
print((A-1)*(B-1))

### FIXED CODE ###

A,B = map(int, input().split())
print((A-1)*(B-1))
map(int,input().split())
h1,m1,h2,m2,k=map(int,input().split())

s=h1*60+m1
e=h2*60+m2

a=e-s

print(a-k)

### FIXED CODE ###

h1,m1,h2,m2,k=map(int,input().split())

s=h1*60+m1
e=h2*60+m2

a=e-s

print(a-k)
import sys
sys.setrecursionlimit(10**9)

def func(a,b):
    if a <= b:
        return a
    else:
        return func(b,abs(b-K))

N,K=map(int, input().split())
print(func(N,abs(N-K)))


### FIXED CODE ###

def func(a,b):
    if a <= b:
        return a
    else:
        return func(b,abs(b-K))

N,K=map(int, input().split())
N=N%K
print(func(N,abs(N-K)))
import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def evencount(n):
  cnt=0
  while n&1==0:
    cnt+=1
    i>>1
  return cnt
n,m=map(int,input().split())
a=list(map(int,input().split()))
if all(set([evencount(i) for i in a])):
  for i in range(n):
    a[i]//=2
  d=lcm(*a)
  print((m+d)//2//d)
else:print(0)

### FIXED CODE ###

from math import gcd
from functools import reduce
def lcm_base(x, y):
    return (x * y) // gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def evencount(n):
  cnt=0
  while n%2==0:
    cnt+=1
    n//=2
  return cnt
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  a[i]//=2
if all(evencount(i) == evencount(a[0]) for i in a):
  d=lcm(*a)
  print((m+d)//2//d)
else:print(0)
c = [list(input()) for i in range(3)]
s = ""
for j in range(3):
  s += c[i][i]
print(s)  


### FIXED CODE ###

c = [list(input()) for i in range(3)]
s = ""
for j in range(3):
  s += str(c[j][j])
print(s)
n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

memory = [[-1 for i in range(q)]for j in range(n)]

def f(i, m):
    if memory[i][m] != -1:
        return memory[i][m]
    if m == 0:
        return 1
    elif m < 0:
        return 0
    elif i >= n:
        return 0
    elif f(i+1, m):
        memory[i+1][m] = 1
        return 1
    elif f(i+1, m-a[i]):
        memory[i+1][m-a[i]] = 1
        return 1
    else:
        return 0

for k in m:
    print('yes' if f(0, k) else 'no')


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
memory = [[-1 for i in range(max(m)+1)]for j in range(n)]

def f(i, m):
    if m == 0:
        return 1
    elif i >= n:
        return 0
    elif memory[i][m] != -1:
        return memory[i][m]
    elif m - a[i] >= 0:
        res0 = f(i+1, m)
        res1 = f(i+1, m-a[i])
        if res0 or res1:
            memory[i][m] = 1
            return 1
        else:
            memory[i][m] = 0
            return 0
    else:
        res = f(i+1, m)
        memory[i][m] = res
        return res

for k in m:
    print('yes' if f(0, k) else 'no')
from heapq import heapify, heappush, heappop
n = int(input())
L = [int(i) for i in input().split()]
heapify(L)
for i in range(n-1):
    s = (L[0]+L[1])/2
    L = L[2:] 
    heappush(L,s)
ans = heapq.heappop(L)
print(ans)

### FIXED CODE ###

a = int(input())
s = input()
print(s if a>=3200 else 'red')
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

if __name__ == "__main__":
    N = int(input())
    num = math.factorial(N)
    pf = prime_factors(num)
    c = Counter(pf)
    
    res = 1

    for i in c.values():
        res *= i + 1
    
    print(res % (10**9+7))

### FIXED CODE ###

import math
from collections import Counter

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

if __name__ == "__main__":
    N = int(input())
    num = math.factorial(N)
    pf = prime_factors(num)
    c = Counter(pf)
    
    res = 1

    for i in c.values():
        res *= i + 1
    
    print(res % (10**9+7))
bingo = []
for i in range(3):
  row = [int(j) for j in input().split()]
  bingo.append(row)
ans = "No"
n = int(input())
for i in range(n):
  lot = int(input())
  for j in range(len(bingo)):
    col = 0
    for k in range(len(bingo[j])):
      if bingo[j][k] == lot:
      	bingo[j][k] = -1
      	col += bingo[j][k]
    if sum(bingo[j]) == -3:
  	  ans = "Yes"
  	if col == -3:
    	ans = "Yes"
if (bingo[0][0] + bingo[1][1] + bingo[2][2]) == -3:
  ans = "Yes"
if (bingo[0][2] + bingo[1][1] + bingo[2][0]) == -3:
  ans = "Yes"
print(ans) 

### FIXED CODE ###

bingo = []
for i in range(3):
  row = [int(j) for j in input().split()]
  bingo.append(row)
ans = "No"
n = int(input())
for i in range(n):
  lot = int(input())
  for j in range(len(bingo)):
    for k in range(len(bingo[j])):
      if bingo[j][k] == lot:
      	bingo[j][k] = -1
    if sum(bingo[j]) == -3:
  	  ans = "Yes"
if (bingo[0][0] + bingo[1][1] + bingo[2][2]) == -3:
  ans = "Yes"
if (bingo[0][2] + bingo[1][1] + bingo[2][0]) == -3:
  ans = "Yes"
if (bingo[0][0] + bingo[1][0] + bingo[2][0]) == -3:
  ans = "Yes"
if (bingo[0][1] + bingo[1][1] + bingo[2][1]) == -3:
  ans = "Yes"
if (bingo[0][2] + bingo[1][2] + bingo[2][2]) == -3:
  ans = "Yes"
print(ans)
A = input()
B = input()

dp = [[None] * (len(B) + 1) for _ in range(len(A) + 1)]
def dfs(a=0, b=0):
    if a >= len(A) or b >= len(B):
        return 0

    if dp[a][b] is not None:
        return dp[a][b]

    match = A[a] == B[b]
    if match:
        r = dfs(a + 1, b + 1) + 1
    else:
        r = max(dfs(a + 1, b), dfs(a, b + 1))
    dp[a][b] = r
    return r

dfs()
# print(dfs())
# print(dp)

# print("---")
# for v in dp:
#     print(*map(lambda x: x if x is not None else "*", v))

def or_inf(v):
    return float('inf') if v is None else v

def reconst(a=0, b=0):
    if a >= len(A) or b >= len(B):
        return ''

    match = A[a] == B[b]
    if match:
        return reconst(a + 1, b + 1) + A[a]
    else:
        if or_inf(dp[a + 1][b]) >= or_inf(dp[a][b + 1]):
            return reconst(a + 1, b)
        else:
            return reconst(a, b + 1)
print(reconst()[::-1])


### FIXED CODE ###

s = input()
t = input()

lens = len(s)
lent = len(t)

# dp = [[None] * lent for _ in range(lens)]
# def dfs(aindex=0, bindex=0):
#     if aindex >= lens:
#         return 0
#     if bindex >= lent:
#         return 0
#
#     if dp[aindex][bindex] is not None:
#         return dp[aindex][bindex]
#
#     if s[aindex] == t[bindex]:
#         r = dfs(aindex + 1, bindex + 1) + 1
#     else:
#         r = max(dfs(aindex + 1, bindex), dfs(aindex, bindex + 1))
#     dp[aindex][bindex] = r
#     return r
#
# print(dfs())

shift = [1 << x for x in range(3000 + 1)]

dp = [[0] * (lent + 1) for _ in range(lens + 1)]
for aindex in range(lens - 1, -1, -1):
    for bindex in range(lent - 1, -1, -1):
        if s[aindex] == t[bindex]:
            r = dp[aindex + 1][bindex + 1] + 1
        else:
            r = max(dp[aindex + 1][bindex], dp[aindex][bindex + 1])
        dp[aindex][bindex] = r

ans = ""
ls = len(s)
lt = len(t)
ls = 0
lt = 0
while ls < lens and lt < lent:
    if dp[ls][lt] == dp[ls + 1][lt]:
        ls += 1
    elif dp[ls][lt] == dp[ls][lt + 1]:
        lt += 1
    else:
        ans += t[lt]
        ls += 1
        lt += 1
print(ans)
import math

n = int(input())
a = [int(i) for i in input().split()]
m = []
if len(a) == 2:
    print(max(a))

else:
    for i in range(n-2):
        m.append(math.gcd(a[i],a[i+1]))
    m.append(math.gcd(a[0],a[n-1]))
    m = list(set(m))
    m.sort()
    print(m[1])


### FIXED CODE ###

from fractions import gcd

n = int(input())
a = [int(i) for i in input().split()]
l,r = [0],[0]
for i in range(1,n):
    l.append(gcd(l[i-1],a[i-1]))
    r.append(gcd(r[i-1],a[-i]))
r = r[::-1]
ans = 0

for i in range(n):
    ans = max(ans,gcd(l[i],r[i]))
print(ans)
N=int(input())
x,y=map(int,input().split())
import math
import numpy as np


def distance(x, y, i, j):
    d = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
    return d

da = np.zeros([N, N])
for i in range(N):
    for j in range(N):
        Da = distance(x, y, i, j)
        da[i][j] = Da
avg = da.sum() * math.factorial(N-1) / math.factorial(N)
print(avg)

### FIXED CODE ###

import math
N = int(input())
x = [0]*N
y = [0]*N
for i in range(N):
    x[i],y[i] = map(int,input().split())
at=[]
for i in range(N):
    for j in range(N):
        ea = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
        at.append(ea)
da = 0
for ag in at:
    da += ag
avg = da * math.factorial(N - 1) / math.factorial(N)
print(avg)
b = input().strip()

if b == 'A':
  return 'T'
elif b == 'T':
  return 'A'
elif b == 'C':
  return 'G'
else:
  return 'C'

### FIXED CODE ###

b = input().strip()
 
if b == 'A':
  print('T')
elif b == 'T':
  print('A')
elif b == 'C':
  print('G')
else:
  print('C')
n=int(input())
a=[i+1:int(input()) for i in range(n)]
v=1
for c in range(n):
    v=a[v]
    if v==2:
        print(c+1)
        break
else:
    print(-1)

### FIXED CODE ###

n=int(input())
a={i+1:int(input()) for i in range(n)}
v=1
for c in range(n):
    v=a[v]
    if v==2:
        print(c+1)
        break
else:
    print(-1)