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 unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(
            think(
                [
                    [84, 97, 66],
                    [79, 89, 11],
                    [61, 59, 7]
                ],
                [89, 7, 87, 79, 24, 84, 30]
            ),
            'Yes'
        )

    def test_2(self):
        self.assertEqual(
            think(
                [
                    [41, 7, 46],
                    [26, 89, 2],
                    [78, 92, 8]
                ],
                [6, 45, 16, 57, 17]
            ),
            'No'
        )

    def test_3(self):
        self.assertEqual(
            think(
                [
                    [60, 88, 34],
                    [92, 41, 43],
                    [65, 73, 48]
                ],
                [60, 43, 88, 11, 48, 73, 65, 41, 92, 34]
            ),
            'Yes'
        )


def solve():
    a, b = read()
    result = think(a, b)
    write(result)


def read():
    a = []
    for _ in range(3):
        a.append(read_int(3))
    b = []
    n = read_int(1)[0]
    for _ in range(n):
        b.append(read_int(1)[0])
    return a, b


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a, b):
    check_mark = 0
    for q in b:
        for row in a:
            for i, cell in enumerate(row):
                if cell == q:
                    row[i] = check_mark
    return 'Yes' if is_bingo(a, check_mark) else 'No'


def write(result):
    print(result)


def is_bingo(a, check_mark):
    rows = len(a)
    cols = len(a[0])

    for y in range(rows):
        if is_bingo_found_in_row(a, y, check_mark):
            return True

    for x in range(cols):
        if is_bingo_found_in_col(a, x, check_mark):
            return True

    if is_bingo_found_in_diagonal(a, check_mark):
        return True
    return False


def is_bingo_found_in_row(a, y, check_mark):
    row = a[y]
    return all(map(lambda x: x == check_mark, row))


def is_bingo_found_in_col(a, x, check_mark):
    col = []
    for row in a:
        col.append(row[x])
    return all(map(lambda x: x == check_mark, col))


def is_bingo_found_in_diagonal(a, check_mark):
    rows = len(a)
    cols = len(a[0])
    if rows != cols:
        return False

    diagonal = []
    for i in range(rows):
        diagonal.append(a[i][i])
    if all(map(lambda x: x == check_mark, diagonal)):
        return True

    diagonal = []
    for i in range(rows):
        diagonal.append(a[i][rows - i - 1])
    if all(map(lambda x: x == check_mark, diagonal)):
        return True

    return False


if __name__ == '__main__':
    
    solve()

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

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())
b_list=[]
for i in range(N):
  b_list.append(int(input()))
 
for i in b_list:
  A1 = [x if x != i else -1 for x in A1]
  A2 = [y if y != i else -1 for y in A2]
  A3 = [z if z != i else -1 for z in A3]
 
if sum(A1)==-3 or sum(A2)==-3 or sum(A3)==-3:
  print('Yes')
  sys.exit()
for t in range(3):
  if A1[t]+A2[t]+A3[t] == -3:
    print('Yes')
    sys.exit()
if A1[0]+A2[1]+A3[2] == -3 or A1[2]+A2[1]+A3[0] == -3:
  print('Yes')
  sys.exit()
print('No')

Solution (Python):
import numpy as np

A=np.zeros((3,3),dtype=int)
B=np.zeros((3,3),dtype=int)


for i in range(3):
    A[i][0],A[i][1],A[i][2]=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 A[i][j]==b:
                B[i][j]=1


ans=False


for i in range(3):
    cnt=0
    for j in range(3):
        cnt+=B[i][j]
    if cnt==3:
        ans=True


for i in range(3):
    cnt=0
    for j in range(3):
        cnt+=B[j][i]
    if cnt==3:
        ans=True


cnt=0
for i in range(3):
    cnt+=B[i][i]
if cnt==3:
    ans=True


cnt=0
for i in range(3):
    cnt+=B[i][2-i]
if cnt==3:
    ans=True

if ans==True:
    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()))
d = [a[0],b[0],c[0]]
e = [a[1],b[1],c[1]]
f = [a[2],b[2],c[2]]
g = [a[0],b[1],c[2]]
h = [a[2],b[1],c[0]]

n = int(input())

bs = []
for _ in range(n):
    bs.append(int(input()))
       
for l in [a,b,c,d,e,f,g,h]:
    if (l[0] in bs) and (l[1] in bs) and (l[2] in bs):
        print("Yes")
        break
else:
    print("No")

Solution (Python):
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
d = [a[0],b[0],c[0]]
e = [a[1],b[1],c[1]]
f = [a[2],b[2],c[2]]
g = [a[0],b[1],c[2]]
h = [a[2],b[1],c[0]]

n = int(input())

bs = []
for _ in range(n):
    bs.append(int(input()))

for l in [a,b,c,d,e,f,g,h]:
    if (l[0] in bs) and (l[1] in bs) and (l[2] in bs):
        print("Yes")
        break
else:
        print("No")

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

bingo = [[False] * 3, [False] * 3, [False] * 3]

for i in range(3):
    for j in range(3):
        for x in range(N):
            if A[i][j] == B[x]:
                bingo[i][j] = True
ans = 'No'

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

print(ans)

Solution (Python):
size = 3
A_list = [[]] * size
A_list[0] = list(map(int, input().split(' ')))
A_list[1] = list(map(int, input().split(' ')))
A_list[2] = list(map(int, input().split(' ')))
N = int(input())
b_list = [int(input()) for _ in range(N)]
bingo_flag = False
for i in range(size):
    count = 0
    for j in range(size):
        if A_list[i][j] in b_list:
            count += 1
        else:
            break
    if count == size:
        bingo_flag = True
        break
if not bingo_flag:
    for j in range(size):
        count = 0
        for i in range(size):
            if A_list[i][j] in b_list:
                count += 1
            else:
                break
        if count == size:
            bingo_flag = True
            break
if not bingo_flag:
    count = 0
    for i in range(size):
        if A_list[i][i] in b_list:
            count += 1
        else:
            break
    if count == 3:
        bingo_flag = True
if not bingo_flag:
    count = 0
    for i in range(size):
        j = size - 1 - i
        if A_list[i][j] in b_list:
            count += 1
        else:
            break
    if count == size:
        bingo_flag = True
if bingo_flag:
    print('Yes')
else:
    print('No')

Solution (Python):
A = [[0]*3]*3
for i in range(3):
    A[i] = list(map(int,input().split()))
N = int(input())
for _ in range(N):
    a = int(input())
    for i in range(3):
        if a in A[i]:
            A[i][A[i].index(a)] = 0
for i in range(3):
    if A[i].count(0) == 3:
        print("Yes")
        exit()
for i in range(3):
    if A[0][i] == 0 and A[1][i] == 0 and A[2][i] == 0:
        print("Yes")
        exit()
for i in range(3):
    if A[i][i] != 0:
        break
    if i == 2:
        print("Yes")
        exit()
if A[2][0] == 0 and A[1][1] == 0 and A[0][2] == 0:
    print("Yes")
    exit()
print("No")

Solution (Python):
from sys import exit, stdin
A = [list(map(int, stdin.readline().rstrip().split())) for _ in range(3)]
bin_A = [[0]*3 for _ in range(3)]
N = int(stdin.readline().rstrip())
B = [int(stdin.readline().rstrip()) for _ in range(N)]
for i in range(N):
    for j in range(3):
        for k in range(3): 
            if A[j][k] == B[i]:
                bin_A[j][k] = 1
ans = 'No'
for i in range(3):
    if bin_A[i][0] + bin_A[i][1] + bin_A[i][2] == 3:
        ans = 'Yes'
for j in range(3):
    if bin_A[0][j] + bin_A[1][j] + bin_A[2][j] == 3:
        ans = 'Yes'
if bin_A[0][0] + bin_A[1][1] + bin_A[2][2] == 3:
    ans = 'Yes'
if bin_A[0][2] + bin_A[1][1] + bin_A[2][0] == 3:
    ans = 'Yes'
print(ans)

Solution (Python):
l=[list(map(int,input().split())) for i in range(3)]
n=int(input())
H=[0,0,0]
W=[0,0,0]
S=[0,0]

for i in range(n):
    b=int(input())
    for h in range(3):
        for w in range(3):
            if b==l[h][w]:
                H[h]+=1
                W[w]+=1
                if h==w:
                    S[0]+=1
                if h+w==2:
                    S[1]+=1

check=False
for h in H:
    if h==3:
        check=True
for w in W:
    if w==3:
        check=True
for s in S:
    if s==3:
        check=True

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

Solution (Python):
import numpy as np
N_1=list(map(int, input().split()))
N_2=list(map(int, input().split()))
N_3=list(map(int, input().split()))
N=int(input())
a=[int(input()) for i in range(N)]

n=np.array([N_1,N_2,N_3])

for a_n in a:
    if a_n in n:
        n[n==a_n]=0
    else:
        pass
i=0
    
if np.all(n[0:,0]==0)==True:
    i=+1
    
elif np.all(n[0:,1]==0)==True:
    i+=1
    
elif np.all(n[0:,2]==0)==True:
    i+=1
    
elif np.all(n[0,0:]==0)==True:
    i+=1
    
elif np.all(n[1,0:]==0)==True:
    i+=1

elif np.all(n[2,0:]==0)==True:
    i+=1

elif n[0,0]==0 and n[1,1]==0  and n[2,2] ==0:
    i+=1
    
elif n[0,2]==0 and n[1,1]==0 and n[2,0] ==0:
    i+=1
    
if i>0:
    print("Yes")
else:
    print("No")

Solution (Python):

bingo_card = list()
for i in range(3):
    bingo_card.append(input().split(' '))

pick_count = int(input().strip())

picked_number = list()
for j in range(pick_count):
    picked_number.append(input().strip())


bingo_line = list()

for i in range(3):
    bingo_line.append(bingo_card[i-1])

bingo_line.append([bingo_card[0][0], bingo_card[1][0], bingo_card[2][0]])
bingo_line.append([bingo_card[0][1], bingo_card[1][1], bingo_card[2][1]])
bingo_line.append([bingo_card[0][2], bingo_card[1][2], bingo_card[2][2]])

bingo_line.append([bingo_card[0][0], bingo_card[1][1], bingo_card[2][2]])
bingo_line.append([bingo_card[0][2], bingo_card[1][1], bingo_card[2][0]])

established_line = [line for line in bingo_line if len(set(line) & set(picked_number)) == 3]
print('Yes' if len(established_line) > 0 else 'No')

Solution (Python):
import sys

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

n = int(input())
bs = list()
for ii in range(0,n):
    bs.append(int(input()))

for b in bs:
    for ii in range(0,3):
        for jj in range(0,3):
            if bingo[ii][jj] == b:
                bingo[ii][jj] = 0

for ii in range(0,3):
    tmp_row = 0
    tmp_col = 0
    for jj in range(0,3):
        tmp_row = tmp_row + bingo[ii][jj]
        tmp_col = tmp_col + bingo[jj][ii]

    if (tmp_row == 0) or (tmp_col == 0):
        print('Yes')
        sys.exit()

ob1 = bingo[0][0] + bingo[1][1] + bingo[2][2]
ob2 = bingo[0][2] + bingo[1][1] + bingo[2][0]

if (ob1 == 0) or (ob2 == 0):
    print('Yes')
    sys.exit()

print('No')

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

X = []
X += [set(A[i]) for i in range(3)]
X += [set([A[j][i] for j in range(3)]) for i in range(3)]
X += [set([A[0][2], A[1][1], A[2][0]]), set([A[2][2], A[1][1], A[0][0]])]

for x in X:
  if x <= B:
    print('Yes')
    break
else:
  print('No')

Solution (Python):
def bingo(marked):
    for i in range(3):
        all_marked = True
        for j in range(3):
            if not marked[i][j]:
                all_marked = False
        if all_marked:
            return True
    
    for i in range(3):
        all_marked = True
        for j in range(3):
            if not marked[j][i]:
                all_marked = False
        if all_marked:
            return True
    
    all_marked = True
    for i in range(3):
        if not marked[i][i]:
            all_marked = False
    if all_marked:
        return True
    
    all_marked = True
    for i in range(3):
        if not marked[2 - i][i]:
            all_marked = False
    if all_marked:
        return True

    return False
            
A = [[] for i in range(3)]
marked=  [[False 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 i in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                marked[i][j] = True
                
if bingo(marked):
    print("Yes")
else:
    print("No")

Solution (Python):
import numpy as np

A = np.array([list(map(int, input().split())) for _ in range(3)])
N = int(input())
for _ in range(N):
    b = int(input())
    A[np.where(A == b)] = -1

if -3 in np.sum(A, axis=1) or -3 in np.sum(A, axis=0):
    print("Yes")
elif A[0, 0] + A[1, 1] + A[2, 2] == -3:
    print("Yes")
elif A[0, 2] + A[1, 1] + A[2, 0] == -3:
    print("Yes")
else:
    print("No")

Solution (Python):
bingoDict = {}
bingoList = []
pos = 0
mark = 0 


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


for row in range(len(bingoList)):
  for item in range(len(bingoList[row])):
    pos += 1
    tempList = [] 
    tempList.append(bingoList[row][item])
    tempList.append(0)
    bingoDict[pos] = tempList


N = int(input())


for i in range(N):
  numCalled = int(input())
  for key in bingoDict:
    if numCalled == bingoDict[key][0]:
      bingoDict[key][1] += 1


  
for key in bingoDict:
  if (key == 1 or key == 4 or key == 7) and key + 2 <= 9:
    if bingoDict[key][1] and bingoDict[key + 1][1] and bingoDict[key + 2][1] >= 1:
      mark = 1
  if key + 6 <= 9:
    if bingoDict[key][1] and bingoDict[key + 3][1] and bingoDict[key + 6][1] >= 1:
      mark = 1
  if key == 1:
    if bingoDict[key][1] and bingoDict[key + 4][1] and bingoDict[key + 8][1] >= 1:
      mark = 1
  if key == 3:
    if bingoDict[key][1] and bingoDict[key + 2][1] and bingoDict[key + 4][1] >= 1:
      mark = 1

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

Solution (Python):
dic={}
a=[]
for i in range(1,100):
    dic[i]=[-1,-1]
for i in range(3):
    a.append(list(map(int,input().split())))
    for j in range(3):
        dic[a[i][j]]=[i,j]
n=int(input())
for i in range(n):
    x=int(input())
    if(dic[x]!=[-1,-1]):
        a[dic[x][0]][dic[x][1]]=0
flag=0
for i in range(3):
    if(max(a[i][1],a[i][2],a[i][0])==0):
        flag=1
        break
    elif(max(a[1][i],a[2][i],a[0][i])==0):
        flag=1
        break
if(max(a[0][0],a[1][1],a[2][2])==0):
    flag=1
elif(max(a[0][2],a[1][1],a[2][0])==0):
    flag=1
if(flag==1):
    print ('Yes')
else:
    print ('No')

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

for i in range(3):
	for j in range(3):
		C[i][j]=False
		for k in range(N):
			if A[i][j]==B[k]:
				C[i][j]=True
answer="No"
for i in range(3):
	if (C[i][0] and C[i][1] and C[i][2]):
		answer="Yes"
	if (C[0][i] and C[1][i] and C[2][i]):
		answer="Yes"
if (C[0][0] and C[1][1] and C[2][2]):
	answer="Yes"
if (C[2][0] and C[1][1] and C[0][2]):
	answer="Yes"
print(answer)

Solution (Python):

def check(grid):
	bingo=False
	
	for i in range(3):
		count=0
		for j in range(3):
			if grid[i][j]==1:
				count+=1
		if count==3:
			bingo=True
	
	for i in range(3):
		count=0
		for j in range(3):
			if grid[j][i]==1:
				count+=1
		if count==3:
			bingo=True
	
	count=0
	for i in range(3):
		if grid[i][i]==1:
			count+=1
	if count==3:
		bingo=True
	
	count=0
	for i in range(3):
		if grid[i][2-i]==1:
			count+=1
	if count==3:
		bingo=True
		
	return bingo
		
pos={}
for i in range(3):
	temp=list(map(int,input().split(' ')))
	for j,t in enumerate(temp):
		pos[t]=[i,j]
grid=[[0 for i in range(3)] for j in range(3)]

n=int(input())
for i in range(n):
	t=int(input())
	if t in pos.keys():
		r,c=pos[t]
		grid[r][c]=1
bingo=check(grid)

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

Solution (Python):
def resolve():
    a, b, c = map(int, input().split())
    d, e, f = map(int, input().split())
    g, h, i = map(int, input().split())
    bingo = [a, b, c, d, e, f, g, h, i]
    n = int(input())
    s=0
    for i in range(n):
        z = int(input())
        if z in bingo:
            index = bingo.index(z)
            bingo[index] = 0

    a = bingo[0]
    b = bingo[1]
    c = bingo[2]
    d = bingo[3]
    e = bingo[4]
    f = bingo[5]
    g = bingo[6]
    h = bingo[7]
    i = bingo[8]

    if a + b + c == 0 or d + e + f == 0 or g + h + i == 0 or a + d + g == 0 or b + e + h == 0 or c + f + i == 0 or a + e + i == 0 or c + e + g == 0:
        print("Yes")
    else:
        print("No")
resolve()

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

for i in range(N):
    b = int(input())
    if b in A:
        n = A.index(b)
        A[n] = '*'

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    A = [tuple(map(int, input().split())) for _ in range(3)]
    N = int(input())
    B = [int(input()) for _ in range(N)]

    ans = [[[] for _ in range(3)] for _ in range(3)]
    for i in range(3):
        for j, a in enumerate(A[i]):
            ans[i][j] = a in B

    yes = []
    for i in range(3):
        yes.append(all(ans[i]))
        yes.append(all([ans[0][i], ans[1][i], ans[2][i]]))
    yes.append(all([ans[0][0], ans[1][1], ans[2][2]]))
    yes.append(all([ans[2][0], ans[1][1], ans[0][2]]))

    if any(yes):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    A = [list(map(int, input().split())) for _ in range(3)]
    n = int(input())
    b = [int(input()) for _ in range(n)]
    
    
    
    outs = [[False for _ in range(3)] for _ in range(3)]
    is_bingo = False
    for i in range(3):
        for j in range(3):
            outs[i][j] = A[i][j] in b
    
    
    for i in range(3):
        is_bingo = outs[i][:] == [True for _ in range(3)]
        if is_bingo:
            return "Yes"

    
    for i in range(3):
        is_bingo = [outs[j][i] for j in range(3)] == [True for _ in range(3)]
        if is_bingo:
            return "Yes"
    
    is_bingo = [outs[i][i] for i in range(3)] == [True for _ in range(3)]
    if is_bingo:
        return "Yes"
    is_bingo = [outs[i][-i-1] for i in range(3)] == [True for _ in range(3)]
    if is_bingo:
        return "Yes"
    return "No"

if __name__ == "__main__":
    print(main())

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

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

ans = 'No'                      
count = 0


for i in range(3):
    if ans == 'Yes':            
        break;                  
    count = 0
    for j in range(3):
        count += d[i][j]
        if count == 3:          
            ans = 'Yes'         


for i in range(3):
    if ans == 'Yes':
        break;
    count = 0
    for j in range(3):
        count += d[j][i]
    if count == 3:
        ans = 'Yes'             



count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][i]
    if count == 3:
        ans = 'Yes'             


count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][2 - i]
    if count == 3:              
        ans = 'Yes'
            

print(ans)

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

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

ans = 'No'                      
count = 0

ans = 'No'
for i in range(3):
    if ans == 'Yes':
        break;
    count = 0
    for j in range(3):
        count += d[i][j]
        if count == 3:
            ans = 'Yes'
        
for i in range(3):
    if ans == 'Yes':
        break;
    count = 0
    for j in range(3):
        count += d[j][i]
    if count == 3:
        ans = 'Yes'



count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][i]
    if count == 3:
        ans = 'Yes'


count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][2 - i]
    if count == 3:
        ans = 'Yes'
            

print(ans)

Solution (Python):

import collections


class Solution:
    def solve(self, A, N, B):
        mark = [[False for _ in range(3)] for _ in range(3)]
        bSet = set(B)

        for i, row in enumerate(A):
            for j, val in enumerate(row):
                if val in bSet:
                    mark[i][j] = True

        for row in mark:
            if all(row):
                return True

        for i in range(3):
            isMarked = True

            for j in range(3):
                isMarked &= isMarked & mark[j][i]

            if isMarked:
                return True

        isMarked = True

        
        for i in range(3):
            isMarked &= isMarked & mark[i][i]

        if isMarked:
            return True

        isMarked = True

        
        for i in range(3):
            isMarked &= isMarked & mark[i][3-i-1]

        return isMarked


sol = Solution()

A = []

for j in range(3):
    A.append(list(map(int, input().strip().split())))

N = int(input().strip())
B = []

for i in range(N):
    B.append(int(input().strip()))

print("Yes" if sol.solve(A, N, B) else "No")

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

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

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

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

print(ans)

Solution (Python):
A = []

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

N = int(input())

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

judge = 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:
    judge += 1

for i in range(3):
    
    if A[i][0] in b and A[i][1] in b and A[i][2] in b:
        judge += 1
        break

    
    elif A[0][i] in b and A[1][i] in b and A[2][i] in b:
        judge += 1
        break

if judge >= 1:
    print("Yes")
else:
    print("No")

Solution (Python):



def yoko(A):
    f = False
    for i in range(3):
        if len(set(A[i]))==1:f = True
    return f

def tate(A):
    f = False
    for i in range(3):
        B = [A[0][i],A[1][i],A[2][i]]
        if len(set(B))==1: f = True
    return f


def naname(A):
    f = False
    B = [A[0][0],A[1][1],A[2][2]]
    if len(set(B))==1: f = True
    B = [A[0][2], A[1][1], A[2][0]]
    if len(set(B))==1: f = True

    return f


A = []

A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))

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

F1 = tate(A)
F2 = yoko(A)
F3 = naname(A)


if F1 or F2 or F3: print('Yes')
else: print('No')

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

field = [[False for _ in range(3)] for _ in range(3)]
for x in b:
    for i in range(3):
        for j in range(3):
            if x == numbers[i][j]:
                field[i][j] = True

for i in range(3):
    bingo = True
    for j in range(3):
        bingo &= field[i][j]
    if bingo:
        print('Yes')
        exit()

for j in range(3):
    bingo = True
    for i in range(3):
        bingo &= field[i][j]
    if bingo:
        print('Yes')
        exit()

bingo = True
for i in range(3):
    bingo &= field[2-i][i]
if bingo:
    print('Yes')
    exit()
bingo = True
for i in range(3):
    bingo &= field[i][i]
if bingo:
    print('Yes')
    exit()

print('No')

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

for k in range(n):
    b = int(input())
    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 ans == 'Yes':
        break;
    count = 0
    for j in range(3):
        count += d[i][j]
        if count == 3:
            ans = 'Yes'
            break;

count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count = 0
    for j in range(3):
        count += d[j][i]
    if count == 3:
        ans = 'Yes'
        break;

count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][i]
    if count == 3:
        ans = 'Yes'

count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][2 - i]
    if count == 3:
        ans = 'Yes'
            

print(ans)

Solution (Python):
a = []
for i in range(3):
  a.append([int(i) for i in input().split()])
n = int(input())
b = []
for i in range(n):
  x = int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k] == x:
        a[j][k] = 0
if a[0][0] == a[1][1] == a[2][2] == 0:
  print("Yes")
elif a[0][2] == a[1][1] == a[2][0] == 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][2] == 0:
  print("Yes")
elif a[0][2] == a[1][2] == a[2][2] == 0:
  print("Yes")
elif 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")
else:
  print("No")

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

for k in range(n):
    b = int(input())
    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 ans == 'Yes':
        break;
    count = 0
    for j in range(3):
        count += d[i][j]
        if count == 3:
            ans = 'Yes'
            break;

count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count = 0
    for j in range(3):
        count += d[j][i]
    if count == 3:
        ans = 'Yes'
        break;

count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][i]
    if count == 3:
        ans = 'Yes'

count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][2 - i]
    if count == 3:
        ans = 'Yes'
            

print(ans)

Solution (Python):
card = []

for _ in range(3):
  card.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 card[i][j] == b:
        card[i][j] = -1
        
def bingo(card):
  for row in card:
    if all(x == -1 for x in row):
      return True
  
  for j in range(3):
    if card[0][j] == -1 and card[1][j] == -1 and card[2][j] == -1:
      return True
    
  if card[0][0] == -1 and card[1][1] == -1 and card[2][2] == -1:
    return True
  
      
  if card[0][2] == -1 and card[1][1] == -1 and card[2][0] == -1:
    return True

  return False

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

Solution (Python):
a = []
for i in range(3):
  inp = [int(x) for x in input().split()]
  a.append(inp)
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))
for i in range(n):
  for j in range(3):
    for k in range(3):
      if a[j][k] == b[i]:
        a[j][k] = 0
if a[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')