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):
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
n = int(input())

A = [[0,0,0],[0,0,0],[0,0,0]]

for _ in range(n):
    b = int(input())
    if b in A1:
        tmp = A1.index(b)
        A[0][tmp] = 1
    elif b in A2:
        tmp = A2.index(b)
        A[1][tmp] = 1
    elif b in A3:
        tmp = A3.index(b)
        A[2][tmp] = 1

if A[0][0] + A[0][1] + A[0][2] == 3 or A[1][0] + A[1][1] + A[1][2] == 3 or A[2][0] + A[2][1] + A[2][2] == 3:
    print('Yes')
elif A[0][0] + A[1][0] + A[2][0] == 3 or A[0][1] + A[1][1] + A[2][1] == 3 or A[0][2] + A[1][2] + A[2][2] == 3:
    print('Yes')
elif A[0][0] + A[1][1] + A[2][2] == 3 or A[0][2] + A[1][1] + A[2][0] == 3:
    print('Yes')
else:
    print('No')

Solution (Python):
a = list(map(int,input().split()))
a += list(map(int,input().split()))
a += list(map(int,input().split()))
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))
index = 0
for i in a:
  if i in b:
    a[index] = 0
  else:
    next
  index += 1

if (a[0]is a[1]is a[2]is 0)or(a[3]is a[4]is a[5]is 0)or (a[6]is a[7]is a[8]is 0)or(a[0]is a[3]is a[6]is 0)or(a[1]is a[4]is a[7]is 0)or(a[2]is a[5]is a[8]is 0)or(a[0]is a[4]is a[8]is 0)or(a[2]is a[4]is a[6]is 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)]
x = [[False, False, False] for _ in range(3)]

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



flag = False

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

if x[0][0] and x[1][1] and x[2][2]:
    flag = True
elif x[2][0] and x[1][1] and x[0][2]:
    flag = True



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

Solution (Python):
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7

def input():
    return sys.stdin.readline().strip()


import numpy as np

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

    N = int(input())
    for j in range(N):
        b = int(input())
        if b in A:
            bi = A.index(b)
            A[bi] = 0

    arr = np.array(A).reshape(3,3)

    row = arr.sum(axis=0)
    col = arr.sum(axis=1)
    diag = sum(arr.diagonal())
    diag_rev = arr[0, 2] + arr[1, 1] + arr[2, 0]

    for r, c in zip(row, col):
        if r == 0 or c == 0:
            print("Yes")
            return 0
    
    if diag == 0 or diag_rev == 0:
        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 = set(int(input()) for i in range(n))

def check():
    for i in range(3):
        if all(a[i][j] in b for j in range(3)):
            return True
        if all(a[j][i] in b for j in range(3)):
            return True
    return all(a[i][i] in b for i in range(3)) or all(a[2-i][i] in b for i in range(3))

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

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

N = int(input())

S = set(int(input()) for _ in range(N))

def check():
    for i in range(3):
        if all(grid[i][j] in S for j in range(3)):
            return True
        if all(grid[j][i] in S for j in range(3)):
            return True
    return all(grid[i][i] in S for i in range(3)) or all(grid[2-i][i] in S for i in range(3))

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

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())
q=[[0,0,0],[0,0,0],[0,0,0]]
for i in range(n):
    b=int(input())
    for c in range(3):
        for x in range(3):
            if b==a[c][x]:
                q[c][x]=1

result='No'
for t in range(3):
    if q[t][0]==q[t][1]==q[t][2]==1:
        result='Yes'
        break
    elif q[0][t]==q[1][t]==q[2][t]==1:
        result='Yes'
        break
if q[0][0]==q[1][1]==q[2][2]==1:
    result='Yes'
elif q[0][2]==q[1][1]==q[2][0]==1:
        result='Yes'

print(result)

Solution (Python):
def B():
    a = [list(map(int,input().split())) for i in range(3)]
    n = int(input())
    b = [int(input()) for i 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
    if (a[0][0] == a[1][1] == a[2][2] == 0) or (a[0][2] == a[1][1] == a[2][0] == 0):
        print("Yes")
        return
    for i in range(3):
        if all(a[i][j] == 0 for j in range(3)) or all(a[j][i] == 0 for j in range(3)):
            print("Yes")
            return
    print("No")

B()

Solution (Python):
def B():
    a = [list(map(int,input().split())) for i in range(3)]
    n = int(input())
    
    for bingo in  (int(input()) for _ in range(n)):
        for i in range(3):
            for j in range(3):
                if a[i][j] == bingo:
                    a[i][j] = 0
    if (a[0][0] == a[1][1] == a[2][2] == 0) or (a[0][2] == a[1][1] == a[2][0] == 0):
        print("Yes")
        return
    for i in range(3):
        if all(a[i][j] == 0 for j in range(3)) or all(a[j][i] == 0 for j in range(3)):
            print("Yes")
            return
    print("No")
B()

Solution (Python):
def B():
    a = [list(map(int,input().split())) for i in range(3)]
    n = int(input())
    
    for bingo in  (int(input()) for _ in range(n)):
        for i in range(3):
            for j in range(3):
                if a[i][j] == bingo:
                    a[i][j] = 0
    if (a[0][0] == a[1][1] == a[2][2] == 0) or (a[0][2] == a[1][1] == a[2][0] == 0):
        print("Yes")
        return
    for i in range(3):
        if (a[i][0] == a[i][1] == a[i][2] == 0) or (a[0][i] == a[1][i] == a[2][i] == 0):
            print("Yes")
            return
    print("No")
B()

Solution (Python):
def B():
    mat = [list(map(int,input().split())) for i in range(3)]
    n = int(input())
    
    for bingo in  (int(input()) for _ in range(n)):
        for i in range(3):
            for j in range(3):
                if mat[i][j] == bingo:
                    mat[i][j] = 0
    for i in range(3):
        if all(mat[i][j] == 0 for j in range(3)):
            print('Yes')
            break
        if all(mat[j][i] == 0 for j in range(3)):
            print('Yes')
            break
    else:
        if mat[0][0] == mat[1][1] == mat[2][2] == 0 or\
                mat[0][2] == mat[1][1] == mat[2][0] == 0:
            print('Yes')
        else:
            print('No')
B()

Solution (Python):
import numpy as np

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

n = int(input())

b = [0]*n

for i in range(n):
    b[i] = int(input())
    a = np.where(a == b[i], 0, a)

if np.any((a==0).all(axis=0)):
    print('Yes')

elif np.any((a==0).all(axis=1)):
    print('Yes')

elif a[1,1] == 0:
    if (a[0,0]==0) or (a[2,2]==0):
        print('Yes')
    elif (a[0,2]==0) or (a[2,0]==0):
        print('Yes')

else:
    print('No')

Solution (Python):
A,B,C=map(int,input().split())
D,E,F=map(int,input().split())
G,H,I=map(int,input().split())
N=int(input())
for i in range(N):
    b=int(input())
    if b==A:
        A=0
    if b==B:
        B=0
    if b==C:
        C=0
    if b==D:
        D=0
    if b==E:
        E=0
    if b==F:
        F=0
    if b==G:
        G=0
    if b==H:
        H=0
    if b==I:
        I=0



if A==0 and B==0 and C==0 or D==0 and E==0 and F==0 or G==0 and H==0 and I==0 or A==0 and D==0 and G==0 or B==0 and E==0 and H==0 or C==0 and F==0 and I==0 or A==0 and E==0 and I==0 or C==0 and E==0 and G==0:
    print("Yes")
else:
    print("No")

Solution (Python):
A = []
for i in range(3):
  As = list(map(int, input().split()))
  A.append(As)
N = int(input())
bs = set()
for i in range(N):
  b = int(input())
  bs.add(b)
D = [[False]*3 for i in range(3)]
for i in range(3):
  for j in range(3):
    if A[i][j] in bs:
      D[i][j] = True
if D[0][0] and D[0][1] and D[0][2]:
  print("Yes")
elif D[1][0] and D[1][1] and D[1][2]:
  print("Yes")
elif D[2][0] and D[2][1] and D[2][2]:
  print("Yes")
elif D[0][0] and D[1][0] and D[2][0]:
  print("Yes")
elif D[0][1] and D[1][1] and D[2][1]:
  print("Yes")
elif D[0][2] and D[1][2] and D[2][2]:
  print("Yes")
elif D[0][0] and D[1][1] and D[2][2]:
  print("Yes")
elif D[2][0] and D[1][1] and D[0][2]:
  print("Yes")
else:
  print("No")

Solution (Python):
a, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, i = map(int, input().split())
L = []
L.append({a, b, c})
L.append({d, e, f})
L.append({g, h, i})
L.append({a, d, g})
L.append({b, e, h})
L.append({c, f, i})
L.append({a, e, i})
L.append({c, e, g})
N = int(input())
B = {int(input()) for i in range(N)}
if any(l <= B for l in L):
  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())
N = int(input())
b = [int(input()) for i in range(N)] 

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

for j in Bingo:
  if set(j).issubset(b):
    print('Yes')
    exit()

print('No')

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


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    A = [list(readnums()) for _ in range(3)]
    c = [[False] * 3 for _ in range(3)]
    N = readint()
    for i in range(N):
        a = readint()
        pos = [(x, y) for y, row in enumerate(A) for x, elem in enumerate(row) if A[x][y] == a]
        if pos:
            x, y = pos[0]
        else:
            continue
        c[x][y] = True

    if all(c[0]) or all(c[1]) or all(c[2]) or all([x[0] for x in c]) or all([x[1] for x in c]) or all([x[2] for x in c]) or all([x[i] for i, x in enumerate(c)]) or all([x[2 - i] for i, x in enumerate(c)]):
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()

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


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    A = [list(readnums()) for _ in range(3)]
    c = [[False] * 3 for _ in range(3)]
    N = readint()
    for i in range(N):
        a = readint()
        pos = [(x, y) for y, row in enumerate(A) for x, elem in enumerate(row) if A[x][y] == a]
        if pos:
            x, y = pos[0]
        else:
            continue
        c[x][y] = True

    if all(c[0]) or all(c[1]) or all(c[2]) or all([c[0][0], c[1][0], c[2][0]]) or all([c[0][1], c[1][1], c[2][1]]) or all([c[0][2], c[1][2], c[2][2]]) or all([c[0][0], c[1][1], c[2][2]]) or all([c[2][0], c[1][1], c[0][2]]):
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()

Solution (Python):
li2 = [input() for i in range(3)]
a = []
for i in range(3):
    a.append([int(x.strip()) for x in li2[i].split()])
bingo = [[0, 0, 0] for i in range(3)]

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


def atari(z):
    for x in range(3):
        for y in range(3):
            if a[x][y] == z:
                bingo[x][y] = 1


for i in range(n):
    atari(b[i])

ans = 0


def check(z1, z2, z3):
    if z1 == 1 and z2 == 1 and z3 == 1:
        global ans
        ans = 1




for i in range(3):
    check(bingo[i][0], bingo[i][1], bingo[i][2])
    check(bingo[0][i], bingo[1][i], bingo[2][i])

check(bingo[0][0], bingo[1][1], bingo[2][2])
check(bingo[2][0], bingo[1][1], bingo[0][2])


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

Solution (Python):
li2 = [input() for i in range(3)]
a = []
for i in range(3):
    a.append([int(x.strip()) for x in li2[i].split()])
bingo = [[0, 0, 0] for i in range(3)]

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


def atari(z):
    for x in range(3):
        for y in range(3):
            if a[x][y] == z:
                bingo[x][y] = 1


for i in range(n):
    atari(b[i])

ans = 0


def check(z1, z2, z3):
    if z1 == 1 and z2 == 1 and z3 == 1:
        global ans
        ans = 1




for i in range(3):
    check(bingo[i][0], bingo[i][1], bingo[i][2])
    check(bingo[0][i], bingo[1][i], bingo[2][i])

check(bingo[0][0], bingo[1][1], bingo[2][2])
check(bingo[2][0], bingo[1][1], bingo[0][2])


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

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

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

for i in range(N):
    b = int(input())
    for j in range(3):
        A[j] = ["$" if num == b else num for num in A[j]]

if ["$"]*3 in A:
    print("Yes")
elif any( [A[j][i] for j in range(3)] == ["$"]*3 for i in range(3) ):
    print("Yes")
elif [A[0][0], A[1][1], A[2][2]] == ["$"]*3 \
            or [A[0][2], A[1][1], A[2][0]] == ["$"]*3:
    print("Yes")
else:
    print("No")

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

n = int(input())
for i in range(n):
    num = input()
    try:
        for y, row in enumerate(bingo):
            try:
                pos = (y, row.index(num))
                break
            except:
                pass
        bingo[pos[0]][pos[1]] = False
    except:
        pass

for i in range(3):
    if not any(bingo[i]):
        print("Yes")
        exit()
for i in range(3):
    if not (bingo[0][i] or bingo[1][i] or bingo[2][i]):
        print("Yes")
        exit()
if not(bingo[0][0] or bingo[1][1] or bingo[2][2]):
    print("Yes")
    exit()
if not(bingo[0][2] or bingo[1][1] or bingo[2][0]):
    print("Yes")
    exit()
print("No")

Solution (Python):
import numpy as np

def my_index(l, x, default=-1):
    if x in l:
        return l.index(x)
    else:
        return default

def resolve():
    ansM = np.zeros((3,3))
    A1 = list(map(int,input().split()))
    A2 = list(map(int,input().split()))
    A3 = list(map(int,input().split()))
    A2.extend(A3)
    A1.extend(A2)
    N = int(input())
    for i in range(N):
        Bi = int(input())
        Q = my_index(A1,Bi)
        if Q >= 0:
            ansM[Q//3,Q%3] = 1
    bg = np.zeros(8)
    bg[0] = sum(ansM[0,:]) // 3
    bg[1] = sum(ansM[1,:]) // 3
    bg[2] = sum(ansM[2,:]) // 3
    bg[3] = sum(ansM[:,0]) // 3
    bg[4] = sum(ansM[:,1]) // 3
    bg[5] = sum(ansM[:,2]) // 3
    bg[6] = (ansM[0,0] + ansM[1,1] + ansM[2,2]) // 3
    bg[7] = (ansM[0,2] + ansM[1,1] + ansM[2,0]) // 3
    if sum(bg) > 0:
        print("Yes")
    else:
        print("No")
resolve()

Solution (Python):
import sys

def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))

A = []
B = [[0,0,0],[0,0,0],[0,0,0]]
ans = "No"
for i in range(3):A.append(ILI())
n = int(input())
for k in range(n):
	b = int(input())
	for i in range(3):
		for j in range(3):
			if A[i][j] == b:B[i][j]=1
B2 = list(zip(*B))
for i in range(3):
	if sum(B[i])==3 or sum(B2[i])==3:
		ans = "Yes"
if B[0][0]+B[1][1]+B[2][2]==3:ans="Yes"
if B[0][2]+B[1][1]+B[2][0]==3:ans="Yes"
print(ans)

Solution (Python):
def main():
    bingo = []
    for i in range(3):
        tmp = list(map(int, input().strip().split()))
        for j in range(3):
            bingo.append(tmp[j])

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

    flag = False

    for i in range(3):
        if (bingo[0+3*i]+bingo[1+3*i]+bingo[2+3*i])==0:
            flag = True

    for i in range(3):
        if (bingo[0+i]+bingo[3+i]+bingo[6+i])==0:
            flag = True

    if (bingo[0]+bingo[4]+bingo[8])==0:
        flag = True
    if (bingo[2]+bingo[4]+bingo[6])==0:
        flag = True

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

main()

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

if (sum(a) == 0) or (sum(b) == 0) or (sum(c) == 0):
    print("Yes")
    exit(0)

for h in range(3):
    if a[h]+b[h]+c[h] == 0:
        print("Yes")
        exit(0)

hh = a[0]+b[1]+c[2]
ee = a[2]+b[1]+c[0]
if (hh == 0) or (ee == 0):
    print("Yes")
    exit(0)

print("No")

Solution (Python):
a = [[0 for j in range(3)] for w in range(3)]
s = [[0 for h in range(3)] for t in range(3)]
ans = 'No'

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

n = int(input())

for k in range(n):
    b = int(input())
    for x in range(0,3,1):
        for y in range(0,3,1):
            if a[x][y] == b:
                s[x][y] = 1

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

print(ans)

Solution (Python):
A = list(map(int, input().split()))
A += list(map(int, input().split()))
A += list(map(int, input().split()))
N = int(input())

bingo = [False]*9

for i in range(N):
    b = int(input())
    if b in A:
        bingo[A.index(b)] = True

for i in range(3):
    if bingo[i*3:(i+1)*3] == [True]*3:
        print("Yes")
        break
    elif bingo[i:7+i:3] == [True]*3:
        print("Yes")
        break
else:
    if ([bingo[0]] + [bingo[4]] + [bingo[8]]) == [True]*3:
        print("Yes")
    elif ([bingo[2]] + [bingo[4]] + [bingo[6]]) == [True]*3:
        print("Yes")
    else:
        print("No")

Solution (Python):
A = [[int(i) for i in input().split()] for i in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]
 
d  = [[0]*3 for i in range(3)]
 
for B in b:
  for i in range(3):
    for j in range(3):
      if A[i][j]==B:
        d[i][j] = 1
 
ans = "No"
for i in range(3):
  if d[i][0]==d[i][1]==d[i][2]==1:
    ans = "Yes"
    break
  elif d[0][i]==d[1][i]==d[2][i]==1:
    ans = "Yes"
    break
if d[0][0]==d[1][1]==d[2][2]==1:
  ans ="Yes"
elif d[2][0]==d[1][1]==d[0][2]==1:
  ans ="Yes"
print(ans)

Solution (Python):
A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]
C = [[False]*3 for _ in range(3)]
for i in B:
    for j in range(3):
        for k in range(3):
            if A[j][k]==i:
                C[j][k]=True
def bingo(C):
    for i in range(3):
        if C[i][0]==C[i][1]==C[i][2]==True:
            return True
    for i in range(3):
        if C[0][i]==C[1][i]==C[2][i]==True:
            return True
    if C[0][0]==C[1][1]==C[2][2]==True:
        return True
    if C[2][0]==C[1][1]==C[0][2]==True:
        return True
if bingo(C):
    print("Yes")
else:
    print("No")

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

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

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

answer = "No"
for i in range(3):
  if data[i][0]==data[i][1]==data[i][2]==1:
    answer = "Yes"
    break
  elif data[0][i]==data[1][i]==data[2][i]==1:
    answer = "Yes"
    break
if data[0][0]==data[1][1]==data[2][2]==1:
  answer ="Yes"
elif data[2][0]==data[1][1]==data[0][2]==1:
  answer ="Yes"
print(answer)

Solution (Python):
def main():
    A = [[0]*3 for _ in range(3)]
    for i in range(3):
        A[i] = list(map(int, input().split()))
    N = int(input())
    hittable = [[False]*3 for _ in range(3)]
    for _ in range(N):
        b = int(input())
        for i in range(3):
            for j in range(3):
                if b==A[i][j]:
                    hittable[i][j]=True
    
    if hittable[0][0] and hittable[1][0] and hittable[2][0]:
        print("Yes")
    elif hittable[0][1] and hittable[1][1] and hittable[2][1]:
        print("Yes")
    elif hittable[0][2] and hittable[1][2] and hittable[2][2]:
        print("Yes")
    elif hittable[0][0] and hittable[0][1] and hittable[0][2]:
        print("Yes")
    elif hittable[1][0] and hittable[1][1] and hittable[1][2]:
        print("Yes")
    elif hittable[2][0] and hittable[2][1] and hittable[2][2]:
        print("Yes")
    elif hittable[0][0] and hittable[1][1] and hittable[2][2]:
        print("Yes")
    elif hittable[0][2] and hittable[1][1] and hittable[2][0]:
        print("Yes")
    else:
        print("No")

main()

Solution (Python):
import math
def main():
    a = list(map(int, input().split()))
    a.extend(list(map(int, input().split())))
    a.extend(list(map(int, input().split())))
    n = int(input())
    for _ in range(n):
        x = int(input())
        a = [True if i == x else i for i in a]
    a = [False if i != True else True for i in a]
    if all(a[0:3]) or all(a[3:6]) or all(a[6:]):
        print("Yes")
    elif all(a[0::3]) or all(a[1::3]) or all(a[2::3]):
        print("Yes")
    elif all(a[0::4]) or all(a[2:7:2]):
        print("Yes")
    else:
        print("No")
    

if __name__ == '__main__':
    main()

Solution (Python):
import sys

Data = []
Status = [[0]*3 for _ in range(3)]
for i in range(3):
    Data.append(list(map(int,input().split())))
N = int(input())
for i in range(N):
    b = int(input())
    
    for y in range(3):
        for x in range(3):
            if b == Data[y][x]:
                Status[y][x] = 1

for y in range(3):
    if Status[y][0] == 1 and Status[y][1] == 1 and Status[y][2] == 1:
        print('Yes')
        sys.exit()
for x in range(3):
    if Status[0][x] == 1 and Status[1][x] == 1 and Status[2][x] == 1:
        print('Yes')
        sys.exit()
if Status[0][0] == 1 and Status[1][1] == 1 and Status[2][2] == 1:
    print('Yes')
    sys.exit()
if Status[0][2] == 1 and Status[1][1] == 1 and Status[2][0] == 1:
    print('Yes')
    sys.exit()
print('No')

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

for x in b:
    for i in range(3):
        for j in range(3):
            if x == a[i][j]:
                a[i][j] = -1
ans = 'No'
for i in range(3):
    if a[i][0] == a[i][1] and a[i][1] == a[i][2]:
        ans = 'Yes'

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

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

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

print(ans)

Solution (Python):
def inlt():
    return(list(map(int, input().split())))


def inp():
    return(int(input()))


A = []
for t in range(3):
    A.append(inlt())

n = inp()
for t in range(n):
    b = inp()
    
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A[i][j] = 0
res = "No"

for i in range(3):
    s = 0
    for j in range(3):
        s += A[i][j]
    if s == 0:
        res = "Yes"
        break

for i in range(3):
    s = 0
    for j in range(3):
        s += A[j][i]
    if s == 0:
        res = "Yes"
        break

s = 0
for i in range(3):
    for j in range(3):
        if i == j:
            s += A[j][i]
if s == 0:
    res = "Yes"

s = 0
for i in range(3):
    for j in range(3):
        if i == j:
            s += A[j][i]
if s == 0:
    res = "Yes"

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

print(res)

Solution (Python):

a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
for x in b:
    for i in range(3):
        for j in range(3):
            if a[i][j] == x:
                a[i][j] = 0
ans = False
if all(a[i][i] == 0 for i in range(3)):
    ans = True
if all(a[i][~i] == 0 for i in range(3)):
    ans = True
for i in range(3):
    if all(a[i][j] == 0 for j in range(3)):
        ans = True
    if all(a[j][i] == 0 for j in range(3)):
        ans = True
print(["No", "Yes"][ans])

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

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

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

if a[0][0] == 0 and a[1][1] == 0 and a[2][2]==0:
    ans = 'Yes'
elif a[0][2] == 0 and a[1][1] == 0 and a[2][0]==0:
    ans = 'Yes'
else: 
    for l in a:
        if sum(l)==0:
            ans = 'Yes'
            break
    for l in zip(*a):
        if sum(l)==0:
            ans = 'Yes'
            break
        

print(ans)

Solution (Python):
a1x = [int(x) for x in input().split(' ')]
a2x = [int(x) for x in input().split(' ')]
a3x = [int(x) for x in input().split(' ')]

sheet = [a1x, a2x, a3x]

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

for i in range(n):
    num = int(input())
    numbers.append(num)

def solve(n, sheet, numbers):
    for number in numbers:
        for row in range(3):
            for column in range(3):
                if sheet[row][column] == number:
                    sheet[row][column] = "X"

    if checkRow(sheet) or checkColumn(sheet) or checkDiagonals(sheet):
        print("Yes")
    else:
        print("No")

def checkRow(sheet):
    for row in range(3):
        marked = 0
        for column in range(3):
            if sheet[row][column] == "X":
                marked += 1
        if marked == 3:
            return True
    
    return False
            
def checkColumn(sheet):
    for row in range(3):
        marked = 0
        for column in range(3):
            if sheet[column][row] == "X":
                marked += 1
        if marked == 3:
            return True
    
    return False

def checkDiagonals(sheet):
    marked = 0
    for i in range(3):
        if sheet[i][i] == "X":
            marked += 1

    if marked != 3:
        marked = 0
        for j in range(3):
            if sheet[j][2-j] == "X":
                marked += 1
    
    if marked == 3:
        return True
    else:
        return False

    

solve(n, sheet, numbers)

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

bingo = False
for i in range(3):
    if grid[i][0] == grid[i][1] == grid[i][2] == 0:
        bingo = True
for i in range(3):
    if grid[0][i] == grid[1][i] == grid[2][i] == 0:
        bingo = True
if grid[0][0] == grid[1][1] == grid[2][2] == 0:
    bingo = True
if grid[0][2] == grid[1][1] == grid[2][0] == 0:
    bingo = True

if bingo:
    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 ck in b:
    for i in range(3):
        for j in range(3):
            if ck == A[i][j]:
                A[i][j] = 0

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

Solution (Python):
def resolve():
    a=[-1]
    for  _ in range(3):
        a.extend(list(map(int,input().split())))
    n=int(input())
    for _ in range(n):
        b=int(input())
        if b in a:
            a[a.index(b)]=0
    if a[1]==a[2]==a[3]==0 or a[4]==a[5]==a[6]==0 or a[7]==a[8]==a[9]==0 or a[1]==a[4]==a[7]==0 or a[2]==a[5]==a[8] or a[3]==a[6]==a[9]==0 or a[1]==a[5]==a[9]==0 or a[3]==a[5]==a[7]==0:
        print("Yes")
    else:
        print("No")        
resolve()

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

for i in b:
    if i in a:
        x = a.index(i)
        c[x] = 1

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