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:
array = [ list(map(int,input().split())) for _ in range(3) ]
number = []
N = int(input())
for _ in range(N):
  number += [ int(input()) ]
for i in range(3):
  for t in range(3):
    if array[i][t] in number:
      array[i][t] = 0
for i in range(1):
  if array[i][0] == array[i+1][0] == array[i+2][0]:
    print('Yes')
    exit()
  elif array[i][1] == array[i+1][1] == array[i+2][1]:
    print('Yes')
    exit()
  elif array[i][2] == array[i+1][2] == array[i+2][2]:
    print('Yes')
    exit()
  elif array[i][0] == array[i][1] == array[i][2]: 
    print('Yes')
    exit()
  elif array[i+1][0] == array[i+1][1] == array[i+1][2]:
    print('Yes')
    exit()
  elif array[i+2][0] == array[i+2][1] == array[i+2][2]:
    print('Yes')
    exit()
    
if array[0][0] == array[1][1] == array[2][2] or array[0][2] == array[1][1] == array[2][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)]
for i in range(3):
    for j in range(3):
        for k in range(n):
            if A[i][j]==b[k]:
                A[i][j]=-1
if A[0][0]==-1 and A[1][1]==-1 and A[2][2]==-1:
    print("Yes")
    exit()
elif A[0][2]==-1 and A[1][1]==-1 and A[2][0]==-1:
    print("Yes")
    exit()
for i in range(3):
    total=0
    if A[i].count(-1)==3:
        print("Yes")
        exit()
    for j in range(3):
        if A[j][i]==-1:
            total+=1
    if total==3:
        print("Yes")
        exit()
print("No")

Submission status: Accepted

Solution code:
def resolve():
	a = []
	bingo = [(0,3,6),(1,4,7),(2,5,8),(0,1,2),(3,4,5)
			 ,(6,7,8),(0,4,8),(2,4,6)]
	for _ in range(3):
		a += list(map(int,input().split()))
	for i in range(int(input())):
		r = int(input())
		if r in a:
			a[a.index(r)]=0
	ans = 'No'
	for i in bingo:
		if a[i[0]] == 0 and a[i[1]]==0 and a[i[2]]==0:
			ans ='Yes'
	print(ans)
resolve()

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())
    if b in a1:
        a1[a1.index(b)] = 0
    if b in a2:
        a2[a2.index(b)] = 0
    if b in a3:
        a3[a3.index(b)] = 0
if (sum(a1) != 0) and (sum(a2) != 0) and (sum(a3) != 0) and (a1[0] + a2[0] + a3[0] != 0) and (a1[1] + a2[1] + a3[1] != 0) and (a1[2] + a2[2] + a3[2] != 0) and a1[0] + a2[1] + a3[2] != 0 and a1[2] + a2[1] + a3[0] != 0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
a = input()
a = a.split()
b = input()
b = b.split()
c = input()
c = c.split()
d = [a[0],b[0],c[0]]
e = [a[1],b[1],c[1]]
f = [a[2],b[2],c[2]]
g = [a[0],b[1],c[2]]
h = [a[2],b[1],c[0]]
n = int(input())
for i in range(n):
    j = int(input())
    for k in range(3):
        if int(a[k])==j:
            a.pop(k)
            a.insert(k,0)
        if int(b[k])==j:
            b.pop(k)
            b.insert(k,0)
        if int(c[k])==j:
            c.pop(k)
            c.insert(k,0)
        if int(d[k])==j:
            d.pop(k)
            d.insert(k,0)
        if int(e[k])==j:
            e.pop(k)
            e.insert(k,0)
        if int(f[k])==j:
            f.pop(k)
            f.insert(k,0)
        if int(g[k])==j:
            g.pop(k)
            g.insert(k,0)
        if int(h[k])==j:
            h.pop(k)
            h.insert(k,0)
if a == [0,0,0] or b == [0,0,0] or c == [0,0,0] or d == [0,0,0] or e == [0,0,0] or f == [0,0,0] or g == [0,0,0] or h == [0,0,0]:
    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())

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

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

np_a = np.array(a)
np_t = np_a.T
d = 0
u = 0

for i in range(3):
    r = np_a[i]
    c = np_t[i]
    d += r[i]
    u += r[2-i]

    if r.sum() and c.sum():
        continue

    print("Yes")
    exit()


if d and u:
    print("No")
else:
    print("Yes")

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

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

bingo = []
for i in range(3):
    x = a[i]
    for j in range(3):
        bingo.append(x[j])

for i in b:
    for j in range(0,9):
        if i == bingo[j]:
            bingo[j] = 0

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

Submission status: Accepted

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

N=int(input())

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

list2=[]
i=0
while i<=2:
    j=0
    while j<=2:
        list2.append(num_list[i][j])
        j=j+1
    i=i+1

s=0
for k in list2:
    if list1.count(k)==1:
        list2[s]=101
        s=s+1
    else:
        s=s+1
        continue

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

Submission status: Accepted

Solution code:
A11,A12,A13 = map(int,input().split())
A21,A22,A23 = map(int,input().split())
A31,A32,A33 = map(int,input().split())

Alist = []
Alist.append(A11)
Alist.append(A12)
Alist.append(A13)
Alist.append(A21)
Alist.append(A22)
Alist.append(A23)
Alist.append(A31)
Alist.append(A32)
Alist.append(A33)
bingolist =[0]*9

N = int(input())
#print (N)
for i in range(N):
  b = int(input())
  #print (b)
  for j in range(len(bingolist)):
    if b ==Alist[j]:
      bingolist[j] = 1

if sum(bingolist[0:3])==3 or sum(bingolist[3:6])==3 or sum(bingolist[6:9])==3 or (bingolist[0]+bingolist[3]+bingolist[6])==3 or (bingolist[1]+bingolist[4]+bingolist[7])==3 or (bingolist[2]+bingolist[5]+bingolist[8])==3 or (bingolist[0]+bingolist[4]+bingolist[8])==3 or (bingolist[2]+bingolist[4]+bingolist[6])==3:
  print ("Yes")
else :
  print ("No")
#print (bingolist[0:3])
#print (bingolist[3:6])
#print (bingolist[6:9])
#print (bingolist)

Submission status: Accepted

Solution code:
#!/usr/local/bin/python3
# https://atcoder.jp/contests/abc157/tasks/abc157_b
import numpy as np

def check(A, b):
    A = np.where(A == b, -1, A)
    return A

def bingo(A):
    for a in A:
        if a[0] == a[1] == a[2] == -1:
            return True
    for a in A.T:
        if a[0] == a[1] == a[2] == -1:
            return True
    if A[0][0] == A[1][1] == A[2][2] == -1:
        return True
    if A[0][2] == A[1][1] == A[2][0] == -1:
        return True
    return False



A = []
for _ in range(3):
    A.append(list(map(int, input().split())))
A = np.array(A)
N = int(input())
for _ in range(N):
    b = int(input())
    A = check(A, b)

# for i in range(3):
#     for j in range(3):
#         print(f"{A[i][j]} ", end="")
#     print("")

if bingo(A):
    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 = [0 for i in range(8)]
for i in range(N):
    b = int(input())
    if b == A[0][0] or b == A[1][0] or b == A[2][0]:
        B[0] += 1
    if b == A[0][1] or b == A[1][1] or b == A[2][1]:
        B[1] += 1
    if b == A[0][2] or b == A[1][2] or b == A[2][2]:
        B[2] += 1
    if b == A[0][0] or b == A[0][1] or b == A[0][2]:
        B[3] += 1
    if b == A[1][0] or b == A[1][1] or b == A[1][2]:
        B[4] += 1
    if b == A[2][0] or b == A[2][1] or b == A[2][2]:
        B[5] += 1
    if b == A[0][0] or b == A[1][1] or b == A[2][2]:
        B[6] += 1
    if b == A[0][2] or b == A[1][1] or b == A[2][0]:
        B[7] += 1
if 3 in B:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

Submission status: Accepted

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

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

    if A[0][0]==0 and A[0][1]==0 and A[0][2]==0:
        return 'Yes'
    elif A[1][0]==0 and A[1][1]==0 and A[1][2]==0:
        return 'Yes'
    elif A[2][0]==0 and A[2][1]==0 and A[2][2]==0:
        return 'Yes'
    elif A[0][0]==0 and A[1][0]==0 and A[2][0]==0:
        return 'Yes'
    elif A[0][1]==0 and A[1][1]==0 and A[2][1]==0:
        return 'Yes'
    elif A[0][2]==0 and A[1][2]==0 and A[2][2]==0:
        return 'Yes'
    elif A[0][0]==0 and A[1][1]==0 and A[2][2]==0:
        return 'Yes'
    elif A[0][2]==0 and A[1][1]==0 and A[2][0]==0:
        return 'Yes'

    return ('No')

print(main())

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

l=[lnii() for i in range(3)]

n=int(input())
for i in range(n):
  b=int(input())
  for h in range(3):
    for w in range(3):
      if l[h][w]==b:
        l[h][w]=-1

if l[0][0]==l[1][1]==l[2][2]==-1 or l[0][2]==l[1][1]==l[2][0]==-1:
  print('Yes')
  exit()
for i in range(3):
  if l[i].count(-1)==3:
    print('Yes')
    exit()
l2=list(zip(*l))
for i in range(3):
  if l2[i].count(-1)==3:
    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)]

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

for i in range(3):
    ans1, ans2 = 0, 0
    for j in range(3):
        if A[i][j] == -1:
            ans1 += 1
        if A[j][i] == -1:
            ans2 += 1
    if ans1 == 3 or ans2 == 3:
        print("Yes")
        exit()

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

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


A = [LI() for _ in range(3)]
N = I()
flag = [[0]*3 for _ in range(3)]

for i in range(N):
    b = I()
    for j in range(3):
        for k in range(3):
            if A[j][k] == b:
                flag[j][k] = 1

for i in range(3):
    if flag[i][0] == flag[i][1] == flag[i][2] == 1 or flag[0][i] == flag[1][i] == flag[2][i] == 1:
        print('Yes')
        exit()

if flag[0][0] == flag[1][1] == flag[2][2] == 1 or flag[0][2] == flag[1][1] == flag[2][0] == 1:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

bingo = [list(mapint()) for _ in range(3)]
N = int(input())
card = [[0]*3 for _ in range(3)]
for _ in range(N):
    n = int(input())
    for i in range(3):
        for j in range(3):
            if n==bingo[i][j]:
                card[i][j] = 1

for i in range(3):
    if sum(card[i])==3:
        print('Yes')
        exit()

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

if card[0][0]+card[1][1]+card[2][2]==3 or card[2][0]+card[1][1]+card[0][2]==3:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

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

for num in nums:
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == num:
                bingo[i][j] = -1

for i in range(3):
    if sum(bingo[i]) == -3:
        print("Yes")
        sys.exit()
    tmp = 0
    for j in range(3):
        tmp += bingo[j][i]
    if tmp == -3:
        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[0][2] == -1 and bingo[1][1] == -1 and bingo[0][2] == -1:
    print("Yes")
    sys.exit()

print("No")

Submission status: Accepted

Solution code:
def LIHW(h):
    return [list(map(int, input().split())) for _ in range(h)]


def LIH(h):
    return [int(input()) for _ in range(h)]


card = LIHW(3)
N = int(input())
num = LIH(N)
bingo = [[0, 0, 0] for _ in range(3)]
for i in num:
    for a in range(3):
        for b in range(3):
            if i == card[a][b]:
                bingo[a][b] = 1
                break
ans = "No"
for i in range(3):
    if bingo[i][0] == 1 and bingo[i][1] == 1 and bingo[i][2] == 1:
        ans = "Yes"
for i in range(3):
    if bingo[0][i] == 1 and bingo[1][i] == 1 and bingo[2][i] == 1:
        ans = "Yes"
if bingo[0][0] == 1 and bingo[1][1] == 1 and bingo[2][2] == 1:
    ans = "Yes"
if bingo[0][2] == 1 and bingo[1][1] == 1 and bingo[2][0] == 1:
    ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

arr = np.array([list(map(int, input().split())) for _ in range(3)])


n = int(input())

for _ in range(n):
    b = int(input())
    arr[np.where(arr == b)] = 0

ans1 = (np.sum(arr, axis=0) == 0).sum() >= 1
ans2 = (np.sum(arr, axis=1) == 0).sum() >= 1
ans3 = (np.diag(arr) == 0).sum() == 3
ans4 = (np.diag(np.rot90(arr)) == 0).sum() == 3

print("Yes" if ans1 or ans2 or ans3 or ans4 else "No")

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


A = [LI() for _ in range(3)]
N = I()
flag = [[0]*3 for _ in range(3)]

for i in range(N):
    b = I()
    for j in range(3):
        for k in range(3):
            if A[j][k] == b:
                flag[j][k] = 1

for i in range(3):
    if flag[i][0] == flag[i][1] == flag[i][2] == 1 or flag[0][i] == flag[1][i] == flag[2][i] == 1:
        print('Yes')
        exit()

if flag[0][0] == flag[1][1] == flag[2][2] == 1 or flag[0][2] == flag[1][1] == flag[2][0] == 1:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

Solution code:
A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
B = [[0 for _ in range(3)] for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                B[i][j] = 1
flag = 0
for i in range(3):
    if sum(B[i])==3:
        flag = 1
        break
for j in range(3):
    cnt = 0
    for i in range(3):
        cnt += B[i][j]
    if cnt==3:
        flag = 1
        break
if B[0][0]+B[1][1]+B[2][2]==3:
    flag = 1
if B[2][0]+B[1][1]+B[0][2]==3:
    flag = 1
if flag==1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np

A1=np.array(list(map(int,input().split())))
A2=np.array(list(map(int,input().split())))
A3=np.array(list(map(int,input().split())))
A=np.concatenate([A1,A2,A3]).reshape(3,3)

N=int(input())

for i in range(N):
    b=int(input())
    A[np.where(A==b)] = 0

if np.all(A[0,:]==0) or np.all(A[1,:]==0) or np.all(A[2,:]==0) or np.all(A[:,0]==0) or np.all(A[:,1]==0) \
    or np.all(A[:,2]==0) or A[0,0]**2+A[1,1]**2+A[2,2]**2==0 or A[0,2]**2+A[1,1]**2+A[2,0]**2==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np

CARD_SIZE = 3


def solve(card, called_numbers):
    checked_card = np.vectorize(lambda n: n in called_numbers)(card)

    for l in checked_card:
        if all(l):
            return True

    for l in zip(*checked_card):
        if all(l):
            return True

    if all([checked_card[n][n] for n in range(CARD_SIZE)]):
        return True
    if all([checked_card[n][CARD_SIZE - n - 1] for n in range(CARD_SIZE)]):
        return True

    return False


def resolve():
    card = [[int(row) for row in input().split()] for _ in range(CARD_SIZE)]

    N = int(input())
    called_numbers = {int(input()) for n in range(N)}

    ret = solve(card, called_numbers)

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

N = int(input())

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

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

for b in B:
    for m in range(3):
        for n in range(3):
            if b == A[m][n]:
                test[m][n] =1

ans = 'No'

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

if test[0][0]+test[1][1]+test[2][2] == 3:
    ans = 'Yes'

if test[2][0]+test[1][1]+test[0][2] == 3:
    ans = 'Yes'

print(ans)

Submission status: Accepted

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    A_ = []
    for a_ in A:
        A_ += [[a__, False] for a__ in a_]
    for b_ in b:
        for a__ in A_:
            if a__[0] == b_:
                a__[1] = True
    if (A_[0][1] and ((A_[1][1] and A_[2][1]) or \
                        (A_[3][1] and A_[6][1]) or \
                        (A_[4][1] and A_[8][1]))) or \
            (A_[1][1] and A_[4][1] and A_[7][1]) or \
            (A_[2][1] and A_[5][1] and A_[8][1]) or \
            (A_[3][1] and A_[4][1] and A_[5][1]) or \
            (A_[6][1] and A_[7][1] and A_[8][1]) or \
            (A_[2][1] and A_[4][1] and A_[6][1]):
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [[int(next(tokens)) for _ in range(3)] for _ in range(3)]  # type: "List[List[int]]"
    N = int(next(tokens))  # type: int
    b = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(A, N, b)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from math import ceil as C, floor as F, sqrt, gcd as G
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as HQ

class Heap:
  def __init__(self, data, reverse=False):
    self.reverse = -1 if reverse else 1
    self.data = [self.reverse * d for d in data]
    HQ.heapify(self.data)
  def push(self, x): return HQ.heappush(self.data, self.reverse * x)
  def pop(self): return self.reverse * HQ.heappop(self.data) 

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

a, b, c = I()
j, k, l = I()
x, y, z = I()

seen = {}
n = I()
for _ in range(n):
    d = I()
    seen[d] = 1

if a in seen and b in seen and c in seen:
    print('Yes')
elif j in seen and k in seen and l in seen:
    print('Yes')
elif x in seen and y in seen and z in seen:
    print('Yes')
elif a in seen and j in seen and x in seen:
    print('Yes')
elif b in seen and k in seen and y in seen:
    print('Yes')
elif c in seen and l in seen and z in seen:
    print('Yes')
elif a in seen and k in seen and z in seen:
    print('Yes')
elif x in seen and k in seen and c in seen:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
L = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
B = list(int(input()) for _ in range(n))
ans = 'No'
for i in range(3):
  for j in range(3):
    for b in B:
      if L[i][j] == b:
        L[i][j] = 0
        
for i in range(3):
  if L[i][0] == L[i][1] == L[i][2] == 0: ans = 'Yes' #横
  if L[0][i] == L[1][i] == L[2][i] == 0: ans = 'Yes' #縦
if L[0][0] == L[1][1] == L[2][2] == 0: ans = 'Yes'
if L[0][2] == L[1][1] == L[2][0] == 0: ans = 'Yes'
  
print(ans)

Submission status: Accepted

Solution code:
masu = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
li = [int(input()) for _ in range(n)]
check = [[0]*3 for _ in range(3)]


for num in li:
    for i in range(3):
        for j in range(3):
            if masu[i][j] == num:
                check[i][j] = 1

for row in check:
    if all(row) == 1:
        print('Yes')
        exit()
for t in range(3):
    count = 0
    for row in check:
        if row[t] == 1:
            count += 1
    if count == 3:
        print('Yes')
        exit()
if check[0][0] + check[1][1] + check[2][2] == 3:
    print('Yes')
    exit()
if check[0][2] + check[1][1] + check[0][2] == 3:
    print('Yes')
    exit()
    
print('No')

Submission status: Accepted

Solution code:
B=[]
for i in range(3):
    A=list(map(int,input().split()))
    B.append(A[0])
    B.append(A[1])
    B.append(A[2])
N=int(input())
for j in range(N):
    b=int(input())
    if b in B:
        B[B.index(b)]=0
if B[0]==0 and B[1]==0 and B[2]==0:
    print('Yes')
elif B[3]==0 and B[4]==0 and B[5]==0:
    print('Yes')
elif B[6]==0 and B[7]==0 and B[8]==0:
    print('Yes')
elif B[0]==0 and B[3]==0 and B[6]==0:
    print('Yes')
elif B[1]==0 and B[4]==0 and B[7]==0:
    print('Yes')
elif B[2]==0 and B[5]==0 and B[8]==0:
    print('Yes')
elif B[0]==0 and B[4]==0 and B[8]==0:
    print('Yes')
elif B[2]==0 and B[4]==0 and B[6]==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    for i in range(N):
        n = b[i]
        for j in range(3):
            for k in range(3):
                if A[j][k] == n:
                    A[j][k] = 0
    if A[0][0] == A[0][1] == A[0][2]:
        print(YES)
    elif A[1][0] == A[1][1] == A[1][2]:
        print(YES)
    elif A[2][0] == A[2][1] == A[2][2]:
        print(YES)
    elif A[0][0] == A[1][0] == A[2][0]:
        print(YES)
    elif A[0][1] == A[1][1] == A[2][1]:
        print(YES)
    elif A[0][2] == A[1][2] == A[2][2]:
        print(YES)
    elif A[0][0] == A[1][1] == A[2][2]:
        print(YES)
    elif A[0][2] == A[1][1] == A[2][0]:
        print(YES)
    else:
        print(NO)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [[int(next(tokens)) for _ in range(3)] for _ in range(3)]  # type: "List[List[int]]"
    N = int(next(tokens))  # type: int
    b = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(A, N, b)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
board = [list(map(int,input().split())) for i in range(3)]
num = int(input())
for n in range(num):
    bi = int(input())
    for i in range(3):
        for j in range(3):
            if board[i][j] == bi:
                board[i][j] = 0

#横
for i in range(3):
    if board[i][0] == board[i][1] == board[i][2] == 0:
        print("Yes")
        exit()
#縦
for i in range(3):
    if board[0][i] == board[1][i] == board[2][i] == 0:
        print("Yes")
        exit()

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

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

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

Submission status: Accepted

Solution code:
def mark(a, b):
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                a[i][j] = 0


def check_h(a):
    for row in a:
        if row == [0, 0, 0]:
            return True


def check_v(a):
    for col in range(3):
        if [row[col] for row in a] == [0, 0, 0]:
            return True


def check_c(a):
    if [a[i][i] for i in range(3)] == [0, 0, 0] or [a[i][2 - i] for i in range(3)] == [0, 0, 0]:
        return True


def resolve():
    A = [list(map(int, input().split())) for _ in range(3)]
    N = int(input())
    for _ in range(N):
        B = int(input())
        mark(A, B)
    if check_h(A) or check_v(A) or check_c(A):
        print("Yes")
    else:
        print("No")
resolve()

Submission status: Accepted

Solution code:
Bingo_1 = list(map(int, input().split()))
Bingo_2 = list(map(int, input().split()))
Bingo_3 = list(map(int, input().split()))

number_table = []
number_count = int(input())
for i in range(number_count):
    number_table.append(int(input()))

for j in range(number_count):
    if number_table[j] == Bingo_1[0]:
        Bingo_1[0] = 0
    elif number_table[j] == Bingo_1[1]:
        Bingo_1[1] = 0
    elif number_table[j] == Bingo_1[2]:
        Bingo_1[2] = 0
    elif number_table[j] == Bingo_2[0]:
        Bingo_2[0] = 0
    elif number_table[j] == Bingo_2[1]:
        Bingo_2[1] = 0
    elif number_table[j] == Bingo_2[2]:
        Bingo_2[2] = 0
    elif number_table[j] == Bingo_3[0]:
        Bingo_3[0] = 0
    elif number_table[j] == Bingo_3[1]:
        Bingo_3[1] = 0
    elif number_table[j] == Bingo_3[2]:
        Bingo_3[2] = 0

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

Submission status: Accepted

Solution code:
import sys
bin = []

for i in range(3):
  lst = list(map(int,input().split()))
  bin.append(lst)
  
n = int(input())
for i in range(n):
  m = int(input())
  for j in range(3):
    for k in range(3):
      if m == bin[j][k]:
        bin[j][k] = 't'
        break
    
    
for i in range(3):
  if bin[i][0] == 't' and bin[i][1] == 't' and bin[i][2] == 't':
    print('Yes')
    sys.exit()
    
for j in range(3):
  if bin[0][j] == 't' and bin[1][j] == 't' and bin[2][j] == 't':
    print('Yes')
    sys.exit()
    
if (bin[0][0] == 't' and bin[1][1] == 't' and bin[2][2] == 't') or (bin[0][2] == 't' and bin[1][1] == 't' and bin[2][0] == 't'):  
  print('Yes')
  sys.exit()
  
print('No')