Harryxun/stf_run huggingface dataset:
import itertools

H,W = map(int,input().split())
A = []
B = []
for _ in range(H):
    A.append(list(map(int,input().split())))

for _ in range(H):
    B.append(list(map(int,input().split())))

S = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        S[i][j] = abs(A[i][j] - B[i][j])

S_S = sorted(list(itertools.chain.from_iterable(S)),reverse=True)
MAX_S = sum(S_S[0:H+W-1])
MAX_SF = [[0] * W for _ in range(H)]
MAX_SR = [[0] * W for _ in range(H)]


MAX_SF[0][0] = S[0][0]
MAX_SR[H-1][W-1] = S[H-1][W-1]
for i in range(H):
    for j in range(W):
        if i == 0 and j == 0:
            continue
        if i == 0:
            MAX_SF[i][j] = MAX_SF[i][j-1] + S[i][j]
        elif j == 0:
            MAX_SF[i][j] = MAX_SF[i-1][j] + S[i][j]
        else:
            MAX_SF[i][j] = max(MAX_SF[i][j-1],MAX_SF[i-1][j]) + S[i][j]

for i in range(H-1,0,-1):
    for j in range(W-1,0,-1):
        if i == H-1 and j == W-1:
            continue
        if i == H-1:
            MAX_SR[i][j] = MAX_SR[i][j+1] + S[i][j]
        elif j == W-1:
            MAX_SR[i][j] = MAX_SR[i+11][j] + S[i][j]
        else:
            MAX_SR[i][j] = min(MAX_SR[i][j+1],MAX_SR[i+1][j]) + S[i][j]

DP = [[[False for _ in range(MAX_S+1)] for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        if i == 0 and j == 0:
            DP[0][0][S[0][0]] = True
        else:
            for d in ((1, 0), (0, 1)):

                if i - d[0] >= 0 and j - d[1] >= 0:
                    for k in range(min(MAX_SF[i][j],abs(MAX_SF[i][j] - MAX_SR[i][j])) + 1):
                        if k + S[i][j] <= MAX_S:
                            if DP[i-d[0]][j-d[1]][k + S[i][j]]:
                                DP[i][j][k] = True

                        if DP[i-d[0]][j-d[1]][abs(k - S[i][j])]:
                            DP[i][j][k] = True

for i in range(MAX_S+1):
    if DP[H-1][W-1][i]:
        print (i)
        exit(0)



### FIXED CODE ###

import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    H,W = LI()
    A = [LI() for _ in range(H)]
    B = [LI() for _ in range(H)]
    C = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            C[i][j] = abs(A[i][j] - B[i][j])
    D = [[set() for _ in range(W+1)] for _ in range(H+1)]
    D[0][1] = {0}
    for i in range(1,H+1):
        for j in range(1,W+1):
            for k in D[i-1][j] | D[i][j-1]:
                D[i][j].add(abs(k+C[i-1][j-1]))
                D[i][j].add(abs(k-C[i-1][j-1]))

    print(min(D[-1][-1]))


if __name__ == '__main__':
    main()
n = int(input())
        s = []
        for i in range(n):
          s.append(input())
         
        ab = 0
        ab_ = 0
        a = 0
        b = 0
        for i in s:
          ab += i.count("AB")
          if i[0] == "B" and i[-1] == "A":
            ab_ += 1
          if i[0] == "B":
            b += 1
          if i[-1] == "A":
            a += 1
        if ab_ == a and ab_ == b and not ab_ == 0:
          print(ab+ab_-1)
        else:
          print(ab+min([a,b]))

### FIXED CODE ###

n = int(input())
s = []
for i in range(n):
  s.append(input())
     
ab = 0
ab_ = 0
a = 0
b = 0
for i in s:
  ab += i.count("AB")
  if i[0] == "B" and i[-1] == "A":
    ab_ += 1
  if i[0] == "B":
    b += 1
  if i[-1] == "A":
    a += 1
if ab_ == a and ab_ == b and not ab_ == 0:
  print(ab+ab_-1)
else:
  print(ab+min([a,b]))
n,k=map(int,input().split())
s=input()

I=[0,]

for i in range(n-1):
    if s[i]!=s[i+1]:
        I.append(i+1)

if len(I)<k:
    I.extend([n+1]*(2*k+1))

X=[]

for i in range(len(I)):
    if s[I[i]]=='0':
        X.append(I[i+2*k]-I[i])
    else:
        X.append(I[i+2*k+1]-I[i])

print(max(X))

### FIXED CODE ###


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

I=[0]

for i in range(n-1):
    if s[i]!=s[i+1]:
        I.append(i+1)
        
r=len(I)

for _ in range(10**6):
        I.append(n)

X=[]

for i in range(r):
    if s[I[i]]=='0':
        X.append(I[i+2*k]-I[i])
    else:
        X.append(I[i+2*k+1]-I[i])

print(max(X))
n=int(input())
a= list(map(int,input().split()))
a=[i-1 for i in a]
b= list(map(int,input().split()))
c= list(map(int,input().split()))

count=0

for i in a:
    if i==cook:
        count+=c[i-1]
    
    count+=b[i] 
    cook=i+1
    
print(count)
    

### FIXED CODE ###

n=int(input())
a= list(map(int,input().split()))
a=[i-1 for i in a]
b= list(map(int,input().split()))
c= list(map(int,input().split()))

count=0
cook=-4
for i in a:
    if i==cook:
        count+=c[i-1]
    
    count+=b[i] 
    cook=i+1
    
print(count)
A = int(input())
W = list(map(int,input().split()))
tmp = 0
ans = 0
wa = 0

for i in range (A):
    wa += W[i]
for i in range (A):
    tmp += W[i]
    tmp_r = wa-tmp
    if i == 0:
        ans = tmp
    if ans > abs(tmp-tmp_r):
        ans = abs(tmp-tmp_r)
print(ans)

### FIXED CODE ###

P,Q,R = map(int,input().split())
A = [P+Q,Q+R,P+R]
A.sort()
print(A[0])
x = []
a = 0
while True:
    x.append(int(input()))
    if x[a] == 0 or a == 9999:
        break
    a += 1
i = 0
while True:
    if x[i] == 0 or i == 10000:
        break
    print('Case ' + str(i + 1) + ': ' + str(x[i]))
    i += 1


### FIXED CODE ###

x = []
a = 0
while True:
    x.append(int(input()))
    if x[a] == 0 or a == 9999:
        break
    a += 1
i = 0
for b in x:
    if b == 0 or i == 10000:
        break
    print('Case ' + str(i + 1) + ': ' + str(b))
    i += 1
h,w=map(int,input().split())
c=[list(map(int,input().split())) for i in range(h)]
ans=[]
for i in range(h):
  for j in range(w):
    if c[i][j]%2==1:
      if i<=h-1:
        ans.append((i,j,i+1,j))
        c[i+1][j]+=1
      elif j<=w-1:
        ans.append((i,j,i,j+1))
        c[i][j+1]+=1
print(len(ans))
for a in ans:
  print(' '.join(map(str,a)))

### FIXED CODE ###

h,w=map(int,input().split())
c=[list(map(int,input().split())) for i in range(h)]
ans=[]
for i in range(h):
  for j in range(w):
    if c[i][j]%2==1:
      if i<h-1:
        ans.append((i+1,j+1,i+2,j+1))
        c[i+1][j]+=1
      elif j<w-1:
        ans.append((i+1,j+1,i+1,j+2))
        c[i][j+1]+=1
print(len(ans))
for a in ans:
  print(' '.join(map(str,a)))
N,M=map(int,input().split())
AC={}
WA={}
for i in range(M):
    a,b=input().split()
    if not(a in AC.keys()):
        if b=="AC":
            AC[a]=1
        else:
            if a in WA.keys():
                WA[a]+=1
            else:
                WA[a]=1
y=0
for i in AC.keys():
    y+=WA[i]
print(sum(AC.values()),y)

### FIXED CODE ###

N,M=map(int,input().split())
AC={}
WA={}
for i in range(M):
    a,b=input().split()
    if not(a in AC.keys()):
        if b=="AC":
            AC[a]=1
        else:
            if a in WA.keys():
                WA[a]+=1
            else:
                WA[a]=1
y=0
for i in AC.keys():
    if i in WA.keys():
        y+=WA[i]
print(sum(AC.values()),y)
N=int(input)
A=list(map(int,input().split()))
A.sort()
print(A[-1]-A[0])


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
A.sort()
print(A[-1]-A[0])
a=input()
while a!=None:
    b=map(int,a.split())
    print(len(str(sum(b))))
    a=input()

### FIXED CODE ###

while True:
	try:
		a=input().split()
	except:
		break
	b=int(a[0])+int(a[1])
	print(len(str(b)))
def divide(x, y):
    s = 1
    if(x < 0):s *= -1
    if(y < 0):s *= -1
    if x == 0:exit(0)
    return abs(x) / abs(y) * s     
 
def _split(_src):
    c = 0
    l = len(_src)
    if l == 0:
        return []
    while c < l and ord('0') <= ord(_src[c]) <= ord('9'):
        c += 1
    if c == 0:
        tmp = _split(_src[1:])
        if tmp != [] and tmp[0] == "-":
            tmp = ["+" , "(", 0 , "-", 1, ")", "*"] + tmp[1:]
        return [_src[0]] + tmp
    else:
        return [int(_src[:c])] + _split(_src[c:])
         
 
def evaluate(src):
    if len(src) == 1:
        return src[0]
         
    if "(" in src:
        l = src.index("(")
        r = src.index(")")
        mid = evaluate(src[l + 1:r])
        return evaluate( src[:l] + [mid] + src[r + 1:])
     
    operators = [("+", lambda x,y:x + y),
                 ("-", lambda x,y:x - y),
                 ("*", lambda x,y:x * y),
                 ("/", divide)
                ]  
     
    for (op,func) in operators:
        if op in src:
            p = src.index(op)
            l = evaluate(src[:p])
            r = evaluate(src[p + 1:])
            return func(l, r)
     
     
for t in xrange(input()):
    _src = raw_input()[:-1]
    src = _split(_src)
    print evaluate(src)

### FIXED CODE ###

def divide(x, y):
    s = 1
    if(x < 0):s *= -1
    if(y < 0):s *= -1
    return abs(x) / abs(y) * s     

operator = {"+":(lambda x,y: x+y),
            "-":(lambda x,y: x-y),
            "*":(lambda x,y: x*y),
            "/":divide
            }

def ind(src, x):
    if x not in src:return 1<<30
    return src.index(x)
 
def _split(_src):
    c = 0
    l = len(_src)
    if l == 0:
        return []
    while c < l and ord('0') <= ord(_src[c]) <= ord('9'):
        c += 1

    if c == 0:
        return [_src[0]] + _split(_src[1:])
    else:
        return [int(_src[:c])] + _split(_src[c:])
         
 
def evaluate(src):
    if len(src) == 1:
        return src[0]
         
    if "(" in src:
        l = src.index("(")
        r = l
        st = 1
        while st:
            r += 1
            if src[r] == "(": st += 1
            if src[r] == ")": st -= 1
        
        mid = evaluate(src[l + 1:r])
        return evaluate( src[:l] + [mid] + src[r + 1:])
    
    pos = min(ind(src, "*"), ind(src,"/"))
    if(pos == 1<<30):
        pos = min(ind(src, "+"), ind(src, "-"))
    op = src[pos]
    l, r = src[pos - 1], src[pos + 1]
    mid = operator[op](l, r)
    return evaluate(src[:pos - 1] + [mid] + src[pos + 2:])

     
for t in xrange(input()):
    _src = raw_input().strip("=")
    src = _split(_src)
    print evaluate(src)
def check_str( ss ):
  sslen = len(ss)
  
  #ccnt = 0
  #for c in ss:
  #  if( ss[0] == c ):
  #    ccnt+=1
  
  if( sslen == ccnt ):
    return False
  
  return (ss[:sslen//2] == ss[sslen//2+1:][::-1])
  
s = input()

slen = len(s)

if( not check_str( s ) ):
  print( "No" )
else:
#print(s[:slen//2])
#print(s[slen//2+1:][::-1])

  s1 =  s[:slen//2]
  s2 = s[slen//2+1:]
  
  
  if( (not check_str( s1 )) or (not check_str( s2 )) ):
    print( "No" )
  else:
    print( "Yes" )

#s1 = s[:len(s)-1]

#s1


### FIXED CODE ###

def check_str( ss ):
  sslen = len(ss)
  
  if( sslen %2 == 0 ): 
    return (ss[:sslen//2] == ss[sslen//2:][::-1])
  else:
  	return (ss[:sslen//2] == ss[sslen//2+1:][::-1])
  
s = input()

slen = len(s)

if( not check_str( s ) ):
  print( "No" )
else:
#print(s[:slen//2])
#print(s[slen//2+1:][::-1])

  s1 =  s[:slen//2]
  s2 = s[slen//2+1:]
  
  
  if( (not check_str( s1 )) or (not check_str( s2 )) ):
    print( "No" )
  else:
    print( "Yes" )

#s1 = s[:len(s)-1]

#s1
S = input()
N = len(S)
MOD = 10 ** 9 + 7

dp = [0 for _ in range(13)]
dp[0] = 1
for i in range(N):
    pp = dp.copy()
    dp = [0 for _ in range(13)]
    s = S[N-i-1]
    b = pow(10, i, 13)
    if s == '?':
        for d in range(13):
            for e in range(10):
                dp[(d+b*e)%13] += pp[d]
                dp[(d+b*e)%13] %= MOD
    else:
        s = int(s)
        for d in range(13):
            dp[(d+b*s)%13] += pp[d]
            dp[(d+b*s)%13] %= MOD

print(dp[5])


### FIXED CODE ###

S = input()
N = len(S)
MOD = 10 ** 9 + 7

dp = [0 for _ in range(13)]
pp = [0 for _ in range(13)]

dp[0] = 1
for i in range(N):
    pp, dp = dp, pp
    for d in range(13):
        dp[d] = 0
    s = S[N-i-1]
    b = pow(10, i, 13)
    if s == '?':
        for d in range(13):
            for e in range(10):
                dp[(d+b*e)%13] += pp[d]
                dp[(d+b*e)%13] %= MOD
    else:
        s = int(s)
        for d in range(13):
            dp[(d+b*s)%13] += pp[d]
            dp[(d+b*s)%13] %= MOD

print(dp[5])
a,b=map(int, input().split())
if a > b: print('GREATER')
elif: a < b:print('LESS')
else: print('EQUAL')

### FIXED CODE ###

a = int(input())
b = int(input())
if a > b: print('GREATER')
elif a < b:print('LESS')
else: print('EQUAL')
print(int((int(input()/2))**2))

### FIXED CODE ###

a=int(input())
print((a//2)*((a+1)//2))
import sys
import bisect
import itertools


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    a.sort()
    acm = list(itertools.accumulate(a))
    t = 0
    c = 0
    for i in range(a[-1] * 2, a[1] - 1, -1):
        for j in range(n - 1, -1, -1):
            pl = bisect.bisect_left(a, i - a[j])
            pr = bisect.bisect_right(a, i - a[j])
            if pl != pr:
                c += (pr - pl)
                t += (pr - pl) * i
            if c > m:
                t -= (c - m) * i
                print(t)
                exit()


if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys
import bisect
import itertools


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    a.sort()
    cor_v = a[0] * 2
    inc_v = a[-1] * 2 + 1
    while - cor_v + inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        for i in range(n-1, -1, -1):
            cost += n - bisect.bisect_left(a, bin_v - a[i])
        #costが制約を満たすか
        if cost >= m:
            cor_v = bin_v
        else:
            inc_v = bin_v
    acm = list(itertools.accumulate([0] + a))
    t = 0
    c = 0
    for i in range(n):
        p = bisect.bisect_left(a, cor_v - a[i])
        t += acm[-1] - acm[p] + a[i] * (n - p)
        c += n - p
    print(t - (c - m) * cor_v)


if __name__ == '__main__':
    solve()
a,b=input().split()
print("H" if a=b="H"or a=b="D" else"D")

### FIXED CODE ###

a,b=input().split()
print("H" if a==b else"D")
n, m, l = map(int, input().split())
A = []
B = []
C = [[0] * l for i in range(n)]
for x in range(n):
	for y in range(m):
		A[x].append(list(map(int, input().split())))

for x in range(m):
	for y in range(l):
		B[x].append(list(map(int, input().split())))

for x in range(n):
	for y in range(l):
		sum = 0
		for z in range(m):
			sum += A[x][z] * B[z][y]
		C[x][y] = sum

for x in range(n):
	for y in range(l-1):
		print("{0} ".format(C[x][y]), end = '')
	print(C[x][l-1])

		

### FIXED CODE ###

n, m, l = map(int, input().split())
A = []
B = []
C = [[0] * l for i in range(n)]
for x in range(n):
	A.append(list(map(int, input().split())))

for x in range(m):
	B.append(list(map(int, input().split())))

for x in range(n):
	for y in range(l):
		sum = 0
		for z in range(m):
			sum += A[x][z] * B[z][y]
		C[x][y] = sum

for x in range(n):
	for y in range(l-1):
		print("{0} ".format(C[x][y]), end = '')
	print(C[x][l-1])
import numpy as np

abcd = input()
#a,b,c,d = [s for s in abcd]

for i in range(2**3):
    ops = ["-","-","-",""]
    for j in range(3):
        if i>>j&1: ops[j] = "+"
    equa = ""
    for s,op in zip(abcd,ops): equa += (s+op)
    if eval(equa) == 7 : break

ans = equa + "=7"
print(ans)


### FIXED CODE ###

import numpy as np

abcd = input()
#a,b,c,d = [s for s in abcd]

for i in range(2**3):
    ops = ["-","-","-",""]
    for j in range(3):
        if i>>j&1: ops[j] = "+"
    equa = ""
    for s,op in zip(abcd,ops): equa += (s+op)
    if eval(equa) == 7 : break

ans = equa + "=7"
print(ans)
import itertools

def main():
    n,m=list(map(int,input().split(' ')))
    swich_all=list(itertools.product([0,1],repeat=n))
    swich=[]
    cnt=0
    for i in range(m):
        swich.append(list(map(int,input().split(' '))))
    check_p=list(map(int,input().split(' ')))
    for i in swich_all:
        tmp=0
        check =True
        for j in range(m):
            for k in swich[j][1:]:
                tmp += i[k-1]
            if tmp%2 != check_p[j]:
                check = False
                break
        if check == True:
            cnt +=1

    print(cnt)

main()

main()

### FIXED CODE ###

import itertools

def main():
    n,m=list(map(int,input().split(' ')))
    swich_all=list(itertools.product([0,1],repeat=n))
    swich=[]
    cnt=0
    for i in range(m):
        swich.append(list(map(int,input().split(' '))))
    check_p=list(map(int,input().split(' ')))
    for i in swich_all:
        check = []
        for j in range(m):
            tmp = 0
            for k in swich[j][1:]:
                tmp += i[k-1]
            check.append(tmp%2)
        if check == check_p:
            cnt +=1

    print(cnt)

main()
int = x
y = x**3
print(y)


### FIXED CODE ###

x = int(input())
print(x ** 3)
a,b = input().split(' ')

print(max(a*b,a-b,a+b))

### FIXED CODE ###

a,b = map(int, input().split())

print(max(a*b,a-b,a+b))
from collections import Counter
N = int(input())
S = [sorted(input()) for _ in range(N)]
S = sorted(S)
print(sum(map(lambda x: x*(x-1)//2, Counter(S).values())))


### FIXED CODE ###

import string
import collections

N = int(input())
count = 0

s = []

for i in range(0,N):
  s.append(''.join(sorted(input())))

  
c = collections.Counter(s)
go = c.most_common()

for i in range(len(go)):
  k = go[i][1]
  count+=k*(k-1)//2
  
print(count)
a=input()

b=input()

if a+b<10:
  print('%d',a+b)
else:
  print('error')

### FIXED CODE ###

a,b=map(int,input().split())

if a+b<10:
  print(a+b)
else:
  print("error")
import sys
def input(): return sys.stdin.buffer.readline().rstrip()
S = input()
Q = int(input())
qs = list(input() for _ in range(Q))
rev = False
for q in qs:
    q = q.split()
    if q[0] == '1':
        rev = not(rev)
    else:
        if (q[1]=='1' and rev is False) or (q[1]=='2' and rev is True):
            S = q[2] + S
        else:
            S = S + q[2]
print(S if rev == 0 else S[::-1])

### FIXED CODE ###

import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()
S = deque(input())
rev = False
apdlft = S.appendleft
apd = S.append

for _ in range(int(input())):
    q = input().split()
    if q[0] == '1':
        rev = not(rev)
    else:
        if (q[1]=='1' and rev is False) or (q[1]=='2' and rev is True):
            apdlft(q[2])
        else:
            apd(q[2])

if rev:
    print((''.join(S))[::-1])
else:
    print(''.join(S))
n=input()
a=list(map(int,input().split()))
for i in range(0,len(a)):
    a[i]=a[i]%min(a)
    a.append(min(a))
    for j in range(len(a)):
        if a[j]==0:
            a.remove(a[j])
print(a[0])

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
while len(a)>1:
    m=min(a)
    def f(n):
        return n%m
    a=map(f,a)
    a=set(a)
    a.add(m)
    a.remove(0)
    a=list(a)
print(a[0])
from collections import deque

def Topologicalsort():
    for i in xrange(v):
        if indeg[i]==0 and color[i]==0:
            bfs(i)

def bfs(s):
    color[s]=2
    q.append(s)
    while len(q)>0:
        i=q.popleft()
        ans.append(i)
        for j in xrange(v):
            if m[i][j]!=-1:
                indeg[j]-=1
                if indeg[j]==0  and color[j]==0:
                    q.append(m[i][j])
                    color[j]=1

v,e=map(int,raw_input().split())
m=[[-1]*v for i in xrange(v)]
indeg=[0]*v
color=[0]*v
ans=deque()
q=deque()
for i in xrange(v):
    s,t=map(int,raw_input().split())
    m[s][t]=t
    indeg[t]+=1
Topologicalsort()
for i in ans:
    print(i)

### FIXED CODE ###

# -*- coding: utf-8 -*-

from collections import deque

def Topologicalsort(n):     #n??????????????°
    start=deque()
    for i in xrange(n):
        if indeg[i]==0 :
            start.append(i)
    while len(start)>0:
        i=start.popleft()
        ans.append(i)
        for j in g[i]:
            indeg[j]-=1
            if indeg[j]==0:
                start.append(j)
    return ans

v,e=map(int,raw_input().split())
g=[[]for i in xrange(v)]
indeg=[0]*v
ans=[]
for i in xrange(e):
    s,t=map(int,raw_input().split())
    g[s].append(t)
    indeg[t]+=1
    
ans=Topologicalsort(v)
for i in ans:
    print(i)
a = input().strip()
l = a.split()
n = int(l[0])
m_l = set()
for i in range(1 , n + 1):
    m_l.add(l[i])
print(len(set(m_l)))


### FIXED CODE ###


a = int(input())
l = [input() for i in range(a)]
print(len(set(l)))
import numpy as np

sheet=[input().split() for l in range(3)]
n=int(input())
b=[input() for i in range(n)]
a=np.array(sheet)
c=0

for i in range(3):
    for j in range(3):
        for k in range(n):
            if a[i][j]==b[k]:
                a[i][j]="x"


if a[0][0]==a[1][1]==a[2][2]="x":
    c+=1

if a[0][2]==a[1][1]==a[2][0]="x":
    c+=1

for z in range(3):
    if a[0][z]==a[1][z]==a[2][z]="x":
        c+=1

if c!=0:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

import numpy as np

sheet=[input().split() for l in range(3)]
n=int(input())
b=[input() for i in range(n)]
a=np.array(sheet)
i,j,k,c,z=0,0,0,0,0

for i in range(3):
    for j in range(3):
        for k in range(n):
            if a[i][j]==b[k]:
                a[i][j]="x"


if a[0][0]==a[1][1]==a[2][2]=="x":
    c+=1

if a[0][2]==a[1][1]==a[2][0]=="x":
    c+=1

for z in range(3):
    if a[0][z]==a[1][z]==a[2][z]=="x":
        c+=1
    if a[z][0]==a[z][1]==a[z][2]=="x":
        c+=1
if c!=0:
    print("Yes")
else:
    print("No")
a=[map(int,input().split() for _ in range(3)]
n=int(input())
b=[int(input()) for _ in range(n)]
used=[[False]*3 for _ in range(3)]
for k in range(n):
    for i in range(3):
        for j in range(3):
            if a[i][j]==b[k]:
                used[i][j]==True

for i in range(3):
    if a[0][i]==a[1][i]==a[2][i]:
        print("Yes")
        exit()
        
for i in range(3):
    if a[i][0]==a[i][1]==a[i][2]:
        print("Yes")
        exit()

for i in range(3):
    if a[0][0]==a[1][1]==a[2][2]:
        print("Yes")
        exit()

for i in range(3):
    if a[0][2]==a[1][1]==a[2][0]:
        print("Yes")
        exit()                
print("No")

### FIXED CODE ###

a=[list(map(int,input().split())) for _ in range(3)]
n=int(input())
b=[int(input()) for _ in range(n)]
used=[[False]*3 for _ in range(3)]
for k in range(n):
    for i in range(3):
        for j in range(3):
            if a[i][j]==b[k]:
                used[i][j]=True

for i in range(3):
    if used[0][i] and used[1][i] and used[2][i]:
        print("Yes")
        exit()
        
for i in range(3):
    if used[i][0] and used[i][1] and used[i][2]:
        print("Yes")
        exit()

if used[0][0] and used[1][1] and used[2][2]:
        print("Yes")
        exit()

if used[0][2] and used[1][1] and used[2][0]:
        print("Yes")
        exit()                
print("No")