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(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 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:
s = list(map(int, input().split()))
t = list(map(int, input().split()))
u = list(map(int, input().split()))

bingo = [s, t, u]

n = int(input())
numbers = [int(input()) for _ in range(n)]

for i in range(3):
    for j in range(3):
        if bingo[i][j] in numbers:
            bingo[i][j] = 0

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

if (bingo[0][0] == 0 and bingo[1][1] == 0 and bingo[2][2] == 0) or \
        (bingo[0][2] == 0 and bingo[1][1] == 0 and bingo[2][0] == 0):
    print('Yes')
    exit()

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

print('No')

Submission status: Accepted

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

d=[[0,0,0],[0,0,0],[0,0,0]]
for k in range(N):
    for i in range(3):
        for j in range(3):
            if a[i][j]==b[k]:
                d[i][j]=1
c=[0]*8
for i in range(3):

    c[0]+=d[i][0]
    c[1] +=d[i][1]
    c[2] +=d[i][2]
    c[3] +=d[0][i]
    c[4] +=d[1][i]
    c[5] +=d[2][i]
    c[6] +=d[i][i]
    c[7] +=d[2-i][i]

if max(c)==3:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A = tuple([tuple(map(int,input().split())) for i in range(3)])
N = int(input())
B = tuple([int(input()) for i in range(N)])
BINGO = [[False]*3 for i in range(3)]
for b in B:
    for y, line in enumerate(A):
        for x, a in enumerate(line):
            if a == b:
                BINGO[y][x] = True
def solve():
    for line in BINGO:
        if line == [True, True, True]:
            return "Yes"
    if BINGO[0][0] == True and BINGO[1][0] == True and BINGO[2][0] == True:
        return "Yes"
    if BINGO[0][1] == True and BINGO[1][1] == True and BINGO[2][1] == True:
        return "Yes"
    if BINGO[0][2] == True and BINGO[1][2] == True and BINGO[2][2] == True:
        return "Yes"
    if BINGO[0][0] == True and BINGO[1][1] == True and BINGO[2][2] == True:
        return "Yes"
    if BINGO[0][2] == True and BINGO[1][1] == True and BINGO[2][0] == True:
        return "Yes"
    return 'No'        
print(solve())

Submission status: Accepted

Solution code:
import sys

card = []
for i in range(3):
    card.append([int(x) for x in input().split()])

N = int(input())
numbers = set()
for i in range(N):
    numbers.add(int(input()))


def checker(aa):
    if len(aa) == 1 and 'x' in aa:
        print('Yes')
        sys.exit()


for i in range(3):
    for j in range(3):
        if card[i][j] in numbers:
            card[i][j] = 'x'

# checks to see if the rows
for row in card:
    s = set()
    for col in row:
        s.add(col)
    checker(s)

# checks to see if the columns
for i in range(3):
    s = set()
    for j in range(3):
        s.add(card[j][i])
    checker(s)
# diagonals
s = set()
for i in range(3):
    s.add(card[i][i])
checker(s)

a = set()
a.add(card[0][2])
a.add(card[1][1])
a.add(card[2][0])
checker(a)


print('No')

Submission status: Accepted

Solution code:
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
n = int(input())
for i in range(n):
  a = int(input())
  if a in A1:
    A1[A1.index(a)] = 0
  if a in A2:
    A2[A2.index(a)] = 0
  if a in A3:
    A3[A3.index(a)] = 0

if sum(A1)==0:
  print("Yes")
elif sum(A2)==0:
  print("Yes")
elif sum(A3)==0:
  print("Yes")
elif A1[0]+A2[0]+A3[0]==0:
  print("Yes")
elif A1[1]+A2[1]+A3[1]==0:
  print("Yes")
elif A1[2]+A2[2]+A3[2]==0:
  print("Yes")
elif A1[0]+A2[1]+A3[2]==0:
  print("Yes")
elif A1[2]+A2[1]+A3[0]==0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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())
B = []
for _ in range(N):
  B.append(int(input()))
for b in range(N):
  for a in range(9):
    if B[b] == A[a]:
      A[a] = 0
BINGO = 'No'
for i in range(3):
  if A[i*3] + A[i*3+1] + A[i*3+2] == 0:
    BINGO = 'Yes'
  if A[i] + A[i+3] + A[i+6] == 0:
      BINGO = 'Yes'
if (A[0] + A[4] + A[8] == 0):
  BINGO = 'Yes'
if (A[2] + A[4] + A[6] == 0):
  BINGO = 'Yes'
print(BINGO)

Submission status: Accepted

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

c = [[-1,-1,-1],[-1,-1,-1],[-1,-1,-1]]

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

ans = False

if c[0][0] == 1 and c[0][1] == 1 and c[0][2] == 1:
    ans = True
if c[1][0] == 1 and c[1][1] == 1 and c[1][2] == 1:
    ans = True
if c[2][0] == 1 and c[2][1] == 1 and c[2][2] == 1:
    ans = True
if c[0][0] == 1 and c[1][0] == 1 and c[2][0] == 1:
    ans = True
if c[0][1] == 1 and c[1][1] == 1 and c[2][1] == 1:
    ans = True
if c[0][2] == 1 and c[1][2] == 1 and c[2][2] == 1:
    ans = True
if c[0][0] == 1 and c[1][1] == 1 and c[2][2] == 1:
    ans = True
if c[2][0] == 1 and c[1][1] == 1 and c[0][2] == 1:
    ans = True

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

Submission status: Accepted

Solution code:
A1 = [0] * 3
A2 = [0] * 3
A3 = [0] * 3
for i in range(3):
    A1[i], A2[i], A3[i] = map(int, input().split())

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

for i in b:
    for j in range(3):
        if A1[j] == i:
            A1[j] = 'ok'
        elif A2[j] == i:
            A2[j] = 'ok'
        elif A3[j] == i:
            A3[j] = 'ok'


if A1[0] == A1[1] == A1[2]:
    print('Yes')

elif A2[0] == A2[1] == A2[2]:
    print('Yes')

elif A3[0] == A3[1] == A3[2]:
    print('Yes')

elif A1[0] == A2[1] == A3[2]:
    print('Yes')

elif A3[0] == A2[1] == A1[2]:
    print('Yes')

elif A1[0] == A2[0] == A3[0]:
    print('Yes')

elif A1[1] == A2[1] == A3[1]:
    print('Yes')

elif A1[2] == A2[2] == A3[2]:
    print('Yes')
    
else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np

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

n = int(input())

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

hit = np.vectorize(lambda x: x in number)(card)

row = hit.all(axis=0).any()
col = hit.all(axis=1).any()

diag1 = hit[0][0] and hit[1][1] and hit[2][2]
diag2 = hit[0][2] and hit[1][1] and hit[2][0]

print('Yes' if row or col or diag1 or diag2 else 'No')

Submission status: Accepted

Solution code:
import numpy as np

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

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

if (A[:,0].sum()==0) or (A[:,1].sum()==0) or (A[:,2].sum()==0):
  print("Yes")
elif (A[0,:].sum()==0) or (A[1,:].sum()==0) or (A[2,:].sum()==0):
  print("Yes")
elif A[0,0]+A[1,1]+A[2,2]==0 or A[2,0]+A[1,1]+A[0,2]==0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:

m = []

for i in range(0, 3):
    m.append([int(n) for n in input().strip().split(" ")])

ns = []
n = int(input().strip())

for i in range(0, n):
    ns.append(int(input().strip()))

for n in ns:
    for i in range(0, 3):
        for j in range(0, 3):
            if m[i][j] == n:
                m[i][j] = 0

import sys

for i in range(0, 3):
    if sum(m[i]) == 0:
        print('Yes')
        sys.exit(0)

for i in range(0, 3):
    if sum([m[0][i], m[1][i], m[2][i]])  == 0:
        print('Yes')
        sys.exit(0)


if sum([m[0][0], m[1][1], m[2][2]]) == 0 or sum([m[0][2], m[1][1], m[2][0]]) == 0:
    print('Yes')
    sys.exit(0)

print('No')

Submission status: Accepted

Solution code:
import numpy as np

data = np.array([input().split() for i in range(3)])
data = data.astype(np.int64)

N = int(input())

ans = 0
for i in range(N):
	check = 0
	num = int(input())
	for x in range(3):
		for y in range(3):
			if num == data[x][y]:
				data[x][y] = -1
				break
		if check == 1:
			break

if data[0][0] == -1 and data[0][1] == -1 and data[0][2] == -1:
	ans = 1
elif data[1][0] == -1 and data[1][1] == -1 and data[1][2] == -1:
	ans = 1
elif data[2][0] == -1 and data[2][1] == -1 and data[2][2] == -1:
	ans = 1
if data[0][0] == -1 and data[1][0] == -1 and data[2][0] == -1:
	ans = 1
elif data[0][1] == -1 and data[1][1] == -1 and data[2][1] == -1:
	ans = 1
elif data[0][2] == -1 and data[1][2] == -1 and data[2][2] == -1:
	ans = 1
elif data[0][0] == -1 and data[1][1] == -1 and data[2][2] == -1:
	ans = 1
elif data[0][2] == -1 and data[1][1] == -1 and data[2][0] == -1:
	ans = 1

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

Submission status: Accepted

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

if n <= 2:
  print("No")
  exit()

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

for i in range(3):
  if len(set(map(tuple, a[i]))) == 1:
    print("Yes")
    exit()
a_0 = []
a_1 = []
a_2 = []
for i in range(3):
  a_0.append(a[i][0])
  a_1.append(a[i][1])
  a_2.append(a[i][2])

a_rcross = []
a_lcross = []
for i in range(3):
  a_rcross.append(a[i][i])
  a_lcross.append(a[i][2-i])
if len(set(map(tuple, a_0))) == 1:
    print("Yes")
    exit()
elif len(set(map(tuple, a_1))) == 1:
    print("Yes")
    exit()
elif len(set(map(tuple, a_2))) == 1:
    print("Yes")
    exit()
elif len(set(map(tuple, a_rcross))) == 1:
    print("Yes")
    exit()
elif len(set(map(tuple, a_lcross))) == 1:
    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())
A = [[A11,A12,A13],[A21,A22,A23],[A31,A32,A33]]
N = int(input())
b_i = list([int(input()) for _ in range(N)])

for bi in b_i:
    for i in range(3):
        for j in range(3):
            if A[i][j] == bi:
                A[i][j] = 'on'

flag_no_bingo = False
#縦調査
for j in range(3):
    if A[0][j] == 'on':
        if A[1][j] == 'on' and A[2][j] == 'on':
            flag_no_bingo = True
#横調査
for i in range(3):
    if A[i][0] == 'on':
        if A[i][1] == 'on' and A[i][2] == 'on':
            flag_no_bingo = True
#斜め調査
if A[0][0] == 'on' and A[1][1] == 'on'  and A[2][2] == 'on' :
    flag_no_bingo = True
if A[0][2] == 'on' and A[1][1] == 'on' and A[2][0] == 'on' :
    flag_no_bingo = True
#結果出力
if flag_no_bingo == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
f = lambda:list(map(int,input().split()))
la = f()+f()+f()
sb = set()
n = int(input())
for i in range(n):
  b = int(input())
  if b in la:
    sb.add(la.index(b))
ls = [{0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}]
for s in ls:
  if s<=sb:
    print('Yes')
    break
else:
  print('No')

Submission status: Accepted

Solution code:
import sys

def LI():
  return [int(s) for s in input().split()]

ROWS = 3
COLS = 3

A = []
A.append(LI())
A.append(LI())
A.append(LI())

BINGO = []
BINGO.append([0]*3)
BINGO.append([0]*3)
BINGO.append([0]*3)

N = int(input())

for n in range(N):
  b = int(input())
  for i in range(ROWS):
    for j in range(COLS):
      if A[i][j] == b:
        BINGO[i][j] = 1
      
if BINGO[0][0] == 1 and BINGO[0][1] == 1 and BINGO[0][2] == 1:
  print('Yes')
  sys.exit()
  
if BINGO[1][0] == 1 and BINGO[1][1] == 1 and BINGO[1][2] == 1:
  print('Yes')
  sys.exit()
  
if BINGO[2][0] == 1 and BINGO[2][1] == 1 and BINGO[2][2] == 1:
  print('Yes')
  sys.exit()
  
if BINGO[0][0] == 1 and BINGO[1][0] == 1 and BINGO[2][0] == 1:
  print('Yes')
  sys.exit()
  
if BINGO[0][1] == 1 and BINGO[1][1] == 1 and BINGO[2][1] == 1:
  print('Yes')
  sys.exit()
  
if BINGO[0][2] == 1 and BINGO[1][2] == 1 and BINGO[2][2] == 1:
  print('Yes')
  sys.exit()
      
if BINGO[0][0] == 1 and BINGO[1][1] == 1 and BINGO[2][2] == 1:
  print('Yes')
  sys.exit()
  
if BINGO[0][2] == 1 and BINGO[1][1] == 1 and BINGO[2][0] == 1:
  print('Yes')
  sys.exit() 
      
print('No')

Submission status: Accepted

Solution code:
from itertools import product
import numpy as np

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

is_open = np.array([[0] * 3 for _ in range(3)])
for i, k in product(range(3), repeat=2):
    if a[i][k] in b:
        is_open[i][k] = 1

bingo = False
for i in range(3):
    if sum(is_open[i, :]) == 3:
        bingo = True
        break
    elif sum(is_open[:, i]) == 3:
        bingo = True
        break
if not bingo:
    if sum(np.diag(is_open)) == 3:
        bingo = True
    elif sum(np.diag(np.fliplr(is_open))) == 3:
        bingo = True

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

Submission status: Accepted

Solution code:
a_1 = list(map(int, input().split()))
a_2 = list(map(int, input().split()))
a_3 = list(map(int, input().split()))

N = int(input())

c_1=[0,0,0]
c_2=[0,0,0]
c_3=[0,0,0]
b = []

count = 0

for i in range(N):
    b.append(int(input()))
    
for i in range(N):
    for j in range(3):
        if b[i] == a_1[j]:
            c_1[j] = 1
        if b[i] == a_2[j]:
            c_2[j] = 1
        if b[i] == a_3[j]:
            c_3[j] = 1
            
if c_1[0] == 1 and c_1[1] == 1 and c_1[2]:
    count += 1
if c_2[0] == 1 and c_2[1] == 1 and c_2[2]:
    count += 1
if c_3[0] == 1 and c_3[1] == 1 and c_3[2]:
    count += 1
if c_1[0] == 1 and c_2[0] == 1 and c_3[0]:
    count += 1
if c_1[1] == 1 and c_2[1] == 1 and c_3[1]:
    count += 1
if c_1[2] == 1 and c_2[2] == 1 and c_3[2]:
    count += 1
if c_1[0] == 1 and c_2[1] == 1 and c_3[2]:
    count += 1
if c_1[2] == 1 and c_2[1] == 1 and c_3[0]:
    count += 1


#print(c_1)
#print(c_2)
#print(c_3)
#print(count)

if count >= 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())
b = [int(input()) for _ in range(N)]

ans = False
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            a[i][j] = 0
            

for i in range(3):
    if sum(a[i])==0:
        ans = True
        break
    if (a[0][i]+a[1][i]+a[2][i])==0:
        ans = True
        break
if (a[0][0]+a[1][1]+a[2][2])==0:
    ans = True

if (a[0][2]+a[1][1]+a[2][0])==0:
    ans = True

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

Submission status: Accepted

Solution code:
bingo = [list(input().split()) for _ in range(3)]
n = int(input())

# ヒットした数字に○をつける
for i in range(n):
    hit = input()
    for line in bingo:
        if hit in line:
            i = line.index(hit)
            line[i] = '○'
            break

# ビンゴしているか判定する
is_bingo = False

for line in bingo:
  if line[0] == line[1] == line[2]:
    is_bingo = True

for i in range(3):
  if bingo[0][i] == bingo[1][i] == bingo[2][i]:
    is_bingo = True

if bingo[0][0] == bingo[1][1] == bingo[2][2]:
  is_bingo = True
elif bingo[0][2] == bingo[1][1] == bingo[2][0]:
  is_bingo = True

if is_bingo:
    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())
S =[int(input()) for i  in range(N)]
ans = "No"

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

if len(set(S)&set(A)) >= 3:
  ans ="Yes"
if len(set(S)&set(B)) >= 3:
  ans ="Yes"
if len(set(S)&set(C)) >= 3:
  ans ="Yes"
if len(set(S)&set(D)) >= 3:
  ans ="Yes"
if len(set(S)&set(E)) >= 3:
  ans ="Yes"
if len(set(S)&set(F)) >= 3:
  ans ="Yes"
if len(set(S)&set(G)) >= 3:
  ans ="Yes"
if len(set(S)&set(H)) >= 3:
  ans ="Yes"

print(ans)

Submission status: Accepted

Solution code:
a0 = list(map(int,input().split(" ")))
a1 = list(map(int,input().split(" ")))
a2 = list(map(int,input().split(" ")))
n = int(input())
b = []

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

for i in range(n):
    for j in range(3):
        if b[i] == a0[j]:
            a0[j] = 0
        if b[i] == a1[j]:
            a1[j] = 0
        if b[i] == a2[j]:
            a2[j] = 0

ans = 0

if a0[0] + a0[1] + a0[2] == 0:
    ans += 1
if a1[0] + a1[1] + a1[2] == 0:
    ans += 1
if a2[0] + a2[1] + a2[2] == 0:
    ans += 1
if a0[0] + a1[0] + a2[0] == 0:
    ans += 1
if a0[1] + a1[1] + a2[1] == 0:
    ans += 1
if a0[2] + a1[2] + a2[2] == 0:
    ans += 1
if a0[0] + a1[1] + a2[2] == 0:
    ans += 1
if a0[2] + a1[1] + a2[0] ==0:
    ans += 1

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

Submission status: Accepted

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

answers = [
    [0, 1, 2],
    [3, 4, 5],
    [6, 7, 8],
    [0, 3, 6],
    [1, 4, 7],
    [2, 5, 8],
    [0, 4, 8],
    [2, 4, 6],
]

A = []
A.extend(list(map(int, input().split())))
A.extend(list(map(int, input().split())))
A.extend(list(map(int, input().split())))

N = int(input())

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

hole = []
for i in b:
    if i in A:
        hole.append(A.index(i))
    else:
        continue

for answer in answers:
    i, j, k = answer
    if i in hole and j in hole and k in hole:
        print("Yes")
        exit(0)
print("No")

Submission status: Accepted

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

f = sys.stdin
A = [list(map(int, f.readline().split(' '))) for _ in range(3)]

f_A = A[0] + A[1] + A[2]

N = int(f.readline())
b = [int(f.readline()) for _ in range(N)]

row = {'0': 0, '1': 0, '2': 0}
col = {'0': 0, '1': 0, '2': 0}
left_diag = 0
right_diag = 0

result = 'No'
for i in range(N):
    idx = -1
    if b[i] in f_A:
        idx = f_A.index(b[i])
    else:
        continue
    i, j = idx // 3, idx % 3
    row[str(i)] += 1
    col[str(j)] += 1
    if i == j:
        left_diag += 1
    if i + j == 2:
        right_diag += 1
    if (row[str(i)] == 3 or col[str(j)] == 3 or left_diag == 3 or right_diag ==
            3):
        result = 'Yes'
        break
# print(row)
# print(col)
# print(left_diag, right_diag)
print(result)

Submission status: Accepted

Solution code:
a,b,c=input().split()
d,e,f=input().split()
g,h,i=input().split()
N=int(input())
numbers=[input() for i in range(N)]



for n in numbers:
    if a==n:
        a=0
    elif b==n:
        b=0
    elif c==n:
        c=0
    elif d==n:
        d=0
    elif e==n:
        e=0
    elif f==n:
        f=0
    elif g== n:
        g = 0
    elif h == n:
        h = 0
    elif i == n:
        i = 0
    else:
        continue

if a==b==c or d==e==f or g==h==i or a==d==g or b==e==h or c==f==i or a==e==i or c==e==g:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
tbl=[list(map(int, input().split())) for _ in range(3)]
N=int(input())
lst=list(int(input()) for _ in range(N))
for i in range(3):
  for j in range(3):
    for x in lst:
      if tbl[i][j] == x:
        tbl[i][j] = 0
        break
if max(tbl[0][0],tbl[0][1],tbl[0][2]) == 0:
  print("Yes")
elif max(tbl[1][0],tbl[1][1],tbl[1][2]) == 0:
  print("Yes")
elif max(tbl[2][0],tbl[2][1],tbl[2][2]) == 0:
  print("Yes")
elif max(tbl[0][0],tbl[1][0],tbl[2][0]) == 0:
  print("Yes")
elif max(tbl[0][1],tbl[1][1],tbl[2][1]) == 0:
  print("Yes")
elif max(tbl[0][2],tbl[1][2],tbl[2][2]) == 0:
  print("Yes")
elif max(tbl[0][0],tbl[1][1],tbl[2][2]) == 0:
  print("Yes")
elif max(tbl[2][0],tbl[1][1],tbl[0][2]) == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
list1 = list(map(int,input().split()))
list2 = list(map(int,input().split()))
list3 = list(map(int,input().split()))
N=int(input())
i=0
list4=[]

rlist1=[]
rlist2=[]
rlist3=[]

while(i<N) :
  a = int(input())
  list4.append(a)
  i+=1

j=0

while(j<len(list4)):
  if(list1.count(list4[j])!=0):
    rlist1.append(list1.index(list4[j]))
  j+=1

k=0
while(k<len(list4)):
  if(list2.count(list4[k])!=0):
    rlist2.append(list2.index(list4[k]))
  k+=1

l=0
while(l<len(list4)):
  if(list3.count(list4[l])!=0):
    rlist3.append(list3.index(list4[l]))
  l+=1

result="No"

rlist1.sort()
rlist2.sort()
rlist3.sort()

if(len(rlist1)==3):
  result="Yes"

if(len(rlist2)==3):
  result="Yes"

if(len(rlist3)==3):
  result="Yes"

if(rlist1.count(0)!=0 and rlist2.count(0)!=0 and rlist3.count(0)!=0):
  result="Yes"

if(rlist1.count(1)!=0 and rlist2.count(1)!=0 and rlist3.count(1)!=0):
  result="Yes"

if(rlist1.count(2)!=0 and rlist2.count(2)!=0 and rlist3.count(2)!=0):
  result="Yes"

if(rlist1.count(0)!=0 and rlist2.count(1)!=0 and rlist3.count(2)!=0):
  result="Yes"

if(rlist1.count(2)!=0 and rlist2.count(1)!=0 and rlist3.count(0)!=0):
  result="Yes"

print(result)

Submission status: Accepted

Solution code:
n1,n2,n3=map(int, input().split())
n4,n5,n6=map(int, input().split())
n7,n8,n9=map(int, input().split())
M=[n1,n2,n3,n4,n5,n6,n7,n8,n9]
O=[0,0,0,0,0,0,0,0,0]
N=int(input())
for i in range(N):
 a=int(input())
 if a in M:
  b=M.index(a)
  if O[b]==0:
   O[b]+=1
a1=[1,0,0,1,0,0,1,0,0]
a2=[0,1,0,0,1,0,0,1,0]
a3=[0,0,1,0,0,1,0,0,1]
a4=[1,1,1,0,0,0,0,0,0]
a5=[0,0,0,1,1,1,0,0,0]
a6=[0,0,0,0,0,0,1,1,1]
a7=[1,0,0,0,1,0,0,0,1]
a8=[0,0,1,0,1,0,1,0,0]
a=[a1,a2,a3,a4,a5,a6,a7,a8]
d=0
for i in range(8):
 c=0
 for j in range(9):
  c+=a[i][j]*O[j]
 if c==3:
  d+=1
if d>=1:
 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())
lista = a+b+c
call_number = []
for i in range(n):
    k = int(input())
    call_number.append(k)
bingo_number_list = []
for m,n in enumerate(lista):
    if n in call_number:
        bingo_number_list.append(m)
    
list0 = [0,1,2]
list1 = [3,4,5]
list2 = [6,7,8]
list3 = [0,3,6]
list4 = [1,4,7]
list5 = [2,5,8]
list6 = [0,4,8]
list7 = [2,4,6]
bingo = 0
for i in range(8):
    if set(list0) <= set(bingo_number_list):
        bingo += 1
    if set(list1) <= set(bingo_number_list):
        bingo += 1
    if set(list2) <= set(bingo_number_list):
        bingo += 1
    if set(list3) <= set(bingo_number_list):
        bingo += 1
    if set(list4) <= set(bingo_number_list):
        bingo += 1
    if set(list5) <= set(bingo_number_list):
        bingo += 1
    if set(list6) <= set(bingo_number_list):
        bingo += 1
    if set(list7) <= set(bingo_number_list):
        bingo += 1

if bingo > 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a1_list = list(map(int, input().split()))
a2_list = list(map(int, input().split()))
a3_list = list(map(int, input().split()))
a1_list.extend(a2_list)
a1_list.extend(a3_list)

n = int(input())
nums = []
for _ in range(n):
  x = int(input())
  nums.append(x)
  
result = "No"
patterns = [[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 p in patterns:
  if a1_list[p[0]] in nums and a1_list[p[1]] in nums and a1_list[p[2]] in nums:
    result = "Yes"
    break
print(result)

Submission status: Accepted

Solution code:
import collections

def bingo(card):
  v = list(card.values())
  bingo = [v[:3], v[3:6], v[6:], 
           v[::3], v[1::3], v[2::3], 
           [v[0], v[4], v[-1]], 
           [v[2], v[4], v[6]]]
  z = [0]*3
  b = [1 if n == z else 0 for n in bingo]
  if 1 in b:
    return "Yes"
  else:
    return "No"

  
card = collections.OrderedDict()
for i in range(3):
  for n in input().split():
    card[n] = 1

while 1:
  try:
    n = input()
    if card.get(n):
  	  card[n] = 0
    
  except:
    break
  
print(bingo(card))

Submission status: Accepted

Solution code:
A = [[],[],[]]
A[0] = list(map(int, input().split()))
A[1] = list(map(int, input().split()))
A[2] = list(map(int, input().split()))
N = int(input())
b = []
for _ in range(N):
    b.append(int(input()))
check = [[0 for _ in range(3)] for _ in range(3)]

for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            check[i][j] = 1
OK = False
for i in range(3):
    if sum(check[i]) == 3:
        OK = True
for i in range(3):
    if check[0][i]+check[1][i]+check[2][i] == 3:
        OK = True
if check[0][0]+check[1][1]+check[2][2] == 3:
    OK = True
if check[0][2]+check[1][1]+check[2][0] == 3:
    OK = True
if OK:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import random

A = input().split()
B = input().split()
C = input().split()

A[0]=int(A[0])
A[1]=int(A[1])
A[2]=int(A[2])

B[0]=int(B[0])
B[1]=int(B[1])
B[2]=int(B[2])

C[0]=int(C[0])
C[1]=int(C[1])
C[2]=int(C[2])


N = input()
N = int(N)


for i in range(N):
  j = input()
  j=int (j)
 
  if A[0] == j :
    A[0] =1
  if A[1] == j :
    A[1] =1
  if A[2] == j :
    A[2] =1
    
  if B[0] == j :
    B[0] =1
  if B[1] == j :
    B[1] =1
  if B[2] == j :
    B[2] =1
    
  if C[0] == j :
    C[0] =1
  if C[1] == j :
    C[1] =1
  if C[2] == j :
    C[2] =1
    
if ((A[0]==1 and A[1]==1 and A[2]==1) or (B[0]==1 and B[1]==1 and B[2]==1) or (C[0]==1 and C[1]==1 and C[2]==1) or (A[0]==1 and B[0]==1 and C[0]==1) or (A[1]==1 and B[1]==1 and C[1]==1) or (A[2]==1 and B[2]==1 and C[2]==1) or (A[0]==1 and B[1]==1 and C[2]==1) or (A[2]==1 and B[1]==1 and C[0]==1)):

  print ("Yes")

else :
  print ("No")

Submission status: Accepted

Solution code:
# from bisect import bisect_left,bisect_right
# from collections import Counter

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 i in range(n):
    b.append(int(input()))

def aru(n):
    if n in b:
        return True
    else:
        return False
# print(a)
ans=[aru(aa) for aa in a]
    
    
# print(ans)

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

# h=list(map(int,input().split()))
# l=sorted(list(map(int,input().split())))

Submission status: Accepted

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

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

if P[0][0] * P[0][1] * P[0][2] == 1 or P[1][0] * P[1][1] * P[1][2] == 1 or P[2][0] * P[2][1]\
*P[2][2] == 1 or P[0][0] * P[1][0] *P[2][0] == 1 or P[0][1] * P[1][1] * P[2][1] == 1 or\
P[0][2] * P[1][2] * P[2][2] == 1 or P[0][0] * P[1][1] * P[2][2] == 1 or\
P[0][2] * P[1][1] * P[2][0] == 1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys
A=[[0]*3 for i in range(3)]
for i in range(3):
  A[i]=list(map(int,input().split()))
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]=10**10
for i in range(3):
  if sum(A[i])==3*10**10:
    print("Yes")
    sys.exit()
a=0
for i in range(3):
  a=a+A[i][0]
if a==3*10**10:
  print("Yes")
  sys.exit()
a=0
for i in range(3):
  a=a+A[i][1]
if a==3*10**10:
  print("Yes")
  sys.exit()
a=0
for i in range(3):
  a=a+A[i][2]
if a==3*10**10:
  print("Yes")
  sys.exit()
if A[0][0]+A[1][1]+A[2][2]==3*10**10 or A[0][2]+A[1][1]+A[2][0]==3*10**10:
  print("Yes")
  sys.exit()
print("No")

Submission status: Accepted

Solution code:
import numpy as np

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


flag = False
n = int(input())
n_list=[list(map(int,input().split())) for i in range(n)]
bingo_list=np.asarray(bingo_list)

for j in n_list:
    if j in bingo_list:
        bingo_list = np.where(bingo_list==j, 0, bingo_list)


for i in range(3):
    if sum(bingo_list[i]) == 0 or sum(bingo_list[:, i]) == 0:
        flag = True
        break

a = (bingo_list[0][0]+bingo_list[1][1]+bingo_list[2][2])
b = (bingo_list[0][2]+bingo_list[1][1]+bingo_list[2][0])
if(a == 0 or b == 0):
    flag = True

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