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:
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
N = int(input())
num = []
for i in range(N):
	n = int(input())
	num.append(n)
chk = []
for i in range(3):
	a = [0]*3
	chk.append(a)
for i in range(3):
	for j in range(3):
		if i == 0:
			if A[j] in num:
				chk[0][j] = 1
		elif i == 1:
			if B[j] in num:
				chk[1][j] = 1
		else:
			if C[j] in num:
				chk[2][j] = 1
if chk[0] == [1,1,1] or chk[1] == [1,1,1] or chk[2] == [1,1,1]:
	print("Yes")
elif chk[0][0] + chk[1][1] + chk[2][2] == 3 :
	print("Yes")
elif chk[0][2] + chk[1][1] + chk[2][0] == 3 :
	print("Yes")
elif chk[0][0] + chk[1][0] + chk[2][0] == 3 :
	print("Yes")
elif chk[0][1] + chk[1][1] + chk[2][1] == 3 :
	print("Yes")
elif chk[0][2] + chk[1][2] + chk[2][2] == 3 :
	print("Yes")
else:
	print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a1 = input().split(" ")
a2 = input().split(" ")
a3 = input().split(" ")
a = a1 + a2 + a3
for i in range(9):
	a[i] = int(a[i])
n = int(input())
for i in range(n):
	b = int(input())
	for j in range(9):
		if b == a[j]:
			a[j] = 0
l = []
l.append(a[0]+a[1]+a[2])
l.append(a[3]+a[4]+a[5])
l.append(a[6]+a[7]+a[8])
l.append(a[0]+a[3]+a[6])
l.append(a[1]+a[4]+a[7])
l.append(a[2]+a[5]+a[8])
l.append(a[0]+a[4]+a[8])
l.append(a[2]+a[4]+a[6])
if 0 in l:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
bingo = [list(map(int,input().split())) for i in range(3)]
N = int(input())
for _ in range(N):
    n = int(input())
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == n:
                bingo[i][j] = -1

for i in range(3):
    if sum(bingo[i]) == -3:
        print("Yes")
        break
else:
    for i in range(3):
        if bingo[0][i]+bingo[1][i]+bingo[2][i] == -3:
            print("Yes")
            break
    else:
        if bingo[0][0]+bingo[1][1]+bingo[2][2] == -3 or bingo[0][2]+bingo[1][1]+bingo[2][0] == -3:
            print("Yes")
        else:
            print("No")

Submission status: Accepted

Solution code:
def check(find):
    for i in range(3):
        ok = True
        for j in range(3):
            ok &= find[i][j]
        if ok:
            return True
    for j in range(3):
        ok = True
        for i in range(3):
            ok &= find[i][j]
        if ok:
            return True
    return find[0][0] and find[1][1] and find[2][2] or \
        find[0][2] and find[1][1] and find[2][0]


def main():
    A = [list(map(int, input().split())) for _ in range(3)]
    N = int(input())
    B = [int(input()) for _ in range(N)]
    find = [[False] * 3 for _ in range(3)]
    for b in B:
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    find[i][j] = True
    if check(find):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
a=[list(map(int,input().split()))for _ in range(3)]
n=int(input())
t=[[0]*3 for i 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:
                t[i][j]=1
for i in range(3):
    f=True
    for j in range(3):
        if t[i][j]==0:
            f=False
    if f:
        print("Yes")
        exit()

for i in range(3):
    f=True
    for j in range(3):
        if t[j][i]==0:
            f=False
    if f:
        print("Yes")
        exit()
f=True
for i in range(3):
    if t[i][i]==0:
        f=False
if f:
    print("Yes")
    exit()

f=True
for i in range(3):
    if t[i][-i-1]==0:
        f=False
if f:
    print("Yes")
    exit()
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())
N = int(input())
B = [int(input()) for _ in range(N)]

tate = [[a11, a21, a31], [a12, a22, a32], [a13, a23, a33]]
yoko = [[a11, a12, a13], [a21, a22, a23], [a31, a32, a33]]
naname = [[a11, a22, a33], [a13, a22, a31]]

for tripe in tate + yoko + naname:
    a, b, c = tripe
    if a in B and b in B and c in B:
        print("Yes")
        break
else:
    print("No")

Submission status: Accepted

Solution code:
a = [input().split() for _ in range(3)]
n = int(input())
b = [input() for _ in range(n)]
ans = "No"
flag = [ [False for _ in range(3)] for _ in range(3)]

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

for i in range(3):
    if all((flag[0][i],flag[1][i],flag[2][i])) or all((flag[i][0],flag[i][1],flag[i][2])):
        ans = "Yes"
if all((flag[0][0],flag[1][1],flag[2][2])) or all((flag[0][2],flag[1][1],flag[2][0])): ans = "Yes"
print(ans)

Submission status: Accepted

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

for k in range(n):
  tmp = int(input())
  for i in range(3):
    for j in range(3):
      if bingo[i][j] == tmp:
        check[i][j] = 1


flag = False
for i in range(3):
  if check[i][0] == check[i][1] == check[i][2]==1:
    flag = True
for i in range(3):
  if check[0][i] == check[1][i] == check[2][i] == 1:
    flag = True
if check[0][0] == check[1][1] == check[2][2]==1 or check[0][2] == check[1][1] == check[2][0]==1:
  flag = True
    
if flag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

n = int(input())

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

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

ans = "No"

for i in range(3):
    if l[i][0] and l[i][1] and l[i][2]:
        ans = "Yes"
    if l[0][i] and l[1][i] and l[2][i]:
        ans = "Yes"

if l[0][0] and l[1][1] and l[2][2]:
    ans = "Yes"
if l[0][2] and l[1][1] and l[2][0]:
    ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]



def main():
    a=[-1 for i in range(9)]
    a[0],a[1],a[2]=map(int,input().split())
    a[3], a[4], a[5] = map(int, input().split())
    a[6], a[7], a[8] = map(int, input().split())
    n=int(input())
    b=[0 for i in range(9)]
    for i in range(n):
        temp=int(input())
        if temp in a:
            b[a.index(temp)]=1
    ans="No"
    if b[0]+b[1]+b[2]>=3:
        ans="Yes"
    elif b[3]+b[4]+b[5]>=3:
        ans="Yes"
    elif b[6]+b[7]+b[8]>=3:
        ans="Yes"
    elif b[0]+b[3]+b[6]>=3:
        ans="Yes"
    elif b[1]+b[4]+b[7]>=3:
        ans="Yes"
    elif b[2]+b[5]+b[8]>=3:
        ans="Yes"
    elif b[0]+b[4]+b[8]>=3:
        ans="Yes"
    elif b[2]+b[4]+b[6]>=3:
        ans="Yes"
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
if N<=2:
  print('No')
for i in range(N):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if b==A[j][k]:
        A[j][k]=101
        
judge = False
for i in range(3):
  if sum(A[i])==303:
    judge = True
    
for i in range(3):
  if (A[0][i]+A[1][i]+A[2][i])==303:
    judge = True

if (A[0][0]+A[1][1]+A[2][2])==303:
  judge = True

if (A[0][2]+A[1][1]+A[2][0])==303:
  judge = True
  
if judge:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
x1 = list(map(int, input().split()))
x2 = list(map(int, input().split()))
x3 = list(map(int, input().split()))
x = x1 + x2 + x3
n = int(input())
a = [0] * 9
for i in range(0, n):
    b = int(input())
    if b in x:
        a[x.index(b)] = 1

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

Submission status: Accepted

Solution code:
l = []

l += list(map(int, input().split()))
l += list(map(int, input().split()))
l += list(map(int, input().split()))

n = int(input())

check = [0]*9

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

h1 = check[0]*check[1]*check[2]
h2 = check[3]*check[4]*check[5]
h3 = check[6]*check[7]*check[8]

v1 = check[0]*check[3]*check[6]
v2 = check[1]*check[4]*check[7]
v3 = check[2]*check[5]*check[8]

d1 = check[0]*check[4]*check[8]
d2 = check[2]*check[4]*check[6]

if h1+h2+h3+v1+v2+v3+d1+d2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a = []
for i in range(3):
    line = list(map(int, input().split()))
    a.append(line)
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
bingo = False
for i in range(3):
    if a[i][0] == 0 and a[i][1] == 0 and a[i][2] == 0: bingo = True
    if a[0][i] == 0 and a[1][i] == 0 and a[2][i] == 0: bingo = True
if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0: bingo = True
if a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0: bingo = True

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

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

def solve():
    A1s = list(map(int, input().split()))
    A2s = list(map(int, input().split()))
    A3s = list(map(int, input().split()))
    As = []
    As.append(A1s)
    As.append(A2s)
    As.append(A3s)
    N = int(input())
    bingo = [[False 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 b == As[i][j]:
                    bingo[i][j] = True

    # 判定
    for i in range(3):
        if bingo[i][0] and bingo[i][1] and bingo[i][2]:
            print("Yes")
            return
        if bingo[0][i] and bingo[1][i] and bingo[2][i]:
            print("Yes")
            return
    if (bingo[0][0] and bingo[1][1] and bingo[2][2] or
        bingo[0][2] and bingo[1][1] and bingo[2][0]):
        print("Yes")
        return
    print("No")



if __name__ == "__main__":
    solve()

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

C = [[False] * 3 for i in range(3)]
for bi in b:
    for j in range(3):
        for i in range(3):
            if A[j][i] == bi:
                C[j][i] = True

ans = False
for j in range(3):
    if C[j][0] == C[j][1] == C[j][2] == True:
        ans = True
for i in range(3):
    if C[0][i] == C[1][i] == C[2][i] == True:
        ans = True
if C[0][0] == C[1][1] == C[2][2] == True:
    ans = True
if C[0][2] == C[1][1] == C[2][0] == True:
    ans = True
print('Yes' if ans else 'No')

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
A=[]
Bingo=[]
for i in range(3):
    row=list(map(int,input().split()))
    A.append(row)
    Bingo.append([0,0,0])

N=int(input())

for i in range(N):
    num=int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k]==num:
                Bingo[j][k]=1
flg=False
for i in range(3):
    if sum(Bingo[i])==3:
        flg=True

for i in range(3):
    if Bingo[0][i]+Bingo[1][i]+Bingo[2][i]==3:
        flg=True
if Bingo[0][0]+Bingo[1][1]+Bingo[2][2]==3:
    flg=True

if Bingo[0][2]+Bingo[1][1]+Bingo[2][0]==3:
    flg=True

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

Submission status: Accepted

Solution code:
import itertools

A = list(itertools.chain.from_iterable([list(map(int,input().split())) for i in range(3)]))
N = int(input())
for i in range(N):
    b = int(input())
    if b in A:
        A[A.index(b)] = 0

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

if A[3] == 0 and A[4] == 0 and A[5] == 0:
    print("Yes")
    exit()
if A[6] == 0 and A[7] == 0 and A[8] == 0:
    print("Yes")
    exit()
if A[0] == 0 and A[3] == 0 and A[6] == 0:
    print("Yes")
    exit()
if A[1] == 0 and A[4] == 0 and A[7] == 0:
    print("Yes")
    exit()
if A[2] == 0 and A[5] == 0 and A[8] == 0:
    print("Yes")
    exit()
if A[0] == 0 and A[4] == 0 and A[8] == 0:
    print("Yes")
    exit()
if A[6] == 0 and A[4] == 0 and A[2] == 0:
    print("Yes")
    exit()
print('No')

Submission status: Accepted

Solution code:
import math
def main():
    A_1 = list(map(int, input().split()))
    A_2 = list(map(int, input().split()))
    A_3 = list(map(int, input().split()))

    A = [A_1, A_2, A_3]


    N = int(input())

    for _ 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

    if sum(A[0]) == 0:
        print("Yes")
    elif sum(A[1]) == 0:
        print("Yes")
    elif sum(A[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")

    return 0
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)

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

N = int(input())

OPEN = []
for _ in range(N):
    b = int(input())

    if b in A:
        OPEN.append(A.index(b))

#print(OPEN)

ans = 'No'

if 0 in OPEN:
    if 1 in OPEN and 2 in OPEN:
        print('Yes')
        exit()

    if 3 in OPEN and 6 in OPEN:
        print('Yes')
        exit()

    if 4 in OPEN and 8 in OPEN:
        print('Yes')
        exit()

if 1 in OPEN:
    if 4 in OPEN and 7 in OPEN:
        print('Yes')
        exit()

if 2 in OPEN:
    if 5 in OPEN and 8 in OPEN:
        print('Yes')
        exit()

    if 4 in OPEN and 6 in OPEN:
        print('Yes')
        exit()

if 3 in OPEN:
    if 4 in OPEN and 5 in OPEN:
        print('Yes')
        exit()

if 6 in OPEN:
    if 7 in OPEN and 8 in OPEN:
        print('Yes')
        exit()

print('No')
exit()

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

cnt = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

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

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

print('No')

Submission status: Accepted

Solution code:
x = [                                                        
  list(map(int, input().split()))                            
  for i in range(3)                                          
]                                                            
                                                             
lines = list()                                               
for i in range(3):                                           
  lines.append(set(x[i]))                                    
  lines.append(set(x[j][i] for j in range(3)))               
                                                             
lines.append({x[i][i] for i in range(3)})                    
lines.append({x[2 - i][i] for i in range(3)})                
                                                             
                                                             
                                                             
z = set()                                                    
for i in range(int(input())):                                
  z.add(int(input()))                                        
                                                             
                                                             
for line in lines:                                           
  if len(z & line) == 3:                                     
    print("Yes")                                             
    break                                                    
else:                                                        
  print("No")

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())
B=[]
for i in range(N):
    B.append(int(input()))

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

flg=False
for i in range(3):
    if sum(A[i])==0:
        flg=True
        break
    if sum(np.transpose(A)[i])==0:
        flg=True
        break
if A[0][0]+A[1][1]+A[2][2]==0:
    flg=True
if A[0][2]+A[1][1]+A[2][0]==0:
    flg=True

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

Submission status: Accepted

Solution code:

grid = list(list(map(int,input().split())) for _ in range(3))

N = int(input())

S = set(int(input()) for _ in range(N))

def check():
    for i in range(3):
        if all(grid[i][j] in S for j in range(3)):
            return True
        if all(grid[j][i] in S for j in range(3)):
            return True
    return all(grid[i][i] in S for i in range(3)) or all(grid[2-i][i] in S for i in range(3))

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

Submission status: Accepted

Solution code:
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))

m = a1 + a2 + a3

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

if ((m[0] in b and m[1] in b and m[2] in b) or
    (m[3] in b and m[4] in b and m[5] in b) or
    (m[6] in b and m[7] in b and m[8] in b) or
    (m[0] in b and m[3] in b and m[6] in b) or
    (m[1] in b and m[4] in b and m[7] in b) or
    (m[2] in b and m[5] in b and m[8] in b) or
    (m[0] in b and m[4] in b and m[8] in b) or
    (m[2] in b and m[4] in b and m[6] in b)):
  print('Yes')
  
else:
  print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
A = [list(map(int, input().split())) for i in range(3)]
B = [[0,0,0],[0,0,0],[0,0,0]]
N = int(input())

def isBingo(A):
  # 横
  for i in range(3):
    if sum(A[i])==3:
      return True
  # 縦
  for i in range(3):
    if A[0][i]+A[1][i]+A[2][i]==3:
      return True
  # 斜め
  if A[0][0]+A[1][1]+A[2][2]==3:
    return True
  if A[0][2]+A[1][1]+A[2][0]==3:
    return True
  
  return False

# 穴をあける
for i in range(N):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if b==A[j][k]:
        B[j][k] += 1

# 判定
if isBingo(B):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
a = []
for i in range(3):
    a += list(map(int, input().split()))
c = [False] * 9
n = int(input())
for i in range(n):
    b = int(input())
    if b in a:
        c[a.index(b)] = True
d = [[c[0], c[1], c[2]], [c[3], c[4], c[5]], [c[6], c[7], c[8]], [c[0], c[3], c[6]], [c[1], c[4], c[7]], [c[2], c[5], c[8]], [c[0], c[4], c[8]], [c[2], c[4], c[6]]]
if [True, True, True] in d:
    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())
number=[int(input()) for i in range(n)]

ac=[False]*3
bc=[False]*3
cc=[False]*3

for i in number:
    for x in range(3):
        if i==a[x]:
            ac[x]=True
        if i==b[x]:
            bc[x]=True
        if i==c[x]:
            cc[x]=True

if all(ac) or all(bc) or all(cc):
    print('Yes')
    exit()
for i in range(3):
    if ac[i]==True and bc[i]==True and cc[i]==True:
        print('Yes')
        exit()
if ac[0]==True and bc[1]==True and cc[2]==True:
    print('Yes')
    exit()
if ac[2]==True and bc[1]==True and cc[0]==True:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

Solution code:
A=[]
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=[]
for _ in range(N):
    B.append(int(input()))
X=[[0,0,0],[0,0,0],[0,0,0]]
for b in B:
    for a in A:
        for i in range(3):
            if a[i]==b:
                X[A.index(a)][i]=1
bin=False
if [1,1,1] in X:
    bin =True
if X[0][0] == X[1][0] and X[2][0] == X[1][0] and X[0][0]==1:
    bin=True
if X[0][1] == X[1][1] and X[2][1] == X[1][1] and X[0][1]==1:
    bin=True
if X[0][2] == X[1][2] and X[2][2] == X[1][2] and X[0][2]==1:
    bin=True
if X[0][0] == X[1][1] and X[2][2] == X[1][1] and X[0][0]==1:
    bin=True
if X[2][0] == X[1][1] and X[2][0] == X[1][1] and X[2][0]==1:
    bin=True
print('Yes' if bin else 'No')

Submission status: Accepted

Solution code:
import sys
from math import factorial


def main(S):
    pass


if __name__ == '__main__':
    A = []
    B = [0] * 9
    for i in range(3):
        A += list(map(int, input().split()))
    n = int(input())

    for i in range(n):
        tmp = int(input())
        for j in range(9):
            if A[j] == tmp:
                B[j] = 1
    ans = 0
    for i in range(3):
        if (B[0 + 3 * i] == 1 and B[1 + 3 * i] == 1 and B[2 + 3 * i] == 1):
            ans = 1
    for i in range(3):
        if (B[0 + i] == 1 and B[3 + i] == 1 and B[6 + i] == 1):
            ans = 1
    if (B[0] == 1 and B[4] == 1 and B[8] == 1):
        ans = 1
    if (B[2] == 1 and B[4] == 1 and B[6] == 1):
        ans = 1

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

Submission status: Accepted

Solution code:
aaa = list(map(int, input().split())) + list(map(int, input().split())) + list(map(int, input().split()))

n = int(input())
for _ in range(n):
    b = int(input())
    try:
        i = aaa.index(b)
    except:
        continue
    if i >= 0:
        aaa[i] = -1
for i, j, k in [(0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6)]:
    if aaa[i] == -1 and aaa[j] == -1 and aaa[k] == -1:
        print('Yes')
        break
else:
    print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
a11, a12, a13 = map(int, input().split())
a21, a22, a23 = map(int, input().split())
a31, a32, a33 = map(int, input().split())

a_list = [a11, a12, a13, a21, a22, a23, a31, a32, a33]
open_list = [False] * 9

n = int(input())

b_list = []

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

for item in b_list:
    for i in range(len(a_list)):
        if a_list[i] == item:
            open_list[i] = True

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

a = list(map(int,input().split()))
a += list(map(int,input().split()))
a += list(map(int,input().split()))

b = [0 for i in range(9)]

n = int(input())

for i in range(n):
    k = int(input())
    for j in range(9):
        if k == a[j]:
            b[j] = 1
            break
ok = [[0,1,2],[3,4,5],[6,7,8],[0,4,8],[2,4,6],[0,3,6],[1,4,7],[2,5,8]]

clear = 0
for ok_i in ok:
    flag = 1
    for ok_i_j in ok_i:
        if b[ok_i_j] == 0:
            flag = 0
            break
    if flag == 1:
        print("Yes")
        clear = 1
        break
if clear == 0:
    print("No")

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
a += list(map(int, input().split()))
a += list(map(int, input().split()))

n = int(input())

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

f = -1
if (0 in ans) and (1 in ans) and (2 in ans):
     f = 1

elif (3 in ans) and (4 in ans) and (5 in ans):
     f = 1

elif (6 in ans) and (7 in ans) and (8 in ans):
     f = 1

elif (0 in ans) and (3 in ans) and (6 in ans):
     f = 1

elif (1 in ans) and (4 in ans) and (7 in ans):
     f = 1

elif (2 in ans) and (5 in ans) and (8 in ans):
     f = 1

elif (0 in ans) and (4 in ans) and (8 in ans):
     f = 1

elif (2 in ans) and (4 in ans) and (6 in ans):
     f = 1

print("Yes" if f == 1 else "No")

Submission status: Accepted

Solution code:
A = []
A.append([int(i) for i in input().split()])
A.append([int(i) for i in input().split()])
A.append([int(i) for i in input().split()])
N = int(input())
b = []
check = [[0]*3 for i in range(3)]
for i in range(N):
    new = int(input())
    b.append(new)
    for j in range(3):
        for k in range(3):
            if A[j][k] == new:
                check[j][k] = 1
    
flag = 0

for i in range(3):
    if check[i][0] == 1 and check[i][1] == 1 and check[i][2] == 1:
        flag = 1
    if check[0][i] == 1 and check[1][i] == 1 and check[2][i] == 1:
        flag = 1

if check[0][0] == 1 and check[1][1]==1 and check[2][2] == 1:
    flag = 1
if check[0][2] == 1 and check[1][1]==1 and check[2][0] == 1:
    flag = 1


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

Submission status: Accepted

Solution code:
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]='o'
if (a[0][0]=='o'and a[0][1]=='o' and a[0][2]=='o') or(a[1][0]=='o'and a[1][1]=='o' and a[1][2]=='o') or(a[2][0]=='o'and a[2][1]=='o' and a[2][2]=='o') or(a[0][0]=='o'and a[1][0]=='o' and a[2][0]=='o') or(a[0][1]=='o'and a[1][1]=='o' and a[2][1]=='o') or(a[0][2]=='o'and a[1][2]=='o' and a[2][2]=='o') or(a[0][0]=='o'and a[1][1]=='o' and a[2][2]=='o') or(a[0][2]=='o'and a[1][1]=='o' and a[2][0]=='o'):
    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 _ in range(N)]
for a in B:
    for j in range(3):
        for k in range(3):
            if A[j][k] == a:
                A[j][k] = 0

# print(A)

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

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

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

print("No")

Submission status: Accepted

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