Problem:
 Score : 200 points    Problem Statement We have a bingo card with a 3\times3 grid. The square at the i -th row from the top and the j -th column from the left contains the number A_{i, j} .  The MC will choose N numbers, b_1, b_2, \cdots, b_N . If our bingo sheet contains some of those numbers, we will mark them on our sheet.  Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.      Constraints  All values in input are integers.  1 \leq A_{i, j} \leq 100  A_{i_1, j_1} \neq A_{i_2, j_2} ((i_1, j_1) \neq (i_2, j_2))  1 \leq N \leq 10  1 \leq b_i \leq 100  b_i \neq b_j (i \neq j)         Input Input is given from Standard Input in the following format:  A_{1, 1}  A_{1, 2}  A_{1, 3}  A_{2, 1}  A_{2, 2}  A_{2, 3}  A_{3, 1}  A_{3, 2}  A_{3, 3}  N  b_1  \vdots  b_N       Output If we will have a bingo, print Yes ; otherwise, print No .        Sample Input 1 84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30      Sample Output 1 Yes  We will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3} , and complete the diagonal from the top-left to the bottom-right.       Sample Input 2 41 7 46
26 89 2
78 92 8
5
6
45
16
57
17      Sample Output 2 No  We will mark nothing.       Sample Input 3 60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34      Sample Output 3 Yes  We will mark all the squares.

Solution (Python):
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
B = [int(input()) for i in range(N)]
for i in range(3):
  for j in range(3):
    for k in(B):
      if A[j][i] == k:
        A[j][i] = 1
        break
      elif k == B[-1]:
        A[j][i] = 0
if sum(A[0]) == 3 or sum(A[1]) == 3 or sum(A[2]) == 3:
  print('Yes')
elif sum([row[0] for row in A]) == 3 or sum([row[1] for row in A]) == 3 or sum([row[2] for row in A]) == 3:
  print('Yes')
elif A[0][0] + A[1][1] + A[2][2] == 3 or A[2][0] + A[1][1] + A[0][2] == 3:
  print('Yes')
else:
  print('No')

Solution (Python):
a= []
for i in range(3):
  a_input = input().split()
  a.append(a_input)

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

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

Solution (Python):
import numpy as np
a = np.array([[int(i) for i in input().split()] for _ in range(3)])
n = int(input())
b = [int(input()) for _ in range(n)]
for i in b:
    a[np.where(i == a)] = 0

if a[0,0] + a[1,1] + a[2,2] == 0 or a[0,2] + a[1,1] + a[2,0] == 0:
    print('Yes')
elif 0 in np.sum(a, axis=0) or 0 in np.sum(a, axis=1):
    print('Yes')
else:
    print('No')

Solution (Python):
A = [list(map(int,input().split())) for i in range(3)]
n = int(input())
B = [int(input()) for _ in range(n)]

for i in range(3):
    for j in range(3):
        for k in range(n):
            if A[i][j] == B[k]:
                A[i][j] = 0

cnt = 0
for i in range(3):
    S = 0
    for j in range(3):
        S += A[i][j]
    if S == 0:
        cnt = 1

for j in range(3):
    S = 0
    for i in range(3):
        S += A[i][j]
    if S == 0:
        cnt = 1

S = A[0][0] + A[1][1] + A[2][2]
if S == 0:
    cnt = 1

S = A[0][2] + A[1][1] + A[2][0]
if S == 0:
    cnt = 1

if cnt == 1:
    print("Yes")
else:
    print("No")

Solution (Python):
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
g,h,i=map(int,input().split())
n=int(input())
B=[int(input()) for j in  range(n)]
 
if (a in B and b in B  and c in B) or (d in B and e in B  and f in B) or (g in B and h in B and i in B) or (a in B and d in B and g in B) or (b in B and e in B and h in B) or (c in B and f in B and i in B) or (a in B and e in B and i in B) or (c in B and e in B and g in B):
    print("Yes")
else:
    print("No")

Solution (Python):
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())

for count in range(N):
    b = int(input())

    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A[i][j] = -1

ans = 'No'
for i in range(3):
    if A[i][0] == A[i][1] == A[i][2] == -1:
        ans = 'Yes'
    if A[0][i] == A[1][i] == A[2][i] == -1:
        ans = 'Yes'
if A[0][0] == A[1][1] == A[2][2] == -1:
    ans = 'Yes'
if A[2][0] == A[1][1] == A[0][2] == -1:
    ans = 'Yes'

print(ans)

Solution (Python):
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
a3=list(map(int,input().split()))
a=[a1,a2,a3]
n=int(input())
bingo=[[0 for i in range(3)] for j in range(3)]
for k in range(n):
    x=int(input())
    for j in range(3):
        for i in range(3):
            if x==a[j][i]:
                bingo[j][i]+=1
for j in range(3):
    if sum(bingo[j])==3:
        print("Yes")
        exit()
for i in range(3):
    if bingo[0][i]+bingo[1][i]+bingo[2][i]==3:
        print("Yes")
        exit()
if bingo[0][0]+bingo[1][1]+bingo[2][2]==3 or bingo[0][2]+bingo[1][1]+bingo[2][0]==3:
    print("Yes")
    exit()
print("No")

Solution (Python):
a_list = []
for i in range(3):
    for j in list(map(int, input().split())):
        a_list.append(j)

N = int(input())

b_list = []
for i in range(N):
    b_list.append(int(input()))    
        
for b in b_list:
    if b in a_list:
        a_list[a_list.index(b)] = 0




line_list = [
    a_list[:3],    
    a_list[3:6],   
    a_list[6:9],   
    a_list[::3],   
    a_list[1::3],  
    a_list[2::3],  
    a_list[::4],   
    a_list[2:7:2], 
]
line_sum_list = list(map(sum, line_list))
if 0 in line_sum_list:
    print('Yes')
else:
    print('No')

Solution (Python):
x = []
b = []
for i in range(3):
    s = list(map(int,input().split()))
    x.append(s)
N = int(input())
for j in range(N):
    b.append(int(input()))
temp =0
for j in range(3):
    if x[0][j] in b and x[1][j] in b and x[2][j] in b:
        temp = 1
        break
for j in range(3):
    if x[j][0] in b and x[j][1] in b and x[j][2] in b:
        temp = 1
        break
if x[0][0] in b and x[1][1] in b and x[2][2] in b:
    temp = 1
elif x[0][2] in b and x[1][1] in b and x[2][0] in b:
    temp = 1
if temp ==1:
    print("Yes")
else:print("No")

Solution (Python):
import numpy as np
one = [int(x) for x in input().split()]
two = [int(x) for x in input().split()]
three = [int(x) for x in input().split()]
l = [one, two, three]
card = np.array(l)
N = int(input())


for n in list(range(N)):
    try:
        b = int(input())
        card = np.where(card == b, 0, card)
    except EOFError:
        break


if card[0, 0] == card[0,1] == card[0,2] or\
card[1,0]==card[1,1]==card[1,2] or \
card[2, 0] == card[2, 1] == card[2, 2] or \
card[0, 0] == card[1, 0] == card[2, 0] or \
card[0, 1] == card[1, 1] == card[2, 1] or \
card[0, 2] == card[1, 2] == card[2, 2] or \
card[0, 0] == card[1, 1] == card[2, 2] or \
card[0, 2] == card[1, 1] == card[2, 0] :
    print('Yes')
else:
    print('No')

Solution (Python):
import sys
a = [input().split() for l in range(3)]
n = int(input())
b = [int(input())for i in range(n)]

for i in range(3):
    for j in range(3):
        if int(a[j][i]) in b :
            a[j][i]=0



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

Solution (Python):
bingo_length = 3

grid = []
for i in range(bingo_length):
    array = list(map(int, input().strip().split()))
    grid.append(array)
    
N = int(input())
b = []
for i in range(N):
  b.append(int(input()))

flag = False
for i in range(bingo_length):
  if grid[i][0] in b and grid[i][1] in b and grid[i][2] in b:
    flag = True
    break
for i in range(bingo_length):
  if grid[0][i] in b and grid[1][i] in b and grid[2][i] in b:
    flag = True
    break
if grid[0][0] in b and grid[1][1] in b and grid[2][2] in b:
  flag = True
if grid[0][2] in b and grid[1][1] in b and grid[2][0] in b:
  flag = True
if flag == True:
  print('Yes')
else:
  print('No')

Solution (Python):
A = []
for _ in range(3):
    A.append([int(i) for i in input().split(' ')])
N = int(input())
a = []
for _ in range(N):
    a.append(int(input()))

for num in a:
    for i in range(3):
        for j in range(3):
            if num == A[i][j]:
                A[i][j] = '*'

ans = 'No'
for i in range(3):
    flg = 0 
    b1 = all(A[i][j] == '*' for j in range(3))
    b2 = all(A[j][i] == '*' for j in range(3))
    b3 = all(A[j][j] == '*' for j in range(3))
    b4 = all(A[2-j][j] == '*' for j in range(3))
    if b1 or b2 or b3 or b4:
        ans = 'Yes'

print(ans)

Solution (Python):
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

key = []
for i, v in enumerate(A):
    for k, j in enumerate(v):
        if (j in B):
            key.append([i, k])

ans = [[[0, 0], [1, 0], [2, 0]], [[0, 1], [1, 1], [2, 1]], [[0, 2], [1, 2], [2, 2]], [[0, 0], [1, 1], [2, 2]], [
    [0, 2], [1, 1], [2, 0]], [[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]], [[2, 0], [2, 1], [2, 2]]]

for i in ans:
    count = 0
    for j in i:
        if (j in key):
            count += 1
    if (count == 3):
        print('Yes')
        exit()

print('No')

Solution (Python):
f = lambda:list(map(int,input().split()))
l = f() + f() + f()
n = int(input())
s = set()

for i in range(n):
    b = int(input())
    if b in l: s|={l.index(b)}

print(['No','Yes'][any(t<=s for t in [{0,1,2},{0,3,6},{0,4,8},{1,4,7},
                                      {2,4,6},{2,5,8},{3,4,5},{6,7,8}])])

Solution (Python):
A = [list(map(int,input().split())) for i in range(3)]
N = int(input())
B = [int(input()) for i in range(N)]

for i in range(3):
	for j in range(3):
		for k in range(N):
			if A[i][j] == B[k]:
				A[i][j] = 0

cnt = 0
for i in range(3):
	S = 0
	for j in range(3):
		S += A[i][j]
	if S == 0:
		cnt = 1
		
for j in range(3):
	S = 0
	for i in range(3):
		S += A[i][j]
	if S == 0:
		cnt = 1
		
S = A[0][0] + A[1][1] + A[2][2]
if S == 0:
	cnt = 1
	
S = A[0][2] + A[1][1] + A[2][0]
if S == 0:
	cnt = 1
	
if cnt == 1:
	print("Yes")
else:
	print("No")

Solution (Python):
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

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

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

    if a[0][i] + a[1][i] + a[2][i] == 0:
        print("Yes")
        exit()

if a[0][0] + a[1][1] + a[2][2] == 0:
    print("Yes")
    exit()
if a[2][0] + a[1][1] + a[0][2] == 0:
    print("Yes")
    exit()

print(ans)

Solution (Python):
a=[list(map(int,input().split())) for _ in range(3)]
n=int(input())
b=list(int(input()) for _ in range(n))

for i in range(3):
    for j in range(3):
        for k in range(n):
            if a[i][j]==b[k]:
                a[i][j]=0
                
for i in range(3):
    if a[i][0]+a[i][1]+a[i][2]==0 or a[0][i]+a[1][i]+a[2][i]==0:
        print('Yes')
        exit()
if a[0][0]+a[1][1]+a[2][2]==0 or a[0][2]+a[1][1]+a[2][0]==0:
    print('Yes')
else:
    print('No')

Solution (Python):
a=[]
for i in range(3):
    ai=list(map(int,input().split()))
    a.append(ai)
n=int(input())
b=[]
for i in range(n):
    b.append(int(input()))
    


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

flag=False
for i in range(3):
    if a[i][0]==a[i][1] and a[i][1]==a[i][2]:
        flag=True
    if a[0][i]==a[1][i] and a[1][i]==a[2][i]:
        flag=True
if a[0][0]==a[1][1] and a[1][1]==a[2][2]:
    flag=True
if a[0][2]==a[1][1] and a[1][1]==a[2][0]:
    flag=True

if flag:
    print('Yes')
else:
    print('No')

Solution (Python):
import numpy as np

A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

BINGO = np.array([[False for i in range(3)]for j in range(3)])

for i in range(3):
    for j in range(3):
        if A[i][j] in B:
            BINGO[i][j] = True


for i in BINGO:
    if False not in i:
        print("Yes")
        exit()

BINGO = BINGO.T 


for i in BINGO:
    if False not in i:
        print("Yes")
        exit()


cross = [BINGO[i][i] for i in range(3)]
cross_re = [BINGO[i][2-i] for i in range(3)]

if False not in cross or False not in cross_re:
    print("Yes")
    exit()

print("No")

Solution (Python):
import numpy as np
tmps = []
for i in range(3):
    tmp = list(map(int, input().split(' ')))
    tmps.append(tmp)
bingo = np.array(tmps)
N = int(input())
for i in range(N):
    bingo = np.where(bingo==int(input()), -1, bingo)
c = 2
x1 = 0
x2 = 0
ret = []
for i in range(3):
    row = np.sum(bingo[i, :])
    col = np.sum(bingo[:, i])
    x1 += np.sum(bingo[i, i])
    x2 += np.sum(bingo[i, c-i])
    ret.append(row)
    ret.append(col)
ret.append(x1)
ret.append(x2)
if -3 in ret:
    print('Yes')
else:
    print('No')

Solution (Python):
A = [list(map(int, input().split())) for i in range(3)]
B = [[0]*3 for i in range(3)]
n = int(input())
for k in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                B[i][j] = 1
if any([all([B[i][j] == 1 for j in range(3)]) for i in range(3)]):
    print('Yes')
    exit()
if any([all([B[i][j] == 1 for i in range(3)]) for j in range(3)]):
    print('Yes')
    exit()
if B[0][0]*B[1][1]*B[2][2] == 1:
    print('Yes')
    exit()
if B[0][2]*B[1][1]*B[2][0] == 1:
    print('Yes')
    exit()
print('No')

Solution (Python):
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
g,h,i=map(int,input().split())
N=int(input())
mylist=[]
for x in range(N):
  j=int(input())
  mylist.append(j)
if a in mylist and b in mylist and c in mylist:
  print('Yes')
elif a in mylist and b in mylist and c in mylist:
  print('Yes')
elif a in mylist and e in mylist and i in mylist:
  print('Yes')
elif a in mylist and d in mylist and g in mylist:
  print('Yes')
elif d in mylist and e in mylist and f in mylist:
  print('Yes')
elif g in mylist and h in mylist and i in mylist:
  print('Yes')
elif c in mylist and e in mylist and g in mylist:
  print('Yes')
elif b in mylist and e in mylist and h in mylist:
  print('Yes')
elif c in mylist and f in mylist and i in mylist:
  print('Yes')
else:
  print('No')

Solution (Python):
import numpy as np

A=[]
for i in range(0,3):
    input_1= list(map(int, input().split()))
    A.extend(input_1)
    
N=int(input())

Bingo=[]
for i in range(0,N):
    Bingo.append(int(input()))

for i in range(0,9):
    for j in range(0,N):
        if Bingo[j]==A[i]:
            A[i]=0
    
np_arr1 = np.array([[A[0], A[1], A[2]], [A[3], A[4], A[5]], [A[6], A[7], A[8]]])


list_horizontal_1=sum([A[0], A[1], A[2]])
list_horizontal_2=sum([A[3], A[4], A[5]])
list_horizontal_3=sum([A[6], A[7], A[8]])

list_vertical_1=sum([A[0], A[3], A[6]])
list_vertical_2=sum([A[1], A[4], A[7]])
list_vertical_3=sum([A[2], A[5], A[8]])

list_closs_1=sum([A[0], A[4], A[8]])
list_closs_2=sum([A[2], A[4], A[6]])

if list_horizontal_1==0 or list_horizontal_2==0 or list_horizontal_3==0 or list_vertical_1==0 or list_vertical_2==0 or list_vertical_3==0 or list_closs_1==0 or list_closs_2==0:
    print('Yes')
else:
    print('No')

Solution (Python):
a = []
for i in range(3):
    a.append(map(int,raw_input().split()))
n = input()
for j in range(n):
    b = input()
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                a[j][k] = 0

diag1 = [a[0][0],a[1][1],a[2][2]]
diag2 = [a[0][2],a[1][1],a[2][0]]
res = 'No'
if sum(diag1) ==0 or sum(diag2) ==0:
    res ='Yes'

rowsum = [sum(a[i]) for i in range(3) ]
if 0 in rowsum:
    res = 'Yes'

colSum = [sum([a[j][i] for j in range(3)]) for i in range(3)]
if 0 in colSum:
    res = 'Yes'

print res

Solution (Python):
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
A3=list(map(int,input().split()))
N=int(input())

i = 0
for i in range(N):
    b = int(input())
    j = 0
    while j<3:
        if A1[j]==b:
            A1[j]=-1
        j+=1
    j = 0
    while j<3:
        if A2[j]==b:
            A2[j]=-1
        j+=1
    j = 0
    while j<3:
        if A3[j]==b:
            A3[j]=-1
        j+=1


if A1[0]==A1[1]==A1[2] or A2[0]==A2[1]==A2[2] or A3[0]==A3[1]==A3[2] or A1[0]==A2[0]==A3[0] or A1[1]==A2[1]==A3[1] or A1[2]==A2[2]==A3[2] or A1[0]==A2[1]==A3[2] or A1[2]==A2[1]==A3[0]:
    print("Yes")
else:
    print("No")

Solution (Python):
A= []
for i in range(3):
    array = list(map(int, input().strip().split()))
    A.append(array)
n=int(input())
b = []
for _ in range(n):
    b.append(int(input()))
ans="No"
for i in range(3):
    count=0
    for j in range(3):
        for k in range(n):
            if A[i][j]==b[k]:
                count=count+1
    if count==3:
        ans='Yes'
    
for i in range(3):
    count=0
    for j in range(3):
        for k in range(n):
            if A[j][i]==b[k]:
                count=count+1
    if count==3:
        ans='Yes'

count=0
for i in range(3):
        for k in range(n):
            if A[i][i]==b[k]:
               count=count+1
if count==3:
    ans='Yes'
count=0
for i in range(3):
        for k in range(n):
            if A[i][2-i]==b[k]:
                count=count+1
if count==3:
    ans='Yes'
print(ans)

Solution (Python):
A=[list(map(int,input().split())) for _ in range(3)]
N=int(input())
B=[int(input()) for _ in range(N)]

c=[[0]*3 for _ in range(3)]
for b in B:
  for i in range(3):
    for j in range(3):
      if A[i][j]==b:
        c[i][j]=1

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

print('No')

Solution (Python):
l=[list(input().split()) for i in range(3)]
n=int(input())
li=[input() for i in range(n)]
if l[0][0] in li and l[0][1] in li and l[0][2] in li:
    print('Yes')
elif l[1][0] in li and l[1][1] in li and l[1][2] in li:
    print('Yes')
elif l[2][0] in li and l[2][1] in li and l[2][2] in li:
    print('Yes')
elif l[0][0] in li and l[1][0] in li and l[2][0] in li:
    print('Yes')
elif l[0][1] in li and l[1][1] in li and l[2][1] in li:
    print('Yes')
elif l[0][2] in li and l[1][2] in li and l[2][2] in li:
    print('Yes')
elif l[0][0] in li and l[1][1] in li and l[2][2] in li:
    print('Yes')
elif l[0][2] in li and l[1][1] in li and l[2][0] in li:
    print('Yes')
else: print('No')

Solution (Python):
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]

for i in range(N):
  for j in range(3):
    for k in range(3):
      if A[j][k]==b[i]:
        A[j][k] = 0

if A[1][1]==0 and A[0][0]==0 and A[2][2]==0 or A[1][1]==0 and A[2][0]==0 and A[0][2]==0 or A[1][1]==0 and A[0][1]==0 and A[2][1]==0 or A[1][1]==0 and A[1][0]==0 and A[1][2]==0 or A[0][0]==0 and A[0][1]==0 and A[0][2]==0 or A[0][0]==0 and A[1][0]==0 and A[2][0]==0 or A[2][2]==0 and A[0][2]==0 and A[1][2]==0 or A[2][2]==0 and A[2][0]==0 and A[2][1]==0:
  print("Yes")
else:
  print("No")

Solution (Python):


A=[]
for i in range(3):
    a=list(map(int,input().split()))
    A.append(a)
N = int(input())
b=[]
for i in range(N):
    B=int(input())
    b.append(B)

Sheet=[[0,0,0],[0,0,0],[0,0,0]]

for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            Sheet[i][j]+=1

if Sheet[0][0]==Sheet[1][0]==Sheet[2][0]==1 or Sheet[0][1]==Sheet[1][1]==Sheet[2][1]==1 or Sheet[0][2]==Sheet[1][2]==Sheet[2][2]==1 or Sheet[0][0]==Sheet[0][1]==Sheet[0][2]==1 or  Sheet[1][0]==Sheet[1][1]==Sheet[1][2]==1 or  Sheet[2][0]==Sheet[2][1]==Sheet[2][2]==1 or  Sheet[0][0]==Sheet[1][1]==Sheet[2][2]==1 or  Sheet[0][2]==Sheet[1][1]==Sheet[2][0]==1:
    print('Yes')
else:
    print('No')

Solution (Python):
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
for i in range(3):
  for j in range(3):
    for k in range(n):
      if a[i][j] == b[k]:
        a[i][j] = 0
ans = 'No'
for i in range(3):
  if a[i][0]+a[i][1]+a[i][2] == 0:
    ans = 'Yes'
  if a[0][i]+a[1][i]+a[2][i] == 0:
    ans = 'Yes'
if a[0][0]+a[1][1]+a[2][2] == 0 or a[2][0]+a[1][1]+a[0][2] == 0:
  ans = 'Yes'
print(ans)

Solution (Python):
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
for i in range(3):
    for j in range(3):
      for k in range(n):
        if a[i][j] == b[k]:
            a[i][j] = 0
ans = 'No'
for i in range(3):
    if a[i][0]+a[i][1]+a[i][2] == 0:
        ans = 'Yes'
    if a[0][i]+a[1][i]+a[2][i] == 0:
        ans = 'Yes'
if a[0][0]+a[1][1]+a[2][2] == 0 or a[2][0]+a[1][1]+a[0][2] == 0:
    ans = 'Yes'
print(ans)

Solution (Python):
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

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

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

Solution (Python):
import numpy as np

A = np.array(list(list(map(int, input().split())) for l in range(3)))
N = int(input())
b = np.array(list(int(input()) for l in range(N)))
bingo = np.zeros((3, 3))
bingo = bingo == 1

for b_i in b:
    hantei = A == b_i
    bingo = np.logical_or(bingo, hantei)

for i in range(3):
    if all(bingo[i]) or all(bingo[:,i]):
        print('Yes')
        exit()

if (bingo[0,0] and bingo[1,1] and bingo[2,2]) or (bingo[0,2] and bingo[1,1] and bingo[2,0]):
    print('Yes')
    exit()

print('No')

Solution (Python):
a11, a12, a13 = map(int, input().split())
a21, a22, a23 = map(int, input().split())
a31, a32, a33 = map(int, input().split())
n = int(input())
b = []
for i in range(n):
    b.append(int(input()))

ans = [[a11, a12, a13], [a21, a22, a23], [a31, a32, a33],
       [a11, a21, a31], [a12, a22, a32], [a13, a23, a33],
       [a11, a22, a33], [a13, a22, a31]]

for a in ans:
    if (a[0] in b) and (a[1] in b) and (a[2] in b):
        print("Yes")
        exit()

print("No")

Solution (Python):
A=[[int(x) for x in input().split()]for i in range(3)]
N = int(input())
b = []
for i in range(N):
    b.append(int(input()))
 
for i in range(3):
    if A[i][0] in b and A[i][1] in b and A[i][2] in b:
        print('Yes')
        exit()
for i in range(3):
    if A[0][i] in b and A[1][i] in b and A[2][i] in b:
        print('Yes')
        exit()
if A[0][0] in b and A[1][1] in b and A[2][2] in b:
    print('Yes')
    exit()
if A[2][0] in b and A[1][1] in b and A[0][2] in b:
    print('Yes')
    exit() 
print('No')

Solution (Python):
import sys

A = [[0] * 3 for i in range(3)]

A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))

N = int(input())
for _ in range(N):
    b = int(input())
    if b in A1:
        for a in [i for i, x in enumerate(A1) if x == b]:
            A[0][a] = 1
    if b in A2:
        for a in [i for i, x in enumerate(A2) if x == b]:
            A[1][a] = 1
    if b in A3:
        for a in [i for i, x in enumerate(A3) if x == b]:
            A[2][a] = 1

for i in range(3):
    if sum(A[i][:]) == 3:
        print('Yes')
        sys.exit()

if A[0][0] == 1 and A[1][0] == 1 and A[2][0] == 1:
    print('Yes')
    sys.exit()
if A[0][1] == 1 and A[1][1] == 1 and A[2][1] == 1:
    print('Yes')
    sys.exit()
if A[0][2] == 1 and A[1][2] == 1 and A[2][2] == 1:
    print('Yes')
    sys.exit()

if A[0][0] == 1 and A[1][1] == 1 and A[2][2] == 1:
    print('Yes')
    sys.exit()

if A[0][2] == 1 and A[1][1] == 1 and A[2][0] == 1:
    print('Yes')
    sys.exit()

print('No')

Solution (Python):
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))

al = a1+a2+a3
n =int(input())

for i in range(n):
    b = int(input())
    if b in al:
        al[al.index(b)] = 0
if al[0] + al[1] + al[2] == 0 or al[3] + al[4] + al[5] == 0 or al[6] + al[7] + al[8] == 0 or al[0] + al[3] + al[6] == 0 or al[1] + al[4] + al[7] == 0 or al[2] + al[5] + al[8] == 0 or al[0] + al[4] + al[8] == 0 or al[2] + al[4] + al[6] == 0:
    print("Yes")
else:
    print("No")

Solution (Python):
import sys

def check(x):
  if(x[0] == 0 and x[1] == 0 and x[2] == 0):
    return 1
  else:
    return 0

def main():
  a1 = list(map(int, input().split()))
  a2 = list(map(int, input().split()))
  a3 = list(map(int, input().split()))
  num = int(input())
  a9 = a1 + a2 + a3
  x = 0
  z = [int(input()) for i in range(num)]
  for i in z:
    for k, name in enumerate(a9):
      if(i == name):
        a9[k] = 0
  a1 = []
  a2 = []
  a3 = []
  a4 = []
  a5 = []
  a6 = []
  a7 = []
  a8 = []  
  a1.extend([a9[0],a9[1],a9[2]])
  a2.extend([a9[3],a9[4],a9[5]])
  a3.extend([a9[6],a9[7],a9[8]])
  a4.extend([a9[0],a9[3],a9[6]])
  a5.extend([a9[1],a9[4],a9[7]])
  a6.extend([a9[2],a9[5],a9[8]])
  a7.extend([a9[0],a9[4],a9[8]])
  a8.extend([a9[2],a9[4],a9[6]])

  check_list = []
  check_list.append(check(a1))
  check_list.append(check(a2))
  check_list.append(check(a3))
  check_list.append(check(a4))
  check_list.append(check(a5))
  check_list.append(check(a6))
  check_list.append(check(a7))
  check_list.append(check(a8))

  for i in check_list:
    if(i == 1):
      print('Yes')
      x = 1
      sys.exit()
   
  if(x == 0):
    print('No')

if __name__ == '__main__':
  main()

Solution (Python):
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

bingo = []
for i in range(3):
	bingo.append(rl())
N = ri()
B = []
for i in range(N):
	B.append(ri())

h = {}
for i in range(3):
	for j in range(3):
		n = bingo[i][j]
		h[n] = (i,j)
for b in B:
	if b not in h:
		continue
	i, j = h[b]
	bingo[i][j] = 0

def check(b):
	for i in range(3):
		bs = [1 for j in range(3) if b[i][j] == 0]
		if len(bs) == 3:
			return True
	for j in range(3):
		bs = [1 for i in range(3) if b[i][j] == 0]
		if len(bs) == 3:
			return True
	bs = [b[0][0],b[1][1],b[2][2]]
	bs = [1 for v in bs if v == 0]
	if len(bs) == 3:
		return True
	bs = [b[0][2],b[1][1],b[2][0]]
	bs = [1 for v in bs if v == 0]
	if len(bs) == 3:
		return True
	return False

if check(bingo):
	print('Yes')
else:
	print('No')

Solution (Python):
A=[]
for _ in range(3):
    x=list(int(i) for i in input().split())
    A.append(x)
M=[[0 for i in range(3)]for j in range(3)]
n=int(input())

for _ in range(n):
    p=int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==p:
                M[i][j]=1
                break
bool=False
for i in range(3):
    if bool is False:
        sum=0
        for j in range(3):
            sum+=M[i][j]
        if sum==3:
            bool=True
for i in range(3):
    if bool is False:
        sum=0
        for j in range(3):
            sum+=M[j][i]
        if sum==3:
            bool=True
if (M[0][0]+M[1][1]+M[2][2])==3:
    bool=True
if (M[0][2]+M[1][1]+M[2][0])==3:
    bool =True
if bool:
    print("Yes")
else:
    print("No")

Solution (Python):
p1=list(map(int,input().split()))
p2=list(map(int,input().split()))
p3=list(map(int,input().split()))
p=p1+p2+p3
n=int(input())
for _ in range(n):
    b=int(input())
    if b in p:
        p[p.index(b)]=0
if p[0]+p[1]+p[2]==0 or p[3]+p[4]+p[5]==0 or p[6]+p[7]+p[8]==0 or p[0]+p[3]+p[6]==0 or p[1]+p[4]+p[7]==0 or p[2]+p[5]+p[8]==0 or p[0]+p[4]+p[8]==0 or p[2]+p[4]+p[6]==0:
    print("Yes")
else:
    print("No")

Solution (Python):
a = list(list(map(int,input().split())) for i in range(3))
n = int(input())
b = [int(input()) for x in range(n)]
d = [[0 for i in range(3)] for j in range(3)]
ans = "No"
for x in range(n):
    for i in range(3):
        for j in range(3):
            if a[i][j] == b[x]:
                d[i][j] = 1
for i in range(3):
    c = 0
    for j in range(3):
        c+=d[i][j]
    if c == 3:
        ans = "Yes"
for i in range(3):
    c = 0
    for j in range(3):
        c+=d[j][i]
    if c == 3:
        ans = "Yes"
c = 0
for j in range(3):
    c+=d[j][j]
if c == 3:
    ans = "Yes"
c = 0
for j in range(3):
    c+=d[j][2-j]
if c == 3:
    ans = "Yes"
print(ans)

Solution (Python):
a = list(list(map(int,input().split())) for i in range(3))
n = int(input())
b = [int(input()) for x in range(n)]
d = [[0 for i in range(3)] for j in range(3)]
ans = "No"
for x in range(n):
    for i in range(3):
        for j in range(3):
            if a[i][j] == b[x]:
                d[i][j] = 1
for i in range(3):
    c = 0
    for j in range(3):
        c+=d[i][j]
    if c == 3:
        ans = "Yes"
for i in range(3):
    c = 0
    for j in range(3):
        c+=d[j][i]
    if c == 3:
        ans = "Yes"
c = 0
for j in range(3):
    c+=d[j][j]
    if c == 3:
        ans = "Yes"
        c = 0
for j in range(3):
    c+=d[j][2-j]
    if c == 3:
        ans = "Yes"
print(ans)

Solution (Python):


import math

sht = [[0,0,0] for _ in range(3)]

a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())

for i in range(n):
    b=int(input())
    for j in range(3):
        if a[j].count(b)>0:
            sht[j][a[j].index(b)]=1

ans="No"

for i in range(3):
    if sht[i][0]==sht[i][1]==sht[i][2]==1:
        ans="Yes"
    elif sht[0][i]==sht[1][i]==sht[2][i]==1:
        ans="Yes"
if sht[0][0]==sht[1][1]==sht[2][2]==1:
    ans="Yes"
elif sht[0][2]==sht[1][1]==sht[2][0]==1:
    ans="Yes"

print(ans)

Solution (Python):
Bingo=[]
Bingo.append(list(map(int, input().split())))
Bingo.append(list(map(int, input().split())))
Bingo.append(list(map(int, input().split())))
N=int(input())
Num=[]
for i in range(N):
    Num.append(int(input()))
    
ans="No"
for i in range(3):
    if Bingo[i][0] in Num and Bingo[i][1] in Num and Bingo[i][2] in Num:
        ans="Yes"
for i in range(3):
    if Bingo[0][i] in Num and Bingo[1][i] in Num and Bingo[2][i] in Num:
        ans="Yes"

if Bingo[1][0] in Num and Bingo[1][1] in Num and Bingo[2][2] in Num:
    ans="Yes"
    
if Bingo[0][2] in Num and Bingo[1][1] in Num and Bingo[2][0] in Num:
    ans="Yes"

print(ans)

Solution (Python):
card=[] 
for i in range(3):
  card+=list(map(int,input().split()))
n=int(input())
bingo=[0]*9
for i in range(n):
  s=int(input())
  if s in card:
    bingo[card.index(s)]=1
if bingo[0] == 1:
  if (bingo[1] == 1 and bingo[2] == 1) or (bingo[3] == 1 and bingo[6] == 1) or (bingo[4] == 1 and bingo[8] == 1):
    print("Yes")
    exit()
if bingo[2] == 1:
  if (bingo[4] == 1 and bingo[6] == 1) or (bingo[5] == 1 and bingo[8] == 1):
    print("Yes")
    exit()
if (bingo[1] == 1 and bingo[4] == 1 and bingo[7] == 1) or (bingo[3] == 1 and bingo[4] == 1 and bingo[5] == 1) or (bingo[6] == 1 and bingo[7] == 1 and bingo[8] == 1):
    print("Yes")
    exit()
print("No")