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:
b=[list(map(int,input().split()))for i in range(3)]
n=int(input())
nums=set([int(input())for i in range(n)])
for i in range(3):
    for j in range(3):
        if b[i][j] in nums:
            b[i][j]=0
flag=False
for i in range(3):
    if b[i][0] == b[i][1] == b[i][2] == 0:
        flag=True
    if b[0][i] == b[1][i] == b[2][i] == 0:
        flag=True
if b[0][0] == b[1][1] == b[2][2] == 0:
    flag=True
if b[2][0] == b[1][1] == b[0][2] == 0:
    flag=True

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

Submission status: Accepted

Solution code:
list0=[]
date0=input().rstrip().split(" ")
date1=input().rstrip().split(" ")
date2=input().rstrip().split(" ")
list0.append(date0)
list0.append(date1)
list0.append(date2)
num=int(input())
for k in range(num):
  memo=input()
  for i in range(3):
    j=0
    for j in range(3):
      if list0[i][j]==memo:
        list0[i][j]="0"
if list0[0]==['0','0','0'] or list0[1]==['0','0','0'] or list0[2]==['0','0','0']:
  print("Yes")
elif list0[0][1]=="0" and list0[1][1]=="0" and list0[2][1]=="0":
  print("Yes")
elif list0[0][2]=="0" and list0[1][2]=="0" and list0[2][2]=="0":
  print("Yes")
elif list0[0][0]=="0" and list0[1][0]=="0" and list0[2][0]=="0":
  print("Yes")
elif list0[0][0]=="0" and list0[1][1]=="0" and list0[2][2]=="0":
  print("Yes")
elif list0[0][2]=="0" and list0[1][1]=="0" and list0[2][0]=="0":
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys
li = [list(map(int,input().split())) for i in range(3)]
n = int(input())
k = [int(input()) for i in range(n)]
cnt = 0
for i in range(3):
    for j in range(3):
        if li[i][j] in k:
            li[i][j] = -1
        else:
            pass
for a in range(3):
    if li[a][0] == li[a][1] == li[a][2] == -1:
        print("Yes")
        exit()
    else:
        pass
for b in range(3):
    if li[0][b] == li[1][b] == li[2][b] == -1:
        print("Yes")
        exit()
    else:
        pass
if li[0][0] == li[1][1] == li[2][2] == -1:
    print("Yes")
    exit()

elif li[0][2] == li[1][1] == li[2][0] == -1:
    print("Yes")
    exit()
else:
    print("No")

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

f = 0

for i in range(n):
  for m in range(3):
    for n in range(3):
      if a[m][n] ==b[i]:
        a[m][n]='o'
for i in range(3):
  if a[0][i]=='o' and a[1][i]=='o' and a[2][i]=='o':
    f+=1

for i in range(3):
  if a[i][0]=='o' and a[i][1]=='o' and a[i][2]=='o':
    f +=1 

if a[0][0]=='o' and a[1][1]=='o' and a[2][2]=='o':
  f+=1

if a[0][2]=='o' and a[1][1]=='o' and a[2][0]=='o':
  f+=1
  
if f ==0:
  print('No')
else:
  print('Yes')

Submission status: Accepted

Solution code:
a = []
a.extend(map(int, input().split()))
a.extend(map(int, input().split()))
a.extend(map(int, input().split()))
n = int(input())
b = []

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

#print(a, b)

for i in range(len(b)):
  a = [0 if mas == b[i] else mas for mas in a]

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

Submission status: Accepted

Solution code:
mat = [[False]*3 for i in range(3)]
a_mat = []
for i in range(3):
  a_list = list(map(int, input().split()))
  a_mat.append(a_list)
n = int(input())
for i in range(n):
  b = int(input())
  for x in range(3):
    for y in range(3):
      if a_mat[x][y] == b:
        mat[x][y] = True

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

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
flag=0
for i in range(3):
    if A[i][0] == 0 and A[i][1] == 0 and A[i][2]==0:
        flag =1
for i in range(3):
    if A[0][i] == 0 and A[1][i] == 0 and A[2][i]==0:
        flag =1
if A[0][0] ==0 and A[1][1] ==0 and A[2][2]==0:
    flag=1
if  A[0][2] ==0 and A[1][1] ==0 and A[2][0]==0:
    flag = 1

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

Submission status: Accepted

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

n = int(input())

v = []
for j in range(n):
    v.append(int(input()))

for k in v:
    for i in range(3):
        for j in range(3):
            if a[i][j] == k:
                a[i][j] = -1

bingo = False
for i in range(3):
    if a[i][0] == -1 and a[i][1] == -1 and a[i][2] == -1:
        bingo = True
    if a[0][i] == -1 and a[1][i] == -1 and a[2][i] == -1:
        bingo = True

if a[0][0] == -1 and a[1][1] == -1 and a[2][2] == -1:
    bingo = True
elif a[0][2] == -1 and a[1][1] == -1 and a[2][0] == -1:
    bingo = True

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

Submission status: Accepted

Solution code:
import numpy as np

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

n = int(input())

for j in range(n):
    val2 = int(input())
    if np.any(a == val2):
        a = np.where(a==val2, -1, a)

bingo = False
for i in range(3):
    if np.all(a[i,:] == -1):
        bingo = True
        break
    if np.all(a[:,i] == -1):
        bingo = True
        break
if a[0,0] == -1 and a[1,1] == -1 and a[2,2] == -1:
    bingo = True
if a[0,2] == -1 and a[1,1] == -1 and a[2,0] == -1:
    bingo = True

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

Submission status: Accepted

Solution code:
import numpy as np
A = np.array([list(map(int, input().split())) for i in range(3)])
N = int(input())
for i in range(N):
    bingo_num = int(input())
    A = np.where(A == bingo_num, 0, A)
if (0 in np.sum(A, axis=1)
    or 0 in np.sum(A, axis=0)
    or np.sum(np.diag(A)) == 0
        or A[0, 2]+A[1, 1]+A[2, 0] == 0):
    print("Yes")
else:
    print("No")

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)]
flag = True
for i in range(N):
    for n in range(3):
        for m in range(3):
            if A[n][m]==b[i]:
                A[n][m]='o'
for i in range(3):
    if A[i][0]=='o' and A[i][1]=='o' and A[i][2]=='o':
        flag = False
for i in range(3):
    if A[0][i]=='o' and A[1][i]=='o' and A[2][i]=='o':
        flag = False
if A[0][0] == A[1][1]==A[2][2] =='o':
    flag = False
if A[0][2] == A[1][1] ==A[2][0]=='o':
    flag = False
if flag == False:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
s1=list(map(int, input().split()))
s2=list(map(int, input().split()))
s3=list(map(int, input().split()))
n = int(input())
A=set()
for i in range(n):
	s=int(input())
	A.add(s)
c=[0]*9
for i in range(3):
	if s1[i] in A:
		c[i]+=1

for i in range(3):
	if s2[i] in A:
		c[i+3]+=1

for i in range(3):
	if s3[i] in A:
		c[i+6]+=1
p=0
#naname
if c[0]+c[4]+c[8]==3:
	print('Yes')
	p+=1
if p==0 and c[2]+c[4]+c[6]==3:
	print('Yes')
	p+=1

#yoko
if p==0 and c[0]+c[1]+c[2]==3:
	print('Yes')
	p+=1
if p==0 and c[3]+c[4]+c[5]==3:
	print('Yes')
	p+=1
if p==0 and c[6]+c[7]+c[8]==3:
	print('Yes')
	p+=1
#tate
for i in range(3):
	if p==0 and c[i]+c[3+i]+c[6+i]==3:
		print('Yes')
		p+=1

if p==0:
	print('No')

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 b:
  for j in range(3):
    if i in A[j]:
      A[j][A[j].index(i)] = 0
else:
  for i in range(3):
    if (A[0][i] + A[1][i] + A[2][i] == 0) or (A[i][0] + A[i][1] + A[i][2] == 0):
      print('Yes')
      break
  else:
    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')

Submission status: Accepted

Solution code:
import sys



bingo = [[int(c) for c in input().split()] for _ in range(3)]
n = int(input())
a = [int(input()) for _ in range(n)]

ans = [[0,0,0],[0,0,0],[0,0,0]]
num =0

for i in range(n):
    for j in range(3):
        for k in range(3):
            if a[i] == bingo[j][k]:
                ans[j][k] = 1
                num += 1
if num < 3:
    print("No")
    exit()

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


for i in range(3):

    if ans[i][0] == 1 and ans[i][1] == 1 and ans[i][2] == 1:
        print("Yes")
        exit()
    elif ans[0][i] == 1 and ans[1][i] == 1 and ans[2][i] == 1:
        print("Yes")
        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()))
a = a1 + a2 + a3
 
n = int(input())
 
#bがaにあるか確認して0へ
for _ in range(n):
  b = int(input())
  if b in a:
    a[a.index(b)]=0
  
  
check = 0
for i in range(3):
  #縦横のbingo検索
  if (a[3*i]==a[3*i+1] and a[3*i+1]==a[3*i+2]) or (a[i]==a[i+3] and a[i+3]==a[i+6]):
        check+=1
#ななめ
if (a[0]==a[4] and a[4]==a[8]) or (a[2]==a[4] and a[4]==a[6]):
    check+=1
if check>0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=math.floor,math.ceil
from collections import deque
Yes=lambda b:print('Yes')if b else print('No');YES=lambda b:print('YES')if b else print('NO')
is_even=lambda x:True if x%2==0 else False

def main():
  A = []
  for _ in range(3):
    A+=ints()
  n = aint()
  for _ in range(n):
    num = aint()
    for i in range(9):
      if A[i]==num: A[i]=0
  b = sum(A[:3])*sum(A[3:6])*sum(A[6:])*(A[0]+A[3]+A[6])*(A[1]+A[4]+A[7])*(A[2]+A[5]+A[8])*(A[0]+A[4]+A[8])*(A[2]+A[4]+A[6])
  Yes(b==0)
    
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
is_chosen = [False]*9
bingo = {}
for i in range(3):
    for j, a in enumerate([int(i) for i in input().split()]):
        bingo[a] = i*3 + j

N = int(input())
for i in range(N):
    b = int(input())
    if(b in bingo):
        is_chosen[bingo[b]] = True

ans = False
for i in range(3):
    ans |= is_chosen[i] and is_chosen[3 + i] and is_chosen[6 + i]
    ans |= is_chosen[i*3] and is_chosen[i*3 + 1] and is_chosen[i*3 + 2]
ans |= is_chosen[0] and is_chosen[4] and is_chosen[8]
ans |= is_chosen[2] and is_chosen[4] and is_chosen[6]

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

Submission status: Accepted

Solution code:
A = []
A.append( [ int(x) for x in input().split() ] )
A.append( [ int(x) for x in input().split() ] )
A.append( [ int(x) for x in input().split() ] )

N = int( input() )
for nn in range(N):
    b = int( input() )
    for ii in range(3):
        for jj in range(3):
            if( A[ii][jj] == b ):
                A[ii][jj] = 0

ans = False
# tate
for ii in range(3):
    if( sum( A[ii] ) == 0 ):
        ans = True
# yoko
for jj in range(3):
    tmp = 0
    for ii in range(3):
        tmp += A[ii][jj]
    if( tmp == 0 ):
        ans = True
# naname        
if( A[0][0]+A[1][1]+A[2][2] == 0 ):
    ans = True  
if( A[2][0]+A[1][1]+A[0][2] == 0 ):
    ans = True        

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

Submission status: Accepted

Solution code:
import sys
import math
# input処理を高速化する
input = sys.stdin.readline

BingoCard = []

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

N = int(input())

for i in range(N):
    b_i = int(input())

    for j in range(3):
        for k in range(3):
            if BingoCard[j][k] == b_i:
                BingoCard[j][k] =0

#ビンゴかどうか判定
if BingoCard[0] ==[0,0,0]:
    print('Yes')
elif BingoCard[1] ==[0,0,0]:
    print('Yes')
elif BingoCard[2] ==[0,0,0]:
    print('Yes')
elif [n[0] for n in BingoCard] ==[0,0,0]:
    print('Yes')
elif [n[1] for n in BingoCard] ==[0,0,0]:
    print('Yes')
elif [n[2] for n in BingoCard] ==[0,0,0]:
    print('Yes')
elif [BingoCard[n][n] for n in range(3)] ==[0,0,0]:
    print('Yes')
elif [BingoCard[n][2-n] for n in range(3) ] ==[0,0,0]:
    print('Yes')
else:
    print('No')

# print(*BingoCard,sep="\n")

Submission status: Accepted

Solution code:
bingo_card = []
for _ in range(3):
  bingo_card.extend(input().split())
  
N = int(input())

for _ in range(N):
  value = input()
  if value in bingo_card:
    bingo_card[bingo_card.index(value)] = '*'
    
row1 = bingo_card[0] + bingo_card[1] + bingo_card[2]
row2 = bingo_card[3] + bingo_card[4] + bingo_card[5]
row3 = bingo_card[6] + bingo_card[7] + bingo_card[8]
col1 = bingo_card[0] + bingo_card[3] + bingo_card[6]
col2 = bingo_card[1] + bingo_card[4] + bingo_card[7]
col3 = bingo_card[2] + bingo_card[5] + bingo_card[8]
dgn1 = bingo_card[0] + bingo_card[4] + bingo_card[8]
dgn2 = bingo_card[2] + bingo_card[4] + bingo_card[6]

bingo = '***'
if any([
  row1 == bingo,
  row2 == bingo,
  row3 == bingo,
  col1 == bingo, 
  col2 == bingo,
  col3 == bingo,
  dgn1 == bingo,
  dgn2 == bingo
]):
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

memo = [[0]*3 for _3 in range(3)]

for _ in range(n):
    p = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == p:
                memo[i][j] = 1

sums = []

for l in memo:
    sums.append(sum(l))

for k in range(3):
    sums.append(memo[0][k]+memo[1][k]+memo[2][k])

sums.append(memo[0][0] + memo[1][1] + memo[2][2])
sums.append(memo[0][2] + memo[1][1] + memo[2][0])

if max(sums) == 3:
    print("Yes")

else:
    print("No")

Submission status: Accepted

Solution code:
a = list()
for _ in range(3):
    data = input().split(' ')
    a.append([int(d) for d in data])
n = int(input())
b = list()
for _ in range(n):
    b.append(int(input()))
# check data
matched_flag = list()
for i in range(3):
    matched_flag.append([1 if elem in b else 0 for elem in a[i]])
# check rows
for row in matched_flag:
    if sum(row) == 3:
        print('Yes')
        exit(0)
# check cols
for j in range(3):
    if sum([matched_flag[i][j] for i in range(3)]) == 3:
        print('Yes')
        exit(0)
# check diags
if (sum([matched_flag[i][i] for i in range(3)]) == 3) or \
    (sum([matched_flag[i][2-i] for i in range(3)]) == 3):
    print('Yes')
    exit(0)
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 _ in range(n)]
B1 = [0,0,0] 
B2 = [0,0,0]
B3 = [0,0,0]

for i in b:
    if i in A1:
        x = A1.index(i)
        B1[x] = 1
    if i in A2:
        x = A2.index(i)
        B2[x] = 1
    if i in A3:
        x = A3.index(i)
        B3[x] = 1

if B1[0] == B1[1] == B1[2] == 1 or B2[0] == B2[1] == B2[2] == 1 or B3[0] == B3[1] == B3[2] == 1:
    print("Yes")
    exit()
elif B1[0] == B2[0] == B3[0] == 1 or B1[1] == B2[1] == B3[1] == 1 or B1[2] == B2[2] == B3[2] == 1 or B1[0] == B2[1] == B3[2] == 1 or B1[2] == B2[1] == B3[0] == 1:
    print("Yes")
    exit()
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np


def solve():
    sheet = np.zeros(9)
    bingo_inds = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 4, 8], [2, 4, 6], [0, 3, 6], [1, 4, 7], [2, 5, 8]]
    for bi in b:
        if bi in hm:
            sheet[hm[bi]] = 1
    for bi in bingo_inds:
        if sum(np.take(sheet, bi)) == 3:
            print("Yes")
            exit()
    print("No")


r1 = [int(s) for s in input().split(" ")]
r1.extend([int(s) for s in input().split(" ")])
r1.extend([int(s) for s in input().split(" ")])
hm = {v: i for i, v in enumerate(r1)}
n = int(input())
b = [int(input()) for i in range(n)]
solve()

Submission status: Accepted

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

vert = max([sum(bingo[i]) for i in range(3)])
hori = max([sum([bingo[i][j] for i in range(3)]) for j in range(3)])
cros = max(bingo[0][0]+bingo[1][1]+bingo[2][2], bingo[0][2]+bingo[1][1]+bingo[2][0])

if max(vert, hori, cros) == 3:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

num0 = 0
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
                num0 += 1
                if num0 >= 3:
                    if max(A[0]) == 0 or max(A[1]) == 0 or max(A[2]) == 0:
                        print("Yes")
                        exit()
                    elif A[0][0] == A[1][0] == A[2][0] == 0:
                        print("Yes")
                        exit()
                    elif A[0][1] == A[1][1] == A[2][1] == 0:
                        print("Yes")
                        exit()
                    elif A[0][2] == A[1][2] == A[2][2] == 0:
                        print("Yes")
                        exit()
                    elif A[0][0] == A[1][1] == A[2][2] == 0:
                        print("Yes")
                        exit()
                    elif A[0][2] == A[1][1] == A[2][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())
b = [int(input()) for _ in range(n)]

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

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


f = False
for i in range(3):
    tmpf = True
    for j in range(3):
        if bingo[i][j] == 0:
            tmpf = False
    if tmpf:
        f = True

for i in range(3):
    tmpf = True
    for j in range(3):
        if bingo[j][i] == 0:
            tmpf = False
    if tmpf:
        f = True

if bingo[0][0] == 1 and bingo[1][1] == 1 and bingo[2][2] == 1:
    f = True
if bingo[0][2] == 1 and bingo[1][1] == 1 and bingo[2][0] == 1:
    f = True

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))


def main():
    A1 = LI()
    A2 = LI()
    A3 = LI()
    N = II()
    b = [int(input()) for i in range(N)]
    ans = 0
    #print(b)

    if b.count(A2[1])!=0:
        if (b.count(A1[0])!=0 and b.count(A3[2])!=0) or (b.count(A3[0])!=0 and b.count(A1[2])!=0) or (b.count(A1[1])!=0 and b.count(A3[1])!=0) or(b.count(A2[0])!=0 and b.count(A2[2])!=0) :
            ans += 1
    if b.count(A1[0])!=0:
        if (b.count(A2[0])!=0 and b.count(A3[0])!=0) or (b.count(A1[1])!=0 and b.count(A1[2])!=0) :
            ans += 1
    if b.count(A3[2])!=0:
        if (b.count(A1[2])!=0 and b.count(A2[2])!=0) or (b.count(A3[0])!=0 and b.count(A3[1])!=0) :
            ans += 1
    if ans != 0:
        print("Yes")
    else:
        print("No")




if __name__ == "__main__":
	main()

Submission status: Accepted

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

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

r = []
for i,a in enumerate(A):
    if a in B:
        r.append(i)
r = set(r)

for p in P:
    if p.issubset(r):
        print('Yes')
        break
else:
    print('No')

Submission status: Accepted

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

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

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

win = False
for i in range(3):
    row = bingo[i]
    if all(row):
        win = True

for j in range(3):
    col = [bingo[i][j] for i in range(3)]
    if all(col):
        win = True

d1 = [bingo[0][0], bingo[1][1], bingo[2][2]]
d2 = [bingo[0][2], bingo[1][1], bingo[2][0]]

if all(d1) or all(d2):
    win = True

if win:
    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()))
alist = [a1,a2,a3]
N = int(input())
blist = [int(input()) for i in range(N)]
for i in range(N):
    for j in range(3):
        for k in range(3):
            if blist[i] == alist[j][k]:
                alist[j][k] = 0
if alist[0] == [0,0,0] or alist[1] == [0,0,0] or alist[2] == [0,0,0] or [alist[0][0],alist[1][0],alist[2][0]] == [0,0,0] or [alist[0][1],alist[1][1],alist[2][1]] == [0,0,0] or [alist[0][2],alist[1][2],alist[2][2]] == [0,0,0] or [alist[0][0],alist[1][1],alist[2][2]] == [0,0,0] or [alist[2][0],alist[1][1],alist[0][2]] == [0,0,0]:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np
a1 = np.array(input().split(),dtype=int)
a2 = np.array(input().split(),dtype=int)
a3 = np.array(input().split(),dtype=int)
n = int(input())
ban = []
for i in range(3):
    ban.append(a1[i])
for i in range(3):
    ban.append(a2[i])
for i in range(3):
    ban.append(a3[i])
b = [0 for i in range(9)]
for i in range(n):
    x = int(input())
    if x in ban:
        b[ban.index(x)] = 1

if b[0]+b[3]+b[6] == 3 or b[2]+b[5]+b[8] == 3 or b[1]+b[4]+b[7] == 3 or b[0]+b[1]+b[2] == 3 or b[3]+b[4]+b[5] == 3 or b[6]+b[7]+b[8] == 3 or b[0]+b[4]+b[8] == 3 or b[2]+b[4]+b[6] == 3:
    print("Yes")
else:
    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())
d=[0,0,0]
e=[0,0,0]
f=[0,0,0]
for i in range(n):
    ab=int(input())
    for i in range(3):
        if a[i] == ab:
            d[i] = 1
        if b[i] == ab:
            e[i] = 1
        if c[i] == ab:
            f[i] = 1
if sum(d)==3 or sum(e)==3 or sum(f)==3:
    print("Yes")
    exit()

for i in range(3):
    if d[i]==e[i]==f[i]==1:
        print("Yes")
        exit()
if d[0]==e[1]==f[2]==1 or d[2]==e[1]==f[0]==1:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
C=list(map(int,input().split()))
D=list(map(int,input().split()))
E=list(map(int,input().split()))
F=[0,0,0]
G=[0,0,0]
H=[0,0,0]
N=int(input())
for j in range(N):
  b=int(input())
  for i in range(3):
    if b==C[i]:
      F[i]=1
    if b==D[i]:
      G[i]=1
    if b==E[i]:
      H[i]=1
      
for k in range(3):
  if F[k]==G[k]==H[k]==1:
    print('Yes')
    exit()

if sum(F)==3 or sum(G)==3 or sum(H)==3:
  print('Yes')
  exit()

if F[0]==G[1]==H[2]==1 or F[2]==G[1]==H[0]==1:
  print('Yes')
  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()))
a=a1+a2+a3
n=int(input())
for _ in range(n):
    b=int(input())
    if b in a:
        a[a.index(b)]=0

check=0
for i in range(3):
    if (a[3*i]==a[3*i+1] and a[3*i+1]==a[3*i+2]) or (a[i]==a[i+3] and a[i+3]==a[i+6]):
        check+=1
if (a[0]==a[4] and a[4]==a[8]) or (a[2]==a[4] and a[4]==a[6]):
    check+=1
if check>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())
listb = [int(input()) for i in range(N)]

for item in listb:
    for i in range(3):
        if A1[i] == item:
            A1[i] = 0
    for j in range(3):
        if A2[j] == item:
            A2[j] = 0
    for k in range(3):
        if A3[k] == item:
            A3[k] = 0
if sum(A1) == 0 or sum(A2) == 0 or sum(A3) == 0:
    print('Yes')
    exit()
for i in range(3):
    if A1[i] == A2[i] and A2[i] == A3[i]:
        print('Yes')
        exit()
if A1[0] == A2[1] == A3[2] or A1[2] == A2[1] == A3[0]:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

Solution code:
import numpy as np

A = [0] * 3
A[0] = list(map(int,input().split()))
A[1] = list(map(int,input().split()))
A[2] = list(map(int,input().split()))
N = int(input())
bn = []
for n in range(N):
  bn.append(int(input()))
for i in range(3):
  for j in range(3):
    A[i][j] = A[i][j] in bn
A = np.array(A)
if sum(np.prod(A,1)) != 0:
  print('Yes')
elif sum(np.prod(A,0)) != 0:
  print('Yes')
elif A[0][0] * A[1][1] * A[2][2] != 0:
  print('Yes')
elif A[2][0] * A[1][1] * A[0][2] != 0:
  print('Yes')
else:
  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)]

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

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

Submission status: Accepted

Solution code:
A = list(map(int,input().split()))
A456 = list(map(int,input().split()))
A789 = list(map(int,input().split()))
A.extend(A456)
A.extend(A789)
N = int(input())
B = []
for i in range(N):
    b = int(input())
    B.append(b)
for i in range(9):
    for u in range(N):
        if A[i] == B[u]:
            A[i] = 0
if A[0] + A[1] + A[2] == 0 or  A[3] + A[4] + A[5] == 0 or A[6] + A[7] + A[8] == 0 :
    print("Yes")
elif A[0] + A[3] + A[6] == 0 or A[1] + A[4] + A[7] == 0 or A[2] + A[5] + A[8] == 0:
    print("Yes")
elif A[0] + A[4] + A[8] == 0 or A[2] + A[4] + A[6] == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A = []
[A.extend(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]
for b in B:
    try:
        i = A.index(b)
        A[i] = 0
    except:
        pass
lines = [
    [0, 1, 2],
    [3, 4, 5],
    [6, 7, 8],
    [0, 3, 6],
    [1, 4, 7],
    [2, 5, 8],
    [0, 4, 8],
    [2, 4, 6],
]
ans = "No"
for line in lines:
    a, b, c = line
    if A[a] == 0 and A[a] == A[b] and A[a] == A[c]:
        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())
b = [int(input()) for i in range(n)]
ans = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]
tmp = []
for i in range(3):
    for j in range(len(b)):
        if b[j] == A1[i]:
            A1[i] = 0
        elif b[j] == A2[i]:
            A2[i] = 0
        
        elif b[j] == A3[i]:
            A3[i] = 0


if sum(A1) == 0 or sum(A2) == 0 or sum(A3) == 0:
    print("Yes")

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

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

else:
    print("No")

Submission status: Accepted

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

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

for y in range(3):
    for z in range(3):
        for x in B:
            if x == A[y][z]:
                A[y][z] = -1

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

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

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:
bingo = []
card = [[0,0,0],[0,0,0],[0,0,0]]
ans = 0
for i in range(3):
    A = list(map(int,input().split()))
    bingo.append(A)
N = int(input())
for i in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == b:
                card[i][j] += 1
if card[0][0]+card[0][1]+card[0][2] >= 3:
    ans += 1
if card[0][0]+card[1][0]+card[2][0] >= 3:
    ans += 1
if card[1][0]+card[1][1]+card[1][2] >= 3:
    ans += 1
if card[2][0]+card[2][1]+card[2][2] >= 3:
    ans += 1
if card[0][1]+card[1][1]+card[2][1] >= 3:
    ans += 1
if card[0][2]+card[1][2]+card[2][2] >= 3:
    ans += 1
if card[0][0]+card[1][1]+card[2][2] >= 3:
    ans += 1
if card[0][2]+card[1][1]+card[2][0] >= 3:
    ans += 1
if ans > 0:
    print("Yes")
else:
    print("No")