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):
bingo = []
for _ in range(3):
    row = list(map(int,input().split()))
    bingo.append(row)

N = int(input())
bingo_flag = [[False] * 3 for _ in range(3)]
for _ in range(N):
    num = int(input())
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == num:
                bingo_flag[i][j] = True


is_bing = False
for i in range(3):
    if bingo_flag[i][0] and bingo_flag[i][1] and bingo_flag[i][2] or \
            bingo_flag[0][i] and bingo_flag[1][i] and bingo_flag[2][i]:
        is_bing = True
        break

if bingo_flag[0][0] and bingo_flag[1][1] and bingo_flag[2][2] or \
        bingo_flag[0][2] and bingo_flag[1][1] and bingo_flag[2][0]:
    is_bing = True

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

Solution (Python):



def input_one_number():
    return int(input())


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


def input_multiple_number_as_list():
    return list(map(int, input().split()))


a= input_multiple_number_as_list()
b= input_multiple_number_as_list()
c = input_multiple_number_as_list()

n= input_one_number()

for i in range(n):
    bq = input_one_number()
    for j in range(3):
        if a[j] == bq:
            a[j] = -1
        if b[j] == bq:
            b[j] = -1
        if c[j] == bq:
            c[j] = -1

if (a[0] == -1 and b[0] == -1 and c[0] == -1) or(a[1] == -1 and b[1] == -1 and c[1] == -1) or (a[2] == -1 and b[2] == -1 and c[2] == -1) or(a[0] == -1 and a[1] == -1 and a[2] == -1) or(b[0] == -1 and b[1] == -1 and b[2] == -1) or(c[0] == -1 and c[1] == -1 and c[2] == -1) or(a[0] == -1 and b[1] == -1 and c[2] == -1) or(a[2] == -1 and b[1] == -1 and c[0] == -1) :
    print("Yes")
else:
    print("No")

Solution (Python):
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N = int(input())
b = set()
for i in range(N):
  b.add(int(input()))

flag = 0

if (A1[0] in b) and (A1[1] in b) and (A1[2] in b):
  flag = 1

if (A2[0] in b) and (A2[1] in b) and (A2[2] in b):
  flag = 1

if (A3[0] in b) and (A3[1] in b) and (A3[2] in b):
  flag = 1

for col in range(3):
  n = 0
  if (A1[col] in b) and (A2[col] in b) and (A3[col] in b):
    flag = 1

if (A1[0] in b) and (A2[1] in b) and (A3[2] in b):
    flag = 1
if (A1[2] in b) and (A2[1] in b) and (A3[0] in b):
    flag = 1    

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

Solution (Python):
A = [list(map(int,input().split())) for i in range(3)]
N = int(input())
bingo = [[False]*3 for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if b == A[i][j]:
                bingo[i][j] = True

ans = False


for i in range(3):
    if all(bingo[i]):
        print('Yes')
        exit()

for i in range(3):
    if all([bingo[0][i],bingo[1][i],bingo[2][i]]):
        print('Yes')
        exit()

if all([bingo[0][0],bingo[1][1],bingo[2][2]]):
    print('Yes')
    exit()

if all([bingo[0][2],bingo[1][1],bingo[2][0]]):
    print('Yes')
    exit()
print('No')

Solution (Python):


A = []

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

N = int(input())

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

for n in range(N):
	b = int(input())

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

for i in range(3):
	if(Flag[i][0] + Flag[i][1] + Flag[i][2] == 3):
		print('Yes')
		exit(0)

	if(Flag[0][i] + Flag[1][i] + Flag[2][i] == 3):
		print('Yes')
		exit(0)

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

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

print('No')

Solution (Python):
a = [list(map(int, input().split())) for _ in range(3)]
c = [[False for j in range(3)] for i in range(3)]
n = int(input())
ans = False

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

for i in range(3):
    flag1 = 1
    flag2 = 1
    for j in range(3):
        flag1 *= c[i][j]
        flag2 *= c[j][i]
    if flag1 or flag2:
        ans = True
        break

if not ans:
    flag1 = 1
    flag2 = 1
    for i in range(3):
        flag1 *= c[i][i]
        flag2 *= c[i][2 - i]
    if flag1 or flag2:
        ans = True

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

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

a1_a = [0]*3
a2_a = [0]*3
a3_a = [0]*3

for i in range(n):
  for j in range(3):
    if a1[j] == b[i]:
      a1_a[j] = 1
    if a2[j] == b[i]:
      a2_a[j] = 1
    if a3[j] == b[i]:
      a3_a[j] = 1
if sum(a1_a) == 3 or sum(a2_a) == 3 or sum(a3_a) == 3:
  print("Yes")
elif a1_a[0] + a2_a[0] + a3_a[0] == 3:
  print("Yes")
elif a1_a[1] + a2_a[1] + a3_a[1] == 3:
  print("Yes")
elif a1_a[2] + a2_a[2] + a3_a[2] == 3:
  print("Yes")
elif a1_a[0] + a2_a[1] + a3_a[2] == 3:
  print("Yes")
elif a1_a[2] + a2_a[1] + a3_a[0] == 3:
  print("Yes")
else:
  print("No")

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

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

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

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

    print(ans)

if __name__ == '__main__':
    resolve()

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

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

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


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

for i in range(3):
    if ans[i][i]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0

for i in range(3):
    if ans[2-i][i]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0
print("No")

Solution (Python):
def main():
    A = []
    for _ in range(3):
        A.append([int(s) for s in input().strip().split()])
    n = int(input().strip())
    B = []
    for _ in range(n):
        B.append(int(input().strip()))
    
    for row in A:
        for i, x in enumerate(row):
            if x in B:
                row[i] = "*"
    for i in range(3):
        if A[i][0] == A[i][1] == A[i][2] == "*" or A[0][i] == A[1][i] == A[2][i] == "*":
            print("Yes")
            return
    if A[0][0] == A[1][1] == A[2][2] == "*" or A[0][2] == A[1][1] == A[2][0] == "*":
        print("Yes")
        return
    print("No")


main()

Solution (Python):
bingo = []
checker = 0
for i in range(3):
    bingo.append([int(j) for j in input().split()])
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if bingo[j][k] == b:
                bingo[j][k] = 0
for i in range(3):
    if checker == 1:
        break
    if bingo[i][0] ==0 and  bingo[i][1] == 0 and bingo[i][2] == 0:
        checker = 1
    if bingo[0][i] == 0 and bingo[1][i] == 0 and bingo[2][i] == 0:
        checker = 1
    if bingo[0][0] == 0 and  bingo[1][1] == 0 and bingo[2][2] == 0:
        checker = 1
    if bingo[0][2] == 0 and bingo[1][1] == 0 and bingo[2][0] == 0:
        checker = 1

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

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) 

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

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

tables = [[0,0,0] for i in range(3)]
for n in range(N):
    for i in range(3):
        for j in range(3):
            if A[i][j] == b[n]:
                tables[i][j] = 1

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

if ans:
    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 for i in range(3)] for j in range(3)]
for a in B:
    for b in range(3):
        for c in range(3):
            if a==A[b][c]:
                C[b][c]=1
t=0
for i in range(3):
    if C[i][0]*C[i][1]*C[i][2]==1:
        print("Yes")
        t=1
        break
    if C[0][i]*C[1][i]*C[2][i]==1:
        print("Yes")
        t=1
        break
if t==0:
    if C[0][0]*C[1][1]*C[2][2]==1:
        print("Yes")
    elif C[0][2]*C[1][1]*C[2][0]==1:
        print("Yes")
    else:
        print("No")

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






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

b1 = [a1[0], a2[0], a3[0]]
b2 = [a1[1], a2[1], a3[1]]
b3 = [a1[2], a2[2], a3[2]]

c1 = [a1[0], a2[1], a3[2]]
c2 = [a1[2], a2[1], a3[0]]

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

ca1 = 0
ca2 = 0
ca3 = 0
cb1 = 0
cb2 = 0
cb3 = 0
cc1 = 0
cc2 = 0
for x in s:
    if x in a1:
        ca1+=1
    if x in a2:
        ca2+=1
    if x in a3:
        ca3+=1
    if x in b1:
        cb1+=1
    if x in b2:
        cb2+=1
    if x in b3:
        cb3+=1
    if x in c1:
        cc1+=1
    if x in c2:
        cc2+=1

if ca1 == 3:
    print("Yes")
elif ca2 == 3:
    print("Yes")
elif ca3 == 3:
    print("Yes")
elif cb1 == 3:
    print("Yes")
elif cb2 == 3:
    print("Yes")
elif cb3 == 3:
    print("Yes")
elif cc1 == 3:
    print("Yes")
elif cc2 == 3:
    print("Yes")
else:
    print("No")

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

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

flag = 0

if a[0][0] == a[0][1] and a[0][1] == a[0][2]:
    flag = 1
if a[1][0] == a[1][1] and a[1][1] == a[1][2]:
    flag = 1
if a[2][0] == a[2][1] and a[2][1] == a[2][2]:
    flag = 1
if a[0][0] == a[1][0] and a[1][0] == a[2][0]:
    flag = 1
if a[0][1] == a[1][1] and a[1][1] == a[2][1]:
    flag = 1
if a[0][2] == a[1][2] and a[1][2] == a[2][2]:
    flag = 1
if a[0][0] == a[1][1] and a[1][1] == a[2][2]:
    flag = 1
if a[0][2] == a[1][1] and a[1][1] == a[2][0]:
    flag = 1

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

Solution (Python):

A_list = []
A_list.append(list(map(int, input().split())))
A_list.append(list(map(int, input().split())))
A_list.append(list(map(int, input().split())))
N = int(input())

B_list = [[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_list[i][j]:
				B_list[i][j] = True

def check():
	for i in range(3):
		if all(B_list[i]) or all(map(lambda j: B_list[j][i], range(3))):
			return True
	
	if all(map(lambda i : B_list[i][i], range(3))) or all(map(lambda i : B_list[i][2 - i], range(3))):
		return True
	
	return False

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

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

N = int(input())
ans = "No"

for i in range(N):
  B = int(input())
  for j in range(len(A)):
    for k in range(len(A[0])):
      if A[j][k] == B:
        A[j][k] = -1


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

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


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

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

print(ans)

Solution (Python):
a = []
for i in range(3):
    aa = list(map(int, input().split()))
    a.append(aa)
n = int(input())
flag = []
for i in range(3):
    flag.append([0, 0, 0])
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                flag[j][k] = 1
ans = False
for j in range(3):
    if flag[0][j] == 1 and flag [1][j] == 1 and flag[2][j] == 1:
        ans = True
for i in range(3):
    if flag[i][0] == 1 and flag [i][1] == 1 and flag[i][2] == 1:
        ans = True
if flag[0][0] == 1 and flag [1][1] == 1 and flag[2][2] == 1:
        ans = True
if flag[2][0] == 1 and flag [1][1] == 1 and flag[0][2] == 1:
        ans = True
if ans:
    print("Yes")
else:
    print("No")

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

Solution (Python):
a=[list(map(int,input().split())) for _ in range(3)]
f=[[0]*3 for _ in range(3)]
for _ in range(int(input())):
  x=int(input())
  for i in range(3):
    for j in range(3):
      if x==a[i][j]:
        f[i][j]=1
ans=0
for i in range(3):
  if all(f[i][j] for j in range(3)) or all(f[j][i] for j in range(3)):
    ans=1
if f[0][0]==f[1][1]==f[2][2]==1 or f[0][2]==f[1][1]==f[2][0]==1:
  ans=1
print("Yes" if ans else "No")

Solution (Python):
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N = int(input())
B = [int(input()) for _ in range(N)]
ans = False
if A1[0] in B and A2[0] in B and A3[0] in B:
    ans = True
if A1[1] in B and A2[1] in B and A3[1] in B:
    ans = True
if A1[2] in B and A2[2] in B and A3[2] in B:
    ans = True
if A1[1] in B and A1[0] in B and A1[2] in B:
    ans = True
if A2[1] in B and A2[0] in B and A2[2] in B:
    ans = True
if A3[1] in B and A3[0] in B and A3[2] in B:
     ans = True
if A1[0] in B and A2[1] in B and A3[2] in B:
     ans = True
if A3[0] in B and A2[1] in B and A1[2] in B:
     ans = True
if ans:
    print("Yes")
else:
    print("No")

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

for i in range(3):
    A = [ALL[0][i],ALL[1][i],ALL[2][i]]
    ALL.append(A)

ALL.append([ALL[0][0],ALL[1][1],ALL[2][2]])
ALL.append([ALL[0][2],ALL[1][1],ALL[2][0]])

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

j = 0
for i in ALL:
    if i[0] in c and i[1] in c and i[2] in c:
        j = 1
        break

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

Solution (Python):
def main():
    a = [ list(map(int, input().split())) for _ in range(3) ]
    f = [ [ False ]*3 for _ in range(3) ]
    n = int(input())
    for i in range(n):
        b = int(input())
        for y in range(3):
            for x in range(3):
                if a[y][x] == b:
                    f[y][x] = True

    is_bingo = False
    
    for y in range(3):
        is_bingo = all(f[y])
        if is_bingo:
            print("Yes")
            return 0
    
    for x in range(3):
        t = []
        for y in range(3):
            t.append(f[y][x])
        is_bingo = all(t)
        if is_bingo:
            print("Yes")
            return 0

    
    is_bingo = all( [f[0][0], f[1][1], f[2][2]] )
    if is_bingo:
        print("Yes")
        return 0
    is_bingo = all( [f[0][2], f[1][1], f[2][0]] )
    if is_bingo:
        print("Yes")
        return 0
    print("No")

main()

Solution (Python):
import numpy as np

a = np.zeros((3,3))
for i in range(3):
    a[i] = np.asarray(input().split(), dtype=np.int32)

n = int(input())

for i in range(n):
    a[a == int(input())] = 0

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

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

if a1.count(0) == 3 or a2.count(0) == 3 or a3.count(0) == 3:
    print('Yes')
elif a1[0] == 0 and a2[0] == 0 and a3[0] == 0:
    print('Yes')
elif a1[1] == 0 and a2[1] == 0 and a3[1] == 0:
    print('Yes')
elif a1[2] == 0 and a2[2] == 0 and a3[2] == 0:
    print('Yes')
elif a1[0] == 0 and a2[1] == 0 and a3[2] == 0:
    print('Yes')
elif a1[2] == 0 and a2[1] == 0 and a3[0] == 0:
    print('Yes')
else:
    print('No')

Solution (Python):
A = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
res = [[0]*3 for _ in range(3)]
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            res[i][j] = 1
            
for i in res:
    if all(i):
        print('Yes')
        exit()
for i in range(3):
    if res[0][i]==1 and res[1][i]==1 and res[2][i]==1:
        print('Yes')
        exit()
if res[0][0]==1 and res[1][1]==1 and res[2][2]==1:
    print('Yes')
    exit()
if res[0][2]==1 and res[1][1]==1 and res[2][0]==1:
    print('Yes')
    exit()
print('No')

Solution (Python):
def main():
    A = [[int(i) for i in input().split()] for j in range(3)]
    seen = [[False]*3 for j in range(3)]
    N = int(input())
    for i in range(N):
        b = int(input())
        for j in range(3):
            for k in range(3):
                if A[j][k] == b:
                    seen[j][k] = True
    flag = False
    for i in range(3):
        if all(seen[i]):
            flag = True
    for i in range(3):
        if all([seen[0][i], seen[1][i], seen[2][i]]):
            flag = True
    if all([seen[0][0], seen[1][1], seen[2][2]]) or \
            all([seen[0][2], seen[1][1], seen[2][0]]):
        flag = True
    if flag:
        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=[int(input()) for i in range(N)]
x=[[0]*3 for i in range(3)]
for b in B:
    for i,l in enumerate(A):
        for j,a in enumerate(l):
            if a==b:
                x[i][j]=1
print('Yes' if sum([all(l) for l in x]+[all(l) for l in zip(*x)]+[all([x[i][i] for i in range(3)]),all([x[i][2-i] for i in range(3)])]) else 'No')

Solution (Python):
from collections import defaultdict

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

    for i in range(3):
        for j in range(3):
            d[A[i][j]].append(i)
            d[A[i][j]].append(j)

    bingo = [[False] * 3 for _ in range(3)]
    N = int(input())
    for _ in range(N):
        b = int(input())
        if d[b]:
            i, j = d[b]
            bingo[i][j] = True

    for i in range(3):
        flag = True
        for j in range(3):
            if bingo[i][j] == False:
                flag = False
                break
        if flag:
            print('Yes')
            exit()

    for j in range(3):
        flag = True
        for i in range(3):
            if bingo[i][j] == False:
                flag = False
                break
        if flag:
            print('Yes')
            exit()
    
    if bingo[0][0] == True and bingo[1][1] == True and bingo[2][2] == True:
        print('Yes')
        exit()

    if bingo[2][0] == True and bingo[1][1] == True and bingo[0][2] == True:
        print('Yes')
        exit()

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

Solution (Python):
from sys import stdin


def main():
    A1 = [int(x) for x in stdin.readline().rstrip().split()]
    A2 = [int(x) for x in stdin.readline().rstrip().split()]
    A3 = [int(x) for x in stdin.readline().rstrip().split()]
    A4 = [A1[0], A2[0], A3[0]]
    A5 = [A1[1], A2[1], A3[1]]
    A6 = [A1[2], A2[2], A3[2]]
    A7 = [A1[0], A2[1], A3[2]]
    A8 = [A1[2], A2[1], A3[0]]
    As = [A1, A2, A3, A4, A5, A6, A7, A8]
    N = int(stdin.readline().rstrip())
    bs = [int(stdin.readline().rstrip()) for _ in range(N)]
    b = set(bs)
    for A in As:
        a = set(A)
        x = a & b
        if(len(x) == 3):
            print('Yes')
            return
    print('No')


if __name__ == "__main__":
    main()

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

n=int(input())
b=[]
for i in range(n):
    b.append(int(input()))
x=[[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 i in range(8):
    if a[x[i][0]-1] in b and a[x[i][1]-1] in b and a[x[i][2]-1] in b:
        print("Yes")
        sys.exit()
print("No")

Solution (Python):
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
N = int(input())
num = []
for i in range(N):
	n = int(input())
	num.append(n)
chk = []
for i in range(3):
	a = [0]*3
	chk.append(a)
for i in range(3):
	for j in range(3):
		if i == 0:
			if A[j] in num:
				chk[0][j] = 1
		elif i == 1:
			if B[j] in num:
				chk[1][j] = 1
		else:
			if C[j] in num:
				chk[2][j] = 1
if chk[0] == [1,1,1] or chk[1] == [1,1,1] or chk[2] == [1,1,1]:
	print("Yes")
elif chk[0][0] + chk[1][1] + chk[2][2] == 3 :
	print("Yes")
elif chk[0][2] + chk[1][1] + chk[2][0] == 3 :
	print("Yes")
elif chk[0][0] + chk[1][0] + chk[2][0] == 3 :
	print("Yes")
elif chk[0][1] + chk[1][1] + chk[2][1] == 3 :
	print("Yes")
elif chk[0][2] + chk[1][2] + chk[2][2] == 3 :
	print("Yes")
else:
	print("No")

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

Solution (Python):
a1 = input().split(" ")
a2 = input().split(" ")
a3 = input().split(" ")
a = a1 + a2 + a3
for i in range(9):
	a[i] = int(a[i])
n = int(input())
for i in range(n):
	b = int(input())
	for j in range(9):
		if b == a[j]:
			a[j] = 0
l = []
l.append(a[0]+a[1]+a[2])
l.append(a[3]+a[4]+a[5])
l.append(a[6]+a[7]+a[8])
l.append(a[0]+a[3]+a[6])
l.append(a[1]+a[4]+a[7])
l.append(a[2]+a[5]+a[8])
l.append(a[0]+a[4]+a[8])
l.append(a[2]+a[4]+a[6])
if 0 in l:
	print("Yes")
else:
	print("No")

Solution (Python):
bingo = [list(map(int,input().split())) for i in range(3)]
N = int(input())
for _ in range(N):
    n = int(input())
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == n:
                bingo[i][j] = -1

for i in range(3):
    if sum(bingo[i]) == -3:
        print("Yes")
        break
else:
    for i in range(3):
        if bingo[0][i]+bingo[1][i]+bingo[2][i] == -3:
            print("Yes")
            break
    else:
        if bingo[0][0]+bingo[1][1]+bingo[2][2] == -3 or bingo[0][2]+bingo[1][1]+bingo[2][0] == -3:
            print("Yes")
        else:
            print("No")

Solution (Python):
def check(find):
    for i in range(3):
        ok = True
        for j in range(3):
            ok &= find[i][j]
        if ok:
            return True
    for j in range(3):
        ok = True
        for i in range(3):
            ok &= find[i][j]
        if ok:
            return True
    return find[0][0] and find[1][1] and find[2][2] or \
        find[0][2] and find[1][1] and find[2][0]


def main():
    A = [list(map(int, input().split())) for _ in range(3)]
    N = int(input())
    B = [int(input()) for _ in range(N)]
    find = [[False] * 3 for _ in range(3)]
    for b in B:
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    find[i][j] = True
    if check(find):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline
a=[list(map(int,input().split()))for _ in range(3)]
n=int(input())
t=[[0]*3 for i in range(3)]
for _ in range(n):
    b=int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j]==b:
                t[i][j]=1
for i in range(3):
    f=True
    for j in range(3):
        if t[i][j]==0:
            f=False
    if f:
        print("Yes")
        exit()

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

f=True
for i in range(3):
    if t[i][-i-1]==0:
        f=False
if f:
    print("Yes")
    exit()
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 _ in range(N)]

tate = [[a11, a21, a31], [a12, a22, a32], [a13, a23, a33]]
yoko = [[a11, a12, a13], [a21, a22, a23], [a31, a32, a33]]
naname = [[a11, a22, a33], [a13, a22, a31]]

for tripe in tate + yoko + naname:
    a, b, c = tripe
    if a in B and b in B and c in B:
        print("Yes")
        break
else:
    print("No")

Solution (Python):
a = [input().split() for _ in range(3)]
n = int(input())
b = [input() for _ in range(n)]
ans = "No"
flag = [ [False for _ in range(3)] for _ in range(3)]

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

for i in range(3):
    if all((flag[0][i],flag[1][i],flag[2][i])) or all((flag[i][0],flag[i][1],flag[i][2])):
        ans = "Yes"
if all((flag[0][0],flag[1][1],flag[2][2])) or all((flag[0][2],flag[1][1],flag[2][0])): ans = "Yes"
print(ans)

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

for k in range(n):
  tmp = int(input())
  for i in range(3):
    for j in range(3):
      if bingo[i][j] == tmp:
        check[i][j] = 1


flag = False
for i in range(3):
  if check[i][0] == check[i][1] == check[i][2]==1:
    flag = True
for i in range(3):
  if check[0][i] == check[1][i] == check[2][i] == 1:
    flag = True
if check[0][0] == check[1][1] == check[2][2]==1 or check[0][2] == check[1][1] == check[2][0]==1:
  flag = True
    
if flag:
  print("Yes")
else:
  print("No")

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

n = int(input())

l = [[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]:
                l[i][j] = True

ans = "No"

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

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

print(ans)

Solution (Python):

MOD = 10 ** 9 + 7
INFI = 10**10

import math

import itertools



import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

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






def main():
    a=[-1 for i in range(9)]
    a[0],a[1],a[2]=map(int,input().split())
    a[3], a[4], a[5] = map(int, input().split())
    a[6], a[7], a[8] = map(int, input().split())
    n=int(input())
    b=[0 for i in range(9)]
    for i in range(n):
        temp=int(input())
        if temp in a:
            b[a.index(temp)]=1
    ans="No"
    if b[0]+b[1]+b[2]>=3:
        ans="Yes"
    elif b[3]+b[4]+b[5]>=3:
        ans="Yes"
    elif b[6]+b[7]+b[8]>=3:
        ans="Yes"
    elif b[0]+b[3]+b[6]>=3:
        ans="Yes"
    elif b[1]+b[4]+b[7]>=3:
        ans="Yes"
    elif b[2]+b[5]+b[8]>=3:
        ans="Yes"
    elif b[0]+b[4]+b[8]>=3:
        ans="Yes"
    elif b[2]+b[4]+b[6]>=3:
        ans="Yes"
    print(ans)
if __name__ == "__main__":
    main()