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, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, i = map(int, input().split())
n = int(input())
for j in range(n):
    x = int(input())
    if a == x:
        a = 0
    elif b == x:
        b == 0
    elif c == x:
        c = 0
    elif d == x:
        d = 0
    elif e == x:
        e = 0
    elif f == x:
        f = 0
    elif g == x:
        g = 0
    elif h == x:
        h = 0
    elif i == x:
        i = 0
y =[[a, b, c], [d, e, f], [g, h, i], [a, d, g], [b, e, h], [c, f, i], [a, e, i], [c, e, g]]
print("Yes" if [0, 0, 0] in y else "No")

Submission status: Accepted

Solution code:
seen = [0,0,0,0,0,0,0,0,0]
seen[0],seen[1],seen[2] = (map(int,input().split()))
seen[3],seen[4],seen[5] = (map(int,input().split()))
seen[6],seen[7],seen[8] = (map(int,input().split()))
over = False
N = int(input())
for x in range(N):
  num = int(input())
  if num in seen:
    seen[seen.index(num)] = "O"
if seen[0] == "O":
  if seen[1] == seen[2] == "O":
    over = True
  elif seen[3] == seen[6] == "O":
    over = True
  elif seen[4] == seen[8] == "O":
    over = True
elif seen[4] == "O":
  if seen[2] == seen[6] == "O":
    over = True
  elif seen[1] == seen[7] == "O":
    over = True
  elif seen[3] == seen[5] == "O":
    over = True
elif seen[8] == "O":
  if seen[6] == seen[7] == "O":
    over = True
  if seen[2] == seen[5] == "O":
    over = True
if not over:
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
seen = [0,0,0,0,0,0,0,0,0]
seen[0],seen[1],seen[2] = (map(int,input().split()))
seen[3],seen[4],seen[5] = (map(int,input().split()))
seen[6],seen[7],seen[8] = (map(int,input().split()))
over = "No"
N = int(input())
for x in range(N):
  num = int(input())
  if num in seen:
    seen[seen.index(num)] = "O"
if seen[0] == "O":
  if seen[1] == "O" and seen[2] == "O":
    over = "Yes"
  if seen[3] == "O" and seen[6] == "O":
    over = "Yes"
  if seen[4] == "O" and seen[8] == "O":
    over = "Yes"
if seen[8] == "O":
  if seen[6] == "O" and seen[7] == "O":
    over = "Yes"
  if seen[2] == "O" and seen[5] == "O":
    over = "Yes"
if seen[4] == "O":
  if seen[6] == "O" and seen[2] == "O":
    over = "Yes"
  if seen[1] == "O" and seen[7] == "O":
    over = "Yes"
  if seen[3] == "O" and seen[5] == "O":
    over = "Yes"
print(over)

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)]
    for b in B:
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    A[i][j] = None
                    break
    for i in range(3):
        for j in range(3):
            if A[i][j] is not None:
                break
        else:
            print("Yes")
            return
    for i in range(3):
        for j in range(3):
            if A[j][i] is not None:
                break
        else:
            print("Yes")
            return
    if all(map(lambda x: x is None, [A[0][0], A[1][1], A[2][2]])) or all(map(lambda x: x is None, [A[0][2], A[1][1], A[2][0]])):
        print("Yes")
        return
    print("No")


if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
a = [0]*3
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(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 sum(a[i]) == 0:
    print("Yes")
    exit()
    
for i in range(3):
  if a[0][i] + a[1][i] + a[2][i] == 0:
    print("Yes")
    exit()
if a[0][0] + a[1][1] + a[2][2] == 0:
  print("Yes")
  exit()
if a[0][2] + a[1][1] + a[2][0] == 0:
  print("Yes")
  exit()
print("No")

Submission status: Accepted

Solution code:
arr = []
arr.append(list(map(int, input().split())))
arr.append(list(map(int, input().split())))
arr.append(list(map(int, input().split())))

def checker(arr):
    if arr[0][0] == arr[0][1] == arr[0][2] == "X":
        return True
    if arr[1][0] == arr[1][1] == arr[1][2] == "X":
        return True
    if arr[2][0] == arr[2][1] == arr[2][2] == "X":
        return True
    if arr[0][0] == arr[1][0] == arr[2][0] == "X":
        return True
    if arr[0][1] == arr[1][1] == arr[2][1] == "X":
        return True
    if arr[0][2] == arr[1][2] == arr[2][2] == "X":
        return True
    if arr[0][0] == arr[1][1] == arr[2][2] == "X":
        return True
    if arr[0][2] == arr[1][1] == arr[2][0] == "X":
        return True
    return False

for i in range(int(input())):
    a = int(input())
    for i in range(3):
        for j in range(3):
            if arr[i][j] == a:
                arr[i][j] = "X"
    
if checker(arr): print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
board, dp = [], []
bingo = False

for _ in range(3):
    board.append(list(map(int, input().split()))) 
    dp.append([0, 0, 0])

N = int(input())

for _ in range(N):
    num = int(input())

    for r in range(3):
        for c in range(3):
            if num == board[r][c]:
                dp[r][c] = 1

for i in range(3):
    if dp[i][0] == dp[i][1] == dp[i][2] == 1 or dp[0][i] == dp[1][i] == dp[2][i] == 1:
        bingo = True
        print("Yes")
        break

if not bingo:
    if dp[0][0] == dp[1][1] == dp[2][2] == 1 or dp[0][2] == dp[1][1] == dp[2][0] == 1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
board=[0,0,0,0,0,0,0,0,0]
board[0],board[1],board[2] = map(int,input().split())
board[3],board[4],board[5] = map(int,input().split())
board[6],board[7],board[8] = map(int,input().split())
for _ in range(int(input())):
    x = int(input())
    if x in board:
        board[board.index(x)] = "X"
found = "No"
if board[0] == "X":
    if board[1] == "X" and board[2] == "X":
        found = "Yes"
    elif board[4] == "X" and board[8] == "X":
        found = "Yes"
    elif board[3] == "X" and board[6] == "X":
        found = "Yes"
if board[8] == "X":
    if board[5] == "X" and board[2] == "X":
        found = "Yes"
    elif board[7] == "X" and board[6] == "X":
        found = "Yes"
if board[4] == "X":
    if board[1] == "X" and board[7] == "X":
        found = "Yes"
    elif board[3] == "X" and board[5] == "X":
        found = "Yes"
    elif board[2] == "X" and board[6] == "X":
        found = "Yes"
print(found)

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)]
G=[['*']*3,['*']*3,['*']*3]
for i in range(3):
  for j in range(3):
    if A[i][j] not in b:
      G[i][j]=A[i][j]

if G[0][0]==G[1][1]==G[2][2]=='*':
  print('Yes')
  exit()
elif G[0][2]==G[1][1]==G[2][0]=='*':
  print('Yes')
  exit()
else:
  for i in range(3):
    if G[i][0]==G[i][1]==G[i][2]=='*':
      print('Yes')
      exit()
    elif G[0][i]==G[1][i]==G[2][i]=='*':
      print('Yes')
      exit()

print('No')

Submission status: Accepted

Solution code:
bingo = []
sheet = set()
for _ in range(3):
  lst = [int(i) for i in input().split()]
  bingo.append(lst)
n = int(input())
for _ in range(n):
  a = int(input())
  for i in range(3):
    for j in range(3):
      if bingo[i][j] == a:
        num = 3 * i + j
        sheet.add(num)
if 0 in sheet and 1 in sheet and 2 in sheet:
  print('Yes')
elif 0 in sheet and 3 in sheet and 6 in sheet:
  print('Yes')
elif 0 in sheet and 4 in sheet and 8 in sheet:
  print('Yes')
elif 1 in sheet and 4 in sheet and 7 in sheet:
  print('Yes')
elif 2 in sheet and 5 in sheet and 8 in sheet:
  print('Yes')
elif 2 in sheet and 4 in sheet and 6 in sheet:
  print('Yes')
elif 3 in sheet and 4 in sheet and 5 in sheet:
  print('Yes')
elif 6 in sheet and 7 in sheet and 8 in sheet:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
def main():
    bingo = []
    for ss in range(3):
        s = list(map(int,input().strip().split()))
        bingo.append(s)
    
    n = int(input())
    nl = []
    for nn in range(n):
        nl.append(int(input()))
    
    for i in range(3):
        for j in range(3):
            for n in nl:
                if bingo[i][j] == n:
                    bingo[i][j] = -1
    
    for i in range(3):
        if bingo[0][i] == bingo[1][i] == bingo[2][i] == -1:
            print("Yes")
            return
        if bingo[i][0] == bingo[i][1] == bingo[i][2] == -1:
            print("Yes")
            return
    
    if bingo[0][0] == bingo[1][1] == bingo[2][2] == -1:
        print("Yes")
        return
    if bingo[0][2] == bingo[1][1] == bingo[2][0] == -1:
        print("Yes")
        return
    
    print("No")
    return

    
main()

Submission status: Accepted

Solution code:
import numpy as np

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

n = int(input())

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

c = np.zeros(9).reshape(3,3)

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

if (max(c.sum(axis=0))==3) or (max(c.sum(axis=1))==3) or \
    (sum([c[i,i] for i in range(3)])==3) or (c[2,0]+c[1,1]+c[0,2]==3):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc157/tasks/abc157_b

A_list = [[] for _ in range(3)]

for i in range(3):
    A1, A2, A3 = map(int, input().split())
    A_list[i] += [A1, A2, A3]

N = int(input())

set1 = {A_list[0][0], A_list[0][1], A_list[0][2]}
set2 = {A_list[1][0], A_list[1][1], A_list[1][2]}
set3 = {A_list[2][0], A_list[2][1], A_list[2][2]}
set4 = {A_list[0][0], A_list[1][0], A_list[2][0]}
set5 = {A_list[0][1], A_list[1][1], A_list[2][1]}
set6 = {A_list[0][2], A_list[1][2], A_list[2][2]}
set7 = {A_list[0][0], A_list[1][1], A_list[2][2]}
set8 = {A_list[0][2], A_list[1][1], A_list[2][0]}


b_set = set()

for n in range(N):
    b = int(input())
    b_set.add(b)

if (set1 <= b_set or 
    set2 <= b_set or
    set3 <= b_set or
    set4 <= b_set or
    set5 <= b_set or
    set6 <= b_set or
    set7 <= b_set or
    set8 <= b_set):

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

Submission status: Accepted

Solution code:
a=[list(map(int,input().split())) for _ in range(3)]
n=int(input())
b=set()
c=[[0,0,0] for _ in range(3)]
for i in range(n):
    b.add(int(input()))
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 sum(c[i])==3:
        print("Yes")
        exit()
    elif c[0][i]+c[1][i]+c[2][i]==3:
        print("Yes")
        exit()

if c[0][0]+c[1][1]+c[2][2]==3:
    print("Yes")
elif c[0][2]+c[1][1]+c[2][0]==3:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
n=int(input())
d=[]
for e in sys.stdin:
	e=int(e)
	if e in a:
		a[a.index(e)]=0
	if e in b:
		b[b.index(e)]=0
	if e in c:
		c[c.index(e)]=0
if sum(a)==0 or sum(b)==0 or sum(c)==0:
	print("Yes")
	exit()
for i in range(3):
	if a[i]==0 and b[i]==0 and c[i]==0:
		print("Yes")
		exit()
if (a[0]==0 and b[1]==0 and c[2]==0) or (a[2]==0 and b[1]==0 and c[0]==0):
	print("Yes")
	exit()
print("No")

Submission status: Accepted

Solution code:
import numpy as np
A = np.array([list(map(int,input().split())) for n in range(3)])
N = int(input())
B = [int(input()) for i in range(N)]

for b in B:
  A = np.where(A==b,0,A)

if np.any(np.all(A==0,axis=0)) or np.any(np.all(A==0,axis=1)):
  print("Yes")
  
elif 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:
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    bingo = [False]*9
    dic = dict()
    c = 0
    for _ in range(3):
        tmp = list(IL())
        for rep in tmp:
            dic[rep] = c
            c += 1
    n = I()
    for _ in range(n):
        b = I()
        idx = dic.get(b)
        if idx is None:
            continue
        bingo[idx] = True
    
    flag = False
    for i in range(0,3):
        for j in range(0,7,3):
            if not bingo[i+j]:
                break
        else:
            flag = True
    if flag:
        print('Yes')
        return
        
    for i in range(0,7,3):
        for j in range(0,3):
            if not bingo[i+j]:
                break
        else:
            flag = True
    if flag:
        print('Yes')
        return

    if (bingo[2] and bingo[4] and bingo[6]) or (bingo[0] and bingo[4] and bingo[8]):
        print('Yes')
    else:
        print('No')
    return

if __name__=='__main__':
    solve()

Submission status: Accepted

Solution code:
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
A3=list(map(int,input().split()))
N=int(input())
for i in range(N):
  b=int(input())
  if b in A1:
    t=A1.index(b)
    A1[t]=0
  elif b in A2:
    t=A2.index(b)
    A2[t]=0
  elif b in A3:
    t=A3.index(b)
    A3[t]=0
if sum(A1)==0 or sum(A2)==0 or sum(A3)==0:
  print("Yes")
else:
  for j in range(3):
    if A1[j]+A2[j]+A3[j]==0:
      print("Yes")
      break
  else:
    if A1[0]+A2[1]+A3[2]==0 or A1[2]+A2[1]+A3[0]==0:
      print("Yes")
    else:
      print("No")

Submission status: Accepted

Solution code:
def exe():
    print('Yes')
    exit()

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

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

for i in range(3):
    if sum(A[i]) == 0:
        exe()
    elif A[0][i]+A[1][i]+A[2][i]==0:
        exe()
if A[0][0]+A[1][1]+A[2][2] == 0:
    exe()
elif A[0][2]+A[1][1]+A[2][0] == 0:
    exe()

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

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

print('No')

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]
for b in B:
    for y in range(3):
        for x in range(3):
            if A[y][x] == b:
                A[y][x] = -1
for y in range(3):
    if sum(A[y]) == -3:
        print("Yes")
        exit()
for x in range(3):
    if A[0][x] == A[1][x] == A[2][x] == -1:
        print("Yes")
        exit()
if A[0][0] == A[1][1] == A[2][2] == -1 or A[2][0] == A[1][1] == A[0][2] == -1:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
a = []
for i in range(3):
  t = [int(x) for x in input().split()]
  a.append(t)
n = int(input())
b = [int(input()) for i in range(n)]
m = [[0 for j in range(3)] for i in range(3)]
for i in range(3):
  for j in range(3):
    for k in b:
      if (a[i][j] == k):
        m[i][j] = 1
for i in range(3):
  if (m[i][0] and m[i][1] and m[i][2]):
    print("Yes")
    exit()
for i in range(3):
  if (m[0][i] and m[1][i] and m[2][i]):
    print("Yes")
    exit()
if ((m[0][0] and m[1][1] and m[2][2]) or (m[0][2] and m[1][1] and m[2][0])):
  print("Yes")
  exit()
print("No")

Submission status: Accepted

Solution code:
A=[]
B=[]
for i in range(3):
    A.append(list(map(int,input().split())))
N=int(input())
for i in range(N):
    B.append(int(input()))
for i in range(3):
    for j in range(3):
        for k in range(N):
            if A[i][j]==B[k]:
                A[i][j]=-1
C=[]
for i in range(3):
    if A[0][0]==A[1][1] and A[1][1]==A[2][2] and A[2][2]==-1:
        C.append('Yes')
    elif A[0][2]==A[1][1] and A[1][1]==A[2][0] and A[2][0]==-1:
        C.append('Yes')
    elif A[i][0]==A[i][1] and A[i][1]==A[i][2]:
        C.append('Yes')
    elif A[0][i]==A[1][i] and A[1][i]==A[2][i]:
        C.append('Yes')
    else:
        C.append('No')
if 'Yes' in C:
    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 k in range(N)]
hole = [[0,0,0] for i in range(3)]
ans = "No"

for i in range(3):
  for j in range(3):
    for k in range(N):
      if A[i][j] == b[k]:
        hole[i][j] = 1
  flag_hol = 1
  for j in range(3):
    flag_hol *= hole[i][j]
  if flag_hol == 1:
  	ans = "Yes"

flag_diag1 = 1
flag_diag2 = 1
for j in range(3):
  flag_vert = 1
  for i in range(3):
    flag_vert *= hole[i][j]
  if flag_vert ==1:
    ans = "Yes"
  flag_diag1 *= hole[j][j]
  flag_diag2 *= hole[j][2-j]
if (flag_diag1 == 1) or (flag_diag2 == 1):
  ans = "Yes"
  
print(ans)

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):
  num=int(input())
  if num in a1:
  	a1[a1.index(num)]='O'
  if num in a2:
  	a2[a2.index(num)]='O'
  if num in a3:
  	a3[a3.index(num)]='O'
if a1[0] == 'O' and a1[1] == 'O' and a1[2] == 'O':
  print('Yes')
elif a2[0] == 'O' and a2[1] == 'O' and a2[2] == 'O':
  print('Yes')
elif a3[0] == 'O' and a3[1] == 'O' and a3[2] == 'O':
  print('Yes')
elif a1[0] == 'O' and a2[0] == 'O' and a3[0] == 'O':
  print('Yes')
elif a1[1] == 'O' and a2[1] == 'O' and a3[1] == 'O':
  print('Yes')
elif a1[2] == 'O' and a2[2] == 'O' and a3[2] == 'O':
  print('Yes')
elif a1[0] == 'O' and a2[1] == 'O' and a3[2] == 'O':
  print('Yes')
elif a1[2] == 'O' and a2[1] == 'O' and a3[0] == 'O':
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
import itertools
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a = list(itertools.chain.from_iterable([a1, a2, a3]))

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

for i in b:
    a = [x if x != i else 0 for x in a]

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

Submission status: Accepted

Solution code:
A11, A12, A13 = map(int, input().split())
A21, A22, A23 = map(int, input().split())
A31, A32, A33 = map(int, input().split())
N = int(input())
B = {int(input()) for _ in range(N)}

h1 = {A11, A12, A13}
h2 = {A21, A22, A23}
h3 = {A31, A32, A33}
v1 = {A11, A21, A31}
v2 = {A12, A22, A32}
v3 = {A13, A23, A33}
c1 = {A11, A22, A33}
c2 = {A13, A22, A31}

if len(h1 & B)==3 or len(h2 & B)==3 or len(h3 & B)==3 or len(v1 & B)==3 or len(v2 & B)==3 or len(v3 & B)==3 or len(c1 & B)==3 or len(c2 & B)==3:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# Bingo
A = []
for _ in range(3):
    A += list(map(int, input().split()))
N = int(input())
for _ in range(N):
    b = int(input())
    if b in A:
        A[A.index(b)] = -1
        
# check
diag = (sum(A[0::4]) == -3) | (sum(A[2:8:2]) == -3)
rows = (sum(A[:3]) == -3) | (sum(A[3:6]) == -3) | (sum(A[6:]) == -3)
cols = (sum(A[:7:3]) == -3) | (sum(A[1:8:3]) == -3) | (sum(A[2::3]) == -3)
ans = diag | rows | cols
print(['No', 'Yes'][ans])

Submission status: Accepted

Solution code:
Aij = []
c = 0
for i in range(3):
    Aij += list(map(int, input().split()))
    
N = int(input())
for i in range(N):
    b = int(input())
    if b in Aij:
        Aij[Aij.index(b)] = 0

for i in range(3):
    if Aij[3*i] == Aij[3*i+1] and Aij[3*i] == Aij[3*i+2]:
        c = -1
        break

    if Aij[i] == Aij[i+3] and Aij[i] == Aij[i+6]:
        c = -1
        break

if c == Aij[4]:
    if Aij[0] == Aij[4] and Aij[4] == Aij[8]:
        c = -1
    elif Aij[2] == Aij[4] and Aij[4] == Aij[6]:
        c = -1
    else:
        pass

print(['No', 'Yes'][c])

Submission status: Accepted

Solution code:
Aij = []
c = 0
for i in range(3):
    A = list(map(int, input().split()))
    Aij.append(A[0])
    Aij.append(A[1])
    Aij.append(A[2])

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

for i in range(3):
    if Aij[3*i] == Aij[3*i+1] and Aij[3*i] == Aij[3*i+2]:
        c = -1
        break

    if Aij[i] == Aij[i+3] and Aij[i] == Aij[i+6]:
        c = -1
        break

if c == Aij[4]:
    if Aij[0] == Aij[4] and Aij[4] == Aij[8]:
        c = -1
    elif Aij[2] == Aij[4] and Aij[4] == Aij[6]:
        c = -1
    else:
        pass

print(['No', 'Yes'][c])

Submission status: Accepted

Solution code:
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())
s=set()
for _ in range(N):
  b=int(input())
  if b in A:
    s|={A.index(b)}
bingo=[{0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,5,8},{2,4,6},{3,4,5},{6,7,8}]
print(['No','Yes'][any(s>=b for b in bingo)])

Submission status: Accepted

Solution code:
x = list(map(int,input().split()))
y = list(map(int,input().split()))
z = list(map(int,input().split()))
n = int(input())
for i in range(n):
    b = int(input())
    if b in x:
        x[x.index(b)] = 'T'
    if b in y:
        y[y.index(b)] = 'T'
    if b in z:
        z[z.index(b)] = 'T'
if x[0] == 'T' and x[1] == 'T' and x[2] == 'T':
    print('Yes')
elif y[0] == 'T' and y[1] == 'T' and y[2] == 'T':
    print('Yes')
elif z[0] == 'T' and z[1] == 'T' and z[2] == 'T':
    print('Yes')
elif x[0] == 'T' and y[0] == 'T' and z[0] == 'T':
    print('Yes')
elif x[1] == 'T' and y[1] == 'T' and z[1] == 'T':
    print('Yes')
elif x[2] == 'T' and y[2] == 'T' and z[2] == 'T':
    print('Yes')
elif x[0] == 'T' and y[1] == 'T' and z[2] == 'T':
    print('Yes')
elif x[2] == 'T' and y[1] == 'T' and z[0] == 'T':
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    A = []
    for i in range(3):
        row = list(map(int, input().split()))
        A.append(row)
    
    N = int(input())
    B = []

    for i in range(N):
        B.append(int(input())) 
    
    for i in range(3):
        cnt = 0
        for j in range(3):
            if A[i][j] in B:
                cnt += 1
        if cnt==3:
            print('Yes')
            quit()
            
    for i in range(3):
        cnt = 0
        for j in range(3):
            if A[j][i] in B:
                cnt += 1
        if cnt==3:
            print('Yes')
            quit()

    if A[0][0] in B and A[1][1] in B and A[2][2] in B:
        print('Yes')
        quit()
    
    if A[0][2] in B and A[1][1] in B and A[2][0] in B:
        print('Yes')
        quit()
    
    print('No')

Submission status: Accepted

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

N = int(input())

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

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

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

if (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:
def check(A):
    """ check bingo or not
    :param A: 3*3 matrix, 1 or 0
    :return: is_bingo bool
    """
    for row_id in range(3):
        if sum(A[row_id])==3:
            return True
    
    for column_id in range(3):
        column_sum = 0
        for row_id in range(3):
            column_sum += A[row_id][column_id]
        if column_sum == 3:
            return True

    lr_sum = 0
    rl_sum = 0
    for rc_id in range(3):
        lr_sum += A[rc_id][rc_id]
        rl_sum += A[rc_id][2-rc_id]
    if lr_sum == 3 or rl_sum == 3:
        return True
        
    return False


def search(query, A):
    for row_id in range(3):
        for column_id in range(3):
            if query == A[row_id][column_id]:
                return column_id, row_id 
    return None, None


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

    N = int(input())

    for _ in range(N):
        query = int(input())
        i, j = search(query, A)
        if i != None and j != None:
            B[i][j] = 1

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

Submission status: Accepted

Solution code:
def check(a):
    m = [-1, -1, -1]
    if [a[0][0], a[1][1],a[2][2]] == m:
        print("Yes")
        return
    if [a[0][2], a[1][1], a[2][0]] == m:
        print("Yes")
        return
    for i in range(3):
        if a[i] == m:
            print("Yes")
            return
        elif [r[i] for r in a] == m:
            print("Yes")
            return
    print("No")
    return

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 y,row in enumerate(a):
        try:
            x=row.index(b[i])
            a[y][x]=-1
        except ValueError:
            pass
check(a)

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
a = [[False] * 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:
                a[i][j] = True
ans = False
for i in range(3):
    if a[i][0] and a[i][1] and a[i][2] or a[0][i] and a[1][i] and a[2][i]:
        print('Yes')
        exit()
if a[0][0] and a[1][1] and a[2][2] or a[2][0] and a[1][1] and a[0][2]:
        print('Yes')
        exit()
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()))
A=A1+A2+A3
N=int(input())
s=set()
for _ in range(N):
  b=int(input())
  if b in A:
    s|={A.index(b)}
bingo=[{0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}]
print(["No","Yes"][any(s>=b for b in bingo)])

Submission status: Accepted

Solution code:
import sys
import itertools

def resolve(in_):
    A = tuple(map(int, itertools.chain.from_iterable(line.split() for line in itertools.islice(in_, 3))))
    assert len(A) == 9
    C = [False] * 9
    N = int(next(in_))
    # B = tuple(map(int, itertools.islice(in_, N)))
    B = frozenset(map(int, itertools.islice(in_, N)))

    for i, a in enumerate(A):
        if a in B:
            C[i] = True
    # print(f'{A=} {C=}')

    b = any(all(line) for line in itertools.chain(
        ((C[i * 3], C[i * 3 + 1], C[i * 3 + 2]) for i in range(3)),
        ((C[i], C[i + 3], C[i + 6]) for i in range(3)),
        ((C[0], C[4], C[8]), (C[2], C[4], C[6])),
    ))
    return 'Yes' if b else 'No'


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Aug  9 20:50:35 2020

@author: akros
"""

# -*- coding: utf-8 -*-
"""
Created on Sun Aug  9 16:51:42 2020

@author: akros
"""

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

N = int(input())
a = []

for i in range(N):
    a.append(int(input()))
   
    if A1[0] == a[i]:
        A1[0] = True
    elif a[i] == A1[1]:
        A1[1] = True
    elif a[i] == A1[2]:
        A1[2] = True
    elif a[i] == A2[0]:
        A2[0] = True
    elif a[i] == A2[1]:
        A2[1] = True
    elif a[i] == A2[2]:
        A2[2] = True
    elif a[i] == A3[0]:
        A3[0] = True
    elif a[i] == A3[1]:
        A3[1] = True
    elif a[i] == A3[2]:
        A3[2] = True


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

Submission status: Accepted

Solution code:
A = [[j for j in list(map(int, input().split()))] for i in range(3)]
N = int(input())
B = []
for _ in range(N):
	b = int(input())
	for r in A:
		for i in range(len(r)):
			if r[i] == b:
				r[i] = 0
ans = False
for i in range(3):
	if sum(A[i]) == 0:
		ans = True
if not ans:
	for i in range(3):
		if A[0][i] + A[1][i] + A[2][i] == 0:
			ans = True
if not ans:
	if A[0][0] + A[1][1] + A[2][2] == 0:
		ans = True
	elif A[0][2] + A[1][1] + A[2][0] == 0:
		ans = True
if ans:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
def bingo(appear):
	for j in range(3):
		if appear[0][j] and appear[1][j] and appear[2][j]:
			return "Yes"
	for i in range(3):
		if appear[i][0] and appear[i][1] and appear[i][2]:
			return "Yes"
	if appear[0][0] and appear[1][1] and appear[2][2]:
		return "Yes"
	if appear[0][2] and appear[1][1] and appear[2][0]:
		return "Yes"
	return "No"


card = []
for _ in range(3):
	arr = list(map(int, input().split()))
	card.append(arr)
appear = [[False for _ in range(3)] for _ in range(3)]
n = int(input())
for _ in range(n):
	a = int(input())
	for i in range(3):
		for j in range(3):
			if a == card[i][j]:
				appear[i][j] = True

print(bingo(appear))