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

N=int(input())
for i in range(N):
  x=int(input())
  for row in A:
    for num in range(len(row)):
      if x==row[num]:
        row[num]=0

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

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

for bb in b:
    for i in range(3):
        for j in range(3):
            if l[i][j] == bb:
                ans[i][j] = 1

if 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')
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[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')

else:
    print('No')

Solution (Python):
arr = []
b = []
cmp_arr = [[False] * 3 for _ in range(3)]

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

N = int(input())
for i in range(N):
  b.append(int(input()))

for i in range(3):
  for j in range(3):
    for k in range(N):
      if arr[i][j] == b[k]:
        cmp_arr[i][j] = True

for i in range(3):
  if cmp_arr[i][0] and cmp_arr[i][1] and cmp_arr[i][2]:
    print("Yes");exit()
  if cmp_arr[0][i] and cmp_arr[1][i] and cmp_arr[2][i]:
    print("Yes");exit()

if cmp_arr[0][0] and cmp_arr[1][1] and cmp_arr[2][2]:
  print("Yes");exit()
if cmp_arr[0][2] and cmp_arr[1][1] and cmp_arr[2][0]:
  print("Yes");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)]
cnt = [0]*8
ans = "No"
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            cnt[i] += 1
            cnt[j+3] += 1
            if i == j:
                cnt[-1] += 1
            if i+j == 2:
                cnt[-2] += 1
for k in range(8):
    if cnt[k] >= 3:
        ans = "Yes"
        break
print(ans)

Solution (Python):
import numpy as np

a = [[int(i) for i in input().split()] for _ in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]

for bingo_num in b:
    for line in range(3):
        if bingo_num in a[line]:
            a[line][a[line].index(bingo_num)] =0

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

print("Yes" if flag 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())
R = []
for i in range(N):
  S = int(input())
  R.append(S)

if A1[0] in R and A2[1] in R and A3[2] in R:
  print("Yes")
elif A1[2] in R and A2[1] in R and A3[0] in R:
  print("Yes")
elif A1[0] in R and A1[1] in R and A1[2] in R:
  print("Yes")
elif A2[0] in R and A2[1] in R and A2[2] in R:
  print("Yes")
elif A3[0] in R and A3[1] in R and A3[2] in R:
  print("Yes")
elif A1[0] in R and A2[0] in R and A3[0] in R:
  print("Yes")
elif A2[1] in R and A2[1] in R and A3[1] in R:
  print("Yes")
elif A1[2] in R and A2[2] in R and A3[2] in R:
  print("Yes")
else:
  print("No")

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

bingo = False


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

    if (rowMatches == 3 or colMatches == 3):
        bingo = True
        break

if (bingo):
    print("Yes")
else:
    
    diag1 = 0
    diag2 = 0
    for i in range(3):
        if A[i][i] in B:
            diag1 += 1
        if A[i][3-1-i] in B:
            diag2 += 1

    if (diag1 == 3 or diag2 == 3):
        print("Yes")
    else:
        print("No")

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

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

a_2 = list(zip(*a))
flag_1 = sum(a[0]) == 0 or sum(a[1]) == 0 or sum(a[2]) == 0
flag_2 = sum(a_2[0]) == 0 or sum(a_2[1]) == 0 or sum(a_2[2]) == 0
flag_3 = a[0][0] + a[1][1] + a[2][2] == 0 or a[0][2] + a[1][1] + a[2][0] == 0

print(['No','Yes'][flag_1 or flag_2 or flag_3])

Solution (Python):
l = []

for _ in range(3):
  l += list(map(int, input().split()))

n = int(input())
for _ in range(n):
  b = int(input())
  if b in l:
    l[l.index(b)] = 0

for i in range(3):
  if sum(l[0+3*i:3+3*i]) == 0:
    print("Yes")
    exit()
  
  if sum(l[i:9:3]) == 0:
    print("Yes")
    exit()

if (l[0]+l[4]+l[8]) == 0:
  print("Yes")
  exit()
if (l[2]+l[4]+l[6]) == 0:
  print("Yes")
  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)]

a = []

Atf = [[False] * 3 for _ in range(3)]

for i in range(3):
    for aa in A[i]:
        a.append(aa)

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

res = False

for i in range(3):
    if Atf[i][0] and Atf[i][1] and Atf[i][2]:
        res = True
        break
    elif Atf[0][i] and Atf[1][i] and Atf[2][i]:
        res = True
        break

if not res:
    if Atf[0][0] and Atf[1][1] and Atf[2][2]:
        res = True
    elif Atf[0][2] and Atf[1][1] and Atf[2][0]:
        res = True
 

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

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

n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(9):
        if a[i] == b:
            a[i] = 0


for i in range(3):
    if sum(a[i*3:i*3+3]) == 0:
        print('Yes')
        exit()
    if sum(a[i:9:3]) == 0:
        print('Yes')
        exit()

if (a[0] + a[4] + a[8]) == 0:
    print('Yes')
    exit()
if (a[2] + a[4] + a[6]) == 0:
    print('Yes')
    exit()

print('No')

Solution (Python):
def solve():
    Ass = [tuple(map(int, input().split())) for _ in range(3)]
    N = int(input())
    Bs = set([int(input()) for _ in range(N)])

    isOKss = [[0]*(3) for _ in range(3)]
    for i in range(3):
        for j in range(3):
            if Ass[i][j] in Bs:
                isOKss[i][j] = 1

    for i in range(3):
        for j in range(3):
            if not isOKss[i][j]:
                break
        else:
            return True

    for j in range(3):
        for i in range(3):
            if not isOKss[i][j]:
                break
        else:
            return True

    for i in range(3):
        if not isOKss[i][i]:
            break
    else:
        return True

    for i in range(3):
        if not isOKss[i][2-i]:
            break
    else:
        return True

    return False


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

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

for number in num:
    cnt = 0
    for b in bingo:
        if number in b:
             arr[cnt].append(b.index(number))
        cnt  = cnt + 1

if len(arr[0]) == 3 or len(arr[1]) == 3 or len(arr[2]) == 3:
    print("Yes")
elif 0 in arr[0] and 1 in arr[1] and 2 in arr[2]:
    print("Yes")
elif 2 in arr[0] and 1 in arr[1] and 2 in arr[0]:
    print("Yes")
elif 0 in arr[0] and 0 in arr[1] and 0 in arr[2]:
    print("Yes")
elif 1 in arr[0] and 1 in arr[1] and 1 in arr[2]:
    print("Yes")
elif 2 in arr[0] and 2 in arr[1] and 2 in arr[2]:
    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)]


cnt=0

for i in range(N):
    for j in range(3):
        for k in range(3):
            if b[i] == a[j][k]:
                a[j][k] =1000
                if sum(a[j]) ==3000 or a[0][k]+a[1][k]+a[2][k]==3000 or a[0][0]+a[1][1]+a[2][2]==3000 or a[0][2]+a[1][1]+a[2][0]==3000:
                    cnt +=1
print('Yes' if cnt>0 else 'No')

Solution (Python):
bingo = [list(map(int, input().split())) for _ in range(3)]
def chec_line():
    ret = False
    for i in range(3):
        cnt = 0
        for j in range(3):
            if bingo[i][j] == -1:
                cnt += 1
        if cnt == 3:
            ret =True

    for i in range(3):
        cnt = 0
        for j in range(3):
            if bingo[j][i] == -1:
                cnt += 1
        if cnt == 3:
            ret =True
    cnt = 0
    for i in range(3):
        if bingo[i][i] == -1:
            cnt += 1
    if cnt == 3:
        ret =True
    
    cnt = 0
    for i in range(3):
        if bingo[2-i][i] == -1:
            cnt += 1
    if cnt == 3:
        ret =True

    return ret
def check_num( num):
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == num:
                bingo[i][j] = -1
                

n = int(input())
flag = False
for _ in range(n):
    check_num(int(input()))
    flag = chec_line() 
    if flag:
        break
if flag :
    print('Yes')
else:
    print('No')

Solution (Python):
import numpy as np
a_l = [ list(map(int, input().split())) for _ in range(3) ]
m_l = np.array([ [0]*3 for _ in range(3) ])
n = int(input())
b_l = [ int(input()) for _ in range(n) ]

def check_bingo(m_l):
    if sum(m_l[0]) == 3:
        return True
    if sum(m_l[1]) == 3:
        return True
    if sum(m_l[2]) == 3:
        return True
    if sum(m_l[:,0]) == 3:
        return True
    if sum(m_l[:,1]) == 3:
        return True
    if sum(m_l[:,2]) == 3:
        return True
    if sum([m_l[0,0],m_l[1,1],m_l[2,2]]  ) == 3:
        return True
    if sum([m_l[0,2],m_l[1,1],m_l[2,0]]  ) == 3:
        return True
    return False

for b in b_l:
    for i,a in enumerate(a_l):
        for j,v in enumerate(a):
            if b == v:
                m_l[i][j]=1
if check_bingo(m_l):
    print('Yes')
else:
    print('No')

Solution (Python):
a, b, c = [],[],[]
ans = "No"
num = [[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 _ in range(3):
    n = list(map(int,input().split()))
    for i in range(3):
        a.append(n[i])
        
n = int(input())
for j in range(n):
    b.append(int(input()))
    
for k in range(9):
    for l in b:
        if a[k] == l:
            c.append(int(k))

for m in range(8):
    q = 0
    for p in range(3):
        if num[m][p] in c:
            q += 1
    if q == 3:
        ans = "Yes"
print(ans)

Solution (Python):
def is_b(l):
    return all([a[i][j] in b for i, j in l])

a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
t = [[(i, j) for j in range(3)] for i in range(3)]
t += [[(j, i) for j in range(3)] for i in range(3)]
t += [[(i, i) for i in range(3)]] + [[(2 - i, i) for i in range(3)]]
print('Yes' if any([is_b(ti) for ti in t]) else 'No')

Solution (Python):
import itertools

a = []
for i in range(3):
    aa = list(map(int,input().split()))
    a.append(aa)
a = list(itertools.chain.from_iterable(a))

b = []
n = int(input())
for i in range(n):
    x = int(input())
    if x in a:
        ii = a.index(x)
        b.append(ii)
c = [[0,1,2], [3,4,5], [6,7,8], [0,3,6], [1,4,7], [2,5,8], [0,4,8], [2,4,6]] 
flg = False
for i in range(8):
    ci, cj, ck = c[i][0], c[i][1], c[i][2]
    if ci in b and cj in b and ck in b:
        flg = True
        break
print('Yes') if flg 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())
A10,A11,A12,A20,A21,A22,A30,A31,A32 = 0,0,0,0,0,0,0,0,0
for n in range(N):
  b = int(input())
  
  if A1[0] == b:
    A10 += 1
  elif A1[1] == b:
    A11 += 1
  elif A1[2] == b:
    A12 += 1
  elif A2[0] == b:
    A20 += 1
  elif A2[1] == b:
    A21 += 1
  elif A2[2] == b:
    A22 += 1
  elif A3[0] == b:
    A30 += 1
  elif A3[1] == b:
    A31 += 1
  elif A3[2] == b:
    A32 += 1

if A10+A11+A12 == 3:
  print("Yes")
elif A20+A21+A22 == 3:
  print("Yes")
elif A30+A31+A32 == 3:
  print("Yes")
elif A10+A20+A30 == 3:
  print("Yes")
elif A11+A21+A31 == 3:
  print("Yes")
elif A12+A22+A32 == 3:
  print("Yes")
elif A10+A21+A32 == 3:
  print("Yes")
elif A12+A21+A30 == 3:
  print("Yes")
else:
  print("No")

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

N=int(input())
for i in range(N):
    b = int(input())
    for j in range(3):
        for l in range(3):
            if ls[l][j] == b:
                ls[l][j] = -1
flg = False
for i in range(3):
    if ls[i][0] == ls[i][1] == ls[i][2] == -1:
        print("Yes")
        flg = True
        break
    elif ls[0][i] == ls[1][i] == ls[2][i] == -1:
        print("Yes")
        flg = True
        break
    elif ls[0][0] == ls[1][1] == ls[2][2] == -1:
        print("Yes")
        flg = True
        break
    elif ls[0][2] == ls[1][1] == ls[2][0] == -1:
        print("Yes")
        flg = True
        break
if flg == False:
    print("No")

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

  
  

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


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:
  print("Yes")
  exit()
if a[0][2] + a[1][1] + a[2][0] == 0:
  print("Yes")
  exit()
print("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)

l = [0]*9
n = int(input())

for i in range(n):
    b = int(input())
    for k in range(9):
        if a[k] == b:
            l[k] += 1
 
if l[0] == 1 and l[1] == 1 and l[2] == 1:
    print('Yes')
elif l[3] == 1 and l[4] == 1 and l[5] == 1:
    print('Yes')
elif l[6] == 1 and l[7] == 1 and l[8] == 1:
    print('Yes')
elif l[0] == 1 and l[3] == 1 and l[6] == 1:
    print('Yes')
elif l[1] == 1 and l[4] == 1 and l[7] == 1:
    print('Yes')
elif l[2] == 1 and l[5] == 1 and l[8] == 1:
    print('Yes')
elif l[0] == 1 and l[4] == 1 and l[8] == 1:
    print('Yes')
elif l[2] == 1 and l[4] == 1 and l[6] == 1:
    print('Yes')
else:
    print('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)

l = [0]*9
n = int(input())

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

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

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

n=int(input())

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


 

for i in range(3):
    for j in range(3):
        if list_2d[i][j] in b:
            list_2d[i][j]="x"
            




if list_2d[0]==["x","x","x"] or list_2d[1]==["x","x","x"] or list_2d[2]==["x","x","x"]:
    ans="Yes"
    

elif list_2d[0][0]==list_2d[1][0]==list_2d[2][0]=="x" or  list_2d[0][1]==list_2d[1][1]==list_2d[2][1]=="x" or  list_2d[0][2]==list_2d[1][2]==list_2d[2][2]=="x":
    ans="Yes"


elif  list_2d[0][0]==list_2d[1][1]==list_2d[2][2]=="x" or  list_2d[0][2]==list_2d[1][1]==list_2d[2][0]=="x":
    ans="Yes"
    
else:
    ans="No"
    
print(ans)

Solution (Python):
import numpy as np

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

N = int(input())

NP_A = np.array(A)
b = []
for n in range(N):
  b.append(int(input()))

for n in range(N):
  NP_A = np.where(NP_A==b[n], 0, NP_A)

ans = "No"

for i in range(2):
    if 0 in NP_A.sum(axis=i):
        ans = "Yes"
        break

if ans == "Yes":
    pass
else:
    sum = 0
    for i in range(3):
        sum += NP_A[i, i]
    if sum == 0:
        ans = "Yes"
    else:
        sum = NP_A[0, 2] + NP_A[1, 1] + NP_A[2, 0]
        if sum == 0:
            ans = "Yes"

print(ans)

Solution (Python):
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
lst = []
for _ in range(N):
    i = int(input())
    lst.append(i)

for n, i in enumerate(A1):
    for j in lst:
        if i == j:
            A1[n] = 0

for n, i in enumerate(A2):
    for j in lst:
        if i == j:
            A2[n] = 0
            
for n, i in enumerate(A3):
    for j in lst:
        if i == j:
            A3[n] = 0
            
B1 = sum(A1)
B2 = sum(A2)
B3 = sum(A3)
B4 = A1[0] + A2[0] + A3[0]
B5 = A1[1] + A2[1] + A3[1]
B6 = A1[2] + A2[2] + A3[2]
B7 = A1[0] + A2[1] + A3[2]
B8 = A1[2] + A2[1] + A3[0]

if B1 * B2 * B3 * B4 * B5 * B6 * B7 * B7 * B8 == 0:
    print('Yes')
else:
    print('No')

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

if (
    set(a[0]) <= b
    or set(a[1]) <= b
    or set(a[2]) <= b
    or set(x[0] for x in a) <= b
    or set(x[1] for x in a) <= b
    or set(x[2] for x in a) <= b
    or {a[0][0], a[1][1], a[2][2]} <= b
    or {a[0][2], a[1][1], a[2][0]} <= b
):
    print("Yes")
else:
    print("No")

Solution (Python):


from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')
YES = "Yes"  
NO = "No"  


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    for i in b:
        A = [[(a if a != i else 0) for a in l] for l in A]

    return [NO, YES][any([not any(l) for l in [*A, *[[A[i][j] for i in range(3)] for j in range(3)], [A[0][0], A[1][1], A[2][2]], [A[2][0], A[1][1], A[0][2]]]])]


def main():

    sys.setrecursionlimit(10 ** 6)

    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)]  
    print(f'{solve(A, N, b)}')


if __name__ == '__main__':
    main()

Solution (Python):


from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')
YES = "Yes"  
NO = "No"  


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    for i in b:
        A = [[(a if a != i else 0) for a in l] for l in A]
    return [NO, YES][any([not any(l) for l in A]) or any([not any([A[i][j] for i in range(3)]) for j in range(3)]) or not any([A[0][0], A[1][1], A[2][2]]) or not any([A[2][0], A[1][1], A[0][2]])]


def main():

    sys.setrecursionlimit(10 ** 6)

    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)]  
    print(f'{solve(A, N, b)}')


if __name__ == '__main__':
    main()

Solution (Python):


from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')
YES = "Yes"  
NO = "No"  


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    for i in b:
        A = [[(a if a != i else 0) for a in l] for l in A]
    return [NO, YES][any([sum(l) == 0 for l in A]) or any([sum([A[i][j] for i in range(3)]) == 0 for j in range(3)]) or (A[0][0]+A[1][1]+A[2][2] == 0) or (A[2][0]+A[1][1]+A[0][2] == 0)]


def main():

    sys.setrecursionlimit(10 ** 6)

    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)]  
    print(f'{solve(A, N, b)}')


if __name__ == '__main__':
    main()

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

A = numpy.array([A1, A2, A3])
C = numpy.zeros(A.shape)

N = int(input())
B = []
for _ in range(N):
    b = int(input())
    B.append(b)

    C[A == b] = 1

diag1 = numpy.array([C[0,0], C[1,1], C[2,2]])
diag2 = numpy.array([C[0,2], C[1,1], C[2,0]])

flag = False

if numpy.all(C[0] == 1) or numpy.all(C[1] == 1) or numpy.all(C[2] == 1):
    flag = True

if numpy.all(C.T[0] == 1) or numpy.all(C.T[1] == 1) or numpy.all(C.T[2] == 1):
    flag = True

if numpy.all(diag1 == 1) or numpy.all(diag2 == 1):
    flag = True

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

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

card = [False] * 9
for selection in b:
    for i, a in enumerate(A):
        if selection == a:
            card[i] = True


answer = 'No'

if (card[0] and card[1] and card[2]) \
or (card[3] and card[4] and card[5]) \
or (card[6] and card[7] and card[8]):
    answer = 'Yes'

if (card[0] and card[3] and card[6]) \
or (card[1] and card[4] and card[7]) \
or (card[2] and card[5] and card[8]):
    answer = 'Yes'

if (card[0] and card[4] and card[8]) \
or (card[2] and card[4] and card[6]):
    answer = 'Yes'
print(answer)

Solution (Python):

import numpy as np
a = [[input().split() for l in range(3)]]
a = np.ravel(a)
n = int(input())
b = [input() for i in range(n)]
ans = 'No'

def check(a,b):
    return set(a).issubset(b)

for i in range(3):
    if check(a[i*3:(i*3)+3],b) or check(a[i:i+7:3],b) or check(a[0:9:4],b) or check(a[2:7:2],b):
        ans = 'Yes'

print(ans)

Solution (Python):




def bingo(a, b, c):
    if a[0] == b[0] == c[0]:
        return True
    if a[1] == b[1] == c[1]:
        return True
    if a[2] == b[2] == c[2]:
        return True
    if a[0] == a[1] == a[2]:
        return True
    if b[0] == b[1] == b[2]:
        return True
    if c[0] == c[1] == c[2]:
        return True
    if a[0] == b[1] == c[2]:
        return True
    if a[2] == b[1] == c[0]:
        return True
    return False

l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
n = int(input())
ans = "No"
for i in range(n):
    b = int(input())
    for j in range(3):
        if l1[j] == b:
            l1[j] = 0
        if l2[j] == b:
            l2[j] = 0
        if l3[j] == b:
            l3[j] = 0
    if (bingo(l1,l2,l3)):
         ans = "Yes"

print(ans)

Solution (Python):




























































































global FLAG_LOG
FLAG_LOG = False


def log(value):
    
    
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    
    N = int(lines[3])
    
    values_a1 = list(map(int, lines[0].split()))
    values_a2 = list(map(int, lines[1].split()))
    values_a3 = list(map(int, lines[2].split()))
    values = list()
    for i in range(N):
        values.append(int(lines[i+4]))
    
    
    

    
    flags = [0] * 9

    for n in range(N):
        if values[n] == values_a1[0]:
            flags[0] = 1
        if values[n] == values_a1[1]:
            flags[1] = 1
        if values[n] == values_a1[2]:
            flags[2] = 1
        if values[n] == values_a2[0]:
            flags[3] = 1
        if values[n] == values_a2[1]:
            flags[4] = 1
        if values[n] == values_a2[2]:
            flags[5] = 1
        if values[n] == values_a3[0]:
            flags[6] = 1
        if values[n] == values_a3[1]:
            flags[7] = 1
        if values[n] == values_a3[2]:
            flags[8] = 1

    result = 'No'
    
    if flags[0] * flags[1] * flags[2] == 1:
        result = 'Yes'
    if flags[3] * flags[4] * flags[5] == 1:
        result = 'Yes'
    if flags[6] * flags[7] * flags[8] == 1:
        result = 'Yes'
    
    if flags[0] * flags[3] * flags[6] == 1:
        result = 'Yes'
    if flags[1] * flags[4] * flags[7] == 1:
        result = 'Yes'
    if flags[2] * flags[5] * flags[8] == 1:
        result = 'Yes'
    
    if flags[0] * flags[4] * flags[8] == 1:
        result = 'Yes'
    if flags[2] * flags[4] * flags[6] == 1:
        result = 'Yes'

    return [result]



def get_input_lines():
    lines = list()
    for _ in range(3):
        lines.append(input())
    line = input()
    N = int(line)
    lines.append(line)
    for _ in range(N):
        lines.append(input())
    return lines



def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['84 97 66', '79 89 11', '61 59 7', '7', '89', '7', '87', '79', '24', '84', '30']
        lines_export = ['Yes']
    if pattern == 2:
        lines_input = ['41 7 46', '26 89 2', '78 92 8', '5', '6', '45', '16', '57', '17']
        lines_export = ['No']
    if pattern == 3:
        lines_input = ['60 88 34', '92 41 43', '65 73 48', '10', '60', '43', '88', '11', '48', '73', '65', '41', '92', '34']
        lines_export = ['Yes']
    return lines_input, lines_export



def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode



def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    
    
    
    
    
    
    
    
    
    
    



if __name__ == '__main__':
    main()

Solution (Python):
a1=input("").split(" ")
a2=input("").split(" ")
a3=input("").split(" ")
lista=[]
listmp=[]
for k in range(3):
    listmp+=[int(a1[k])]
lista+=[listmp]
listmp=[]
for k in range(3):
    listmp+=[int(a2[k])]
lista+=[listmp]
listmp=[]
for k in range(3):
    listmp+=[int(a3[k])]
lista+=[listmp]
n=int(input(""))
listn=[]
for i in range(n):
    t=int(input(""))
    listn+=[t]
for i in range(3):
    for k in range(3):
        if(lista[i][k] in listn):
            lista[i][k]=0
p=0
for i in range(3):
    s=0
    for k in range(3):
        s+=lista[i][k]

    if(s==0):
            p=1
for i in range(3):
    s=0
    for k in range(3):
        s+=lista[k][i]

    if(s==0):
            p=1
s=0
for i in range(3):
    s+=lista[i][i]
if(s==0):
    p=1
s=0
for i in range(3):
    s+=lista[i][2-i]
if(s==0):
    p=1
if(p==1):
    print("Yes")
else:
    print("No")

Solution (Python):


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


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

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

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

import numpy as np

for i in range(3):
  a[i]=[1 if x in b else 0 for x in a[i]]   

s_1=max(np.sum(a,axis=0))
s_2=max(np.sum(a,axis=1))
s_3=a[0][0]+a[1][1]+a[2][2]
s_4=a[0][2]+a[1][1]+a[2][0]

if max(s_1,s_2,s_3,s_4)==3:
  print("Yes")
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())
for i in range(n):
    b=int(input())
    if b in A:
        A=np.where(A==b,0,A)
cross=0
if A[0][0]+A[1][1]+A[2][2]==0 or A[2][0]+A[1][1]+A[0][2]==0:
    cross=1
print("NYoe s"[0 in np.sum(A,axis=0) or 0 in np.sum(A,axis=1) or cross ::2])

Solution (Python):
def bingo():
    
    A = list()
    b = list()
    comb_list = list()
    is_bingo = False
    
    for _ in range(3):
        dummy = list(map(int, input().split()))
        A.append(dummy)
    N = int(input())
    for _ in range(N):
        dummy = int(input())
        b.append(dummy)
    
    for i in range(3):
        
        comb_list.append([A[i][0], A[i][1], A[i][2]])
        
        comb_list.append([A[0][i], A[1][i], A[2][i]])
    
    comb_list.append([A[0][0], A[1][1], A[2][2]])
    comb_list.append([A[0][2], A[1][1], A[2][0]])
    
    for i in b:
        for j in range(8):
            for k in range(3):
                if i == comb_list[j][k]:
                    comb_list[j][k] = 'null'
    
    for i in comb_list:
        for j in i:
            if 'null' != j:
                is_bingo = False
                break
            else:
                is_bingo = True
        
        if is_bingo == True:
            return 'Yes'
    
    if is_bingo == False:
        return 'No'
        

result = bingo()
print(result)