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):
al1 = list(map(int, input().split()))
al2 = list(map(int, input().split()))
al3 = list(map(int, input().split()))

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

for b in bl:
    if b in al1:
        al1[al1.index(b)] = -1
    if b in al2:
        al2[al2.index(b)] = -1
    if b in al3:
        al3[al3.index(b)] = -1

if sum(al1) == -3 or sum(al2) == -3 or sum(al3) == -3:
    print('Yes')
    exit()
if al1[0] + al2[1] + al3[2] == -3 or al1[2] + al2[1] + al3[0] == -3:
    print('Yes')
    exit()

for i in range(3):
    if al1[i] + al2[i] + al3[i] == -3:
        print('Yes')
        exit()

print('No')

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

for b in bl:
    if b in al:
        check[al.index(b)] = 1

if [1,1,1] in [check[:3], check[3:6], check[6:], check[0:7:3], check[1:8:3], check[2:9:3], check[0:9:4], check[2:8:2]]:
    print("Yes")
else:
    print("No")

Solution (Python):
a=[]
for _ in range(3):
    a.append(list(map(int,input().split())))
n=int(input())
b=[]
for _ in range(n):
    b.append(int(input()))
for k in range(n):
    for i in range(3):
        for j in range(3):
            if a[i][j]==b[k]:
                a[i][j]=0
for i in range(3):
    if sum(a[i])==0:
        print('Yes')
        exit()
    elif 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')
else:
    print('No')

Solution (Python):
import sys
import itertools as it

a = [row for row in map(lambda i:list(map(int, input().split())), range(3))]
n = int(input())
b = [int(input()) for i in range(n)]

res = False
for row in a:
    if all(i in b for i in row):
        res = True
for j in range(3):
    if all(a[i][j] in b for i in range(3)):
        res = True
if all(a[i][i] in b for i in range(3)):
    res = True
if all(a[i][2 - i] in b for i in range(3)):
    res = True

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

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

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


for i in range(3):
    if(A[i][0] in b and A[i][1] in b and A[i][2] in b):
        print('Yes')
        exit()
    if(A[0][i] in b and A[1][i] in b and A[2][i] in b):
        print('Yes')
        exit()
if(A[0][0] in b and A[1][1] in b and A[2][2] in b):
    print('Yes')
    exit()
if(A[0][2] in b and A[1][1] in b and A[2][0] in b):
    print('Yes')
    exit()

print('No')

Solution (Python):
def main():
    import itertools
    a = tuple(map(int,input().split()))
    b = tuple(map(int,input().split()))
    c = tuple(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())
    listB = [int(input()) for x in range(n)]
    X = itertools.permutations(listB,3)
    R = list(X)
    if a in R or b in R or c in R or d in R or e in R or f in R or g in R or h in R:
      print("Yes")
    else:
      print("No")
main()

Solution (Python):




















import sys
def p(*_a):
  
  _s=" ".join(map(str,_a))
  
  sys.stderr.write(_s+"\n")

yn = lambda b: print('Yes') if b else print('No')

A = [[int(i) for i in input().split()] for _ in range(3)]

N = int(input())
B = [int(input()) for _ in range(N)]

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

p(A)
a = A[0][0] + A[1][1] + A[2][2]
if a == 0:
  yn(True)
  exit()

a = A[0][2] + A[1][1] + A[2][0]
if a == 0:
  yn(True)
  exit()

a = 0
for i in range(3):
  a = 0
  for j in range(3):
    a += A[i][j]
  if a == 0:
    yn(True)
    exit()

a = 0
for j in range(3):
  a = 0
  for i in range(3):
    a += A[i][j]
  if a == 0:
    yn(True)
    exit()

yn(False)

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

flag =False
check_c1 = 0
check_c2 = 0
for i in range(3):
    check_v = 0
    check_h = 0
    for j in range(3):
        check_v += A[j][i]
        check_h += A[i][j]
        check_c1 += A[i][i]
        check_c2 += A[2-i][i]
    if (check_v == 0 or check_h == 0):
        flag = True
if (check_c1 == 0 or check_c2 == 0):
    flag = True

if flag:
    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())
C1 =  [0] * 3
C2 =  [0] * 3
C3 =  [0] * 3
for j in range(N):
    b = int(input())
    if b in A1:
        C1[A1.index(b)]=1
    if b in A2:
        C2[A2.index(b)] = 1
    if b in A3:
        C3[A3.index(b)] = 1

if sum(C1)==3 or sum(C2)==3 or sum(C3)==3:
    print('Yes')
    sys.exit()
elif C1[0]+C2[1]+C3[2]==3:
    print('Yes')
    sys.exit()
elif C3[0]+C2[1]+C1[2]==3:
    print('Yes')
    sys.exit()
else:
    for m in range(3):
        if C1[m]+C2[m]+C3[m]==3:
            print('Yes')
            sys.exit()

print('No')

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

c = [[0 for _ in range(3)] for _ in range(3)]
result = ""

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

for i in range(3):
    if c[i][0] == c[i][1] == c[i][2] == 1:
        result = "Yes"
        break
    elif c[0][i] == c[1][i] == c[2][i] == 1:
        result = "Yes"
        break

if c[0][0] == c[1][1] == c[2][2] == 1:
    result = "Yes"
elif c[0][2] == c[1][1] == c[2][0] == 1:
    result = "Yes"

if result == "":
    result ="No"

print(result)

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

for _ in range(N):
    B = int(input())
    if B in A:
        A[A.index(B)] = 0

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

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

n = int(input())
B = set(int(input()) for _ in range(n))
ans = False

for i in range(3):
    if all(A[i][j] in B for j in range(3)):
        ans = True

for i in range(3):
    if all(A[j][i] in B for j in range(3)):
        ans = True

if all(A[i][i] in B for i in range(3)):
    ans = True


if all(A[i][2-i] in B for i in range(3)):
    ans = True

print("Yes" if ans else "No")

Solution (Python):
import sys

a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
d = [int(input()) for f in range(n)]

for k in range(3):
  if a[k][0] in d and a[k][1] in d and a[k][2] in d:
    print("Yes")
    sys.exit()
  elif a[0][k] in d and a[1][k] in d and a[2][k] in d:
    print("Yes")
    sys.exit()
if a[0][0] in d and a[1][1] in d and a[2][2] in d:
  print("Yes")
  sys.exit()
elif a[0][2] in d and a[1][1] in d and a[2][0] in d:
  print("Yes")
  sys.exit()
else:
  print("No")

Solution (Python):
card = [list(map(int, input().split())) for i in range(3)]
N = int(input())
bingo = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
ans = 'No'
for _ in range(N):
    x = int(input())
    for i in range(3):
        for j in range(3):
            if x == card[i][j]:
                bingo[i][j] = 1

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

print(ans)

Solution (Python):
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 i in range(N):
  B = int(input())
  if B in A:
    A[A.index(B)] = 0

bingo = [A[0] + A[1] + A[2],
         A[3] + A[4] + A[5],
         A[6] + A[7] + A[8],
         A[0] + A[4] + A[8],
         A[2] + A[4] + A[6],
         A[0] + A[3] + A[6],
         A[1] + A[4] + A[7],
         A[2] + A[5] + A[8]]

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

Solution (Python):
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7

a_matrix = []
for i in range(3):
    a_vec = list(map(int, input().split()))
    a_matrix.append(a_vec)

a_mat = np.array(a_matrix)

def bingo_check(m):
    ch1 = (0 in m.sum(axis = 0))
    ch2 = (0 in m.sum(axis = 1))
    ch3 = not (m.trace())
    ch4 = not (np.rot90(m).trace())
    return ch1 or ch2 or ch3 or ch4
    
def num_change(n):
    dim1 = a_mat.shape[0]
    dim2 = a_mat.shape[1]
    for i in range(dim1):
        for j in range(dim2):
            if a_mat[i][j] == n:
                a_mat[i][j] = 0

n = int(input())
for i in range(n):
    b = int(input())
    num_change(b)

if bingo_check(a_mat):
    print('Yes')
else:
    print('No')

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

n = int(input())

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

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

Solution (Python):
num = 0
table = {}
for _ in range(3):
    row = map(int, input().split())
    for r in row:
        table[r] = num
        num += 1

N = int(input())

bingo = set()
for _ in range(N):
    b = int(input())
    if b in table:
        bingo.add(table[b])

atari = [
    {0,1,2},
    {3,4,5},
    {6,7,8},
    {0,3,6},
    {1,4,7},
    {2,5,8},
    {0,4,8},
    {2,4,6}
]

for a in atari:
    if a <= bingo:
        print('Yes')
        break
else:
    print('No')

Solution (Python):
from sys import exit
def judge_line(card):
    for i in range(0,9,3):
        for j in range(3):
            if card[i+j] != 0:
                break
            else:
                if j == 2:
                    print("Yes")
                    exit(0)
                else:
                    None
        
        
def judge_row(card):
    for i in range(3):
        for j in range(i,9,3):
            if card[j] != 0:
                break
            else:
                if j == 6 or j == 7 or j == 8:
                    print("Yes")
                    exit(0)
                else:
                    None

def judge_rightslanting(card):
    if card[0] == 0 and card[4] == 0 and card[8] == 0:
        print("Yes")
        exit(0)

def judge_leftslanting(card):
    if card[2] == 0 and card[4] == 0 and card[6] == 0:
        print("Yes")
        exit(0)


card = []

for _ in range(3):
    card += [int(x) for x in input().split()]

N = int(input())
for i in range(N):
    b = int(input())
    try:
        ind = card.index(b)
        card[ind] = 0
    except ValueError:
        None
    
    judge_line(card)
    judge_row(card)
    judge_rightslanting(card)
    judge_leftslanting(card)

print("No")

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

if X[0][0]*X[0][1]*X[0][2] + X[1][0]*X[1][1]*X[1][2] + X[2][0]*X[2][1]*X[2][2] + X[0][0]*X[1][0]*X[2][0] + X[0][1]*X[1][1]*X[2][1] + X[0][2]*X[1][2]*X[2][2] + X[0][0]*X[1][1]*X[2][2] + X[0][2]*X[1][1]*X[0][2] > 0:
    print('Yes')
else:
    print('No')

Solution (Python):

import sys
import numpy as np
import itertools as itlt
from collections import deque



s = [[0,0,0]
    ,[0,0,0]
    ,[0,0,0]]    
s[0] = [int(x) for x in sys.stdin.readline().split()]
s[1] = [int(x) for x in sys.stdin.readline().split()]
s[2] = [int(x) for x in sys.stdin.readline().split()]
g = [[0,0,0]
    ,[0,0,0]
    ,[0,0,0]]
N = int(sys.stdin.readline())
p = list([0]*N)
s = np.array(s)
for _ in range(N):
    a = int(sys.stdin.readline())
    b = np.where(s == a)
    for i in range(np.size(b[0])):
        g[b[0][i]][b[1][i]] = 1




flg_win = 0

for i in range(3):
    if (g[i][0] + g[i][1] + g[i][2]) == 3:
        flg_win = 1
    if (g[0][i] + g[1][i] + g[2][i]) == 3:
        flg_win = 1

if (g[0][0]+g[1][1]+g[2][2]) == 3:
    flg_win = 1

if (g[0][2]+g[1][1]+g[2][0]) == 3:
    flg_win = 1

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

Solution (Python):
board = []
for i in range(3):
  temp = list(map(int, input().split()))
  board.append(temp)
n = int(input())
TF = [[False] * 3 for i in range(3)]
for _ in range(n):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if board[i][j] == b:
        TF[i][j] = True
res = False
for i in range(3):
  res = res or (TF[i][0] and TF[i][1] and TF[i][2])
  res = res or (TF[0][i] and TF[1][i] and TF[2][i])
res = res or (TF[0][0] and TF[1][1] and TF[2][2])
res = res or (TF[0][2] and TF[1][1] and TF[2][0])
print('Yes' if res else 'No')

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

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

correct=[{0,1,2},{3,4,5},{6,7,8},{2,5,8},{1,4,7},{0,3,6},{0,4,8},{2,4,6}]

for i in correct:
    if i <= set(open):
        print('Yes')
        break
else:
    print('No')

Solution (Python):

a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
for i in range(n):
    m = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == m:
                a[j][k] = 0
f = False
for j in range(3):
    if a[j][0] == 0 and a[j][1] == 0 and a[j][2] == 0:
        f = True
    if a[0][j] == 0 and a[1][j] == 0 and a[2][j] == 0:
        f = True
if (a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0) or (a[2][0] == 0 and a[1][1] == 0 and a[0][2] == 0):
    f = True
if f:
    print('Yes')
else:
    print('No')

Solution (Python):

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

ans = [[0] * 3 for _ in range(3)]

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

chk = False
if ans[0][0] == ans[0][1] == ans[0][2] == 1:
  print("Yes")
elif ans[1][0] == ans[1][1] == ans[1][2] == 1:
  print("Yes")
elif ans[2][0] == ans[2][1] == ans[2][2] == 1:
  print("Yes")
elif ans[0][0] == ans[1][0] == ans[2][0] == 1 :
  print("Yes")
elif ans[0][1] == ans[1][1] == ans[2][1] == 1 :
  print("Yes")
elif ans[0][2] == ans[1][2] == ans[2][2] == 1 :
  print("Yes")
elif ans[0][0] == ans[1][1] == ans[2][2] == 1 :
  print("Yes")
elif ans[0][2] == ans[1][1] == ans[2][0] == 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 j in range (n)]
ans = "No"
for k in range (n):
  for l in range(3):
    for m in range(3):
      if a[l][m] == b[k]:
        a[l][m] = 0
for o in range(3):
  if a[o][0] == a[o][1] == a[o][2] or a[0][o] == a[1][o] == a[2][o]:
    ans = "Yes"
if a[0][0] == a[1][1] == a[2][2] or a[2][0] == a[1][1] == a[0][2]:
  ans = "Yes"
print(ans)

Solution (Python):
import itertools
import functools
import math
from collections import Counter
from itertools import combinations

A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
A3=list(map(int,input().split()))
N=int(input())
for i in range(N):
    chk = int(input())
    for m in range(3):
        if A1[m] == chk:
            A1[m] = 0
        if A2[m] == chk:
            A2[m] = 0
        if A3[m] == chk:
            A3[m] = 0



if (A1[0] == 0 and A1[1] == 0 and A1[2] == 0) \
or (A2[0] == 0 and A2[1] == 0 and A2[2] == 0) \
or (A3[0] == 0 and A3[1] == 0 and A3[2] == 0) \
or (A1[0] == 0 and A2[0] == 0 and A3[0] == 0) \
or (A1[1] == 0 and A2[1] == 0 and A3[1] == 0) \
or (A1[2] == 0 and A2[2] == 0 and A3[2] == 0) \
or (A1[0] == 0 and A2[1] == 0 and A3[2] == 0) \
or (A1[2] == 0 and A2[1] == 0 and A3[0] == 0) :
    print('Yes')
else:
    print('No')

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

n = int(input())

for j in range(n):
    b = int(input())
    for l in range(3):
        if A[l][0] == b:
            A[l][0] = 0
        if A[l][1] == b:
            A[l][1] = 0
        if A[l][2] == b:
            A[l][2] = 0
if A[0][0]==A[1][1]==A[2][2]==0:
    print("Yes")
    sys.exit()
elif A[0][2]==A[1][1]==A[2][0]==0:
    print("Yes")
    sys.exit()
elif A[0][0]==A[0][1]==A[0][2]==0:
    print("Yes")
    sys.exit()
elif A[1][0]==A[1][1]==A[1][2]==0:
    print("Yes")
    sys.exit()
elif A[2][0]==A[2][1]==A[2][2]==0:
    print("Yes")
    sys.exit()
elif A[0][0]==A[1][0]==A[2][0]==0:
    print("Yes")
    sys.exit()
elif A[0][1]==A[1][1]==A[2][1]==0:
    print("Yes")
    sys.exit()    
elif A[0][2]==A[1][2]==A[2][2]==0:
    print("Yes")
    sys.exit()   
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 i in range(n):
    b = int(input())
    for j in range(3):
        if A1[j] == b:
            A1[j] = 0
        if A2[j] == b:
            A2[j] = 0
        if A3[j] == b:
            A3[j] = 0

if A1[0]==A1[1]==A1[2]==0:
    print("Yes")
    exit
elif A2[0]==A2[1]==A2[2]==0:
    print("Yes")
    exit
elif A3[0]==A3[1]==A3[2]==0:
    print("Yes")
    exit

elif A1[0]==A2[0]==A3[0]==0:
    print("Yes")
    exit
elif A1[1]==A2[1]==A3[1]==0:
    print("Yes")
    exit
elif A1[2]==A2[2]==A3[2]==0:
    print("Yes")
    exit
    
elif A1[0]==A2[1]==A3[2]==0:
    print("Yes")
    exit
elif A1[2]==A2[1]==A3[0]==0:
    print("Yes")
    exit
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 i in range(N):
    B = int(input())
    for j in range(3):
        if A1[j] == B:
            A1[j] = 0
        if A2[j] == B:
            A2[j] = 0
        if A3[j] == B:
            A3[j] = 0

if sum(A1) == 0:
    print("Yes")
    exit()
if sum(A2) == 0:
    print("Yes")
    exit()
if sum(A3) == 0:
    print("Yes")
    exit()
for i in range(3):
    if A1[i]+A2[i]+A3[i] == 0:
        print("Yes")
        exit()
if A1[0] + A2[1] + A3[2] == 0:
    print("Yes")
    exit()
if A1[2] + A2[1] + A3[0] == 0:
    print("Yes")
    exit()
print("No")

Solution (Python):
import sys

A=[list(map(int,input().split())) for _ in range(3)]
n=int(input())
for i in range(n):
    b=int(input())
    for l in range(3):
        if b in A[l]:
            A[l][A[l].index(b)]=0

for i in range(3):
    if A[i][0] == A[i][1] == A[i][2]:
        print('Yes')
        sys.exit()
    elif 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')
    sys.exit()
elif A[0][2] == A[1][1] == A[2][0]:
    print('Yes')
    sys.exit()
else:
    print('No')

Solution (Python):
A11, A12, A13 = input().split(' ')
A21, A22, A23 = input().split(' ')
A31, A32, A33 = input().split(' ')
A11 = int(A11)
A12 = int(A12)
A13 = int(A13)
A21 = int(A21)
A22 = int(A22)
A23 = int(A23)
A31 = int(A31)
A32 = int(A32)
A33 = int(A33)
N = int(input())
b = []
for i in range(N):
  bi = int(input())
  b.append(bi)
if A11 in b and A12 in b and A13 in b:
  print('Yes')
elif A21 in b and A22 in b and A23 in b:
  print('Yes')
elif A31 in b and A32 in b and A33 in b:
  print('Yes')
elif A11 in b and A21 in b and A31 in b:
  print('Yes')
elif A12 in b and A22 in b and A32 in b:
  print('Yes')
elif A13 in b and A23 in b and A33 in b:
  print('Yes')
elif A11 in b and A22 in b and A33 in b:
  print('Yes')
elif A13 in b and A22 in b  and A31 in b:
  print('Yes')
else:
  print('No')

Solution (Python):
def check():
    for i in range(3):
        f1 = True
        f2 = True
        for j in range(3):
            f1 = f1 and card[i][j]
            f2 = f2 and card[j][i]
        if f1 or f2:
            return 'Yes'
    f1 = True
    f2 = True
    for i in range(3):
        f1 = f1 and card[i][i]
        f2 = f2 and card[i][2-i]
    if f1 or f2:
        return 'Yes'
    return 'No'

card = [[False] * 3 for _ in range(3)]
A = []
for _ in range(3):
    a = list(map(int, input().split()))
    A += a
N = int(input())
for _ in range(N):
    b = int(input())
    if b in A:
        idx = A.index(b)
        card[idx // 3][idx % 3] = True
print(check())

Solution (Python):
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N = int(input())

for i in range(N):
    b = int(input())
    for t in range(3):
        if A1[t] == b:
            A1[t] = -1
        elif A2[t] == b:
            A2[t] = -1
        elif A3[t] == b:
            A3[t] = -1

if A1 == [-1, -1, -1] \
        or A2 == [-1, -1, -1] \
        or A3 == [-1, -1, -1] \
        or A1[1] == A2[1] == A3[1] == -1 \
        or A1[2] == A2[2] == A3[2] == -1 \
        or A1[0] == A2[0] == A3[0] == -1 \
        or A1[0] == A2[1] == A3[2] == -1 \
        or A1[2] == A2[1] == A3[0] == -1 \
        or A1[0] == A2[0] == A3[0] == -1 \
        or A1[1] == A2[1] == A3[1] == -1 \
        or A1[2] == A2[2] == A3[2] == -1:
    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()))
ka = a + b + c
x = int()
n = int(input())
for i in range(n):
    k = int(input())
    if k in ka: ka[ka.index(k)] = x
ans = "No"
if ka[0] == x and ka[1] == x and ka[2] == x:ans = "Yes"
elif ka[3] == x and ka[4] == x and ka[5] == x:ans = "Yes"
elif ka[6] == x and ka[7] == x and ka[8] == x:ans = "Yes"
elif ka[0] == x and ka[3] == x and ka[6] == x:ans = "Yes"
elif ka[1] == x and ka[4] == x and ka[7] == x:ans = "Yes"
elif ka[2] == x and ka[5] == x and ka[8] == x:ans = "Yes"
elif ka[0] == x and ka[4] == x and ka[8] == x:ans = "Yes"
elif ka[2] == x and ka[4] == x and ka[6] == x:ans = "Yes"
print(ans)

Solution (Python):
import sys

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

for i in range(N):
    b = int(input())
    if b in A[0]:
        A[0][A[0].index(b)] = 0
    elif b in A[1]:
        A[1][A[1].index(b)] = 0
    elif b in A[2]:
        A[2][A[2].index(b)] = 0

for i in range(3):
    if A[i][0] == A[i][1] == A[i][2]:
        print('Yes')
        sys.exit()
    elif 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')
    sys.exit()
elif A[0][2] == A[1][1] == A[2][0]:
    print('Yes')
    sys.exit()
else:
    print('No')

Solution (Python):

A = [[0] * 3, [0] * 3, [0] * 3]
Field = [[False] * 3, [False] * 3, [False] * 3]

for i in range(0, 3):
    A1, A2, A3 = list(map(int, input().split()))
    A[i][0] = A1
    A[i][1] = A2
    A[i][2] = A3

N = int(input())
B = [0] * N
for i in range(0, N):
    B[i] = int(input())

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

Ans = False
for i in range(3):
    field = True
    for j in range(3):
        if Field[i][j] == False:
            field = False
    
    if field==True:
        Ans = True
        break
else:
    Ans = False
    for i in range(3):
        field = True
        for j in range(3):
            if Field[j][i] == False:
                field = False
        
        if field==True:
            Ans = True
            break
    else:
        Ans = False
        if Field[0][0] and Field[1][1] and Field[2][2]:
            Ans = True
        if Field[0][2] and Field[1][1] and Field[2][0]:
            Ans = True

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

Solution (Python):
import sys

A = [0] * 3

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

N = int(input())
for i in range(N):
    b = int(input())
    if b in A[0]:
        A[0][A[0].index(b)] = 0
    elif b in A[1]: 
        A[1][A[1].index(b)] = 0
    elif b in A[2]:
        A[2][A[2].index(b)] = 0

for i in range(3):
    if A[i][0] == A[i][1] == A[i][2]:
        print("Yes")
        sys.exit()
    elif 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")
    sys.exit()
elif A[0][2] == A[1][1] == A[2][0]:
    print("Yes")
    sys.exit()
else:
    print("No")

Solution (Python):
la1=list(map(int,input().split()))
la2=list(map(int,input().split()))
la3=list(map(int,input().split()))
n=int(input())
ln=[int(input()) for i in range(n)]
la=[la1,la2,la3]
ls=[[0,0,0],[0,0,0],[0,0,0]]
for i in range(3):
  for j in range(3):
    if la[i][j] in ln:
      ls[i][j]=1
if ls[0]==[1,1,1] or ls[1]==[1,1,1] or ls[2]==[1,1,1]:
  print("Yes")
elif ls[0][0]==ls[1][0]==ls[2][0]==1 or ls[0][1]==ls[1][1]==ls[2][1]==1 or ls[0][2]==ls[1][2]==ls[2][2]==1:
  print("Yes")
elif ls[0][0]==ls[1][1]==ls[2][2]==1 or ls[0][2]==ls[1][1]==ls[2][0]==1:
  print("Yes")
else:
  print("No")

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

N = int(input())

for _ in range(N):
    b = input()
    for i in range(3):
        if b in bingo_card[i]:
            j = bingo_card[i].index(b)
            bingo_card[i][j] = "O"
            break

def check_h():
    for line in bingo_card:
        for s in line:
            if s != "O":
                break
        else:
            return True
    return False

def check_v():
    for i in range(3):
        for j in range(3):
            if bingo_card[j][i] != "O":
                break
        else:
            return True
    return False

def check_d():
    for x in [True, False]:
        for i in range(3):
            if x:
                if bingo_card[i][i] != "O":
                    break
            else:
                if bingo_card[i][2 - i] != "O":
                    break
        else:
            return True
    return False

checks = [check_h, check_v, check_d]
for check in checks:
    if check():
        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()))
x = a+b+c
ans = "No"
N = int(input())
for i in range(N) :
    b = int(input())
    x = ["x" if i == b else i for i in x]

for i in range(3) :
    if x[i] == x[i+3] == x[i+6] == "x" :
        ans = "Yes"
    if x[3*i] == x[3*i+1] == x[3*i+2] == "x" :
        ans = "Yes"
if x[0] == x[4] == x[8] == "x" :
    ans = "Yes"
if x[2] == x[4] == x[6] == "x" :
    ans = "Yes"
print(ans)

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

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


checkList = list()
for i in range(3):
    checkList.append(set(A[i]))
for j in range(3):
    checkList.append(set([A[0][j], A[1][j], A[2][j]]))
checkList.append(set([A[0][0], A[1][1], A[2][2]]))
checkList.append(set([A[0][2], A[1][1], A[2][0]]))

flag = False
for s in checkList:
    if len(s - B) == 0:
        flag = True
        break

if flag:
    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()))
x = a1 + a2 + a3

n=int(input())
ans='No'

for i in range(n):
  ent=int(input())
  x=['x' if i==ent else i for i in x]

if x[0]==x[3]==x[6]=='x':ans='Yes'
elif x[1]==x[4]==x[7]=='x':ans='Yes'
elif x[2]==x[5]==x[8]=='x':ans='Yes'
elif x[0]==x[1]==x[2]=='x':ans='Yes'
elif x[3]==x[4]==x[5]=='x':ans='Yes'
elif x[6]==x[7]==x[8]=='x':ans='Yes'
elif x[0]==x[4]==x[8]=='x':ans='Yes'
elif x[2]==x[4]==x[6]=='x':ans='Yes'

print(ans)

Solution (Python):
import numpy as np
zeroarr = np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])
l1= list(map(int, input().split()))
l2= list(map(int, input().split()))
l3=list(map(int, input().split()) )
bing = np.array([np.array(l1), np.array(l2), np.array(l3)])
n=int(input())
x=[]
for _ in range(n):
  l=int(input())
  x.append(l)
def check(ls, b, dd):
    for i in ls:
        if i in b:
            xxx=np.argwhere(b==i)
            for m in xxx:
                dd[m[0], m[1]]=1
check(x, bing, zeroarr)
def matrixsum(a):
    ans="No"
    if a[0,0]+a[0,1]+a[0,2]==3:
        ans="Yes"
    if a[1,0]+a[1,1]+a[1,2]==3:
        ans="Yes"
    if a[2,0]+a[2,1]+a[2,2]==3:
        ans="Yes"
    if a[0,0]+a[1,0]+a[2,0]==3:
        ans="Yes"
    if a[0,1]+a[1,1]+a[2,1]==3:
        ans="Yes"
    if a[0,2]+a[1,2]+a[2,2]==3:
        ans="Yes"
    if a[0,0]+a[1,1]+a[2,2]==3:
        ans="Yes"
    if a[0,2]+a[1,1]+a[2,0]==3:
        ans="Yes"
    return ans
print(matrixsum(zeroarr))

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

C=[[False]*3 for _ in range(3)]
D=[(0,0),(0,1),(0,2),(1,0),(1,1),(1,2),(2,0),(2,1),(2,2)]

N=int(input())
for _ in range(N):
    b=int(input())
    for (p,q) in D:
        if A[p][q]==b:
            C[p][q]=True

T=False
for i in range(3):
    U=True
    for j in range(3):
        U&=C[i][j]
    T|=U
    
for j in range(3):
    U=True
    for i in range(3):
        U&=C[i][j]
    T|=U 

U=True
for i in range(3):
    U&=C[i][i]
T|=U

U=True
for i in range(3):
    U&=C[i][2-i]
T|=U

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