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.



Sample input:
84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30


Sample output:
Yes

Submission status: Accepted

Solution code:
#! env/bin/local python3
# -*- coding: utf-8 -*-

import numpy as np

a_1 = list(map(int, input().split()))
a_2 = list(map(int, input().split()))
a_3 = list(map(int, input().split()))
_ = input()
pickup_number = []
while True:
    try:
        pickup_number.append(int(input()))
    except EOFError:
        break

a = np.array([a_1, a_2, a_3])

for pn in pickup_number:
    a[a == pn] = -1

flag = False
if -3 in np.sum(a, axis=0) or -3 in np.sum(a, axis=1):
    flag = True
if np.sum(a.diagonal()) == -3 or a[0][2] + a[1][1] + a[2][0] == -3:
    flag = True

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

Submission status: Accepted

Solution code:
import sys
bingo = list(list(map(int, input().split())) for _ in range(3))
n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == b:
                bingo[i][j] = False
for i in range(3):
    for j in range(3):
        if bingo[i][j]:
            break
    else:
        print('Yes')
        exit()

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

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

for i in range(3):
    if bingo[i][2 - i]:
        break
else:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

Solution code:
a=[]
b=[]
for _ in range(3):
    a.append(list(map(int,input().split())))
N=int(input())
for _ in range(N):
    b.append(int(input()))
for i in range(N):
    for j in range(3):
        for k in range(3):
            if b[i]==a[k][j]:
                a[k][j]=0
if (a[0][0]==0 and a[0][1]==0 and a[0][2]==0)or(a[1][0]==0 and a[1][1]==0 and a[1][2]==0) or (a[2][0]==0 and a[2][1]==0 and a[2][2]==0) or (a[0][0]==0 and a[1][0]==0 and a[2][0]==0) or (a[0][1]==0 and a[1][1]==0 and a[2][1]==0) or (a[0][2]==0 and a[1][2]==0 and a[2][2]==0) or (a[0][0]==0 and a[1][1]==0 and a[2][2]==0) or (a[0][2]==0 and a[1][1]==0 and a[2][0]==0):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

p1 = [False]*3
p2 = [False]*3
p3 = [False]*3

for i in b:
  if i in a1:
    p1[a1.index(i)] = True
  if i in a2:
    p2[a2.index(i)] = True
  if i in a3:
    p3[a3.index(i)] = True
    
if all(p1) or all(p2) or all(p3):
  print("Yes")
  exit()
  
for i in range(3):
  if all([p1[i],p2[i],p3[i]]):
    print("Yes")
    exit()
  
if all([p1[0],p2[1],p3[2]]):
  print("Yes")
  exit()
  
if all([p1[2],p2[1],p3[0]]):
  print("Yes")
  exit()
  
print("No")

Submission status: Accepted

Solution code:
Ai_j = []
for i in range(3):
    Ai_j.append(list(map(int,input().split())))
N = int(input())
number_list = []
for i in range(N):
    number_list.append(int(input()))
'''
print(Ai_j)
print(N)
print(number_list)
'''

for x in number_list:
    for i in range(3):
        for j in range(3):
           if  Ai_j[i][j] == x:
               Ai_j[i][j] = '○'
#print(Ai_j)

count = 0

if Ai_j[0][0] == Ai_j[0][2] == Ai_j[0][1] == '○': count+=1
if Ai_j[1][0] == Ai_j[1][2] == Ai_j[1][1] == '○': count+=1
if Ai_j[2][0] == Ai_j[2][2] == Ai_j[2][1] == '○': count+=1
if Ai_j[0][0] == Ai_j[1][0] == Ai_j[2][0] == '○': count+=1
if Ai_j[0][1] == Ai_j[1][1] == Ai_j[2][1] == '○': count+=1
if Ai_j[0][2] == Ai_j[1][2] == Ai_j[2][2] == '○': count+=1
if Ai_j[0][0] == Ai_j[1][1] == Ai_j[2][2] == '○': count+=1
if Ai_j[0][2] == Ai_j[1][1] == Ai_j[2][0] == '○': count+=1

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

Submission status: Accepted

Solution code:
a1 = list(input().split())
a2 = list(input().split())
a3 = list(input().split())
n = int(input())
b = [input() for _ in range(n)]
x = []
x.append(a1)
x.append(a2)
x.append(a3)
y = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for i in range(3):
    for j in range(3):
        for k in range(n):
            if x[i][j] == b[k]:
                y[i][j] = 1
if y[0] == [1, 1, 1] or y[1] == [1, 1, 1] or y[2] == [1, 1, 1]:
    print('Yes')
elif y[0][0] == 1 and y[1][0] == 1 and y[2][0] == 1:
    print('Yes')
elif y[0][1] == 1 and y[1][1] == 1 and y[2][1] == 1:
    print('Yes')
elif y[0][2] == 1 and y[1][2] == 1 and y[2][2] == 1:
    print('Yes')
elif y[0][0] == 1 and y[1][1] == 1 and y[2][2] == 1:
    print('Yes')
elif y[0][2] == 1 and y[1][1] == 1 and y[2][0] == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np
import sys
a_list = np.array([list(map(int, input().split())) for _ in range(3)])
n = int(input())
 
for _ in range(n):
    b = int(input())
    
    for a in a_list:
        for idx, aa in enumerate(a):
            if aa == b:
                a[idx] = 0

# 縦横対角
for i in range(3):
    if list(a_list[i, :]) == [0, 0, 0] or list(a_list[:, i]) == [0, 0, 0]:
        print("Yes")
        sys.exit()
    

# 斜め
if ([a_list[i, i] for i in range(3)] == [0, 0, 0]) or ([a_list[0, 2], a_list[1, 1], a_list[2, 0]] == [0, 0, 0]):
    print("Yes")
    sys.exit()

print("No")

Submission status: Accepted

Solution code:
a=[list(map(int,input().split()))for _ in range(3)]
for i in range(int(input())):
  b=int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k]==b:a[j][k]=0
ans="No"
for i in range(3):
  if a[i][0]==a[i][1]==a[i][2]==0:ans="Yes"
  if a[0][i]==a[1][i]==a[2][i]==0:ans="Yes"
if a[0][0]==a[1][1]==a[2][2]==0:ans="Yes"
if a[2][0]==a[1][1]==a[0][2]==0:ans="Yes"
print(ans)

Submission status: Accepted

Solution code:
a = [0]*3

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

n = int(n)
b_ = [0]*n
for i in range(0,n):
  b_[i] = input()
 
b = [int(i) for i in b_]

for i in range(0,3):
  for j in range(0,3):
    if(a[i][j] in b):
      a[i][j] = 10000
    else:
      continue

if(sum(a[0])==30000 or sum(a[1])==30000 or sum(a[2])==30000):
  print("Yes")
  exit()
elif(a[0][0] + a[1][1] + a[2][2] ==30000 or a[0][2] + a[1][1] + a[0][2]== 30000):
  print("Yes")
  exit()
elif(a[0][0] + a[1][0] + a[2][0] == 30000 or a[0][1] + a[1][1] + a[2][1] == 30000 or a[0][2] + a[1][2] + a[2][2] == 30000):
  print("Yes")
  exit()
else:
  print("No")

Submission status: Accepted

Solution code:
card = [list(map(int,input().split())) for c in range(3)]
N = int(input())
nums = [int(input()) for n in range(N)]
ans =0
ind = [[False,False,False],[False,False,False],[False,False,False]]

for index,c in enumerate(card):
	for index2,c2 in enumerate(c):
		for n in nums:
			if n == c2:
				ind[index][index2] = True

if (ind[0][0] == True and ind[1][1] == True and ind[2][2] == True) or \
	(ind[0][2] == True and ind[1][1] == True and ind[2][0] == True)  or \
	(ind[0][0] == True and ind[1][0] == True and ind[2][0] == True)  or \
	(ind[0][1] == True and ind[1][1] == True and ind[2][2] == True)  or \
	(ind[0][2] == True and ind[1][2] == True and ind[2][2] == True)  or \
	(ind[0][0] == True and ind[0][1] == True and ind[0][2] == True)  or \
	(ind[1][0] == True and ind[1][1] == True and ind[1][2] == True)  or \
	(ind[2][0] == True and ind[2][1] == True and ind[2][2] == True):
  	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
import numpy as np

a = [list(map(int, input().split(' '))) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
c = [[0 for i in range(3)] for j in range(3)]
f = False

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

for i in range(3):
	if c[i][0] + c[i][1] + c[i][2] == 3:
		f = True
		break
	elif c[0][i] + c[1][i] + c[2][i] == 3:
		f = True
		break
	elif c[2][0] + c[1][1] + c[0][2] == 3 or c[0][0] + c[1][1] + c[2][2] == 3:
		f = True
		break
if f:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu May  7 14:17:13 2020

@author: shinba
"""
import sys

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

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

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

if Bingo[0][0] == 1 and Bingo[1][1] == 1 and Bingo[2][2] == 1:
    print("Yes")
    sys.exit()
if Bingo[2][0] == 1 and Bingo[1][1] == 1 and Bingo[0][2] == 1:
    print("Yes")
    sys.exit()

print("No")

Submission status: Accepted

Solution code:
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
Am = [A1[0], A2[1], A3[2]]
Al = [A1[2], A2[1], A3[0]]
n = int(input())
B = []
for k in range(n):
    b = int(input())
    B.append(b)
#タテ
for i in range(3):
    chk1 = A1[i]
    chk2 = A2[i]
    chk3 = A3[i]
    if chk1 in B:
        if chk2 in B:
            if chk3 in B:
                print('Yes')
                exit()

cnt = 0
for j in A1:
    if j in B:
        cnt += 1
if cnt == 3:
    print('Yes')
    exit()

cnt = 0
for j in A2:
    if j in B:
        cnt += 1
if cnt == 3:
    print('Yes')
    exit()

cnt = 0
for j in A3:
    if j in B:
        cnt += 1
if cnt == 3:
    print('Yes')
    exit()

cnt = 0
for j in Am:
    if j in B:
        cnt += 1
if cnt == 3:
    print('Yes')
    exit()

cnt = 0
for j in Al:
    if j in B:
        cnt += 1
if cnt == 3:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

Solution code:
def isbingo(ls:list) -> bool:
    for x in ls:
        if set(x)=={0}:return 0
    for x in range(3):
        if ls[0][x] == ls[1][x] == ls[2][x]:return 0
    if ls[0][0] == ls[1][1] == ls[2][2]:return 0
    if ls[0][2] == ls[1][1] == ls[2][0]:return 0
    return 1
a,b,c=(list(map(int,input().split()))for _ in'___')
p=list(map(int,(input()for _ in [0]*int(input()))));a = [a,b,c]
for x in range(3):
    for y in range(3):
        if a[x][y] in p:a[x][y] = 0
print("YNeos"[isbingo(a)::2])

Submission status: Accepted

Solution code:
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[i].count(0)==3:
        ans='Yes'
for i in range(3):
    temp=[A[0][i],A[1][i],A[2][i]]
    if temp.count(0)==3:
        ans='Yes'
if A[0][0]==0 and A[1][1]==0 and A[2][2]==0:
    ans='Yes'
elif A[0][2]==0 and A[1][1]==0 and A[2][0]==0:
    ans='Yes'
print(ans)

Submission status: Accepted

Solution code:
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 n in range(N):
    called_num = int(input())
    exist_list = [called_num in A[i] for i in range(3)]
    if True in exist_list:
        called_row = exist_list.index(True)
        A[called_row] = [0 if x==called_num else x for x in A[called_row]]
        
sum_row = np.sum(A, axis=1)
sum_col = np.sum(A, axis=0)
sum_diag1 = np.diag(A).sum()
sum_diag2 = A[0][2] + A[1][1] + A[2][0] #良い実装が思いつかなかった

if 0 in sum_row or 0 in sum_col or 0 in [sum_diag1, sum_diag2]: #書き方イマイチ
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

Q = int(input())
for i in range(Q):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                marked[j][k] = True
                
for i in range(3):
    if marked[i][0] == marked[i][1] == marked[i][2] == True:
        print("Yes")
        exit()
    if marked[0][i] == marked[1][i] == marked[2][i] == True:
        print("Yes")
        exit()
if marked[0][0] == marked[1][1] == marked[2][2] == True:
    print("Yes")
    exit()
if marked[0][2] == marked[1][1] == marked[2][0] == True:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
import sys
A=[list(map(int,input().split())) for i in range(3)]
N=int(input())
b=[list(map(int,input().split())) for i in range(N)]
flat=[j for i in A for j in i]
for i,value in enumerate(flat):
    if [value] in b:
         flat[i]=-1
for i in range(3):
    if flat[i*3]==flat[i*3+1]==flat[i*3+2]==-1:
        print('Yes')
        sys.exit()
    if flat[i]==flat[i+3]==flat[i+6]==-1:
        print('Yes')
        sys.exit()
if flat[0]==flat[4]==flat[8]==-1 or flat[2]==flat[4]==flat[6]==-1:
    print('Yes')
    sys.exit()
print('No')

Submission status: Accepted

Solution code:
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
n=int(input())
for i in range(n):
    p=int(input())
    for q in range(3):
        if a[q]==p:
            a[q]=0
        if b[q]==p:
            b[q]=0
        if c[q]==p:
            c[q]=0
f=0
if a[0]==a[1]==a[2] or b[0]==b[1]==b[2] or c[0]==c[1]==c[2]:
    f=1
if a[0]==b[0]==c[0] or a[1]==b[1]==c[1] or a[2]==b[2]==c[2]:
    f=1
if a[0]==b[1]==c[2] or a[2]==b[1]==c[0]:
    f=1
print("Yes" if f==1 else "No")

Submission status: Accepted

Solution code:
A,B,C=map(int,input().split())
D,E,F=map(int,input().split())
G,H,I=map(int,input().split())
N=int(input())
l=list()
for i in range(N):
  b=int(input())
  l.append(b)

if A in l and B in l and C in l:
  print('Yes')
  exit()

if A in l and D in l and G in l:
  print('Yes')
  exit()
  
if A in l and E in l and I in l:
  print('Yes')
  exit()

if D in l and E in l and F in l:
  print('Yes')
  exit()
  
if G in l and H in l and I in l:
  print('Yes')
  exit()

if B in l and E in l and H in l:
  print('Yes')
  exit()
  
if C in l and F in l and I in l:
  print('Yes')
  exit()
  
if C in l and E in l and G in l:
  print('Yes')
  exit()
  
else:
  print('No')

Submission status: Accepted

Solution code:
f = list(map(int, input().split()))
s = list(map(int, input().split()))
t = list(map(int, input().split()))
n = int(input())
k = []
for i in range(n):
    k.append(int(input()))

lis = []

lis.append(f)
lis.append(s)
lis.append(t)

ans = 0

for i in lis:
    c =0
    for n in range(len(i)):
        if i[n] in k:
            i[n] = 'X'
            c += 1
            if c == 3:
                ans +=1
                break

if f[0] == 'X' and s[0] == 'X' and t[0] == 'X':
    ans +=1
elif f[1] == 'X' and s[1] == 'X' and t[1] == 'X':
    ans += 1
elif f[2] == 'X' and s[2] == 'X' and t[2] == 'X':
    ans += 1
elif f[0] == 'X' and s[1] == 'X' and t[2] == 'X':
    ans += 1
elif f[2] == 'X' and s[1] == 'X' and t[0] == 'X':
    ans += 1
    
if ans >= 1:
    print('Yes')
elif ans == 0:
    print('No')

Submission status: Accepted

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

bingo = []
for i in range(3):
    for j in range(3):
        for k in range(n):
            if a[i][j] == b[k]:
                a[i][j] = 0
#print(a)
for i in range(3):
    if a[i][0] == 0 and a[i][1] == 0 and a[i][2] == 0 :
        print("Yes")
        exit()
for i in range(3):
    if a[0][i] == 0 and a[1][i] == 0 and a[2][i] == 0 :
        print("Yes")
        exit()
if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
        print("Yes")
        exit()
if a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0:
        print("Yes")
        exit()

print("No")
exit()

Submission status: Accepted

Solution code:
A = list()
for i in range(3):
  A += list(map(int, input().split()))
  
N = int(input())
for i in range(N):
  b = int(input())
  for j in range(len(A)):
    if A[j] == b:
      A[j] = 0

for i in range(3):
  if A[3*i:3*i+3] == [0, 0, 0]:
    print('Yes')
    exit()
  elif [A[i], A[i+3], A[i+6]] == [0, 0, 0]:
    print('Yes')
    exit()
  elif [A[0], A[4], A[8]] == [0, 0, 0] or [A[2], A[4], A[6]] == [0, 0, 0]:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

Solution code:
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]=0
ans="No"
for i in range(3):
    if a[i][0]==a[i][1]==a[i][2]:
        ans="Yes"
    if a[0][i]==a[1][i]==a[2][i]:
        ans="Yes"
if a[0][0]==a[1][1]==a[2][2]:
    ans="Yes"
if a[0][2]==a[1][1]==a[2][0]:
    ans="Yes"
print(ans)

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for _ in range(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
        
bingo = False
for row in A:
  if sum(row) == 0:
    bingo = True
for col in zip(*A):
  if sum(col) == 0:
    bingo = True
if sum(A[i][i] for i in range(3)) == 0:
  bingo =True
if sum(A[i][3 - i - 1] for i in range(3)) == 0:
  bingo = True
  
print("Yes" if bingo == True else "No")

Submission status: Accepted

Solution code:
import numpy as np
a = [input().split() for i in range(3)]
N = int(input())
b = [int(input()) for i in range(N)] 

a = np.array(a,  dtype=np.int64).reshape(9)
b = np.array(b, dtype=np.int64)

for i in range(N):
    for j in range(len(a)):
        if b[i] == a[j]:
            a[j] = -1

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

Submission status: Accepted

Solution code:
import itertools

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

A_2d=[list(map(int,list(input().split()))) for i in range(3)]
A=list(itertools.chain.from_iterable(A_2d)) # A_1d

N = int(input())

for _ in range(N):
  b = int(input())
  A = [0 if i == b else i for i in A]
  
if judge():
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys

a = []

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

n = int(input())
for j in range(n):
    tmp = int(input())
    for x in range(3):
        for y in range(3):
            if(a[x][y] == tmp):
                a[x][y] = 0


if a[0][0] == 0 and a[0][1] == 0 and a[0][2] == 0:
    print('Yes')
    sys.exit()
elif a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
    print('Yes')
    sys.exit()
elif a[0][0] == 0 and a[1][0] == 0 and a[2][0] == 0:
    print('Yes')
    sys.exit()
elif a[0][1] == 0 and a[1][1] == 0 and a[2][1] == 0:
    print('Yes')
    sys.exit()
elif a[0][2] == 0 and a[1][2] == 0 and a[2][2] == 0:
    print('Yes')
    sys.exit()
elif a[1][0] == 0 and a[1][1] == 0 and a[1][2] == 0:
    print('Yes')
    sys.exit()
elif a[2][0] == 0 and a[2][1] == 0 and a[2][2] == 0:
    print('Yes')
    sys.exit()
elif a[2][0] == 0 and a[1][1] == 0 and a[0][2] == 0:
    print('Yes')
    sys.exit()
else:
    print('No')
    sys.exit()

Submission status: Accepted

Solution code:
import sys
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
B = [0] * N
for i in range(N):
    B[i] = int(input())

R1 = [False] * 3
R2 = [False] * 3
R3 = [False] * 3

for b in B:
    if b in A1:
        R1[A1.index(b)] = True
    if b in A2:
        R2[A2.index(b)] = True
    if b in A3:
        R3[A3.index(b)] = True

if R1[0] and R1[1] and R1[2]:
    print("Yes")
    sys.exit(0)

if R2[0] and R2[1] and R2[2]:
    print("Yes")
    sys.exit(0)

if R3[0] and R3[1] and R3[2]:
    print("Yes")
    sys.exit(0)

if R1[0] and R2[0] and R3[0]:
    print("Yes")
    sys.exit(0)

if R1[1] and R2[1] and R3[1]:
    print("Yes")
    sys.exit(0)

if R1[2] and R2[2] and R3[2]:
    print("Yes")
    sys.exit(0)

if R1[0] and R2[1] and R3[2]:
    print("Yes")
    sys.exit(0)

if R1[2] and R2[1] and R3[0]:
    print("Yes")
    sys.exit(0)
    
print("No")

Submission status: Accepted

Solution code:
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]=0
ans="No"
for i in range(3):
    if a[i][0]==a[i][1]==a[i][2]:
        ans="Yes"
    if a[0][i]==a[1][i]==a[2][i]:
        ans="Yes"
if a[0][0]==a[1][1]==a[2][2]:
    ans="Yes"
if a[0][2]==a[1][1]==a[2][0]:
    ans="Yes"
print(ans)

Submission status: Accepted

Solution code:
# B - Bingo

A = []
for _ in range(3):
    A.append([int(a) for a in input().split()])

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

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

print(ans)

Submission status: Accepted

Solution code:
a=[list(map(int, 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
flag=False
for i in range(3):
    if a[i][0]==a[i][1]==a[i][2]==0:
        flag=True
for i in range(3):
    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[0][2]==a[1][1]==a[2][0]==0:
    flag=True
print('Yes' if flag else 'No')

Submission status: Accepted

Solution code:
a=[list(map(int,input().split()))for _ in range(3)]
for i in range(int(input())):
  b=int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k]==b:a[j][k]=0
ans="No"
for i in range(3):
  if a[i][0]==a[i][1]==a[i][2]==0:ans="Yes"
  if a[0][i]==a[1][i]==a[2][i]==0:ans="Yes"
if a[0][0]==a[1][1]==a[2][2]==0:ans="Yes"
if a[2][0]==a[1][1]==a[0][2]==0:ans="Yes"
print(ans)

Submission status: Accepted

Solution code:
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())
    a1 = [0 if i == b else i for i in a1]
    a2 = [0 if i == b else i for i in a2]
    a3 = [0 if i == b else i for i in a3]
    
if a1[0] == a2[0] == a3[0] == 0 or a1[1] == a2[1] == a3[1] == 0 or a1[2] == a2[2] == a3[2] == 0 or a1[0] == a2[1] == a3[2] == 0 or a1[2] == a2[1] == a3[0] == 0 or a1[0] == a1[1] == a1[2] or a2[0] == a2[1] == a2[2] or a3[0] == a3[1] == a3[2]:
    print('Yes') 
else:
    print('No')

Submission status: Accepted

Solution code:
def resolve():
  A = [[int(item) for item in input().split()] for i in range(3)]
  N = int(input())
  B = [int(input()) for i in range(N)]
  
  table = [[a in B for a in row] for row in A]
  
  for i in range(3):
    if table[i][0] == table[i][1] == table[i][2] == True:
      print("Yes")
      return
    if table[0][i] == table[1][i] == table[2][i] == True:
      print("Yes")
      return
    
  if table[0][0] == table[1][1] == table[2][2] == True or table[0][2] == table[1][1] == table[2][0] == True:
    print("Yes")
    return 
  
  print("No")
  
resolve()

Submission status: Accepted

Solution code:
a=[[],[],[]]

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

n = int(input())

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

y0 = (a[0][0] == a[0][1] == a[0][2])
y1 = (a[1][0] == a[1][1] == a[1][2])
y2 = (a[2][0] == a[2][1] == a[2][2])

t0 = (a[0][0] == a[1][0] == a[2][0])
t1 = (a[0][1] == a[1][1] == a[2][1])
t2 = (a[0][2] == a[1][2] == a[2][2])

n1 = (a[0][0] == a[1][1] == a[2][2])
n2 = (a[0][2] == a[1][1] == a[2][0])

if y0 or y1 or y2 or t0 or t1 or t2 or n1 or n2:
    print('Yes')
else :
    print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy3
import collections
import itertools as it
import math
import numpy as np
 
#  = input()
#  = int(input())
yoko = [list(map(int, input().split())) for _ in range(3)]
is_flag = [False] * 9
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

yoko = list(np.array(yoko).flatten())

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

    if b in yoko:
        is_flag[yoko.index(b)] = True

is_flag = list(np.array(is_flag).reshape(3, 3))

line = is_flag # yoko
line += list(np.array(is_flag).T) # tate
line += [[line[0][0], line[1][1], line[2][2]], [line[0][2], line[1][1], line[2][0]]]

for l in line:
    if sum(l) == 3:
        print('Yes')
        break
else:
    print('No')
#print(yoko)
#print(tate)
#print(naname)

Submission status: Accepted

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

for a in A:
    for i, x in enumerate(a):
        if x in b:
            a[i] = "o"

# 横
for a in A:
    if len(set(a)) == 1:
        print("Yes")
        exit()

# 縦
T = []
for i in range(3):
    temp = []
    for j in range(3):
        temp.append(A[j][i])
    T.append(temp)

for t in T:
    if len(set(t)) == 1:
        print("Yes")
        exit()

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

print("No")

Submission status: Accepted

Solution code:
def resolve():
    a = [[int(i) for i in input().split()] for _ in range(3)]
    ans = 'No'
    n = int(input())
    for _ in range(n):
        b = int(input())
        for i in range(3):
            for j in range(3):
                if b == a[i][j]:
                    a[i][j] = 0

    for i in range(3):
        if sum(a[i]) == 0 or sum([a[0][i], a[1][i], a[2][i]]) == 0:
            ans = 'Yes'
        elif sum([a[0][0], a[1][1], a[2][2]]) == 0 or sum([a[0][2], a[1][1], a[2][0]]) == 0:
            ans = 'Yes'
    print(ans)

resolve()

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for _ in range(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
ans = False     
for row in A:
    if sum(row) == 0:
        ans = True
for col in zip(*A):
    if sum(col) == 0:
        ans = True

if sum(A[i][i] for i in range(3)) == 0:
    ans =True
if sum(A[i][3 - i - 1] for i in range(3)) == 0:
    ans =True

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    A = [list(map(int,rl().split())) for _ in range(3)]
    N = int(rl())
    b = [int(rl()) 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()

Submission status: Accepted

Solution code:
import numpy as np

A = np.zeros([3, 3], dtype=int)
M = np.zeros([3, 3], dtype=int)

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

for b in B:
    M[A == b] = 1

if np.any(np.all(M==1, axis=0) == True) or np.any(np.all(M==1, axis=1) == True):
    print('Yes')
elif M[0,0]*M[1,1]*M[2,2]:
    print('Yes')
elif M[0,2]*M[1,1]*M[2,0]:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

A = LIR(3)
n = I()
B = IR(n)

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

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

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

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

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

print("No")