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):
import sys
import numpy as np

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

for i in range(3):
    for j in range(N):
        if A[i][0] == n[j]:
            for k in range(N):
                if A[i][1] == n[k]:
                    for l in range(N):
                        if A[i][2] == n[l]:
                            print('Yes')
                            sys.exit()

for i in range(3):
    for j in range(N):
        if A[0][i] == n[j]:
            for k in range(N):
                if A[1][i] == n[k]:
                    for l in range(N):
                        if A[2][i] == n[l]:
                            print('Yes')
                            sys.exit()

for j in range(N):
    if A[0][0] == n[j]:
        for k in range(N):
            if A[1][1] == n[k]:
                for l in range(N):
                    if A[2][2] == n[l]:
                        print('Yes')
                        sys.exit()

for j in range(N):
    if A[2][0] == n[j]:
        for k in range(N):
            if A[1][1] == n[k]:
                for l in range(N):
                    if A[2][0] == n[l]:
                        print('Yes')
                        sys.exit()

print('No')

Solution (Python):
import sys

a_list = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
b_list = [int(input()) for _ in range(n)]
bingo_list = [[0,0,0] for _ in range(3)]

for b in b_list:
    for i,row in enumerate(a_list):
        for j,n in enumerate(row):
            if n == b:
                bingo_list[i][j] = 1

for row in bingo_list:
    if sum(row) == 3:
        print('Yes')
        sys.exit()

for i in range(3):
    num = bingo_list[0][i] + bingo_list[1][i] + bingo_list[2][i]
    if num >= 3:
        print('Yes')
        sys.exit()

if bingo_list[0][0] + bingo_list[1][1] + bingo_list[2][2] >= 3:
    print('Yes')
    sys.exit()

if bingo_list[0][2] + bingo_list[1][1] + bingo_list[2][0] >= 3:
    print('Yes')
    sys.exit()

print('No')

Solution (Python):
list_1 = list(map(int, input().split()))
list_2 = list(map(int, input().split()))
list_3 = list(map(int, input().split()))
list_bingo = list_1 + list_2 + list_3
list_check =[]
n = int(input())
for i in range(n):
    b = int(input())
    if b in list_bingo:
        list_check.append(list_bingo.index(b))
if 0 in list_check and 1 in list_check and 2 in list_check or 3 in list_check and 4 in list_check and 5 in list_check or 6 in list_check and 7 in list_check and 8 in list_check:
    print("Yes")
elif 0 in list_check and 3 in list_check and 6 in list_check or 1 in list_check and 4 in list_check and 7 in list_check or 2 in list_check and 5 in list_check and 8 in list_check:
    print("Yes")
elif 0 in list_check and 4 in list_check and 8 in list_check or 2 in list_check and 4 in list_check and 6 in list_check:
    print("Yes")
else:
    print("No")

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


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


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    a11, a12, a13 = LI()
    a21, a22, a23 = LI()
    a31, a32, a33 = LI()
    n = I()
    b = IR(n)
    if a11 in b and a12 in b and a13 in b:
        print('Yes')
    elif a21 in b and a22 in b and a23 in b:
        print('Yes')
    elif a31 in b and a32 in b and a33 in b:
        print('Yes')
    elif a11 in b and a21 in b and a31 in b:
        print('Yes')
    elif a12 in b and a22 in b and a32 in b:
        print('Yes')
    elif a13 in b and a23 in b and a33 in b:
        print('Yes')
    elif a11 in b and a22 in b and a33 in b:
        print('Yes')
    elif a13 in b and a22 in b and a31 in b:
        print('Yes')
    else:
        print('No')
    return



if __name__ == "__main__":
    solve()

Solution (Python):
a=[list(map(int,input().split()))for _ in range(3)]
for i in range(int(input())):
  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[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):
import sys

a_list = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
b_list = [int(input()) for _ in range(n)]
bingo_list = [[0,0,0] for _ in range(3)]

for b in b_list:
    for i,row in enumerate(a_list):
        for j,n in enumerate(row):
            if n == b:
                bingo_list[i][j] = 1

for row in bingo_list:
    if sum(row) == 3:
        print('Yes')
        sys.exit()

for i in range(3):
    num = bingo_list[0][i] + bingo_list[1][i] + bingo_list[2][i]
    if num >= 3:
        print('Yes')
        sys.exit()

if bingo_list[0][0] + bingo_list[1][1] + bingo_list[2][2] >= 3:
    print('Yes')
    sys.exit()

if bingo_list[0][2] + bingo_list[1][1] + bingo_list[2][0] >= 3:
    print('Yes')
    sys.exit()

print('No')

Solution (Python):
import sys

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

for i in range(0, N, 1):
	b = int(input())
	for j in range(0, 3, 1):
		for k in range(0, 3, 1):
			if b == a[j][k]:
				a[j][k] = 0

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

if a[0][0] == a[1][1] and a[1][1] == a[2][2]:
	print("Yes")
	sys.exit(0)
elif a[0][2] == a[1][1] and a[1][1] == a[2][0]:
	print("Yes")
	sys.exit(0)

print("No")

Solution (Python):


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))

N = int(input())

S = []
for _ in range(N):
    S.append(int(input()))  

for _S in S:
    for _l1 in range(len(l1)):
        if (_S == l1[_l1]):
            l1[_l1] = 0
    for _l2 in range(len(l2)):
        if (_S == l2[_l2]):
            l2[_l2] = 0
    for _l3 in range(len(l3)):
        if (_S == l3[_l3]):
            l3[_l3] = 0

isBingo = "No"
if (sum(l1) == 0 or sum(l2) == 0 or sum(l3) == 0 or l1[0] + l2[0] + l3[0] == 0 or l1[1] + l2[1] + l3[1] == 0 or l1[2] + l2[2] + l3[2] == 0 or l1[0] + l2[1] + l3[2] == 0 or l1[2] + l2[1] + l3[0] == 0):
    isBingo = "Yes"

print(isBingo)

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())
b = [int(input()) for i in range(n)]

for i in b:
    if i in a:
        a[a.index(i)] = 0

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

Solution (Python):
import sys

A11, A12, A13 = map(int, input().split())
A21, A22, A23 = map(int, input().split())
A31, A32, A33 = map(int, input().split())

card = [[A11, A12, A13],
        [A21, A22, A23],
        [A31, A32, A33]]

h = [[0, 0, 0],
     [0, 0, 0],
     [0, 0, 0]]

a = []

for l in sys.stdin:
    a.append(int(l))

for i in a:
    for j in range(3):
        for k in range(3):
            if card[j][k] == i:
                h[j][k] = 1

if max(sum(h[0]), sum(h[1]), sum(h[2])) == 3:
    print("Yes")
elif max((h[0][0] + h[1][0] + h[2][0]), (h[0][1] + h[1][1] + h[2][1]), (h[0][2] + h[1][2] + h[2][2])) == 3:
    print("Yes")
elif max((h[0][0] + h[1][1] + h[2][2]), (h[0][2] + h[1][1] + h[2][0])) == 3:
    print("Yes")
else:
    print("No")

Solution (Python):

import numpy as np


A1,B1,C1 = map(int, input().split())
A2,B2,C2 = map(int, input().split())
A3,B3,C3 = map(int, input().split())

np_arr = np.array([[A1,B1,C1], [A2,B2,C2],[A3,B3,C3]])

bingo_list=(np_arr==-1)

K= int(input())

for num in range(K):
    Z = int(input())
    bingo_list+=(np_arr==Z)





if sum(bingo_list[:,0])==3 or sum(bingo_list[:,1])==3 or sum(bingo_list[:,2])==3 or sum(bingo_list[0,:])==3 or sum(bingo_list[1,:])==3 or sum(bingo_list[2,:])==3 or (bingo_list[0,0]*1+bingo_list[1,1]*1+bingo_list[2,2]*1)==3 or (bingo_list[2,0]*1+bingo_list[1,1]*1+bingo_list[0,2]*1)==3:
    print("Yes")
else:
    print("No")

Solution (Python):
import sys
input = sys.stdin.readline

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

for b in B:
    A = [["hit" if i==b else i for i in a] for a in A]

for w in range(3):
    if all(a=="hit" for a in A[w]):
        print("Yes")
        quit()

for h in range(3):
    if all(A[i][h]=="hit" for i in range(3)):
        print("Yes")
        quit()

if A[0][0]=="hit" and A[1][1]=="hit" and A[2][2]=="hit":
    print("Yes")
    quit()

if A[0][-1]=="hit" and A[1][-2]=="hit" and A[2][-3]=="hit":
    print("Yes")
    quit()

print("No")

Solution (Python):
listA1 = input().split(" ")
listA2 = input().split(" ")
listA3 = input().split(" ")

matrix = [listA1, listA2, listA3]

matrixBool = [[False for i in range(3)] for j in range(3)]

n = int(input())
bingo = False
for i in range(n):
    a = input()

    for l in range(3):
        for j in range(3):

            if matrix[l][j] == a:
                matrixBool[l][j] = True

for l in range(3):
    c = 0
    for i in range(3):
        if matrixBool[l][i] == True:
            c = c+1

    if c == 3:
        bingo = True
        break

for l in range(3):
    c = 0
    for i in range(3):
        if matrixBool[i][l] == True:
            c = c + 1

    if c == 3:
        bingo = True
        break

if (matrixBool[0][0] == True) and (matrixBool[1][1] == True) and (matrixBool[2][2] == True):
    bingo = True


if (matrixBool[0][2] == True) and (matrixBool[1][1] == True) and (matrixBool[2][0] == True):
    bingo = True

if bingo == True:
    print("Yes")
else:
    print("No")

Solution (Python):
list1=list(map(int,input().split()))
list2=list(map(int,input().split()))
list3=list(map(int,input().split()))
n=int(input())
nums = list()
for i in range(n):
    temp = int(input())
    nums.append(temp)

a=list1
a.extend(list2)
a.extend(list3)

a=[i in nums for i in a]
if (a[0] and a[1] and a[2])or \
   (a[3] and a[4] and a[5])or \
   (a[6] and a[7] and a[8])or \
   (a[0] and a[3] and a[6])or \
   (a[1] and a[4] and a[7])or \
   (a[2] and a[5] and a[8])or \
   (a[0] and a[4] and a[8])or \
   (a[2] and a[4] and a[6]):
    print("Yes")
else:
    print("No")

Solution (Python):
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.extend(b)
a.extend(c)

n = int(input())
nums = []
for i in range(n):
  nums.append(int(input()))
  
a = [ i in nums for i in a]
if((a[0] and a[1] and a[2])  or
   (a[3] and a[4] and a[5])  or
   (a[6] and a[7] and a[8])  or
   (a[0] and a[3] and a[6])  or
   (a[1] and a[4] and a[7])  or
   (a[2] and a[5] and a[8])  or
   (a[0] and a[4] and a[8])  or
   (a[2] and a[4] and a[6])):
  print("Yes")
else:
  print("No")

Solution (Python):
list1 = list(map(int,input().split()))
list2 = list(map(int,input().split()))
list3 = list(map(int,input().split()))
n=int(input())
b_list=list(map(int,[input() for i in range(4,n+4)]))


list_all=[list1,list2,list3]

for i in b_list:
    sub={i:'t'}
    list_all = [[sub.get(x,x) for x in inner] for inner in list_all]

if list_all[1][1]=='t':
    if list_all[0][0]=='t' and list_all[2][2]=='t':
        print('Yes')
    elif list_all[0][2]=='t' and list_all[2][0]=='t':
        print('Yes')
    elif list_all[0][1]=='t' and list_all[2][1]=='t':
        print('Yes')
    elif list_all[1][0]=='t' and list_all[1][2]=='t':
        print('Yes')

else:
    if list_all[0][0]=='t' and list_all[1][0]=='t' and list_all[2][0]=='t':
        print('Yes')
    elif list_all[0][0]=='t' and list_all[0][1]=='t' and list_all[0][2]=='t':
        print('Yes')
    elif list_all[0][2]=='t' and list_all[1][2]=='t' and list_all[2][2]=='t':
        print('Yes')
    elif list_all[2][0]=='t' and list_all[2][1]=='t' and list_all[2][2]=='t':
        print('Yes')
    else:
        print('No')

Solution (Python):
ar = []
br = [[],[],[]]
cr = [[],[]]
for i in range(3):
    r = list(map(int,input().split(" ")))
    for i in range(3):
        br[i].append(r[i])
    ar.append(r)
cr[0].append(ar[0][0])
cr[0].append(ar[1][1])
cr[0].append(ar[2][2])
cr[1].append(ar[2][0])
cr[1].append(ar[1][1])
cr[1].append(ar[0][2])
a = int(input())
dr = []
for i in range(a):
    l = int(input())
    dr.append(l)
for rr in ar:
    count = 0
    for r in rr:
        if r in dr:
            count += 1
    if count == 3:
        print("Yes")
        exit()
for rr in br:
    count = 0
    for r in rr:
        if r in dr:
            count += 1
    if count == 3:
        print("Yes")
        exit()
for rr in cr:
    count = 0
    for r in rr:
        if r in dr:
            count += 1
    if count == 3:
        print("Yes")
        exit()
print("No")

Solution (Python):
a1_1, a1_2, a1_3 = map(int, input().split())
a2_1, a2_2, a2_3 = map(int, input().split())
a3_1, a3_2, a3_3 = map(int, input().split())
a_list=[a1_1, a1_2, a1_3, a2_1, a2_2, a2_3, a3_1, a3_2, a3_3]
n = int(input())
b=[]
for i in range(n):
  b_i = int(input())
  b.append(b_i)
  for j in range(len(a_list)):
    if a_list[j] == b_i:
      a_list[j] = -1
if ((a_list[0]==-1 and a_list[1] == -1 and a_list[2] == -1) or
    (a_list[3]==-1 and a_list[4] == -1 and a_list[5] == -1) or
    (a_list[6]==-1 and a_list[7] == -1 and a_list[8] == -1) or
    (a_list[0]==-1 and a_list[3] == -1 and a_list[6] == -1) or
    (a_list[1]==-1 and a_list[4] == -1 and a_list[7] == -1) or
    (a_list[2]==-1 and a_list[5] == -1 and a_list[8] == -1) or
    (a_list[0]==-1 and a_list[4] == -1 and a_list[8] == -1) or
	(a_list[2]==-1 and a_list[4] == -1 and a_list[6] == -1)):
  print("Yes")
else:
  print("No")

Solution (Python):
card = [input().split() for _ in range(3)]
n = int(input())

hit = set()
for _ in range(n):
    b = input()
    for i in range(3):
        for j in range(3):
            if b == card[i][j]:
                hit.add(i * 3 + j + 1)

bingo = [
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9},
    {1, 4, 7},
    {2, 5, 8},
    {3, 6, 9},
    {1, 5, 9},
    {3, 5, 7}
]

for b in bingo:
    if b.issubset(hit):
        print("Yes")
        break
else:
    print("No")

Solution (Python):
A=[]
for i in range(3):
  a,b,c=map(int,input().split())
  A+=[a,b,c]
  
n=int(input())
T=[0]*9
for i in range(n):
  p=int(input())
  if p in A:
    T[A.index(p)]=1
    
if [1,1,1] in [T[0:3],T[3:6],T[6:9],T[0:7:3],T[1:9:3],T[2:9:3],T[0:10:4],T[2:7:2]]:
  print("Yes")
else:
  print("No")

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

N = int(input())
B = []
for j in range(N):
    B.append(int(input()))

res = np.array([int(i in B) for i in A.ravel()]).reshape(3, 3)
diag_sum = res[0, 0] + res[1, 1] + res[2, 2]
diag_sum2 = res[0, 2] + res[1, 1] + res[2, 0]
if (res.sum(axis=0) == 3).any() or (res.sum(axis=1) == 3).any() or diag_sum == 3 or diag_sum2 == 3:
    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)]
ans = [-1] * 9
for i in range(n):
    if b[i] in a[0]:
        ans[a[0].index(b[i])] = 0
    elif b[i] in a[1]:
        ans[a[1].index(b[i]) + 3] = 0
    elif b[i] in a[2]:
        ans[a[2].index(b[i]) + 6] = 0
if (ans[0] == 0 and ans[1] == 0 and ans[2] == 0) or\
   (ans[0] == 0 and ans[3] == 0 and ans[6] == 0) or\
   (ans[3] == 0 and ans[4] == 0 and ans[5] == 0) or\
   (ans[6] == 0 and ans[7] == 0 and ans[8] == 0) or\
   (ans[1] == 0 and ans[4] == 0 and ans[7] == 0) or\
   (ans[2] == 0 and ans[5] == 0 and ans[8] == 0) or\
   (ans[0] == 0 and ans[4] == 0 and ans[8] == 0) or\
   (ans[2] == 0 and ans[4] == 0 and ans[6] == 0):
    print('Yes')
else:
    print('No')

Solution (Python):
if __name__ == '__main__':
    a = [list(map(int, input().split())) for e in range(3)]
    n = int(input())
    b = [int(input()) for _ in range(n)]
    c = 'No'
    for i in range(len(a)):
        for j in range(len(a)):
            if a[i][j] in b:
                a[i][j] = 0

    for i in range(len(a)):
         if {a[i][j] for j in range(len(a))} == {0}:
             c = 'Yes'
         if {a[j][i] for j in range(len(a))} == {0}:
            c = 'Yes'
    if {a[j][j] for j in range(len(a))} == {0}:
        c = 'Yes'
    if {a[-(j+1)][j] for j in range(len(a))} == {0}:
        c = 'Yes'
    print(c)

Solution (Python):
import sys

def main():
    bingo = []
    for i in range(3):
        line = sys.stdin.readline().rstrip('\n').split()
        bingo.append(line[0])
        bingo.append(line[1])
        bingo.append(line[2])

    line = sys.stdin.readline().rstrip('\n')
    N = int(line)

    inputs = []
    for i in range(N):
        line = sys.stdin.readline().rstrip('\n')
        inputs.append(line)

    for i in [0, 3, 6]:
        if (bingo[i] in inputs) and (bingo[i+1] in inputs) and (bingo[i+2] in inputs):
            print('Yes')
            return

    for i in [0, 1, 2]:
        if (bingo[i] in inputs) and (bingo[i+3] in inputs) and (bingo[i+6] in inputs):
            print('Yes')
            return

    if (bingo[0] in inputs) and (bingo[4] in inputs) and (bingo[8] in inputs):
        print('Yes')
        return

    if (bingo[2] in inputs) and (bingo[4] in inputs) and (bingo[6] in inputs):
        print('Yes')
        return

    print('No')

main()

Solution (Python):
B=[];bingo=0
import numpy as np
A=np.zeros((3,3),dtype=int)
for i in range(3):
  a,b,c=map(int,input().split())
  A[i][0]=a
  A[i][1]=b
  A[i][2]=c
N=int(input())
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]=0

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

for i in range(3):
    f = True
    for j in range(3):
        if a[i][j] != 0:
            f = False
            break
    if f:
        print("Yes")
        exit(0)
    
    f = True
    for j in range(3):
        if a[j][i] != 0:
            f = False
            break
    if f:
        print("Yes")
        exit(0)

f = True
for i in range(3):
    if a[i][i] != 0:
        f = False
        break
if f:
    print("Yes")
    exit(0)

f = True
for i in range(3):
    if a[i][2 - i] != 0:
        f = False
        break
if f:
    print("Yes")
    exit(0)

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())
lb = []
for i in range(N):
  lb.append(int(input()))
res = "No"

for i in range(N):
  if A11 == lb[i]:
    A11 = 0
  if A12 == lb[i]:
    A12 = 0
  if A13 == lb[i]:
    A13 = 0
  if A21 == lb[i]:
    A21 = 0
  if A22 == lb[i]:
    A22 = 0
  if A23 == lb[i]:
    A23 = 0
  if A31 == lb[i]:
    A31 = 0
  if A32 == lb[i]:
    A32 = 0
  if A33 == lb[i]:
    A33 = 0
    
if A11 + A12 + A13 == 0 or A21 + A22 + A23 == 0 or A31 + A32 + A33 == 0 or A11 + A21 + A31 == 0 or A12 + A22 + A32 == 0 or A13 + A23 + A33 == 0 or A11 + A22 + A33 == 0 or A13 + A22 + A31 == 0:
    res = "Yes"
    
print(res)

Solution (Python):
from __future__ import print_function

import array
import bisect
import collections
import copy
import fractions
import functools
import heapq
import itertools
import math
import operator
import random
import re
import string
import sys
import time
from collections import Counter, deque
from fractions import Fraction, gcd
from functools import reduce
from heapq import heapify, heappop, heappush, heappushpop, heapreplace
from itertools import accumulate
from operator import mul
from queue import PriorityQueue as pq
from queue import Queue



input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    
    s1 = set()
    s2 = set()
    matrix = []
    matrix_check = [[0 for i in range(3)] for j in range(3)]

    
    for i in range(3):
        l = list(map(int, input().strip().split()))
        s1.update(l)
        matrix.append(l)
    n = int(input().strip())
    a = [0 for i in range(n)]
    for i in range(n):
        a[i] = int(input().strip())
        s2.add(a[i])
    s_union = s1 & s2

    
    for i in range(len(matrix)):
        for j in range(len(matrix[i])):
            if matrix[i][j] in s_union:
                matrix_check[i][j] = 1
    eprint('matrix_check ', end=':\n')
    eprint(matrix_check) 

    
    for i in range(len(matrix_check)):
        if matrix_check[i] == [1, 1, 1] or [row[i] for row in matrix_check] == [1, 1, 1]:
            print("Yes")
            return

    if [matrix_check[i][i] for i in range(3)] == [1,1,1] or [matrix_check[i][-(i+1)] for i in range(3)] == [1,1,1]:
        print("Yes")
        return

    print("No")
    return
    
if __name__ == '__main__':
    main()

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 b[i]==a[j][k]:
                    a[j][k]=0

if a[0][0]+a[0][1]+a[0][2]==0:
    print("Yes")
elif a[1][0]+a[1][1]+a[1][2]==0:
    print("Yes")
elif a[2][0]+a[2][1]+a[2][2]==0:
    print("Yes")
elif a[0][0]+a[1][0]+a[2][0]==0:
    print("Yes")
elif a[0][1]+a[1][1]+a[2][1]==0:
    print("Yes")
elif a[0][2]+a[1][2]+a[2][2]==0:
    print("Yes")
elif a[0][0]+a[1][1]+a[2][2]==0:
    print("Yes")
elif a[2][0]+a[1][1]+a[0][2]==0:
    print("Yes")
else:
    print("No")

Solution (Python):
A = []
for i in range(3):
    A.append(list(input().split()))
N = int(input())
B = []
for i in range(N):
    B.append(input())
B=set(B)
if set(A[0]) <= B or set(A[1]) <= B or set(A[2]) <= B or {A[0][0], A[1][0], A[2][0]} <= B or\
{A[0][1], A[1][1], A[2][1]} <= B or {A[0][2], A[1][2], A[2][2]} <= B \
or {A[0][0], A[1][1], A[2][2]} <= B or {A[0][2], A[1][1], A[2][0]} <= B:
    print("Yes")
else:
    print("No")

Solution (Python):
def resolve():
    a = [input().split() for i in range(3)]
    n = int(input())
    b = [input() for i in range(n)]
    
    r=[[0] * 3 for i in range(3)]
    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
    
    for i in range(3):
        if r[0][i] + r[1][i] + r[2][i] == 3:
            print("Yes")
            return
    for i in range(3):
        if r[i][0] + r[i][1] + r[i][2] == 3:
            print("Yes")
            return
    if r[0][0] + r[1][1] + r[2][2] == 3:
        print("Yes")
        return
    if r[0][2] + r[1][1] + r[2][0] == 3:
        print("Yes")
        return
    print("No")

resolve()

Solution (Python):
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
b = set(b)
g = [0]*9
for i in range(3):
  for j in range(3):
    if a[i][j] in b:
      g[i*3+j] = 1
for i,j,k in [[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6],[0,1,2],[3,4,5],[6,7,8]]:
  if g[i]==g[j]==g[k]==1:
    print('Yes')
    exit()
print('No')

Solution (Python):
a = []
for i in range(3):
    a.append(list(map(int, input().split())))
d = []
for _ in range(int(input())):
    d.append(int(input()))
for i in range(3):
    t = 0
    t2 = 0
    for j in range(3):
        if a[i][j] in d:
            t += 1
        if a[j][i] in d:
            t2 += 1
        if t == 3 or t2 == 3:
            print("Yes")
            exit()
t = 0
t2 = 0
for i in range(3):
    for j in range(3):
        if i == j and a[i][j] in d:
            t += 1
        if i + j == 2  and a[i][j] in d:
            t2 += 1
if t == 3 or t2 == 3:
    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())
x=[a, b, c, d, e, f, g, h, i]
y=[False, False, False, False, False, False, False, False, False]
z=[[0, 1, 2], [3, 4, 5], [6, 7, 8],[0,3,6], [1, 4 ,7], [2, 5, 8], [0, 4, 8], [2, 4,6]]

N = int(input())
for p in range(N):
  n = int(input())
  for q in range(9):
    if n == x[q]:
      y[q]=True
  for r in range(8):
    if y[z[r][0]] and y[z[r][1]] and y[z[r][2]]:
      print('Yes')
      exit()
print('No')

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    import numpy as np

    CARD = np.array(A,dtype=np.int8)

    for i in range(N):
        CARD[CARD==b[i]] = 0   

    CARD = CARD==0

    
    if np.all(CARD,axis=0).sum() > 0:
        print(YES)
        return
    
    if np.all(CARD,axis=1).sum()>0:
        print(YES)
        return
    
    if np.all(np.diag(CARD)):
        print(YES)
        return
    
    if np.all(np.diag(np.fliplr(CARD))):
        print(YES)
        return
    
    print(NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [[int(next(tokens)) for _ in range(3)] for _ in range(3)]  
    N = int(next(tokens))  
    b = [int(next(tokens)) for _ in range(N)]  
    solve(A, N, b)

if __name__ == '__main__':
    main()

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

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

for i in b:
    for j in range(len(a)):
        if a[j] == i:
            a[j] = 0
   
flag = False

for i in [0, 1, 2]:
    if a[i] + a[i + 3] + a[i + 6] == 0:
        flag = True
    elif a[i * 3] + a[i * 3 + 1] + a[i * 3 + 2] == 0:
        flag = True
    elif i == 0 and (a[0] + a[4] + a[8] == 0 or a[2] + a[4] + a[6] == 0):
        flag = True

if flag:
    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()))
if A[0][0] in b and A[0][1] in b and A[0][2] in b:
  print("Yes")
elif A[1][0] in b and A[1][1] in b and A[1][2] in b:
  print("Yes")
elif A[2][0] in b and A[2][1] in b and A[2][2] in b:
  print("Yes")
elif A[0][0] in b and A[1][0] in b and A[2][0] in b:
   print("Yes")
elif A[0][1] in b and A[1][1] in b and A[2][1] in b:
  print("Yes")
elif A[0][2] in b and A[1][2] in b and A[2][2] in b:
  print("Yes")
elif A[0][0] in b and A[1][1] in b and A[2][2] in b:
  print("Yes")
elif A[0][2] in b and A[1][1] in b and A[2][0] in b:
  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 = [[(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),(0,2)]]
for L in Bingo:
  f = True
  for x,y in L:
    if A[x][y] not in b:
      f = False
  if f:
    print ("Yes")
    break
else:
  print ("No")

Solution (Python):
li_1 = list(map(int,input().split()))
li_2 = list(map(int,input().split()))
li_3 = list(map(int,input().split()))
ans = []
n = int(input())
li_b = []
for i in range(n):
  b= int(input())
  if b in li_1:
    id = li_1.index(b)
    ans.append(id)
  if b in li_2:
    id = li_2.index(b) + 3
    ans.append(id)
  if b in li_3:
    id = li_3.index(b) + 6
    ans.append(id)
tf = False
ans.sort()
for i in ans:
  if i ==0 or i==3 or i==6:
    if i+1 in ans:
      if i+2 in ans:
        tf = True
  if i==0 or i==1 or i==2:
    if i+3 in ans:
      if i+6 in ans:
        tf = True
  if 0 in ans:
    if 4 in ans:
      if 8 in ans:
        tf = True
  if 2 in ans:
    if 4 in ans:
      if 6 in ans:
        tf = True
if tf==True:
  print("Yes")
else:
  print("No")

Solution (Python):
bingo = [input().split() for i in range(3)]
card = [[0, 0, 0] for i in range(3)]
n = int(input())
for i in range(n):
    num = str(input())
    for rowNum in range(3):
        for colNum in range(3):
            if bingo[rowNum][colNum] == num:
                card[rowNum][colNum] = 1


for i in range(3):
    s = 0
    for item in card[i]:
        s += int(item)
    if s == 3:
        print('Yes')
        exit()


for colNum in range(3):
    s = 0
    for rowNum in range(3):
        s += int(card[rowNum][colNum])
    if s == 3:
        print('Yes')
        exit()
        

if int(card[0][0]) + int(card[1][1]) + int(card[2][2]) == 3:
    print('Yes')
    exit()
elif int(card[0][2]) + int(card[1][1]) + int(card[2][0]) == 3:
    print('Yes')
    exit()

print('No')