Problem:
 Score : 200 points    Problem Statement We have a bingo card with a 3\times3 grid. The square at the i -th row from the top and the j -th column from the left contains the number A_{i, j} .  The MC will choose N numbers, b_1, b_2, \cdots, b_N . If our bingo sheet contains some of those numbers, we will mark them on our sheet.  Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.      Constraints  All values in input are integers.  1 \leq A_{i, j} \leq 100  A_{i_1, j_1} \neq A_{i_2, j_2} ((i_1, j_1) \neq (i_2, j_2))  1 \leq N \leq 10  1 \leq b_i \leq 100  b_i \neq b_j (i \neq j)         Input Input is given from Standard Input in the following format:  A_{1, 1}  A_{1, 2}  A_{1, 3}  A_{2, 1}  A_{2, 2}  A_{2, 3}  A_{3, 1}  A_{3, 2}  A_{3, 3}  N  b_1  \vdots  b_N       Output If we will have a bingo, print Yes ; otherwise, print No .        Sample Input 1 84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30      Sample Output 1 Yes  We will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3} , and complete the diagonal from the top-left to the bottom-right.       Sample Input 2 41 7 46
26 89 2
78 92 8
5
6
45
16
57
17      Sample Output 2 No  We will mark nothing.       Sample Input 3 60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34      Sample Output 3 Yes  We will mark all the squares.

Solution (Python):
A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
if N<=2:
  print('No')
for i in range(N):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if b==A[j][k]:
        A[j][k]=101
        
judge = False
for i in range(3):
  if sum(A[i])==303:
    judge = True
    
for i in range(3):
  if (A[0][i]+A[1][i]+A[2][i])==303:
    judge = True

if (A[0][0]+A[1][1]+A[2][2])==303:
  judge = True

if (A[0][2]+A[1][1]+A[2][0])==303:
  judge = True
  
if judge:
  print('Yes')
else:
  print('No')

Solution (Python):


x1 = list(map(int, input().split()))
x2 = list(map(int, input().split()))
x3 = list(map(int, input().split()))
x = x1 + x2 + x3
n = int(input())
a = [0] * 9
for i in range(0, n):
    b = int(input())
    if b in x:
        a[x.index(b)] = 1

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

Solution (Python):
l = []

l += list(map(int, input().split()))
l += list(map(int, input().split()))
l += list(map(int, input().split()))

n = int(input())

check = [0]*9

for i in range(n):
    b = int(input())
    if b in l:
        check[l.index(b)] = 1

h1 = check[0]*check[1]*check[2]
h2 = check[3]*check[4]*check[5]
h3 = check[6]*check[7]*check[8]

v1 = check[0]*check[3]*check[6]
v2 = check[1]*check[4]*check[7]
v3 = check[2]*check[5]*check[8]

d1 = check[0]*check[4]*check[8]
d2 = check[2]*check[4]*check[6]

if h1+h2+h3+v1+v2+v3+d1+d2:
    print('Yes')
else:
    print('No')

Solution (Python):
a = []
for i in range(3):
    line = list(map(int, input().split()))
    a.append(line)
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
bingo = False
for i in range(3):
    if a[i][0] == 0 and a[i][1] == 0 and a[i][2] == 0: bingo = True
    if a[0][i] == 0 and a[1][i] == 0 and a[2][i] == 0: bingo = True
if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0: bingo = True
if a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0: bingo = True

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

Solution (Python):


def solve():
    A1s = list(map(int, input().split()))
    A2s = list(map(int, input().split()))
    A3s = list(map(int, input().split()))
    As = []
    As.append(A1s)
    As.append(A2s)
    As.append(A3s)
    N = int(input())
    bingo = [[False for _ in range(3)] for __ in range(3)]

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

        for i in range(3):
            for j in range(3):
                if b == As[i][j]:
                    bingo[i][j] = True

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



if __name__ == "__main__":
    solve()

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 = [[False] * 3 for i in range(3)]
for bi in b:
    for j in range(3):
        for i in range(3):
            if A[j][i] == bi:
                C[j][i] = True

ans = False
for j in range(3):
    if C[j][0] == C[j][1] == C[j][2] == True:
        ans = True
for i in range(3):
    if C[0][i] == C[1][i] == C[2][i] == True:
        ans = True
if C[0][0] == C[1][1] == C[2][2] == True:
    ans = True
if C[0][2] == C[1][1] == C[2][0] == True:
    ans = True
print('Yes' if ans else 'No')

Solution (Python):


A=[]
Bingo=[]
for i in range(3):
    row=list(map(int,input().split()))
    A.append(row)
    Bingo.append([0,0,0])

N=int(input())

for i in range(N):
    num=int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k]==num:
                Bingo[j][k]=1
flg=False
for i in range(3):
    if sum(Bingo[i])==3:
        flg=True

for i in range(3):
    if Bingo[0][i]+Bingo[1][i]+Bingo[2][i]==3:
        flg=True
if Bingo[0][0]+Bingo[1][1]+Bingo[2][2]==3:
    flg=True

if Bingo[0][2]+Bingo[1][1]+Bingo[2][0]==3:
    flg=True

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

Solution (Python):
import itertools

A = list(itertools.chain.from_iterable([list(map(int,input().split())) for i in range(3)]))
N = int(input())
for i in range(N):
    b = int(input())
    if b in A:
        A[A.index(b)] = 0

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

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

Solution (Python):
import math
def main():
    A_1 = list(map(int, input().split()))
    A_2 = list(map(int, input().split()))
    A_3 = list(map(int, input().split()))

    A = [A_1, A_2, A_3]


    N = int(input())

    for _ in range(N):
        b = int(input())
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    A[i][j] = 0

    if sum(A[0]) == 0:
        print("Yes")
    elif sum(A[1]) == 0:
        print("Yes")
    elif sum(A[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")

    return 0
if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)

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

N = int(input())

OPEN = []
for _ in range(N):
    b = int(input())

    if b in A:
        OPEN.append(A.index(b))



ans = 'No'

if 0 in OPEN:
    if 1 in OPEN and 2 in OPEN:
        print('Yes')
        exit()

    if 3 in OPEN and 6 in OPEN:
        print('Yes')
        exit()

    if 4 in OPEN and 8 in OPEN:
        print('Yes')
        exit()

if 1 in OPEN:
    if 4 in OPEN and 7 in OPEN:
        print('Yes')
        exit()

if 2 in OPEN:
    if 5 in OPEN and 8 in OPEN:
        print('Yes')
        exit()

    if 4 in OPEN and 6 in OPEN:
        print('Yes')
        exit()

if 3 in OPEN:
    if 4 in OPEN and 5 in OPEN:
        print('Yes')
        exit()

if 6 in OPEN:
    if 7 in OPEN and 8 in OPEN:
        print('Yes')
        exit()

print('No')
exit()

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

cnt = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

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

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

print('No')

Solution (Python):
x = [                                                        
  list(map(int, input().split()))                            
  for i in range(3)                                          
]                                                            
                                                             
lines = list()                                               
for i in range(3):                                           
  lines.append(set(x[i]))                                    
  lines.append(set(x[j][i] for j in range(3)))               
                                                             
lines.append({x[i][i] for i in range(3)})                    
lines.append({x[2 - i][i] for i in range(3)})                
                                                             
                                                             
                                                             
z = set()                                                    
for i in range(int(input())):                                
  z.add(int(input()))                                        
                                                             
                                                             
for line in lines:                                           
  if len(z & line) == 3:                                     
    print("Yes")                                             
    break                                                    
else:                                                        
  print("No")

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

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

flg=False
for i in range(3):
    if sum(A[i])==0:
        flg=True
        break
    if sum(np.transpose(A)[i])==0:
        flg=True
        break
if A[0][0]+A[1][1]+A[2][2]==0:
    flg=True
if A[0][2]+A[1][1]+A[2][0]==0:
    flg=True

if flg:
    print('Yes')
else:
    print('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()))

m = a1 + a2 + a3

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

if ((m[0] in b and m[1] in b and m[2] in b) or
    (m[3] in b and m[4] in b and m[5] in b) or
    (m[6] in b and m[7] in b and m[8] in b) or
    (m[0] in b and m[3] in b and m[6] in b) or
    (m[1] in b and m[4] in b and m[7] in b) or
    (m[2] in b and m[5] in b and m[8] in b) or
    (m[0] in b and m[4] in b and m[8] in b) or
    (m[2] in b and m[4] in b and m[6] in b)):
  print('Yes')
  
else:
  print('No')

Solution (Python):

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

def isBingo(A):
  
  for i in range(3):
    if sum(A[i])==3:
      return True
  
  for i in range(3):
    if A[0][i]+A[1][i]+A[2][i]==3:
      return True
  
  if A[0][0]+A[1][1]+A[2][2]==3:
    return True
  if A[0][2]+A[1][1]+A[2][0]==3:
    return True
  
  return False


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


if isBingo(B):
  print('Yes')
else:
  print('No')

Solution (Python):
a = []
for i in range(3):
    a += list(map(int, input().split()))
c = [False] * 9
n = int(input())
for i in range(n):
    b = int(input())
    if b in a:
        c[a.index(b)] = True
d = [[c[0], c[1], c[2]], [c[3], c[4], c[5]], [c[6], c[7], c[8]], [c[0], c[3], c[6]], [c[1], c[4], c[7]], [c[2], c[5], c[8]], [c[0], c[4], c[8]], [c[2], c[4], c[6]]]
if [True, True, True] in d:
    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()))
n=int(input())
number=[int(input()) for i in range(n)]

ac=[False]*3
bc=[False]*3
cc=[False]*3

for i in number:
    for x in range(3):
        if i==a[x]:
            ac[x]=True
        if i==b[x]:
            bc[x]=True
        if i==c[x]:
            cc[x]=True

if all(ac) or all(bc) or all(cc):
    print('Yes')
    exit()
for i in range(3):
    if ac[i]==True and bc[i]==True and cc[i]==True:
        print('Yes')
        exit()
if ac[0]==True and bc[1]==True and cc[2]==True:
    print('Yes')
    exit()
if ac[2]==True and bc[1]==True and cc[0]==True:
    print('Yes')
    exit()
print('No')

Solution (Python):
A=[]
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
A3=list(map(int,input().split()))
A=[A1,A2,A3]
N=int(input())
B=[]
for _ in range(N):
    B.append(int(input()))
X=[[0,0,0],[0,0,0],[0,0,0]]
for b in B:
    for a in A:
        for i in range(3):
            if a[i]==b:
                X[A.index(a)][i]=1
bin=False
if [1,1,1] in X:
    bin =True
if X[0][0] == X[1][0] and X[2][0] == X[1][0] and X[0][0]==1:
    bin=True
if X[0][1] == X[1][1] and X[2][1] == X[1][1] and X[0][1]==1:
    bin=True
if X[0][2] == X[1][2] and X[2][2] == X[1][2] and X[0][2]==1:
    bin=True
if X[0][0] == X[1][1] and X[2][2] == X[1][1] and X[0][0]==1:
    bin=True
if X[2][0] == X[1][1] and X[2][0] == X[1][1] and X[2][0]==1:
    bin=True
print('Yes' if bin else 'No')

Solution (Python):
import sys
from math import factorial


def main(S):
    pass


if __name__ == '__main__':
    A = []
    B = [0] * 9
    for i in range(3):
        A += list(map(int, input().split()))
    n = int(input())

    for i in range(n):
        tmp = int(input())
        for j in range(9):
            if A[j] == tmp:
                B[j] = 1
    ans = 0
    for i in range(3):
        if (B[0 + 3 * i] == 1 and B[1 + 3 * i] == 1 and B[2 + 3 * i] == 1):
            ans = 1
    for i in range(3):
        if (B[0 + i] == 1 and B[3 + i] == 1 and B[6 + i] == 1):
            ans = 1
    if (B[0] == 1 and B[4] == 1 and B[8] == 1):
        ans = 1
    if (B[2] == 1 and B[4] == 1 and B[6] == 1):
        ans = 1

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

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

n = int(input())
for _ in range(n):
    b = int(input())
    try:
        i = aaa.index(b)
    except:
        continue
    if i >= 0:
        aaa[i] = -1
for i, j, k in [(0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6)]:
    if aaa[i] == -1 and aaa[j] == -1 and aaa[k] == -1:
        print('Yes')
        break
else:
    print('No')

Solution (Python):

a11, a12, a13 = map(int, input().split())
a21, a22, a23 = map(int, input().split())
a31, a32, a33 = map(int, input().split())

a_list = [a11, a12, a13, a21, a22, a23, a31, a32, a33]
open_list = [False] * 9

n = int(input())

b_list = []

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

for item in b_list:
    for i in range(len(a_list)):
        if a_list[i] == item:
            open_list[i] = True

if (open_list[0] and open_list[1] and open_list[2]) or (open_list[3] and open_list[4] and open_list[5]) or (open_list[6] and open_list[7] and open_list[8]) or (open_list[0] and open_list[3] and open_list[6]) or (open_list[1] and open_list[4] and open_list[7]) or (open_list[2] and open_list[5] and open_list[8]) or (open_list[0] and open_list[4] and open_list[8]) or (open_list[2] and open_list[4] and open_list[6]):
    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()))

b = [0 for i in range(9)]

n = int(input())

for i in range(n):
    k = int(input())
    for j in range(9):
        if k == a[j]:
            b[j] = 1
            break
ok = [[0,1,2],[3,4,5],[6,7,8],[0,4,8],[2,4,6],[0,3,6],[1,4,7],[2,5,8]]

clear = 0
for ok_i in ok:
    flag = 1
    for ok_i_j in ok_i:
        if b[ok_i_j] == 0:
            flag = 0
            break
    if flag == 1:
        print("Yes")
        clear = 1
        break
if clear == 0:
    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())

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

f = -1
if (0 in ans) and (1 in ans) and (2 in ans):
     f = 1

elif (3 in ans) and (4 in ans) and (5 in ans):
     f = 1

elif (6 in ans) and (7 in ans) and (8 in ans):
     f = 1

elif (0 in ans) and (3 in ans) and (6 in ans):
     f = 1

elif (1 in ans) and (4 in ans) and (7 in ans):
     f = 1

elif (2 in ans) and (5 in ans) and (8 in ans):
     f = 1

elif (0 in ans) and (4 in ans) and (8 in ans):
     f = 1

elif (2 in ans) and (4 in ans) and (6 in ans):
     f = 1

print("Yes" if f == 1 else "No")

Solution (Python):
A = []
A.append([int(i) for i in input().split()])
A.append([int(i) for i in input().split()])
A.append([int(i) for i in input().split()])
N = int(input())
b = []
check = [[0]*3 for i in range(3)]
for i in range(N):
    new = int(input())
    b.append(new)
    for j in range(3):
        for k in range(3):
            if A[j][k] == new:
                check[j][k] = 1
    
flag = 0

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

if check[0][0] == 1 and check[1][1]==1 and check[2][2] == 1:
    flag = 1
if check[0][2] == 1 and check[1][1]==1 and check[2][0] == 1:
    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())
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]='o'
if (a[0][0]=='o'and a[0][1]=='o' and a[0][2]=='o') or(a[1][0]=='o'and a[1][1]=='o' and a[1][2]=='o') or(a[2][0]=='o'and a[2][1]=='o' and a[2][2]=='o') or(a[0][0]=='o'and a[1][0]=='o' and a[2][0]=='o') or(a[0][1]=='o'and a[1][1]=='o' and a[2][1]=='o') or(a[0][2]=='o'and a[1][2]=='o' and a[2][2]=='o') or(a[0][0]=='o'and a[1][1]=='o' and a[2][2]=='o') or(a[0][2]=='o'and a[1][1]=='o' and a[2][0]=='o'):
    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 _ in range(N)]
for a in B:
    for j in range(3):
        for k in range(3):
            if A[j][k] == a:
                A[j][k] = 0



for i in range(3):
    if sum(A[i]) == 0:
        print("Yes")
        exit()

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

if A[0][0]+A[1][1]+A[2][2] == 0 or A[0][2]+A[1][1]+A[2][0] == 0:
    print("Yes")
    exit()

print("No")

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    for i in range(3):
        for j in range(3):
            if A[i][j] in b:
                A[i][j] = 0
    for i in range(3):
        row_flag = True
        for j in range(3):
            if A[i][j]!=0:
                row_flag = False
        if row_flag == True:
            print(YES)
            return
    for j in range(3):
        line_flag = True
        for i in range(3):
            if A[i][j]!=0:
                line_flag = False
        if line_flag == True:
            print(YES)
            return
    if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
        print(YES)
        return
    if A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0:
        print(YES)
        return
    print(NO)
    return



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

if __name__ == '__main__':
    main()

Solution (Python):
def solve():
    A = [list(map(int, input().split())) for _ in range(3)]
    N = int(input())
    b = [int(input()) for _ in range(N)]
    
    bingo = [[False] * 3 for _ in range(3)]
    for bi in b:
        for i in range(3):
            for j in range(3):
                if A[i][j] == bi:
                    bingo[i][j] = True
    
    for i in range(3):
        cnt = 0
        for j in range(3):
            cnt += bingo[i][j]
        if cnt == 3:
            print('Yes')
            exit()
    for i in range(3):
        cnt = 0
        for j in range(3):
            cnt += bingo[j][i]
        if cnt == 3:
            print('Yes')
            exit()
    cnt = 0
    for i in range(3):
        cnt += bingo[i][i]
    if cnt == 3:
        print('Yes')
        exit()
    cnt = 0
    for i, j in [[0, 2], [1, 1], [2, 0]]:
        cnt += bingo[i][j]
    if cnt == 3:
        print('Yes')
        exit()
    print('No')


if __name__ == '__main__':
    solve()

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a = [LI() for _ in range(3)]
n = I()
b = [I() for _ in range(n)]
if n < 3:
    print('No')
    quit()
for i in range(3):
    for j in range(3):
        if a[i][j] not in b:
            break
    else:
        print('Yes')
        quit()

for i in range(3):
    for j in range(3):
        if a[j][i] not in b:
            break
    else:
        print('Yes')
        quit()

for i in range(3):
    if a[i][i] not in b:
        break
else:
    print('Yes')
    quit()

for i in range(3):
    if a[i][-(i+1)] not in b:
        break
else:
    print('Yes')
    quit()

print('No')

Solution (Python):
import sys
import math
import collections

a1, a2, a3 = map(int, input().split())
a4, a5, a6 = map(int, input().split())
a7, a8, a9 = map(int, input().split())


a = [a1, a2, a3, a4, a5, a6, a7, a8, a9]
c = [0 for k in range(9)]
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(9):
        if a[j] == b:
            c[j] = 1

if c[0] + c[1] + c[2] == 3:
    print("Yes")
    sys.exit()
if c[4] + c[5] + c[3] == 3:
    print("Yes")
    sys.exit()
if c[7] + c[8] + c[6] == 3:
    print("Yes")
    sys.exit()
if c[0] + c[3] + c[6] == 3:
    print("Yes")
    sys.exit()
if c[1] + c[4] + c[7] == 3:
    print("Yes")
    sys.exit()
if c[2] + c[5] + c[8] == 3:
    print("Yes")
    sys.exit()
if c[0] + c[4] + c[8] == 3:
    print("Yes")
    sys.exit()
if c[2] + c[4] + c[6] == 3:
    print("Yes")
    sys.exit()

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

ans='No'

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

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

if a[0][0]+a[1][1]+a[2][2]==0 or a[0][2]+a[1][1]+a[2][0]==0:
  ans='Yes'
print(ans)

Solution (Python):
card = [list(map(int, input().split())) for i in range(3)]
opened = [[False, False, False] 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 card[j][k] == b:
                opened[j][k] = True

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

ok = False
for x, y, dx, dy in dirs:
    o = True
    for i in range(3):
        o = o and opened[x + i * dx][y + i * dy]
    ok = ok or o

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

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

Solution (Python):


As = []
for i in range(3):
    As.append(list(map(int, input().split())))
N = int(input())
Bs = []
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if As[i][j] == b:
                As[i][j] = -1

for i in range(3):
    if set(As[i]) == {-1}:
        print("Yes")
        exit(0)
for j in range(3):
    if As[0][j] == -1 and As[1][j] == -1 and As[2][j] == -1:
        print("Yes")
        exit(0)

if set(As[i][i] for i in range(3)) == {-1}:
    print("Yes")
    exit(0)
if set(As[i][2-i] for i in range(3)) == {-1}:
    print("Yes")
    exit(0)
print("No")

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

cond = 0

for i in range(3):
	if A[i].count(1) == 3:
		cond = 1
for j in range(3):
	if sum([A[k][j] for k in range(3)]) == 3:
		cond = 1


if sum([A[k][k] for k in range(3)]) == 3:
	cond = 1

if A[0][2]+A[1][1]+A[2][0] == 3:
	cond = 1

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

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

N = int(input())
opened = set()
for _ in range(N):
    opened.add(int(input()))


def check():
    for i in range(3):
        if all(A[i][j] in opened for j in range(3)):
            print("Yes")
            return

    for j in range(3):
        if all(A[i][j] in opened for i in range(3)):
            print("Yes")
            return

    if all(A[i][i] in opened for i in range(3)):
        print("Yes")
        return

    if all(A[i][2-i] in opened for i in range(3)):
        print("Yes")
        return

    print("No")
    return


check()

Solution (Python):
a=[list(map(int,input().split())) for _ in range(3)]
a = sum(a,[])
n=int(input())
flag = [0]*9
for _ in range(n):
    b = int(input())
    if b in set(a):
        a_index = a.index(b)
        flag[a_index] = 1
w = [sum(flag[j*3+i] for i in range(3)) for j in range(3)]
h = [sum(flag[j+i*3] for i in range(3)) for j in range(3)]
d = [flag[0]+flag[4]+flag[8],flag[2]+flag[4]+flag[6]]
count = w+h+d
print('Yes' if max(count) == 3 else 'No')

Solution (Python):
L=[]
for i in range(3):
    a,b,c=map(int,input().split())
    L+=[a,b,c]
N=int(input())
l= [int(input()) for i in range(N)]
a=[0]*9
for i in l:
    for j in range(9):
        if i==L[j]:
            a[j]=1
if a[0]*a[1]*a[2] or a[3]*a[4]*a[5] or a[6]*a[7]*a[8] or a[0]*a[3]*a[6] or a[1]*a[4]*a[7] or a[2]*a[5]*a[8] or a[0]*a[4]*a[8] or a[6]*a[4]*a[2]:
    print("Yes")
else:
    print("No")

Solution (Python):


import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

A = nan(3)
n = ni()
b = nin(n)

d = [[0] * 3 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]:
                d[j][k] = 1

flag = False
for i in range(3):
    c = 0
    for j in range(3):
        if d[i][j] == 1:
            c += 1
    if c == 3:
        flag = True

for i in range(3):
    c = 0
    for j in range(3):
        if d[j][i] == 1:
            c += 1
    if c == 3:
        flag = True

if d[0][0] == 1 and d[1][1] == 1 and d[2][2] == 1:
    flag = True
if d[0][2] == 1 and d[1][1] == 1 and d[2][0] == 1:
    flag = True

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

Solution (Python):
lst = []
for i in range(3):
    lst.append(list(map(int, input().split())))
arr = []
N  = int(input())
for i in range(N):
    arr.append(int(input()))
for i in range(3):
    for j in range(3):
        if lst[i][j] in arr:
            lst[i][j] = True
        else:
            lst[i][j] = False

bing = False
for i in range(3):
    if lst[i][0] and lst[i][1] and lst[i][2]:
        bing = True
    if lst[0][i]and lst[1][i] and lst[2][i]:
        bing = True
if lst[0][0] and lst[1][1] and lst[2][2]:
    bing = True
if lst[0][2] and lst[1][1] and lst[2][0]:
    bing = True

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

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

bingo=[[False]*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]:
                bingo[j][k]=True
flag=False
for i in range(3):
    if all([bingo[i][0], bingo[i][1], bingo[i][2]]):
        flag=True

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

if all([bingo[0][0],bingo[1][1],bingo[2][2]]):
        flag=True

if all([bingo[0][2],bingo[1][1],bingo[2][0]]):
    flag=True

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