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

bingo = False

# yoko
for i in range(3):
  cnt = 0
  for j in range(3):
    if A[i][j] in B:
      cnt += 1
  if cnt == 3:
    bingo = True

# tate
for j in range(3):
  Cnt = 0
  for i in range(3):
    if A[i][j] in B:
      Cnt +=  1
  if Cnt == 3:
    bingo = True

#naname
cnt = 0
for i in range(3):
  if A [i] [i] in B:
    cnt += 1
if cnt == 3:
  bingo = True
cnt = 0
for i in range(3):
  j = 2 -i
  if A[i][j] in B:
    cnt += 1
if cnt == 3:
  bingo = True
if bingo:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

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

for i in range(3):
  if bingo[i].count(0) == 3:
    print("Yes")
    exit()
  elif bingo[0][i] == 0 and bingo[1][i] == 0 and bingo[2][i] == 0:
    print("Yes")
    exit()
  else:
    pass

if bingo[0][0] == 0 and bingo[1][1] == 0 and bingo[2][2] ==0:
  print("Yes")
  exit()
elif bingo[0][2] == 0 and bingo[1][1] == 0 and bingo[2][0] == 0:
  print("Yes")
  exit()
else:
  print("No")

Submission status: Accepted

Solution code:
N=[list(map(int,input().split())) for j in range(3)]
M=int(input())
K=[int(input()) for v in range(M)]

for b in range(M):
  for t in range(3):
    for r in range(3):
      if N[t][r]==K[b]:
        N[t][r]=0
for i in range(3):
  if N[i][0]+N[i][1]+N[i][2]==0: #たて
    print("Yes")
    exit()
  elif N[0][i]+N[1][i]+N[2][i]==0:
    print("Yes")
    exit()
if N[0][0]+N[1][1]+N[2][2]==0:
  print("Yes")
  exit()
elif  N[0][2]+N[1][1]+N[2][0]==0:
  print("Yes")
  exit()
else:
  print("No")

Submission status: Accepted

Solution code:
import sys
bingo = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
ban = [[False]*3 for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == b:
                ban[i][j] = True
na = []
nb = []
for i in range(3):
    if all(ban[i][j] for j in range(3)) or all(ban[k][i] for k in range(3)):
        print("Yes")
        sys.exit()
    na.append(ban[i][i])
    nb.append(ban[i][2-i])
if all(na) or all(nb):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
L=[list(map(int,input().split())) for _ in range(3)]
N=int(input())
B=[int(input()) for _ in range(N)]
for i in B:
  for j in range(3):
    for k in range(3):
      if i==L[j][k]:
        L[j][k]=0
T=False
for i in range(3):
  if L[i][0]==L[i][1]==L[i][2]:
    T=True
  elif L[0][i]==L[1][i]==L[2][i]:
    T=True
if L[0][0]==L[1][1]==L[2][2] or L[0][2]==L[1][1]==L[2][0]:
  T=True
if T==True:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
row_1 = list(map(int, input().split()))
row_2 = list(map(int, input().split()))
row_3 = list(map(int, input().split()))
N = int(input())
numbers_called = []
for i in range(N):
    b = int(input())
    numbers_called.append(b)

col_1 = [row_1[0], row_2[0], row_3[0]]
col_2 = [row_1[1], row_2[1], row_3[1]]
col_3 = [row_1[2], row_2[2], row_3[2]]
diagonal = [row_1[0], row_2[1], row_3[2]]
anti_diagonal = [row_3[0], row_2[1], row_1[2]]

winning_combinations = [row_1, row_2, row_3, col_1, col_2, col_3, diagonal, anti_diagonal]

is_bingo = False
for combination in winning_combinations:
    # check if every number for this combination has been called
    is_bingo = all([number in numbers_called for number in combination])
    
    if is_bingo:
        break


if is_bingo:
    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 = []
for _ in range(n):
  b.append(int(input()))

result = []
for i in b:
  for j in range(0, 3):
    for k in range(0, 3):
      if A[j][k] == i:
        A[j][k] = "z"

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

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

Submission status: Accepted

Solution code:
a = []
for i in range(3):
  d, b, c = map(int, input().split())
  a.append(d)
  a.append(b)
  a.append(c)
for _ in range(int(input())):
  n = int(input())
  if(n in a):
    a[a.index(n)] = 0
retsu = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
frag = False
for i in range(8):
  frag1 = True
  for s in range(3):
    if(a[retsu[i][s]] > 0):
      frag1 = False
  frag = frag1 or frag
if(frag):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import itertools
import sys

def f_row(L):
  for i in range(3):
    for j in range(3):
      if L[i][j] == False:
        break
      elif j == 2:
        return True
      else:
        continue
  return False

def f_col(L):
  for i in range(3):
    for j in range(3):
      if L[j][i] == False:
        break
      elif j == 2:
        return True
      else:
        continue
  return False
        
def f_rcross(L):
  for i in range(3):
    if L[i][i] == False:
      break
    elif i == 2:
      return True
    else:
      continue
  return False
      
def f_lcross(L):
  for i in range(3):
    if L[i][2-i] == False:
      break
    elif i == 2:
      return True
    else:
      continue
  return False

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

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

for b in B:
  for i, j in itertools.product(range(3), repeat=2):
    if b == A[i][j]:
      L[i][j] = True
      if f_row(L) or f_col(L) or f_rcross(L) or f_lcross(L):
        print('Yes')
        sys.exit()
      break
print('No')

Submission status: Accepted

Solution code:
import sys

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

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

for i in range(3):
  if A[i][0] + A[i][1] + A[i][2] == 0:
    print('Yes')
    sys.exit()
  if A[0][i] + A[1][i] + A[2][i] == 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')

Submission status: Accepted

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

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

lines = [[a[0][0], a[0][1], a[0][2]],
         [a[1][0], a[1][1], a[1][2]],
         [a[2][0], a[2][1], a[2][2]],
         [a[0][0], a[1][0], a[2][0]],
         [a[0][1], a[1][1], a[2][1]],
         [a[0][2], a[1][2], a[2][2]],
         [a[0][0], a[1][1], a[2][2]],
         [a[0][2], a[1][1], a[2][0]]]

for line in lines:
    if not any(line):
        print('Yes')
        exit()

print('No')

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A = [il() for _ in range(3)]
    B = []
    for _ in range(3):
        B.append([False, False, False])

    N = ii()
    for n in range(N):
        b = ii()
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    B[i][j] = True

    for i in range(3):
        if B[i][0] and B[i][1] and B[i][2]:
            print('Yes')
            exit()
    for j in range(3):
        if B[0][j] and B[1][j] and B[2][j]:
            print('Yes')
            exit()
    if (B[0][0] and B[1][1] and B[2][2]) or (B[0][2] and B[1][1] and B[2][0]):
        print('Yes')
        exit()

    print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
A = [list(map(int, input().split())) for _ in range(3)]
c = np.zeros_like(A, dtype=bool)
N = int(input())
for _ in range(N):
    b = int(input())
    for i, line in enumerate(A):
        for j, a in enumerate(line):
            if a == b:
                c[i][j] = True
ans = False
for i in range(3):
    if np.all(c[i]):
        ans = True
    elif np.all(c[:,i]):
        ans = True
for k in range(3):
    if not c[k, k]:
        break
else:
    ans = True
for k in range(3):
    if not c[k, 2 -k]:
        break
else:
    ans = True
print('Yes' if ans else 'No')

Submission status: Accepted

Solution code:
def main():

    board = [list(map(int, input().split())) for _ in range(3)]
    n = int(input())

    calls = list(int(input()) for _ in range(n))

    cmap = { }
    for r in range(3):
        for c in range(3):
            cmap[board[r][c]] = (r, c)

    for call in calls:
        if call in cmap:
            r, c = cmap[call]
            board[r][c] = -1

    if (any(all(board[r][c] == -1 for r in range(3)) for c in range(3)) or
        any(all(board[r][c] == -1 for c in range(3)) for r in range(3)) or
        all(board[i][i] == -1 for i in range(3)) or
        all(board[i][2-i] == -1 for i in range(3))):
        print('Yes')
    else:
        print('No')
          
main()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	
	#横
	B = []
	w1 = list(map(int,input().split()))
	w2 = list(map(int,input().split()))
	w3 = list(map(int,input().split()))
	n = int(input())
	A = []
	for i in range(n):
		cmd = int(input())
		A.append(cmd)
	B.append(w1)
	B.append(w2)
	B.append(w3)

	#縦
	h1 = []
	h2 = []
	h3 = []
	h1.append(w1[0])
	h1.append(w2[0])
	h1.append(w3[0])
	h2.append(w1[1])
	h2.append(w2[1])
	h2.append(w3[1])
	h3.append(w1[2])
	h3.append(w2[2])
	h3.append(w3[2])

	B.append(h1)
	B.append(h2)
	B.append(h3)

	#斜め
	s1 = []
	s2 = []
	s1.append(w1[0])
	s1.append(w2[1])
	s1.append(w3[2])
	s2.append(w1[2])
	s2.append(w2[1])
	s2.append(w3[0])

	B.append(s1)
	B.append(s2)
	
	setA = set(A)
	cnt = 0
	for k in B:
		setB = set(k)
		#intersection
		s_int = setA & setB
		if len(s_int) == 3:
			cnt = 1
			break
	if cnt == 1:
		print("Yes")
	else:
		print("No")

Submission status: Accepted

Solution code:
import sys

an = []
for i in range(3):
  a = [int(num) for num in input().split()]
  an.append(a)

n = int(input())  

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

for b in number:
  for i in range(3):
    for j in range(3):
      if b == an[i][j]:
        an[i][j] = 0

for i in range(3):
  if an[i][0] == an[i][1] and an[i][0] == an[i][2]:
    print("Yes")
    sys.exit()

for j in range(3):
  if an[0][j] == an[1][j] and an[0][j] == an[2][j]:
    print("Yes")
    sys.exit()    

if an[0][0] == an[1][1] and an[0][0] == an[2][2]:
  print("Yes")
  sys.exit() 

if an[0][2] == an[1][1] and an[0][2] == an[2][0]:
  print("Yes")
  sys.exit() 
    
print("No")

Submission status: Accepted

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

    for i in range(3):
        # 縦
        if sum([A[i], A[i+3], A[i+6]]) == 0:
            print("Yes")
            exit()
        # 横
        if sum([A[i*3], A[i*3+1], A[i*3+2]]) == 0:
            print("Yes")
            exit()
    # 斜め
    if sum([A[0], A[4], A[8]]) == 0 or sum([A[2], A[4], A[6]]) == 0:
        print("Yes")
        exit()
    print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
al = [list(map(int, input().split())) for i in range(3)]
al = sum(al, [])
n = int(input())
bl = [int(input()) for i in range(n)]
check = [0 for i in range(9)]
 
for b in bl:
    if b in al:
        check[al.index(b)] = 1
 
if [1,1,1] in [check[:3], check[3:6], check[6:], check[0:7:3], check[1:8:3], check[2:9:3], check[0:9:4], check[2:8:2]]:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A = {}
for i in range(1, 4):
    for j, a in enumerate(map(int, input().split()), 1):
        A[a] = (i,j)

memo = set()

N = int(input())
for _ in range(N):
    b = int(input())
    if b in A:
        memo.add(A[b])

bingo = [
    set([(1,1),(1,2),(1,3)]),
    set([(2,1),(2,2),(2,3)]),
    set([(3,1),(3,2),(3,3)]),
    set([(1,1),(2,1),(3,1)]),
    set([(1,2),(2,2),(3,2)]),
    set([(1,3),(2,3),(3,3)]),
    set([(1,1),(2,2),(3,3)]),
    set([(3,1),(2,2),(1,3)])
]

for b in bingo:
    if len(b.intersection(memo)) == 3:
        print("Yes")
        break
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
card = list(list(map(int,input().split())) for i in range(3))
n = int(input())
for i in range(n):
  x = int(input())
  for j in range(3):
    if x in card[j]:
      card[j]=list(True if s == x else s for s in card[j])
      
for i in range(3):
  if card[i] == [True,True,True]:
    print("Yes")
    sys.exit()
    break
  elif card[0][i]==True and card[1][i]==True and card[2][i] == True:
    print("Yes")
    sys.exit()
    break
if card[0][0]== True and card[1][1]==True and card[2][2]==True:
  print("Yes")
elif card[0][2]==True and card[1][1]== True and  card[2][0] ==True:
  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 (a[0][0] in b) and (a[0][1] in b) and (a[0][2] in b):
    print('Yes')
elif (a[1][0] in b) and (a[1][1] in b) and (a[1][2] in b):
    print('Yes')
elif (a[2][0] in b) and (a[2][1] in b) and (a[2][2] in b):
    print('Yes')
elif (a[0][0] in b) and (a[1][0] in b) and (a[2][0] in b):
    print('Yes')
elif (a[0][1] in b) and (a[1][1] in b) and (a[2][1] in b):
    print('Yes')
elif (a[0][2] in b) and (a[1][2] in b) and (a[2][2] in b):
    print('Yes')
elif (a[0][0] in b) and (a[1][1] in b) and (a[2][2] in b):
    print('Yes')
elif (a[0][2] in b) and (a[1][1] in b) and (a[2][0] in b):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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 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=0
sum1=0
sum2=0
sum3=0
sum4=0
sum5=0
for i in range(3):
  if sum(A[i]) == 0:bingo=1
  sum1 += A[i][0]
  sum2 += A[i][1]
  sum3 += A[i][2]
  sum4 += A[i][i]
  sum5 += A[i][2-i]
if 0 in [sum1,sum2,sum3,sum4,sum5]:bingo=1
print(['No','Yes'][bingo])

Submission status: Accepted

Solution code:
a=[list(map(int,input().split())) for A 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 b==a[j][k]:
        a[j][k]=0

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

Submission status: Accepted

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

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

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

if sum(a[0]) == 0:
    print("Yes")
    sys.exit()
elif sum(a[1]) == 0:
    print("Yes")
    sys.exit()
elif sum(a[2]) == 0:
    print("Yes")
    sys.exit()
else:
    a_t = numpy.array(a).T
    if sum(a_t[0]) == 0:
        print("Yes")
        sys.exit()
    elif sum(a_t[1]) == 0:
        print("Yes")
        sys.exit()
    elif sum(a_t[2]) == 0:
        print("Yes")
        sys.exit()
    else:
        if a[0][0] + a[1][1] + a[2][2] == 0:
            print("Yes")
            sys.exit()
        elif a[0][2] + a[1][1] + a[2][0] == 0:
            print("Yes")
            sys.exit()
print("No")

Submission status: Accepted

Solution code:
A = [ [int(x) for x in input().split()] for _ in range(3) ]
N = int(input())
B = set([ int(input()) for _ in range(N) ])
res = "No"
for i in range(3):
    c1 = 0
    c2 = 0
    for j in range(3):
        c1 += 1 if A[i][j] in B else 0
        c2 += 1 if A[j][i] in B else 0
    if c1==3 or c2==3:
        res = "Yes"
if sum([ 1 if A[j][j] in B else 0 for j in range(3) ]) == 3:
    res = "Yes"
if sum([ 1 if A[j][2-j] in B else 0 for j in range(3) ]) == 3:
    res = "Yes"
print(res)

Submission status: Accepted

Solution code:
a = []

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

for b1 in b:
  for a1 in a:
    if b1 in a1:
      a1[a1.index(b1)] = 0
aa = [[a[0][0],a[1][0],a[2][0]],[a[0][1],a[1][1],a[2][1]],[a[0][2],a[1][2],a[2][2]]]

if a[0].count(0) == 3 or a[1].count(0) == 3 or a[2].count(0) == 3 or aa[0].count(0) == 3 or aa[1].count(0) == 3 or aa[2].count(0) == 3 or a[0][0] == a[1][1] == a[2][2] == 0 or a[0][2] == a[1][1] == a[2][0] == 0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:

def list_check(list1, list2):
    return set(list1).issubset(list2)

a = list()
for _ in range(3):
    a.extend(list(map(int, input().split())))

lists = []

bingo = []
N = int(input())
for _ in range(N):
    b = int(input())
    if b in a:
        idx = a.index(b)
        bingo.append(idx)
        

for i in [0,1,2]:
    l = [i,i+3, i+6]
    lists.append(l)

for i in [0,3,6]:
    l = [i,i+1, i+2]
    lists.append(l)

lists.append([0,4,8])
lists.append([2,4,6])


for li in lists:    
    if list_check(li, bingo):
        print('Yes')
        exit()

print('No')

Submission status: Accepted

Solution code:
def check(A,a,b,c):
  if A[a] == 0:
    if A[b] == 0:
      if A[c] == 0:
        return 1
  return 0

A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N = int(input())
A = A1+A2+A3
for i in range(N):
  b = int(input())
  if b in A:
    A[A.index(b)] = 0
ans = "No"
anslist = []
#bingo check
anslist.append(check(A,0,1,2))
anslist.append(check(A,3,4,5))
anslist.append(check(A,6,7,8))
anslist.append(check(A,0,3,6))
anslist.append(check(A,1,4,7))
anslist.append(check(A,2,5,8))
anslist.append(check(A,0,4,8))
anslist.append(check(A,2,4,6))

if 1 in anslist:
  ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
#Atocoder ABC 157 B "Bingo"

a = list(map(int,input().split()))
b  = list(map(int,input().split()))
c  = list(map(int,input().split()))
box = [a,b,c]

N = int(input())
for i in range(N):
    s = int(input())
    for j in range(3):
        if s == a[j]:
            a[j] = 0
        if s == b[j]:        
            b[j] = 0
        if s == c[j]:        
            c[j] = 0

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

print("No")

Submission status: Accepted

Solution code:
A = []
a = [1]*9
for i in range(3):
    A += input().split()
n = int(input())
for i in range(n):
    b = input()
    if b in A:
        a[A.index(b)] = 0

for i in range(3):
    if a[3*i] + a[3*i+1] + a[3*i+2] == 0 or a[i] + a[i+3] + a[i+6] == 0:
        print('Yes')
        break
else:
    if a[0] + a[4] + a[8] == 0 or a[2] + a[4] + a[6] ==0:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

A = np.asarray([list(map(int, input().split())), list(map(int, input().split())), list(map(int, input().split()))])
n = int(input())
B = []
for _ in range(n):
    B.append(int(input()))

ans = np.zeros((3, 3))


def is_bingo(card) -> bool:
    if card[0, 0] == card[0, 1] == card[0, 2] == 1:
        return True
    if card[1, 0] == card[1, 1] == card[1, 2] == 1:
        return True
    if card[2, 0] == card[2, 1] == card[2, 2] == 1:
        return True
    if card[2, 0] == card[2, 1] == card[2, 2] == 1:
        return True
    if card[0, 0] == card[1, 0] == card[2, 0] == 1:
        return True
    if card[0, 1] == card[1, 1] == card[2, 1] == 1:
        return True
    if card[0, 2] == card[1, 2] == card[2, 2] == 1:
        return True
    if card[0, 0] == card[1, 1] == card[2, 2] == 1:
        return True
    if card[0, 2] == card[1, 1] == card[2, 0] == 1:
        return True
    return False


for b in B:
    if b in A:
        index = np.where(A == b)
        ans[index] = 1
    if is_bingo(ans):
        print('Yes')
        exit()
print('No')

Submission status: Accepted

Solution code:
a=[list(map(int,input().split())) for _ 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 b==a[j][k]:
        a[j][k]=0

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

Submission status: Accepted

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

val = 0
flag = False

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

val = 0
for i in range(3):
    val += A[i][i]
if val == 0:
    flag = True

val = A[0][2] + A[1][1] + A[2][0]
if val == 0:
    flag = True

for i in range(3):
    if sum(A[i]) == 0:
        flag = True
    
    val = 0
    for j in range(3):
        val += A[j][i]
    if val == 0:
        flag = True

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

Submission status: Accepted

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

for _ in range(N):
    b=int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                L[i][j]=1

if L[0][0]==L[0][1]==L[0][2]==1 or L[1][0]==L[1][1]==L[1][2]==1 or L[2][0]==L[2][1]==L[2][2]==1 or L[0][0]==L[1][0]==L[2][0]==1 or L[0][1]==L[1][1]==L[2][1]==1 or L[0][2]==L[1][2]==L[2][2]==1 or L[0][0]==L[1][1]==L[2][2]==1 or L[2][0]==L[1][1]==L[0][2]==1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))

n = int(input())

for _ in range(n):
    b = int(input())
    if b in A1:
        A1[A1.index(b)]=0
    if b in A2:
        A2[A2.index(b)]=0
    if b in A3:
        A3[A3.index(b)]=0
if sum(A1)==0 or sum(A2)==0 or sum(A3)==0 or A1[0]+A2[1]+A3[2]==0 or A1[2]+A2[1]+A3[0]==0 or A1[0]+A2[0]+A3[0]==0 or A1[1]+A2[1]+A3[1]==0 or A1[2]+A2[2]+A3[2]==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# B - Bingo
A = []
for _ in range(3):
    tmp = list(map(int,input().split()))
    A.extend(tmp)
B = [0]*9
N = int(input())
for _ in range(N):
    tmp = int(input())
    for i in range(9):
        if tmp==A[i]:
            B[i] = 1
ans = 'No'
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 B[i]+B[j]+B[k]==3:
        ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]


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

flag = False
if a[0][0] == 0 and a[0][1] == 0 and a[0][2] == 0:
    flag = True
if a[1][0] == 0 and a[1][1] == 0 and a[1][2] == 0:
    flag = True
if a[2][0] == 0 and a[2][1] == 0 and a[2][2] == 0:
    flag = True
if a[0][0] == 0 and a[1][0] == 0 and a[2][0] == 0:
    flag = True
if a[0][1] == 0 and a[1][1] == 0 and a[2][1] == 0:
    flag = True
if a[0][2] == 0 and a[1][2] == 0 and a[2][2] == 0:
    flag = True
if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
    flag = True
if a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0:
    flag = True

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

Submission status: Accepted

Solution code:
def f():
  lst=[]
  lst2=[]
  for _ in range(3):
      lst.append(input().split(" "))
  n=int(input())
  for i in range(n):
    lst2.append(input())
  for i in range(n):
    for j in range(3):
      for k in range(3):
        if lst[j][k]==lst2[i]:
          lst[j][k]="0"
  if lst[0][0]=="0" and lst[1][1]=="0" and lst[2][2]=="0":
    print("Yes")
    return()
  elif lst[0][2]=="0" and lst[1][1]=="0" and lst[2][0]=="0":
    print("Yes")
    return()
  else:
    for i in range(3):
      if lst[i][0]=="0" and lst[i][1]=="0" and lst[i][2]=="0":
        print("Yes")
        return()
      elif lst[0][i]=="0" and lst[1][i]=="0" and lst[2][i]=="0":
        print("Yes")
        return()
  print("No")
  return()

if __name__=="__main__":
  f()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A = [list(map(int, readline().split())) for _ in range(3)]
    N, *B = map(int, read().split())

    nums = [False] * 101
    for b in B:
        nums[b] = True

    for i in range(3):
        ok = True
        for j in range(3):
            if not nums[A[i][j]]:
                ok = False
                break

        if ok:
            print('Yes')
            return

    for j in range(3):
        ok = True
        for i in range(3):
            if not nums[A[i][j]]:
                ok = False
                break

        if ok:
            print('Yes')
            return

    if nums[A[0][0]] and nums[A[1][1]] and nums[A[2][2]]:
        print('Yes')
        return

    if nums[A[0][2]] and nums[A[1][1]] and nums[A[0][2]]:
        print('Yes')
        return

    print('No')

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

N = int(input())

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

C = [[0,0,0],[0,0,0],[0,0,0]]
Ans = "No"

for i in range(3):
    for j in range(3):
        if A[i][j] in B:         #AijはリストBに含まれるかどうか
            C[i][j] = 1

for i in range(3):
    if C[i][0]+C[i][1]+C[i][2] == 3:
        Ans ="Yes"

for i in range(3):
    if C[0][i]+C[1][i]+C[2][i] == 3:
        Ans ="Yes"
        
if C[0][0]+C[1][1]+C[2][2] == 3 or C[0][2]+C[1][1]+C[2][0] == 3:
    Ans = "Yes"
    
print(Ans)

Submission status: Accepted

Solution code:
A = [list(map(int,input().split())) for n in range(3)]
N = int(input())
B = [int(input()) for n in range(N)]
C = [[0,0,0],[0,0,0],[0,0,0]]
ans = "No"

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

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

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

for i in range(3):
  if C[0][0]+C[1][1]+C[2][2]==3 or C[0][2]+C[1][1]+C[2][0]==3:
    ans = "Yes"

print(ans)