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 = [0] * 3
a[0] = list(map(int, input().split()))
a[1] = list(map(int, input().split()))
a[2] = list(map(int, input().split()))
N = int(input())

bingo = [[0,0,0],
        [0,0,0],
        [0,0,0]]
for i in range(N):
    b = int(input())

    for j in range(3):
        for k in range(3):
            if(a[j][k] == b): bingo[j][k] = 1

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

Solution (Python):
A = [ [0]*3 for i in range(3)];

for i in range(3) :
	s = input().split(' ');
	for j in range(3) :
		A[i][j] = int(s[j]);

Check = [ [0]*3 for i 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 :
				Check[j][k] = 1;
ans = 0;
for i in range(3) :
	bingo = 0;
	for j in range(3) :
		bingo += Check[i][j];
		if bingo == 3 :
			ans = 1;

for i in range(3) :
	bingo = 0;
	for j in range(3) :
		bingo += Check[j][i];
		if bingo == 3 :
			ans = 1;

bingo = 0;
for i in range(3) :
	bingo += Check[i][i];
	if bingo == 3 :
			ans = 1;

bingo = 0;
for i in range(3) :
	bingo += Check[i][2-i];
	if bingo == 3 :
			ans = 1;

if ans :
	print('Yes');
else :
	print('No');

Solution (Python):
a = []
b = []

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

n = int(input())

for i in range(n):
    b.append(int(input()))


for i in range(3):
    yoko = set(a[i])
    if yoko <= set(b):
        print("Yes")
        exit()


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


naname1 = {a[0][0], a[1][1], a[2][2]}
naname2 = {a[0][2], a[1][1], a[2][0]}

if naname1 <= set(b):
    print("Yes")
    exit()
elif naname2 <= set(b):
    print("Yes")
    exit()
else:
    print("No")

Solution (Python):
a=[]
for i in range(3):
  *x,=map(int,input().split())
  a+=x
n=int(input())
b=[]
for i in range(n):
    b.append(int(input()))
ans=[False for _ in range(9)]
for i in b:
    for j in a:
        if i==j:
            ans[a.index(i)]=True
if all(ans[0:3]) or all(ans[3:6]) or all(ans[6:9]):
    print("Yes")
elif all(ans[0:7:3]) or all(ans[1:8:3]) or all(ans[2:9:3]):
    print("Yes")
elif all(ans[0:5:4]) or all(ans[2:7:2]):
    print("Yes")
else:
    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())
A = [A11, A12, A13, A21, A22, A23, A31, A32, A33]
bingo = [0, 0, 0, 0, 0, 0, 0, 0, 0]
N = int(input())
B = []
for _ in range(N):
    B.append(int(input()))

for i, b in enumerate(B):
    for j, a in enumerate(A):
        if a == b:
            bingo[j] = 1

if (bingo[0] == bingo[1] == [2] == 1) or (bingo[3] == bingo[4] == bingo[5] == 1) or (bingo[6] == bingo[7] == bingo[8] == 1) or (bingo[0] == bingo[3] == bingo[6] == 1) or (bingo[1] == bingo[4] == bingo[7] == 1) or (bingo[2] == bingo[5] == bingo[8] == 1) or (bingo[0] == bingo[4] == bingo[8] == 1) or (bingo[2] == bingo[4] == bingo[6] == 1):
    print('Yes')
else:
    print('No')

Solution (Python):
ans = "No"
c = []
for i in range(3):
    t = list(map(int, input().split()))
    c.append(t)

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

for i in range(3):
    x = []
    for j in range(3):
        x.append(c[j][i])
    else:
        c.append(x)


for i in range(1):
    x = []
    for j in range(3):
        x.append(c[j][j])
    else:
        c.append(x)

for i in range(1):
    x = []
    for j in range(3):
        x.append(c[j][2-j])
    else:
        c.append(x)

for i in range(8):
    for j in range(3):
        if c[i][j] not in b:
            break
    else:
        ans = "Yes"
        break

print(ans)

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

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

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

flag = 0
for i in range(3):
    for j in range(3):
        if A[0][0]*A[0][1]*A[0][2] == 101**3 \
        or A[1][0]*A[1][1]*A[1][2] == 101**3 \
        or A[2][0]*A[2][1]*A[2][2] == 101**3 \
        or A[0][0]*A[1][0]*A[2][0] == 101**3 \
        or A[0][1]*A[1][1]*A[2][1] == 101**3 \
        or A[0][2]*A[1][2]*A[2][2] == 101**3 \
        or A[0][0]*A[1][1]*A[2][2] == 101**3 \
        or A[2][0]*A[1][1]*A[0][2] == 101**3:
            flag = 1
            break

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

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

R=[[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 B[i]==A[j][k]:
                R[j][k]=1

ans=0

for l in range(3):
    if R[l][0]==1 and R[l][1]==1 and R[l][2]==1:
        ans=1

for m in range(3):
    if R[0][m]==1 and R[1][m]==1 and R[2][m]==1:
        ans=1

if R[0][0]==1 and R[1][1]==1 and R[2][2]==1:
    ans=1

if R[0][2]==1 and R[1][1]==1 and R[2][0]==1:
    ans=1



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

Solution (Python):
import numpy as np

bingo = []

for i in range(3):
    bingo.append(list(map(int,input().split())))
n = int(input())

bingo = np.array(bingo)
for i in range(n):
    
    x = int(input())
    
    for j in range(3):
        for k in range(3):
            if bingo[j][k] == x:
                bingo[j][k] = 0

ct = 0
sum1 = 0
for i in range(3):
    sum1 += bingo[i][i]
sum2 = 0
for i in range(3):
    sum2 += bingo[i][2-i]

if sum1 == 0 or sum2 == 0:
    ct += 1
if (sum(bingo.sum(axis=0)==0) >= 1) or (sum(bingo.sum(axis=1)==0) >= 1):
    ct += 1
    
if ct > 0:
    print("Yes")
else:
    print("No")

Solution (Python):
def main():
    a = [list(map(int, (input().split()))) for _ in range(3)]
    n = int(input())
    ans = []
    for i in range(n):
        m = int(input())
        for j in range(3):
            for k in range(3):
                if a[j][k] == m:
                    ans.append((j,k))
    
    if (0,0) in ans and (1,1) in ans and (2,2) in ans:
        print("Yes")
    elif (0,0) in ans and (0,1) in ans and (0,2) in ans:
        print("Yes")
    elif (1,0) in ans and (1,1) in ans and (1,2) in ans:
        print("Yes")
    elif (2,0) in ans and (2,1) in ans and (2,2) in ans:
        print("Yes")
    elif (0,0) in ans and (1,0) in ans and (2,0) in ans:
        print("Yes")
    elif (0,1) in ans and (1,1) in ans and (2,1) in ans:
        print("Yes")
    elif (0,2) in ans and (1,2) in ans and (2,2) in ans:
        print("Yes")
    elif (0,2) in ans and (1,1) in ans and (2,0) in ans:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Solution (Python):
a = []
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
c = [[False] * 3 for i in range(3)]
n = int(input())
for i in range(n):
    b = int(input())
    ok = False
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                c[j][k] = True
                ok = True
                break
        if ok:
            break
if c[0][0] == c[0][1] == c[0][2] == True or c[1][0] == c[1][1] == c[1][2] == True or c[2][0] == c[2][1] == c[2][2] == True or c[0][0] == c[1][0] == c[2][0] == True or c[0][1] == c[1][1] == c[2][1] == True or c[0][2] == c[1][2] == c[2][2] == True or c[0][0] == c[1][1] == c[2][2] == True or c[0][2] == c[1][1] == c[2][0] == True:
    print('Yes')
else:
    print('No')

Solution (Python):



L=[]
Check=[]
for n in range(9):
  Check.append(-(n+1))

for i in range(3):
  NL=list(map(int, input().split()))
  L.append(NL[0])
  L.append(NL[1])
  L.append(NL[2])

N=int(input())
for j in range(N):
  I=int(input())
  if I in L:
    Check[L.index(I)]=1
  
for k in range(3):
  if Check[0+3*k]==Check[1+3*k]==Check[2+3*k]:
    print('Yes')
    exit()

for l in range(3):
  if Check[0+l]==Check[3+l]==Check[6+l]:
    print('Yes')
    exit()

if Check[0]==Check[4]==Check[8] or Check[2]==Check[4]==Check[6]:
  print('Yes')
  exit()

print('No')

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

for i in range(3):
  for j in range(3):
    if a[i][j] in b:
      m[i][j]=1

cnt0=0
cnt1=0
cnt2=0
cnt3=0
cnt4=0
cnt5=0
cnt6=0
cnt7=0
ans="No"

for i in range(3):
  if m[0][i]==1:
    cnt0+=1
  if m[1][i]==1:
    cnt1+=1
  if m[2][i]==1:
    cnt2+=1
  if m[i][0]==1:
    cnt3+=1
  if m[i][1]==1:
    cnt4+=1
  if m[i][2]==1:
    cnt5+=1
  if m[i][i]==1:
    cnt6+=1
  if m[i][2-i]==1:
    cnt7+=1

if cnt0==3 or cnt1==3 or cnt2==3 or cnt3==3:
  ans="Yes"
if cnt4==3 or cnt5==3 or cnt6==3 or cnt7==3:
  ans="Yes"  
print(ans)

Solution (Python):
A=[]
for i in [0]*3:
    A+=list(map(int,input().split()))
N=int(input())
B=[0]*9
for i in range(N):
    i=int(input())
    if i in A:
        B[A.index(i)]=1
res=0
for i in range(3):
    res+=B[3*i]*B[3*i+1]*B[3*i+2]
    res+=B[i]*B[i+3]*B[i+6]
res+=B[0]*B[4]*B[8]+B[2]*B[4]*B[6]
print(['No','Yes'][res>0])

Solution (Python):
A = [[int(j) for j in input().split()] for i in range(3)]
N = int(input())
B = [False] * 101

for i in range(N):
    B[int(input())] = True

ans = 'No'
for i in range(3):
    if all([B[v] for v in A[i]]):
        ans = 'Yes'
        break

for j in range(3):
    if all([B[A[i][j]] for i in range(3)]):
        ans = 'Yes'
        break

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

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

print(ans)

Solution (Python):
card=[]

for i in range(3):
    a,b,c= map(int,input().split())
    card.append(a)
    card.append(b)
    card.append(c)

N = int(input())

for i in range(N):
    b=int(input())
    if b in card:
        num=card.index(b)
        card[num]=0

r1=card[0]+card[1]+card[2]
r2=card[3]+card[4]+card[5]
r3=card[6]+card[7]+card[8]

l1=card[0]+card[3]+card[6]
l2=card[1]+card[4]+card[7]
l3=card[2]+card[5]+card[8]

m1=card[0]+card[4]+card[8]
m2=card[2]+card[4]+card[6]

if r1==0:
    print("Yes")
elif r2==0:
    print("Yes")
elif r3==0:
    print("Yes")
elif l1==0:
    print("Yes")
elif l2==0:
    print("Yes")
elif l3==0:
    print("Yes")
elif m1==0:
    print("Yes")
elif m2==0:
    print("Yes")
else:
    print("No")

Solution (Python):
cd = []
for i in range(3):
  p = input().split(" ")
  p = [int(j) for j in p]
  cd.append(p)

n = input()
n = int(n)
tf = []

for i in range(n):
  p = input()
  for j in range(3):
    if int(p) in cd[j]:
      tf.append([j, cd[j].index(int(p))])

id0 = [i[0] for i in tf]
id1 = [i[1] for i in tf]
df = [i[0] - i[1] for i in tf]
sm = [i[0] + i[1] for i in tf]

if id0.count(0) == 3:
  print("Yes")
elif id0.count(1) == 3:
  print("Yes")
elif id0.count(2) == 3:
  print("Yes")
elif id1.count(0) == 3:
  print("Yes")
elif id1.count(1) == 3:
  print("Yes")
elif id1.count(2) == 3:
  print("Yes")
elif df.count(0) == 3:
  print("Yes")
elif sm.count(2) == 3:
  print("Yes")
else:
  print("No")

Solution (Python):
L1 = list(map(int, input().split()))
L2 = list(map(int, input().split()))
L3 = list(map(int, input().split()))
L = L1 + L2 + L3
N = int(input())
A = [0]*9
for _ in range(N):
  i = int(input())
  if i in L:
    A[L.index(i)] = 1
if sum(A[:3])==3 or sum(A[3:6])==3 or sum(A[6:])==3:
  print('Yes')
elif A[0]+A[3]+A[6]==3 or A[1]+A[4]+A[7]==3 or A[2]+A[5]+A[8]==3:
  print('Yes')
elif A[0]+A[4]+A[8]==3 or A[2]+A[4]+A[6]==3:
  print('Yes')
else:
  print('No')

Solution (Python):
import math
import sys
def main():
    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 k in range(n):
        ball = int(input())
        for j, contents in enumerate(a):
            for i, num in enumerate(contents):
                if num == ball:
                    a[j][i] = 0
    
    for j, contents in enumerate(a):
        if sum(contents) == 0:
            print('Yes')
            sys.exit()
        if a[0][j] + a[1][j] + a[2][j] == 0:
            print('Yes')
            sys.exit()
    if a[0][0] + a[1][1] + a[2][2] == 0:
        print('Yes')
        sys.exit()
    if a[0][2] + a[1][1] + a[2][0] == 0:
        print('Yes')
        sys.exit()

    print('No')
    

if __name__ == '__main__' :
    main()

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

n = int(input())
b = list(int(input()) for i in range(n))

if a1[0] in b and a2[0] in b and a3[0] in b:
    print('Yes')
elif a1[1] in b and a2[1] in b and a3[1] in b:
    print('Yes')
elif a1[2] in b and a2[2] in b and a3[2] in b:
    print('Yes')
elif a1[0] in b and a2[1] in b and a3[2] in b:
    print('Yes')
elif a1[2] in b and a2[1] in b and a3[0] in b:
    print('Yes')
elif a1[0] in b and a1[1] in b and a1[2] in b:
    print('Yes')
elif a2[0] in b and a2[1] in b and a2[2] in b:
    print('Yes')
elif a3[0] in b and a3[1] in b and a3[2] in b:
    print('Yes')
else:
    print('No')

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

def check(line, num_set):
  for num in line:
    if(not(num in num_set)):
      return False
  return True

if (check([A[0][0], A[0][1], A[0][2]], B)
    or check([A[1][0], A[1][1], A[1][2]], B)
    or check([A[2][0], A[2][1], A[2][2]], B)
    
    or check([A[0][0], A[1][0], A[2][0]], B)
    or check([A[0][1], A[1][1], A[2][1]], B)
    or check([A[0][2], A[1][2], A[2][2]], B)
    
    or check([A[0][0], A[1][1], A[2][2]], B)
    or check([A[2][0], A[1][1], A[0][2]], B)):
  print("Yes")
else:
  print("No")

Solution (Python):
a1 = [int(i) for i in input().split()]
a2 = [int(i) for i in input().split()]
a3 = [int(i) for i in input().split()]



a = a1+a2+a3
n = int(input())
ans = [int(input()) for _ in range(n)]

aa = [0] * 9
for i in ans:
    for ind,j in enumerate(a):

        if i==j:

            aa[ind]=1

f=0
if aa[0]==1 and	aa[1]==1 and aa[2]==1:
    f=1
elif aa[0]==1 and aa[3]==1 and aa[6]==1:
    f=1
elif aa[3]==1 and aa[4]==1 and aa[5]==1:
    f=1
elif aa[6]==1 and aa[7]==1 and aa[8]==1:
    f=1
elif aa[7]==1 and aa[4]==1 and aa[1]==1:
    f=1
elif aa[2]==1 and aa[5]==1 and aa[8]==1:
    f=1
elif aa[6]==1 and aa[4]==1 and aa[2]==1:
    f=1
elif aa[0]==1 and aa[4]==1 and aa[8]==1:
    f=1
if f==1:
    print('Yes')
else:
    print('No')

Solution (Python):
def check():
    A = [[int(i) for i in input().split()] for _ in range(3)]
    N = int(input())
    
    for _ in range(N):
        num = int(input())
        for i in range(3):
            for j in range(3):
                if A[i][j] == num:
                    A[i][j] = '*'
    checklist = [a for a in A]
    checklist2 = [[a[i] for a in A] for i in range(3)]
    checklist3 = [[A[0][0], A[1][1], A[2][2]], [A[0][2], A[1][1], A[2][0]]]
    
    a = [checklist, checklist2, checklist3]
    
    for aaa in a:
        for check in aaa:
            if check == ['*', '*', '*']:
                return 'Yes'
    return 'No'
print(check())

Solution (Python):
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
a3 = list(map(int,input().split()))
n = int(input())
b = [0] * n
for i in range(n):
	b[i] = int(input())

for i in range(n):
	for j in range(3):
		if a1[j] == b[i]:
			a1[j] = -1
	for j in range(3):
		if a2[j] == b[i]:
			a2[j] = -1
	for j in range(3):
		if a3[j] == b[i]:
			a3[j] = -1
if set(a1) == {-1}:
	print("Yes")
elif set(a2) == {-1}:
	print("Yes")
elif set(a3) == {-1}:
	print("Yes")
elif a1[0] == a2[0] and a3[0] == -1:
	print("Yes")
elif a1[1] == a2[1] and a3[1] == -1:
	print("Yes")
elif a1[2] == a2[2] and a3[2] == -1:
	print("Yes")
elif a1[0] == a2[1] and a3[2] == -1:
	print("Yes")
elif a1[2] == a2[1] and a3[0] == -1:
	print("Yes")
else:
	print("No")

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

ans = [[0,0,0] for i in range(3)]
ans1 = [[0,0,0] for i in range(3)]

res = False

for i in range(n):
    for a in range(3):
        for c in range(3):
            if b[i] == List[a][c]:
                ans[a][c] = 1
                ans1[c][a] = 1

if ans[1][1] == 1:
    if ans[0][0] > 0 and ans[2][2] > 0:
        res = True
    if ans[2][0] > 0 and ans[0][2] > 0:
        res = True
                
for i in range(3):
    if ans[i][0] > 0 and ans[i][1] > 0 and ans[i][2] > 0:
        res = True
    if ans1[i][0] > 0 and ans1[i][1] > 0 and ans1[i][2] > 0:
        res = True
            
if res:
    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()))

a=[]
a.append(a1)
a.append(a2)
a.append(a3)


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

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

for m in range(3):
  if a[m][0]+a[m][1]+a[m][2]==0:
    yes=1
for n in range(3):
  if a[0][n]+a[1][n]+a[2][n]==0:
    yes=1
if a[0][0]+a[1][1]+a[2][2]==0:
  yes=1
if a[0][2]+a[1][1]+a[2][0]==0:
  yes=1
if yes==1:
  print("Yes")
else:
  print("No")

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

n = int(input())

for _ 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):
    c1 = 0
    c2 = 0
    for j in range(3):
        if a[i][j] == 0:
            c1 += 1
        if a[j][i] == 0:
            c2 += 1
    if c1 == 3 or c2 == 3:
        ans = "Yes"

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

print(ans)

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

for i in range(n):
  b = int(input())
  for x in range(3):
    if a1[x] == b:
      a1[x] = 0
      break
  for y in range(3):
    if a2[y] == b:
      a2[y] = 0
      break
  for z in range(3):
    if a3[z] == b:
      a3[z] = 0
      break



if sum(a1) == 0 or sum(a2) == 0 or sum(a3) ==0:
  print('Yes')
  sys.exit()

for i in range(3):
  w = a1[i] + a2[i] + a3[i]
  if w == 0:
    print('Yes')
    sys.exit()

if a1[0] + a2[1] + a3[2] == 0 or a1[2] + a2[1] + a3[0] == 0:
  print('Yes')
  sys.exit()
print('No')

Solution (Python):
L = []
M = [[0 for i in range(3)] for j in range(3)]
for i in range(3):
  L_i = [int(s) for s in input().rstrip().split(' ')]
  L.append(L_i)
N = int(input())
for num in range(N):
  x = 0
  b_num = int(input())
  for k in range(3):
    for l in range(3):
      if L[k][l] == b_num:
        M[k][l] = 1
        x = 1
        break
    if x == 1:
      break
if M[0][0]*M[1][0]*M[2][0] + M[0][1]*M[1][1]*M[2][1] + M[0][2]*M[1][2]*M[2][2] >= 1:
  print("Yes")
elif M[0][0]*M[0][1]*M[0][2] + M[1][0]*M[1][1]*M[1][2] + M[2][0]*M[2][1]*M[2][2] >= 1:
  print("Yes")
elif M[0][0]*M[1][1]*M[2][2] + M[0][2]*M[1][1]*M[2][0] >= 1:
  print("Yes")
else:
  print("No")

Solution (Python):
import sys

matrix = []
for i in range(3):
  matrix.append([int(j) for j in input().split()])


def find(b):
  for i in range(3):
    for j in range(3):
      if matrix[i][j] == b:
        return (i, j)
  return None

matched = [[False for _ in range(3)]
           for _ in range(3)]
n = int(input())
for i in range(n):
  b = int(input())
  result = find(b)
  if result is not None:
    matched[result[0]][result[1]] = True
    
for i in range(3):
  ans = True
  for j in range(3):
    if not matched[i][j]:
      ans = False
      break
  if ans:
    print('Yes')
    sys.exit()
  
for i in range(3):
  ans = True
  for j in range(3):
    if not matched[j][i]:
      ans = False
      break
  if ans:
    print('Yes')
    sys.exit()
  
if matched[0][0] and matched[1][1] and matched[1][1]:
  print('Yes')
  sys.exit()

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

Solution (Python):
a = []
for i in range(3):
  a += list(map(int,input().split()))
n = int(input())
b = []
for i in range(n):
  b = int(input())
  if b in a:
    a[a.index(b)] = 0
ans = 0
if a[0]+a[4]+a[8] == 0 or a[2]+a[4]+a[6] == 0:
  ans = 1
if ans != 1:
  for i in range(3):
    if sum(a[i*3:i*3+3]) == 0 or a[i]+a[i+3]+a[i+6] == 0:
      ans = 1
      break
if ans == 1:
  print("Yes")
else:
  print("No")

Solution (Python):
import itertools

A = []
for i in range(3):
  A_i = list(map(int, input().split()))
  A.append(A_i)
  
A = list(itertools.chain.from_iterable(A))
N = int(input())

for _ in range(N):
  b = int(input())
  for i, a in enumerate(A):
    if a == b:
      A[i] = 0
      break
  if A[0] == A[1] == A[2] or A[3] == A[4] == A[5] or A[6] == A[7] == A[8] or A[0] == A[3] == A[6] or A[1] == A[4] == A[7] or A[2] == A[5] == A[8] or A[0] == A[4] == A[8] or A[2] == A[4] == A[6]:
    print('Yes')
    exit()

print('No')

Solution (Python):

from collections import deque, defaultdict
import bisect
from math import factorial

def main():
    As = []
    for _ in range(3):
        A = list(map(int, input().split()))
        As.append(A)
    N = int(input())
    Bs = set([int(input()) for _ in range(N)])

    is_success = False
    for A in As:
        if len(Bs & set(A)) == 3:
            is_success = True

    for i in range(3):
        C = Bs & set([A[i] for A in As])
        if len(C) == 3:
            is_success = True

    D = set([As[0][0], As[1][1], As[2][2]])
    if len(Bs & D) == 3:
        is_success = True
    D = set([As[0][2], As[1][1], As[2][0]])
    if len(Bs & D) == 3:
        is_success = True

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


if __name__ == '__main__':
    main()

Solution (Python):
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
b = []
for i in range(N):
  b.append(int(input()))
pin = 0
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')
    pin = 1
    break
  elif (A[i][0] in b) and (A[i][1] in b) and (A[i][2] in b):
    print('Yes')
    pin = 1
    break
if pin == 0:
  if ((A[0][0] in b) and (A[1][1] in b) and (A[2][2] in b)) or ((A[0][2] in b) and (A[1][1] in b) and (A[2][0] in b)):
    print('Yes')
    pin = 1
if pin == 0:
  print('No')

Solution (Python):


grid = []
for _ in range(3):
    array = list(map(int, input().strip().split()))
    grid.append(array)

def judge():
    for i in range(3):
        if grid[i][0] == 0 and grid[i][1] == 0 and grid[i][2] == 0:
            return True
        if grid[0][i] == 0 and grid[1][i] == 0 and grid[2][i] == 0:
            return True
    if grid[0][0] == 0 and grid[1][1] == 0 and grid[2][2] == 0:
        return True
    if grid[0][2] == 0 and grid[1][1] == 0 and grid[2][0] == 0:
        return True
    return False

n = int(input())
ans = "No"
for _ in range(n):
    b = int(input())
    for i in range(3):
        if b in grid[i]:
            grid[i][grid[i].index(b)] = 0
    if judge():
        ans = "Yes"


print (ans)

Solution (Python):

if __name__ == '__main__':
    a1 = [int(i) for i in input().split()]
    a2 = [int(i) for i in input().split()]
    a3 = [int(i) for i in input().split()]
    n = int(input())

    b = [int(input()) for i in range(n)]

    result = "No"

    if all([i in b for i in a1]):
        result = "Yes"
    if all([i in b for i in a2]):
        result = "Yes"
    if all([i in b for i in a3]):
        result = "Yes"
    
    for i in range(3):
        if all([i in b for i in [a1[i], a2[i], a3[i]]]):
            result = "Yes"
    
    if all([i in b for i in [a1[0], a2[1], a3[2]]]):
        result = "Yes"
        
    if all([i in b for i in [a1[2], a2[1], a3[0]]]):
        result = "Yes"
    
    print(result)

Solution (Python):
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
S = [[], [], []]
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            S[i].append(1)
        else:
            S[i].append(0)

t = 0


for i in range(3):
    if sum(S[i]) == 3:
        t = 1
    for j in range(3):
        if sum([S[i][j] for i in range(3)]) == 3:
            t = 1
if S[0][0] + S[1][1] + S[2][2] == 3 or S[0][2] + S[1][1] + S[2][0] == 3:
    t = 1

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

Solution (Python):
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

lst = list(map(int, read().split()))
arr=lst[:9]
tf = [False] * 10
for i in lst[10:]:
  if i in arr:
    tf[arr.index(i)] = True

t=[[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 i in t:
  a = True
  for j in i:
    if not tf[j]:
      a = False
  if a:
    print('Yes')
    quit()
else:
  print('No')

Solution (Python):
a=[]
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())
numlist=set(a)

for i in range(n):
    b = int(input())
    if b in numlist:
        for j in range(len(a)):
            if a[j]==b:
                a[j]=0
                break

flag=False
if a[0]==0:
    if a[3]==0 and a[6]==0:
        flag=True
    elif a[1]==0 and a[2]==0:
        flag=True
    elif a[4]==0 and a[8]==0:
        flag=True
elif a[4]==0:
    if a[3] ==0 and a[5]==0:
        flag=True
    if a[1]==0 and a[7]==0:
        flag=True
    if a[6]==0 and a[2]==0:
        flag=True
elif a[8]==0:
    if a[2]==0 and a[5]==0:
        flag=True
    if a[1]==0 and a[2]==0:
        flag=True
    
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
A = [-1]*101
d = []
for i in range(3):
    a,b,c = map(int,input().split())
    d.append(a)
    d.append(b)
    d.append(c)
    A[a] = 0
    A[b] = 0
    A[c] = 0
N = int(input())
b = []
for i in range(N):
    b.append(int(input()))

for i in range(N):
    A[b[i]] += 1

if (A[d[0]]==1 and A[d[1]]==1 and A[d[2]]==1) or (A[d[3]]==1 and A[d[4]]==1 and A[d[5]]==1) or (A[d[6]]==1 and A[d[7]]==1 and A[d[8]]==1) or (A[d[0]]==1 and A[d[3]]==1 and A[d[6]]==1) or (A[d[1]]==1 and A[d[4]]==1 and A[d[7]]==1) or (A[d[2]]==1 and A[d[5]]==1 and A[d[8]]==1) or (A[d[0]]==1 and A[d[4]]==1 and A[d[8]]==1) or (A[d[2]]==1 and A[d[4]]==1 and A[d[6]]==1):
    print("Yes")
else:
    print("No")

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

N = int(input())
B = [0]*N
for i in range(N):
    B[i] = int(input())

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

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

if flag == False:
    if A[0][0] == -1 and A[1][1] == -1 and A[2][2] == -1:
        flag = True
    elif A[0][2] == -1 and A[1][1] == -1 and A[2][0] == -1:
        flag = True

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

Solution (Python):
def resolve():

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

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

    for i in range(3):
        for j in range(3):
            if A[i][j] in B:
                memo[i][j] = 1

    for i in range(3):
        if memo[i][0] == 1 and memo[i][1] == 1 and memo[i][2] == 1:
            print("Yes")
            return
    
    for j in range(3):
        if memo[0][j] == 1 and memo[1][j] == 1 and memo[2][j] == 1:
            print("Yes")
            return

    if memo[0][0] == 1 and memo[1][1] == 1 and memo[2][2] == 1:
        print('Yes')
        return
    
    if memo[0][2] == 1 and memo[1][1] == 1 and memo[2][0] == 1:
        print("Yes")
        return
    
    print("No")


if __name__ == "__main__":
    resolve()