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):


def main():
    *N, = map(int, open(0).read().split())
    A = N[0:9]
    N_number = N[9]
    b = N[10:]

    Ab_comm = set(A) & set(b)
    A_rep = [0 if i in Ab_comm else i for i in A]

    Ax=[]
    Ay=[]
    for i in range(0,3):
        Ax.append(A_rep[3*i] + A_rep[3*i + 1] + A_rep[3*i + 2])
        Ay.append(A_rep[i] + A_rep[i + 3] + A_rep[i + 6])
    An=[]
    An.append(A_rep[0] + A_rep[4] + A_rep[8])
    An.append(A_rep[2] + A_rep[4] + A_rep[6])
    if min(Ax + Ay + An) == 0:
        print("Yes")
    else:
        print("No")
        

main()

Solution (Python):
bingoMatrix=[list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()))]
n=int(input())
bingo=[]
fidnbingo=False
for i in range(n):
  bingo.append(int(input()))

result=[]
for i in range(3):
    tmpList=[]
    for j in range(3):
        tmpList.append(bingoMatrix[i][j])
    result.append(tmpList)
for i in range(3):
    tmpList=[]
    for j in range(3):
        tmpList.append(bingoMatrix[j][i])
    result.append(tmpList)
tmpList=[]
for i in range(3):
    tmpList.append(bingoMatrix[i][i])
result.append(tmpList)
result.append([bingoMatrix[0][2],bingoMatrix[1][1],bingoMatrix[2][0]])
for item in result:
    counter=0
    for i in item:
        if bingo.count(i):
            counter+=1
    if counter==3:
        fidnbingo=True
        break
if fidnbingo:
  	print ("Yes")
else:
	print ("No")

Solution (Python):
bingo_map = [[int(j) for j in input().split()] for i in range(3)]
n = int(input())
b_inputs = [int(input()) for i in range(n)]

for i in range(3):
    for j in range(3):
        if bingo_map[i][j] in b_inputs:
            bingo_map[i][j]=1
        else:
            bingo_map[i][j]=0

def check():
    for i in range(3):
        if sum(bingo_map[i])==3:
            return 'Yes'
                
    for j in range(3):
        if sum([bingo_map[k][j] for k in range(3)])==3:
            return 'Yes'

    if bingo_map[0][0] + bingo_map[1][1] + bingo_map[2][2]==3:
        return 'Yes'
    if bingo_map[0][2] + bingo_map[1][1] + bingo_map[2][0]==3:
        return 'Yes'
    return 'No'

print(check())

Solution (Python):
a = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _1 in range(n)]
for bingo in b:
    for i in range(3):
        for j in range(3):
            if a[i][j] == bingo:
                a[i][j] = 0
triple_pair =[a[0][t1]+a[1][t1]+a[2][t1] for t1 in range(3)] + [a[t2][0]+a[t2][1]+a[t2][2] for t2 in range(3)] + [a[0][0]+a[1][1]+a[2][2]] + [a[0][2]+a[1][1]+a[2][0]]
if 0 in triple_pair:
    print("Yes")
else:
    print("No")

Solution (Python):
*A, = map(int, open(0).read().split())
N = A[9]
B = A[10:]
A = A[:9]

T = [False]*9

for b in B:
    if b in A:
        T[A.index(b)] = True

bingo = [(0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6),
         (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6)]

for a, b, c in bingo:
    if T[a] and T[b] and T[c]:
        print('Yes')
        break
else:
    print('No')

Solution (Python):
a = []
for _ in range(3):
    a.append(list(map(int,input().split()))) 
n = int(input())
num_list = []
for _ in range(n):
    num_list.append(int(input()))
    
flg = False
for i in range(3):
    if a[i][0] in num_list and a[i][1] in num_list and a[i][2] in num_list:
        flg = True
        break
        
for i in range(3):
    if a[0][i] in num_list and a[1][i] in num_list and a[2][i] in num_list:
        flg = True
        break
        
if flg != True:
    diago = list([a[0][0],a[1][1],a[2][2]])
    if diago[0] in num_list and diago[1] in num_list and diago[2] in num_list:
        flg = True
        
if flg != True:
    diago2 = list([a[2][0],a[1][1],a[2][0]])
    if diago2[0] in num_list and diago2[1] in num_list and diago2[2] in num_list:
        flg = True
        
if flg:
    print("Yes")
else:
    print("No")

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  A = [[int(x) for x in readline().split()] for _ in range(3)]
  N = int(readline())
  bingo = [[False]*3 for _ in range(3)]
  for _ in range(N):
    b = int(input())
    for i in range(3):
      for j in range(3):
        if A[i][j] == b:
          bingo[i][j] = True
  ans = 'No'
  for i in range(3):
    if bingo[i][0] == bingo[i][1] == bingo[i][2] == True:
      ans = 'Yes'
    if bingo[0][i] == bingo[1][i] == bingo[2][i] == True:
      ans = 'Yes'
  if bingo[0][0] == bingo[1][1] == bingo[2][2] == True:
    ans = 'Yes'
  if bingo[0][2] == bingo[1][1] == bingo[2][0] == True:
    ans = 'Yes'
  print(ans)
  
  
if __name__ == '__main__':
  main()

Solution (Python):
a = []
while True:
    inp = input().split()
    if len(inp) == 3:
        a.append([int(x) for x in inp])
    else:
        break
n = int(inp[0])
bingo = [[False for _ in range(3)] for __ in range(3)]
for _ in range(n):
    b = int(input())
    for i in range(3):
        if b in a[i]:
            bingo[i][a[i].index(b)] = True
ans = "No"
for i in range(3):
    if bingo[i][0] == bingo[i][1] == bingo[i][2] == True:
        ans = "Yes"
    if bingo[0][i] == bingo[1][i] == bingo[2][i] == True:
        ans = "Yes"
if bingo[0][0] == bingo[1][1] == bingo[2][2] == True or bingo[0][2] == bingo[1][1] == bingo[2][0] == True:
    ans = "Yes"
print(ans)

Solution (Python):
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''
grid = []
for _ in range(3):
	temp = []
	temp = list(map(int,input().split()))
	grid.append(temp)
N = int(input())
b = []
for _ in range(N):
	b.append(int(input()))
for x in b:
	for i in range(3):
		for j in range(3):
			if grid[i][j]==x:
				grid[i][j]= -(grid[i][j])
ans = -1

for i in range(3):
	if grid[i][0]<0 and grid[i][1]<0 and grid[i][2]<0:
		ans  = 1
		break
	elif(grid[0][i]<0 and grid[1][i]<0 and grid[2][i]<0):
		ans = 1
		break
if ans!=1:
	if (grid[0][0]<0 and grid[1][1]<0 and grid[2][2]<0):
		ans = 1
	if( grid[0][2]<0 and grid[1][1]<0 and grid[2][0]<0):
		ans =1  
if(ans ==1):
	print("Yes")
else:
	print("No")

Solution (Python):
A = []
ans = "No"

for _ in range(3):
    row = list(map(int, input().split()))
    A.append(row)

N = int(input())
for _ in range(N):
    bi = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == bi:
                A[i][j] = 0
                break

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

if A[0][0] == A[1][1] == A[2][2]:
    ans = "Yes"

if A[2][0] == A[1][1] == A[0][2]:
    ans = "Yes"
print(ans)

Solution (Python):
import sys
a=[[0 for i in range(3)] for j in range(3)]
for i in range(3):
    a[i]=list(map(int,input().split()))
n=int(input())
for _ in range(n):
    m=int(input())
    for i in range(3):
        for j in range(3):
            if m==a[i][j]:
                a[i][j]=0
    for k in range(3):
        if a[k][0]==0 and a[k][1]==0 and a[k][2]==0:
            print('Yes')
            sys.exit()
        if a[0][k]==0 and a[1][k]==0 and a[2][k]==0:
            print('Yes')
            sys.exit()
    if a[0][0]==0 and a[1][1]==0 and a[2][2]==0:
        print('Yes')
        sys.exit()
    if a[0][2]==0 and a[1][1]==0 and a[2][0]==0:
        print('Yes')
        sys.exit()
print('No')

Solution (Python):


a = []

for i in range(3):
    a.append(tuple(map(int, input().split())))

n = int(input())

tbl = [ [0 for i in range(3)] for j in range(3) ]

for i in range(n):
    b = int(input())
    for y in range(3):
        for x in range(3):
            if a[y][x] == b:
                tbl[y][x] = 1

if tbl[0][0] * tbl[0][1] * tbl[0][2] == 1:
    print('Yes')
elif tbl[1][0] * tbl[1][1] * tbl[1][2] == 1:
    print('Yes')
elif tbl[2][0] * tbl[2][1] * tbl[2][2] == 1:
    print('Yes')
elif tbl[0][0] * tbl[1][0] * tbl[2][0] == 1:
    print('Yes')
elif tbl[0][1] * tbl[1][1] * tbl[2][1] == 1:
    print('Yes')
elif tbl[0][2] * tbl[1][2] * tbl[2][2] == 1:
    print('Yes')
elif tbl[0][0] * tbl[1][1] * tbl[2][2] == 1:
    print('Yes')
elif tbl[0][2] * tbl[1][1] * tbl[2][0] == 1:
    print('Yes')
else:
    print('No')

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

N = int(input())
b = []
for i in range(N):
    b.append(int(input()))

bingo = []
for t in range(N):
    for i in range(3):
        if b[t] in A[i]:
            j = A[i].index(b[t])
            
            A[i][j] = True

answer = "No"
for i in range(3):
    if A[i][0] == A[i][1] == A[i][2]:
        answer = "Yes"

for j in range(3):
    if A[0][j] == A[1][j] == A[2][j]:
        answer = "Yes"
if A[0][0] == A[1][1] == A[2][2]:
    answer = "Yes"

if A[2][0] == A[1][1] == A[0][2]:
    answer = "Yes"
    

print(answer)

Solution (Python):

A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
ans = 'No'
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            A[i][j] = True
        else:
            A[i][j] = False

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

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

if A[0][0] and A[1][1] and A[2][2]:
    ans = 'Yes'
if A[0][2] and A[1][1] and A[2][0]:
    ans = 'Yes'

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    card = []
    for _ in range(3):
        card.append(list(map(int, input().split())))
    bingo = [[0 for _ in range(3)] for _ in range(3)]
    N = int(input())
    for _ in range(N):
        b = int(input())
        for i in range(3):
            for j in range(3):
                if card[i][j] == b:bingo[i][j] = 1
    is_bingo = False
    for i in range(3):
        if bingo[i][0] == 1 and bingo[i][1] == 1 and bingo[i][2] == 1:
            is_bingo = True
            break
        if bingo[0][i] == 1 and bingo[1][i] == 1 and bingo[2][i] == 1:
            is_bingo = True
            break
    if bingo[0][0] == 1 and bingo[1][1] == 1 and bingo[2][2] == 1:
        is_bingo = True
    if bingo[0][2] == 1 and bingo[1][1] == 1 and bingo[2][0] == 1:
        is_bingo = True
    if is_bingo:
        print("Yes")
    else:
        print("No")
if __name__ == "__main__":
    main()

Solution (Python):
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = a + b + c
n = int(input())
n_list = [int(input()) for i in range(n)]
o = [False, False, False, False, False, False, False, False, False]
flag = False
for i in n_list:
    if i in d:
        o[d.index(i)] = True

for i in range(0, 7, 3):

    if o[i] and o[i + 1] and o[i + 2]:
        flag = True
        break

for i in range(0, 3):
    if o[i] and o[i + 3] and o[i + 6]:
        flag = True
        break

if o[0] and o[4] and o[8]:
    flag = True
if o[2] and o[4] and o[6]:
    flag = True

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

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):
        if a[i][j] in b:
            a[i][j] = -1
bingo = 0

for i in range(3):
    if a[i][0] == a[i][1] == a[i][2] == -1:
        bingo = 1
        
for j in range(3):
    if a[0][j] == a[1][j] == a[2][j] == -1:
        bingo = 1

if a[0][0] == a[1][1] == a[2][2] == -1 or a[0][2] == a[1][1] == a[2][0]:
    bingo = 1

if bingo == 1:
    print('Yes')

else:
    print('No')

Solution (Python):
bi =[list(map(int,input().split())) for i in range(3)]
n=int(input())
isok = [[0 for i in range(3)]for j in range(3)]
for i in range(n):
    x = int(input())
    for j in range(3):
        for k in range(3):
            if bi[j][k] == x:
                isok[j][k] = 1

clear = 0
for i in range(3):
    if isok[i][0] and isok[i][1] and isok[i][2]:
        clear = 1
    if isok[0][i] and isok[1][i] and isok[2][i]:
        clear = 1
if isok[0][0] and isok[1][1] and isok[2][2]:
    clear = 1
if isok[2][0] and isok[1][1] and isok[0][2]:
    clear = 1
print("Yes" if clear else "No")

Solution (Python):
import numpy as np
card = []
for _ in range(3):
    card.append(list(map(int, input().split())))
card = np.array(card)

N = int(input())

B = [int(input()) for _ in range(N)]


for b in B:
    for i in range(3):
        for j in range(3):
            if b == card[i][j]:
                card[i][j] = 0

count_by_row = (card == 0).sum(axis=1)
count_by_col = (card == 0).sum(axis=0)

if (3 in count_by_row) or (3 in count_by_col):
    print("Yes")
elif card[0][0] == 0 and card[1][1] == 0 and card[2][2] == 0:
    print("Yes")
elif card[0][2] == 0 and card[1][1] == 0 and card[2][0] == 0:
    print("Yes")
else:
    print("No")

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):
        if A[i][j] in B:
            A[i][j]=-1

is_bingo=False

for i in range(3):
    if A[i][0]==A[i][1]==A[i][2]==-1:
        is_bingo=True
        break

for i in range(3):
    if A[0][i]==A[1][i]==A[2][i]==-1:
        is_bingo=True
        break

if A[0][0]==A[1][1]==A[2][2]==-1 or A[2][0]==A[1][1]==A[0][2]==-1:
    is_bingo=True

print("Yes" if is_bingo==True else "No")

Solution (Python):
A=[]
for i in range(3):
  B=list(map(int,input().split()))
  A.append(B)
N=int(input())
b=[0]*N
for i in range(N):
  b[i]=int(input())
lis=[]
bingo=[[(0,0),(0,1),(0,2)],[(1,0),(1,1),(1,2)],[(2,0),(2,1),(2,2)],[(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)]]
for i in range(3):
  for j in range(3):
    if A[i][j] in b:
      lis.append((i,j))
ans=0
for i in range(8):
  count=0
  for j in range(3):
    if bingo[i][j] in lis:
      count+=1
  if count==3:
    ans+=1
    print('Yes')
    break
if ans==0:
  print('No')

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a = [list(map(int, readline().split())) for i in range(3)]
n = int(readline())
b = [int(readline()) for _ in range(n)]
for bb in b:
    for j in range(3):
        for k in range(3):
            if a[j][k] == bb:
                a[j][k] = 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[2][0] == a[1][1] == a[0][2] == 0:
    ans = 'Yes'
print(ans)

Solution (Python):
A = [input().split() for _ in range(3)]
n = int(input())
B = [input() for _ in range(n)]
ans = False
bng = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for i in range(n):
    for j in range(3):
        for k in range(3):
            if A[j][k] == B[i]:
                bng[j][k] = 1

for i in range(3):
    if bng[i][0] == bng[i][1] == bng[i][2] == 1:
        ans = True
    if bng[0][i] == bng[1][i] == bng[2][i] == 1:
        ans = True

if bng[0][0] == bng[1][1] == bng[2][2] == 1:
    ans = True
if bng[0][2] == bng[1][1] == bng[2][0] == 1:
    ans = True

if ans:
    print("Yes")
else:
    print("No")

Solution (Python):
from itertools import product

A = [list(map(int,input().split())) for i in range(3)]
n = int(input())
crd = [[False,False,False] for i in range(3)]
for _ in range(n):
    b = int(input())
    for i,j in product(range(3),range(3)):
        if b == A[i][j]:
            crd[i][j] = True

line = [[(0,0),(0,1),(0,2)],[(1,0),(1,1),(1,2)],[(2,0),(2,1),(2,2)],\
        [(0,0),(1,0),(2,0)],[(0,1),(1,1),(2,1)],[(0,2),(1,2),(2,2)],\
        [(0,0),(1,1),(2,2)],[(2,0),(1,1),(0,2)]]


for l in line:
    if crd[l[0][0]][l[0][1]] and crd[l[1][0]][l[1][1]] and crd[l[2][0]][l[2][1]]:
        print('Yes')
        exit()

print('No')

Solution (Python):
a11,a12,a13 = input().split()
a21,a22,a23 = input().split()
a31,a32,a33 = input().split()
A=[[a11,a12,a13],[a21,a22,a23],[a31,a32,a33]]
N = int(input())
b=[input() for i in range(N)]
bingo=[[False,False,False],[False,False,False],[False,False,False]]

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

ans="No"
if bingo[0][0] and bingo[0][1] and bingo[0][2]:
  ans = "Yes"
if bingo[1][0] and bingo[1][1] and bingo[1][2]:
  ans = "Yes"
if bingo[2][0] and bingo[2][1] and bingo[2][2]:
  ans = "Yes"
if bingo[0][0] and bingo[1][0] and bingo[2][0]:
  ans = "Yes"
if bingo[0][1] and bingo[1][1] and bingo[2][1]:
  ans = "Yes"
if bingo[0][2] and bingo[1][2] and bingo[2][2]:
  ans = "Yes"
if bingo[0][0] and bingo[1][1] and bingo[2][2]:
  ans = "Yes"
if bingo[0][2] and bingo[1][1] and bingo[2][0]:
  ans = "Yes"
  
print(ans)

Solution (Python):
import sys

row1 = [int(n) for n in input().split()]
row2 = [int(n) for n in input().split()]
row3 = [int(n) for n in input().split()]

card = [row1,row2,row3]



N = int(input())
for n in range(N):
    bn = int(input())
    for i in range(len(card)):
        for j in range(len(card)):
            if card[i][j] == bn:
                card[i][j] = 0



for i in range(len(card)):
    check_i = 0
    for j in range(len(card)):
        check_i += card[i][j]
    
    if check_i == 0:
        print('Yes')
        sys.exit(0)
for j in range(len(card)):
    check_j = 0
    for i in range(len(card)):
        check_j += card[i][j]
    
    if check_j == 0:
        print('Yes')
        sys.exit(0)

check_diag1 = 0
check_diag2 = 0
for i in range(len(card)):
    check_diag1 += card[i][i]
    check_diag2 += card[len(card)-i-1][i]


if check_diag1 == 0 or check_diag2 == 0:
    print('Yes')
    sys.exit(0)

print('No')

Solution (Python):
def main():
    a = [[] for i in range(3)]

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

    n = int(input())

    for i in range(n):
        c = int(input())
        for j in range(3):
            for k in range(3):
                if a[j][k] == c:
                    a[j][k] = -1

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

    if a[0][0] == -1 and a[1][1] == -1 and a[2][2] == -1:
        ans = "Yes"
    if a[0][2] == -1 and a[1][1] == -1 and a[2][0] == -1:
        ans = "Yes"

    print(ans)

main()

Solution (Python):
import math
A=[list(map(int,input().split())) for n in range(3)]
N=int(input())
D=[int(input()) for i in range(N)]
F=[]
ans="No"
for d in D:
    for aa in A:
        for a in aa:
            if d==a:
               F.append([A.index(aa)+2,aa.index(d)+2])
            else:
                continue

for f1 in F:
    for f2 in F:
        for f3 in F:
            if f1==f2 or f2==f3 or f3==f1:
                continue
            elif math.atan2((f2[1]-f1[1]),(f2[0]-f1[0]))==math.atan2((f3[1]-f1[1]),(f3[0]-f1[0])):
                ans="Yes"
                break
            else:
                continue

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A = [LIST() for _ in range(3)]
N = INT()
b = [INT() for _ in range(N)]

for n in b:
  for i in range(3):
    for j in range(3):
      if A[i][j] == n:
        A[i][j] = 0
        
for i in range(3):
  if sum(A[i]) == 0:
    print("Yes")
    exit()
    
for i in range(3):
  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[0][2] + A[1][1] + A[2][0] == 0:
  print("Yes")
  exit()
  
print("No")

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A = [LIST() for _ in range(3)]
N = INT()
b = [INT() for _ in range(N)]

check = [[0]*3 for _ in range(3)]

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

for i in range(3):
  if sum(check[i]) == 3:
    print("Yes")
    exit()

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

Solution (Python):
import sys
from io import StringIO
import unittest

import numpy as np

def resolve():
    a = np.array([list(map(int, input().split())) for _ in range(3)])
    n = int(input())
    b = set([int(input()) for _ in range(n)])
    flag = 0

    for i in range(3):
        if set(a[i]).issubset(b) or set(a[:, i]).issubset(b):
            flag = 1
            break

    if set([a[0][0], a[1][1], a[2][2]]).issubset(b) or set([a[0][2], a[1][1], a[2][0]]).issubset(b):
        flag = 1

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



class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30"""
        output = """Yes"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """41 7 46
26 89 2
78 92 8
5
6
45
16
57
17"""
        output = """No"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34"""
        output = """Yes"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

Solution (Python):
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
g,h,i=map(int,input().split())
List=[]
List+=[a,b,c,d,e,f,g,h,i]
n=int(input())
lst=[int(input()) for i in range(n)]
p=set()
for i in lst:
  if i in List:
    p.add(List.index(i))
if 3 in p and 4 in p and 5 in p:
  print("Yes")
elif 0 in p and 1 in p and 2 in p:
  print("Yes")
elif 6 in p and 7 in p and 8 in p:
  print("Yes")
elif 0 in p and 3 in p and 6 in p:
  print("Yes")
elif 1 in p and 4 in p and 7 in p:
  print("Yes")
elif 2 in p and 5 in p and 8 in p:
  print("Yes")
elif 0 in p and 4 in p and 8 in p:
  print("Yes")
elif 2 in p and 4 in p and 6 in p:
  print("Yes")
else:
  print("No")

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):
Asq = []
for i in range(3) :
    Asq.append(list(input().split()))

N = int(input())
b = []
c = 0
y = 0
for k in range(N) :
    b.append(input())
    for i in range(3) :
        for j in range(3) :
            if Asq[i][j] == b[k] :
                s = Asq[i][j]
                Asq[i][j] = '
                c += 1

if c >= 3 :
    for i in range(3) :
        if (Asq[i][0] == '
            y = 1
        elif (Asq[0][i] == '
            y = 1
    if Asq[0][0] == '
        y = 1
    elif Asq[0][2] == '
        y = 1

if y == 1 :
    print('Yes')
else :
    print('No')

Solution (Python):
a = [list( input().split()) for _ in range(3)]

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

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[0][2] == a[1][1] == a[2][0] == "0":
    print("Yes")
    exit()
print("No")

Solution (Python):
def read():
    board = []
    for _ in range(3):
        board.append([int(num) for num in input().split()])
    return board

board = read()
N = int(input())
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if board[i][j] == b:
                board[i][j] = True

good = False

for i in range(3):
    if board[i][0] == board[i][1] == board[i][2] == True:
        good = True
    if board[0][i] == board[1][i] == board[2][i] == True:
        good = True

if board[0][0] == board[1][1] == board[2][2] == True:
    good = True
if board[0][2] == board[1][1] == board[2][0] == True:
    good = True

if good:
    print("Yes")
else:
    print("No")

Solution (Python):
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")

Solution (Python):
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
an = [a1, a2, a3]
n = int(input())
bn = []
counter = 0
for _ in range(n):
  bn.append(int(input()))
  
for i in bn:
  for j in an:
    if i in j:
      j[j.index(i)] = 0

for k in an:
  if k.count(0) == 3:
    print('Yes')
    exit()
    
for l in range(3):
  if an[0][l] == 0 and an[1][l] == 0 and an[2][l] == 0:
    print('Yes')
    exit()
    
if an[0][0] == 0 and an[1][1] == 0 and an[2][2] == 0:
  print('Yes')
  exit()
if an[0][2] == 0 and an[1][1] == 0 and an[2][0] == 0:
  print('Yes')
  exit()
  
print('No')

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):
  if a[0][i] in b and a[1][i] in b and a[2][i] in b:
    print('Yes')
    exit()
  if a[i][0] in b and a[i][1] in b and a[i][2] 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):
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

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('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)]
flag =False
for i in range(3):
  if all(a[i][j] in b for j in range(3)):
    flag=True
  if all(a[j][i] in b for j in range(3)):
    flag=True
if all(a[j][j] in b for j in range(3)) or all(a[i][2-i] in b for i in range(3)) :
  flag=True
if(flag):
  print("Yes")
else:
  print("No")

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

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

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


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

J_0 = A[0][0] + A[1][0] + A[2][0]
J_1 = A[0][1] + A[1][1] + A[2][1]
J_2 = A[0][2] + A[1][2] + A[2][2]
nana1 = A[0][0] + A[1][1] + A[2][2]
nana2 = A[0][2] + A[1][1] + A[2][0]
if sum(A[0]) == 0 or sum(A[1]) == 0 or sum(A[2]) == 0:
    print("Yes")
elif J_0 == 0 or J_1 == 0 or J_2 == 0:
    print("Yes")
elif nana1 == 0 or nana2 == 0:
    print("Yes")
else:
    print("No")

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

ans = 'No'        
for m in range(3):
  if a[m][0] == a[m][1] == a[m][2]:
    ans = 'Yes'
  if a[0][m] == a[1][m] == a[2][m]:
    ans = 'Yes'
if a[0][0] == a[1][1] == a[2][2]:
  ans = 'Yes'
if a[0][2] == a[1][1] == a[2][0]:
  ans = 'Yes'
print(ans)