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=list(list(map(int,input().split())) for _ in range(3))
N=int(input())
B=list(int(input()) for _ in range(N))

R=[[0,0,0],[0,0,0],[0,0,0]]

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

ans=0

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

for m in range(3):
    if R[0][m]==1 and R[1][m]==1 and R[2][m]==1:
        ans=1

if R[0][0]==1 and R[1][1]==1 and R[2][2]==1:
    ans=1

if R[0][2]==1 and R[1][1]==1 and R[2][0]==1:
    ans=1

#print(R)

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

Submission status: Accepted

Solution code:
import numpy as np

bingo = []

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

bingo = np.array(bingo)
for i in range(n):
    
    x = int(input())
    
    for j in range(3):
        for k in range(3):
            if bingo[j][k] == x:
                bingo[j][k] = 0

ct = 0
sum1 = 0
for i in range(3):
    sum1 += bingo[i][i]
sum2 = 0
for i in range(3):
    sum2 += bingo[i][2-i]

if sum1 == 0 or sum2 == 0:
    ct += 1
if (sum(bingo.sum(axis=0)==0) >= 1) or (sum(bingo.sum(axis=1)==0) >= 1):
    ct += 1
    
if ct > 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def main():
    a = [list(map(int, (input().split()))) for _ in range(3)]
    n = int(input())
    ans = []
    for i in range(n):
        m = int(input())
        for j in range(3):
            for k in range(3):
                if a[j][k] == m:
                    ans.append((j,k))
    #print(ans)
    if (0,0) in ans and (1,1) in ans and (2,2) in ans:
        print("Yes")
    elif (0,0) in ans and (0,1) in ans and (0,2) in ans:
        print("Yes")
    elif (1,0) in ans and (1,1) in ans and (1,2) in ans:
        print("Yes")
    elif (2,0) in ans and (2,1) in ans and (2,2) in ans:
        print("Yes")
    elif (0,0) in ans and (1,0) in ans and (2,0) in ans:
        print("Yes")
    elif (0,1) in ans and (1,1) in ans and (2,1) in ans:
        print("Yes")
    elif (0,2) in ans and (1,2) in ans and (2,2) in ans:
        print("Yes")
    elif (0,2) in ans and (1,1) in ans and (2,0) in ans:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = []
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
c = [[False] * 3 for i in range(3)]
n = int(input())
for i in range(n):
    b = int(input())
    ok = False
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                c[j][k] = True
                ok = True
                break
        if ok:
            break
if c[0][0] == c[0][1] == c[0][2] == True or c[1][0] == c[1][1] == c[1][2] == True or c[2][0] == c[2][1] == c[2][2] == True or c[0][0] == c[1][0] == c[2][0] == True or c[0][1] == c[1][1] == c[2][1] == True or c[0][2] == c[1][2] == c[2][2] == True or c[0][0] == c[1][1] == c[2][2] == True or c[0][2] == c[1][1] == c[2][0] == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#N=int(input())
#N,M=map(int, input().split())
#L=list(map(int, input().split()))
L=[]
Check=[]
for n in range(9):
  Check.append(-(n+1))

for i in range(3):
  NL=list(map(int, input().split()))
  L.append(NL[0])
  L.append(NL[1])
  L.append(NL[2])

N=int(input())
for j in range(N):
  I=int(input())
  if I in L:
    Check[L.index(I)]=1
  
for k in range(3):
  if Check[0+3*k]==Check[1+3*k]==Check[2+3*k]:
    print('Yes')
    exit()

for l in range(3):
  if Check[0+l]==Check[3+l]==Check[6+l]:
    print('Yes')
    exit()

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

print('No')

Submission status: Accepted

Solution code:
a=[]
for i in range(3):
  c=list(map(int,input().split()))
  a.append(c)
m=[[0,0,0] for i in range(3)]
n=int(input())
b=[]
for i in range(n):
  b.append(int(input()))

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

cnt0=0
cnt1=0
cnt2=0
cnt3=0
cnt4=0
cnt5=0
cnt6=0
cnt7=0
ans="No"

for i in range(3):
  if m[0][i]==1:
    cnt0+=1
  if m[1][i]==1:
    cnt1+=1
  if m[2][i]==1:
    cnt2+=1
  if m[i][0]==1:
    cnt3+=1
  if m[i][1]==1:
    cnt4+=1
  if m[i][2]==1:
    cnt5+=1
  if m[i][i]==1:
    cnt6+=1
  if m[i][2-i]==1:
    cnt7+=1

if cnt0==3 or cnt1==3 or cnt2==3 or cnt3==3:
  ans="Yes"
if cnt4==3 or cnt5==3 or cnt6==3 or cnt7==3:
  ans="Yes"  
print(ans)

Submission status: Accepted

Solution code:
A=[]
for i in [0]*3:
    A+=list(map(int,input().split()))
N=int(input())
B=[0]*9
for i in range(N):
    i=int(input())
    if i in A:
        B[A.index(i)]=1
res=0
for i in range(3):
    res+=B[3*i]*B[3*i+1]*B[3*i+2]
    res+=B[i]*B[i+3]*B[i+6]
res+=B[0]*B[4]*B[8]+B[2]*B[4]*B[6]
print(['No','Yes'][res>0])

Submission status: Accepted

Solution code:
A = [[int(j) for j in input().split()] for i in range(3)]
N = int(input())
B = [False] * 101

for i in range(N):
    B[int(input())] = True

ans = 'No'
for i in range(3):
    if all([B[v] for v in A[i]]):
        ans = 'Yes'
        break

for j in range(3):
    if all([B[A[i][j]] for i in range(3)]):
        ans = 'Yes'
        break

if B[A[0][0]] == B[A[1][1]] == B[A[2][2]] == True:
    ans = 'Yes'

if B[A[2][0]] == B[A[1][1]] == B[A[0][2]] == True:
    ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
card=[]

for i in range(3):
    a,b,c= map(int,input().split())
    card.append(a)
    card.append(b)
    card.append(c)

N = int(input())

for i in range(N):
    b=int(input())
    if b in card:
        num=card.index(b)
        card[num]=0

r1=card[0]+card[1]+card[2]
r2=card[3]+card[4]+card[5]
r3=card[6]+card[7]+card[8]

l1=card[0]+card[3]+card[6]
l2=card[1]+card[4]+card[7]
l3=card[2]+card[5]+card[8]

m1=card[0]+card[4]+card[8]
m2=card[2]+card[4]+card[6]

if r1==0:
    print("Yes")
elif r2==0:
    print("Yes")
elif r3==0:
    print("Yes")
elif l1==0:
    print("Yes")
elif l2==0:
    print("Yes")
elif l3==0:
    print("Yes")
elif m1==0:
    print("Yes")
elif m2==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
cd = []
for i in range(3):
  p = input().split(" ")
  p = [int(j) for j in p]
  cd.append(p)

n = input()
n = int(n)
tf = []

for i in range(n):
  p = input()
  for j in range(3):
    if int(p) in cd[j]:
      tf.append([j, cd[j].index(int(p))])

id0 = [i[0] for i in tf]
id1 = [i[1] for i in tf]
df = [i[0] - i[1] for i in tf]
sm = [i[0] + i[1] for i in tf]

if id0.count(0) == 3:
  print("Yes")
elif id0.count(1) == 3:
  print("Yes")
elif id0.count(2) == 3:
  print("Yes")
elif id1.count(0) == 3:
  print("Yes")
elif id1.count(1) == 3:
  print("Yes")
elif id1.count(2) == 3:
  print("Yes")
elif df.count(0) == 3:
  print("Yes")
elif sm.count(2) == 3:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
L1 = list(map(int, input().split()))
L2 = list(map(int, input().split()))
L3 = list(map(int, input().split()))
L = L1 + L2 + L3
N = int(input())
A = [0]*9
for _ in range(N):
  i = int(input())
  if i in L:
    A[L.index(i)] = 1
if sum(A[:3])==3 or sum(A[3:6])==3 or sum(A[6:])==3:
  print('Yes')
elif A[0]+A[3]+A[6]==3 or A[1]+A[4]+A[7]==3 or A[2]+A[5]+A[8]==3:
  print('Yes')
elif A[0]+A[4]+A[8]==3 or A[2]+A[4]+A[6]==3:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
import math
import sys
def main():
    a = [[0 for i in range(3)] for j in range(3)]
    for i in range(3):
        a[i] = list(map(int, input().split()))

    n = int(input())

    for k in range(n):
        ball = int(input())
        for j, contents in enumerate(a):
            for i, num in enumerate(contents):
                if num == ball:
                    a[j][i] = 0
    
    for j, contents in enumerate(a):
        if sum(contents) == 0:
            print('Yes')
            sys.exit()
        if a[0][j] + a[1][j] + a[2][j] == 0:
            print('Yes')
            sys.exit()
    if a[0][0] + a[1][1] + a[2][2] == 0:
        print('Yes')
        sys.exit()
    if a[0][2] + a[1][1] + a[2][0] == 0:
        print('Yes')
        sys.exit()

    print('No')
    

if __name__ == '__main__' :
    main()

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 = list(int(input()) for i in range(n))

if a1[0] in b and a2[0] in b and a3[0] in b:
    print('Yes')
elif a1[1] in b and a2[1] in b and a3[1] in b:
    print('Yes')
elif a1[2] in b and a2[2] in b and a3[2] in b:
    print('Yes')
elif a1[0] in b and a2[1] in b and a3[2] in b:
    print('Yes')
elif a1[2] in b and a2[1] in b and a3[0] in b:
    print('Yes')
elif a1[0] in b and a1[1] in b and a1[2] in b:
    print('Yes')
elif a2[0] in b and a2[1] in b and a2[2] in b:
    print('Yes')
elif a3[0] in b and a3[1] in b and a3[2] in b:
    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 = set([int(input()) for _ in range(N)])

def check(line, num_set):
  for num in line:
    if(not(num in num_set)):
      return False
  return True

if (check([A[0][0], A[0][1], A[0][2]], B)
    or check([A[1][0], A[1][1], A[1][2]], B)
    or check([A[2][0], A[2][1], A[2][2]], B)
    
    or check([A[0][0], A[1][0], A[2][0]], B)
    or check([A[0][1], A[1][1], A[2][1]], B)
    or check([A[0][2], A[1][2], A[2][2]], B)
    
    or check([A[0][0], A[1][1], A[2][2]], B)
    or check([A[2][0], A[1][1], A[0][2]], B)):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
a1 = [int(i) for i in input().split()]
a2 = [int(i) for i in input().split()]
a3 = [int(i) for i in input().split()]



a = a1+a2+a3
n = int(input())
ans = [int(input()) for _ in range(n)]

aa = [0] * 9
for i in ans:
    for ind,j in enumerate(a):

        if i==j:

            aa[ind]=1

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

Submission status: Accepted

Solution code:
def check():
    A = [[int(i) for i in input().split()] for _ in range(3)]
    N = int(input())
    
    for _ in range(N):
        num = int(input())
        for i in range(3):
            for j in range(3):
                if A[i][j] == num:
                    A[i][j] = '*'
    checklist = [a for a in A]
    checklist2 = [[a[i] for a in A] for i in range(3)]
    checklist3 = [[A[0][0], A[1][1], A[2][2]], [A[0][2], A[1][1], A[2][0]]]
    
    a = [checklist, checklist2, checklist3]
    
    for aaa in a:
        for check in aaa:
            if check == ['*', '*', '*']:
                return 'Yes'
    return 'No'
print(check())

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 = [0] * n
for i in range(n):
	b[i] = int(input())

for i in range(n):
	for j in range(3):
		if a1[j] == b[i]:
			a1[j] = -1
	for j in range(3):
		if a2[j] == b[i]:
			a2[j] = -1
	for j in range(3):
		if a3[j] == b[i]:
			a3[j] = -1
if set(a1) == {-1}:
	print("Yes")
elif set(a2) == {-1}:
	print("Yes")
elif set(a3) == {-1}:
	print("Yes")
elif a1[0] == a2[0] and a3[0] == -1:
	print("Yes")
elif a1[1] == a2[1] and a3[1] == -1:
	print("Yes")
elif a1[2] == a2[2] and a3[2] == -1:
	print("Yes")
elif a1[0] == a2[1] and a3[2] == -1:
	print("Yes")
elif a1[2] == a2[1] and a3[0] == -1:
	print("Yes")
else:
	print("No")

Submission status: Accepted

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

ans = [[0,0,0] for i in range(3)]
ans1 = [[0,0,0] for i in range(3)]

res = False

for i in range(n):
    for a in range(3):
        for c in range(3):
            if b[i] == List[a][c]:
                ans[a][c] = 1
                ans1[c][a] = 1

if ans[1][1] == 1:
    if ans[0][0] > 0 and ans[2][2] > 0:
        res = True
    if ans[2][0] > 0 and ans[0][2] > 0:
        res = True
                
for i in range(3):
    if ans[i][0] > 0 and ans[i][1] > 0 and ans[i][2] > 0:
        res = True
    if ans1[i][0] > 0 and ans1[i][1] > 0 and ans1[i][2] > 0:
        res = True
            
if res:
    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()))
#print(a1,a2,a3)
a=[]
a.append(a1)
a.append(a2)
a.append(a3)
#print(a)
#print(a[0][0],a[1][1],a[2][2])
n=int(input())
b=[]
for i in range(n):
  b.append(int(input()))
#print(b)
for i in range(n):
  for m in range(3):
    for n in range(3):
      if a[m][n]==b[i]:
        a[m][n]=0
yes=0
#print(a)
for m in range(3):
  if a[m][0]+a[m][1]+a[m][2]==0:
    yes=1
for n in range(3):
  if a[0][n]+a[1][n]+a[2][n]==0:
    yes=1
if a[0][0]+a[1][1]+a[2][2]==0:
  yes=1
if a[0][2]+a[1][1]+a[2][0]==0:
  yes=1
if yes==1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

n = int(input())

for _ 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):
    c1 = 0
    c2 = 0
    for j in range(3):
        if a[i][j] == 0:
            c1 += 1
        if a[j][i] == 0:
            c2 += 1
    if c1 == 3 or c2 == 3:
        ans = "Yes"

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

print(ans)

Submission status: Accepted

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

for i in range(n):
  b = int(input())
  for x in range(3):
    if a1[x] == b:
      a1[x] = 0
      break
  for y in range(3):
    if a2[y] == b:
      a2[y] = 0
      break
  for z in range(3):
    if a3[z] == b:
      a3[z] = 0
      break
#print(a1)
#print(a2)
#print(a3)
if sum(a1) == 0 or sum(a2) == 0 or sum(a3) ==0:
  print('Yes')
  sys.exit()

for i in range(3):
  w = a1[i] + a2[i] + a3[i]
  if w == 0:
    print('Yes')
    sys.exit()

if a1[0] + a2[1] + a3[2] == 0 or a1[2] + a2[1] + a3[0] == 0:
  print('Yes')
  sys.exit()
print('No')

Submission status: Accepted

Solution code:
L = []
M = [[0 for i in range(3)] for j in range(3)]
for i in range(3):
  L_i = [int(s) for s in input().rstrip().split(' ')]
  L.append(L_i)
N = int(input())
for num in range(N):
  x = 0
  b_num = int(input())
  for k in range(3):
    for l in range(3):
      if L[k][l] == b_num:
        M[k][l] = 1
        x = 1
        break
    if x == 1:
      break
if M[0][0]*M[1][0]*M[2][0] + M[0][1]*M[1][1]*M[2][1] + M[0][2]*M[1][2]*M[2][2] >= 1:
  print("Yes")
elif M[0][0]*M[0][1]*M[0][2] + M[1][0]*M[1][1]*M[1][2] + M[2][0]*M[2][1]*M[2][2] >= 1:
  print("Yes")
elif M[0][0]*M[1][1]*M[2][2] + M[0][2]*M[1][1]*M[2][0] >= 1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys

matrix = []
for i in range(3):
  matrix.append([int(j) for j in input().split()])
#print(matrix)

def find(b):
  for i in range(3):
    for j in range(3):
      if matrix[i][j] == b:
        return (i, j)
  return None

matched = [[False for _ in range(3)]
           for _ in range(3)]
n = int(input())
for i in range(n):
  b = int(input())
  result = find(b)
  if result is not None:
    matched[result[0]][result[1]] = True
    
for i in range(3):
  ans = True
  for j in range(3):
    if not matched[i][j]:
      ans = False
      break
  if ans:
    print('Yes')
    sys.exit()
  
for i in range(3):
  ans = True
  for j in range(3):
    if not matched[j][i]:
      ans = False
      break
  if ans:
    print('Yes')
    sys.exit()
  
if matched[0][0] and matched[1][1] and matched[1][1]:
  print('Yes')
  sys.exit()

if matched[0][2] and matched[1][1] and matched[2][0]:
  print('Yes')
  sys.exit()
  
print('No')

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 = int(input())
  if b in a:
    a[a.index(b)] = 0
ans = 0
if a[0]+a[4]+a[8] == 0 or a[2]+a[4]+a[6] == 0:
  ans = 1
if ans != 1:
  for i in range(3):
    if sum(a[i*3:i*3+3]) == 0 or a[i]+a[i+3]+a[i+6] == 0:
      ans = 1
      break
if ans == 1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import itertools

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

for _ in range(N):
  b = int(input())
  for i, a in enumerate(A):
    if a == b:
      A[i] = 0
      break
  if A[0] == A[1] == A[2] or A[3] == A[4] == A[5] or A[6] == A[7] == A[8] or A[0] == A[3] == A[6] or A[1] == A[4] == A[7] or A[2] == A[5] == A[8] or A[0] == A[4] == A[8] or A[2] == A[4] == A[6]:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from collections import deque, defaultdict
import bisect
from math import factorial

def main():
    As = []
    for _ in range(3):
        A = list(map(int, input().split()))
        As.append(A)
    N = int(input())
    Bs = set([int(input()) for _ in range(N)])

    is_success = False
    for A in As:
        if len(Bs & set(A)) == 3:
            is_success = True

    for i in range(3):
        C = Bs & set([A[i] for A in As])
        if len(C) == 3:
            is_success = True

    D = set([As[0][0], As[1][1], As[2][2]])
    if len(Bs & D) == 3:
        is_success = True
    D = set([As[0][2], As[1][1], As[2][0]])
    if len(Bs & D) == 3:
        is_success = True

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
b = []
for i in range(N):
  b.append(int(input()))
pin = 0
for i in range(3):
  if (A[0][i] in b) and (A[1][i] in b) and (A[2][i] in b):
    print('Yes')
    pin = 1
    break
  elif (A[i][0] in b) and (A[i][1] in b) and (A[i][2] in b):
    print('Yes')
    pin = 1
    break
if pin == 0:
  if ((A[0][0] in b) and (A[1][1] in b) and (A[2][2] in b)) or ((A[0][2] in b) and (A[1][1] in b) and (A[2][0] in b)):
    print('Yes')
    pin = 1
if pin == 0:
  print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
grid = []
for _ in range(3):
    array = list(map(int, input().strip().split()))
    grid.append(array)

def judge():
    for i in range(3):
        if grid[i][0] == 0 and grid[i][1] == 0 and grid[i][2] == 0:
            return True
        if grid[0][i] == 0 and grid[1][i] == 0 and grid[2][i] == 0:
            return True
    if grid[0][0] == 0 and grid[1][1] == 0 and grid[2][2] == 0:
        return True
    if grid[0][2] == 0 and grid[1][1] == 0 and grid[2][0] == 0:
        return True
    return False

n = int(input())
ans = "No"
for _ in range(n):
    b = int(input())
    for i in range(3):
        if b in grid[i]:
            grid[i][grid[i].index(b)] = 0
    if judge():
        ans = "Yes"
#    print (grid)

print (ans)

Submission status: Accepted

Solution code:

if __name__ == '__main__':
    a1 = [int(i) for i in input().split()]
    a2 = [int(i) for i in input().split()]
    a3 = [int(i) for i in input().split()]
    n = int(input())

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

    result = "No"

    if all([i in b for i in a1]):
        result = "Yes"
    if all([i in b for i in a2]):
        result = "Yes"
    if all([i in b for i in a3]):
        result = "Yes"
    
    for i in range(3):
        if all([i in b for i in [a1[i], a2[i], a3[i]]]):
            result = "Yes"
    
    if all([i in b for i in [a1[0], a2[1], a3[2]]]):
        result = "Yes"
        
    if all([i in b for i in [a1[2], a2[1], a3[0]]]):
        result = "Yes"
    
    print(result)

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)]
S = [[], [], []]
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            S[i].append(1)
        else:
            S[i].append(0)

t = 0


for i in range(3):
    if sum(S[i]) == 3:
        t = 1
    for j in range(3):
        if sum([S[i][j] for i in range(3)]) == 3:
            t = 1
if S[0][0] + S[1][1] + S[2][2] == 3 or S[0][2] + S[1][1] + S[2][0] == 3:
    t = 1

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

lst = list(map(int, read().split()))
arr=lst[:9]
tf = [False] * 10
for i in lst[10:]:
  if i in arr:
    tf[arr.index(i)] = True

t=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
for i in t:
  a = True
  for j in i:
    if not tf[j]:
      a = False
  if a:
    print('Yes')
    quit()
else:
  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())
numlist=set(a)
# print(numlist)
for i in range(n):
    b = int(input())
    if b in numlist:
        for j in range(len(a)):
            if a[j]==b:
                a[j]=0
                break
# print(a)
flag=False
if a[0]==0:
    if a[3]==0 and a[6]==0:
        flag=True
    elif a[1]==0 and a[2]==0:
        flag=True
    elif a[4]==0 and a[8]==0:
        flag=True
elif a[4]==0:
    if a[3] ==0 and a[5]==0:
        flag=True
    if a[1]==0 and a[7]==0:
        flag=True
    if a[6]==0 and a[2]==0:
        flag=True
elif a[8]==0:
    if a[2]==0 and a[5]==0:
        flag=True
    if a[1]==0 and a[2]==0:
        flag=True
    
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A = [-1]*101
d = []
for i in range(3):
    a,b,c = map(int,input().split())
    d.append(a)
    d.append(b)
    d.append(c)
    A[a] = 0
    A[b] = 0
    A[c] = 0
N = int(input())
b = []
for i in range(N):
    b.append(int(input()))

for i in range(N):
    A[b[i]] += 1

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

Submission status: Accepted

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

N = int(input())
B = [0]*N
for i in range(N):
    B[i] = int(input())

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

flag = False
for i in range(3):
    if A[i][0] == -1 and A[i][1] == -1 and A[i][2] == -1:
        flag = True
        break
    if A[0][i] == -1 and A[1][i] == -1 and A[2][i] == -1:
        flag = True
        break

if flag == False:
    if A[0][0] == -1 and A[1][1] == -1 and A[2][2] == -1:
        flag = True
    elif A[0][2] == -1 and A[1][1] == -1 and A[2][0] == -1:
        flag = True

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

Submission status: Accepted

Solution code:
def resolve():

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

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

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

    for i in range(3):
        if memo[i][0] == 1 and memo[i][1] == 1 and memo[i][2] == 1:
            print("Yes")
            return
    
    for j in range(3):
        if memo[0][j] == 1 and memo[1][j] == 1 and memo[2][j] == 1:
            print("Yes")
            return

    if memo[0][0] == 1 and memo[1][1] == 1 and memo[2][2] == 1:
        print('Yes')
        return
    
    if memo[0][2] == 1 and memo[1][1] == 1 and memo[2][0] == 1:
        print("Yes")
        return
    
    print("No")


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

#############
# Libraries #
#############

import math
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#############
# Main Code #
#############

a,b,c = list(map(int,input().split()))
d,e,f = list(map(int,input().split()))
g,h,i = list(map(int,input().split()))

bingo = [a,b,c,d,e,f,g,h,i]


check = [0,0,0,0,0,0,0,0,0]

N = int(input())
for i in range(N):
  z = int(input())
  for j in range(9):
    if bingo[j] == z:
      check[j] = 1
      
is_bingo = 0

if check[0] and check[1] and check[2]:
  is_bingo = 1
if check[3] and check[4] and check[5]:
  is_bingo = 1
if check[6] and check[7] and check[8]:
  is_bingo = 1
if check[0] and check[3] and check[6]:
  is_bingo = 1
if check[1] and check[4] and check[7]:
  is_bingo = 1
if check[2] and check[5] and check[8]:
  is_bingo = 1
if check[0] and check[4] and check[8]:
  is_bingo = 1
if check[2] and check[4] and check[6]:
  is_bingo = 1

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

Submission status: Accepted

Solution code:
x = []
for i in range(3):
    x1 , y1, z1 =[int(i) for i in input().split()]
    x.append(x1)
    x.append(y1)
    x.append(z1)

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

for i in range(n):
    for j in range(9):
        if s[i] == x[j]:
            x[j] = 0

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

Submission status: Accepted

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

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())
c = [[0,0,0],[0,0,0],[0,0,0]]

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

flag = False

for i in range(3):
    if c[0][i] + c[1][i] + c[2][i] == 3 and flag == False:
        print("Yes")
        flag = True
        break
        
    if c[i][0] + c[i][1] + c[i][2] == 3 and flag == False:
        print("Yes")
        flag = True
        break

    """
    if c[i%3][0] + c[(i+1)%3][1] + c[(i+2)%3][2] == 3 and flag == False:
        print("Yes")
        flag = True
        break
    """
    if c[0][0] + c[1][1] + c[2][2] == 3 and flag == False:
        print("Yes")
        flag = True
        break

    if c[0][2] + c[1][1] + c[2][0] == 3 and flag == False:
        print("Yes")
        flag = True
        break

if flag == False:
    print("No")

Submission status: Accepted

Solution code:
A = []
for i in range(3):
    A.append(input().split())
N = int(input())
for i in range(N):
    X = input()
    for j in range(3):
        if A[j][0] == X:
            A[j][0] = 'X'
        if A[j][1] == X:
            A[j][1] = 'X'
        if A[j][2] == X:
            A[j][2] = 'X'
result = []
for i in range(3):
    result.append(A[i])
if (result[0][0] == result[0][1] == result[0][2]) or (result[1][0] == result[1][1] == result[1][2]) or (result[2][0] == result[2][1] == result[2][2]):
    print('Yes')
elif (result[0][0] == result[1][0] == result[2][0]) or (result[0][1] == result[1][1] == result[2][1]) or (result[0][2] == result[1][2] == result[2][2]):
    print('Yes')
elif (result[0][0] == result[1][1] == result[2][2]) or (result[0][2] == result[1][1] == result[2][0]):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
A = []
card = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
r = False
for _ in range(3):
    a = list(map(int, input().split()))
    A.append(a)
n = int(input())
B = []
for _ in range(n):
    b = int(input())
    B.append(b)
for b in B:
    for k, a in enumerate(A):
        if b in a:
            card[k][a.index(b)] = 1
for i in range(3):
    if card[0][i] == card[1][i] == card[2][i] == 1:
        r = True
for i in range(3):
    if card[i][0] == card[i][1] == card[i][2] == 1:
        r = True
if (
    card[0][0] == card[1][1] == card[2][2] == 1
    or card[0][2] == card[1][1] == card[2][0] == 1
):
    r = True
print("Yes") if r else print("No")