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:
from sys import stdin
import numpy as np

lines = stdin.readlines()

a1 = [int(x) for x in lines[0].rstrip().split()]
a2 = [int(x) for x in lines[1].rstrip().split()]
a3 = [int(x) for x in lines[2].rstrip().split()]

counter = 0
n = int(lines[3].rstrip())
for i in range(n):
    if a1[0] == int(lines[4+i].rstrip()):
        for j in range(n):
            if a1[1] == int(lines[4+j].rstrip()):
                for k in range(n):
                    if a1[2] == int(lines[4+k].rstrip()):
                        counter += 1
                        break
                else:
                    continue
                break
        else:
            continue
        break

for i in range(n):
    if a2[0] == int(lines[4+i].rstrip()):
        for j in range(n):
            if a2[1] == int(lines[4+j].rstrip()):
                for k in range(n):
                    if a2[2] == int(lines[4+k].rstrip()):
                        counter += 1
                        break
                else:
                    continue
                break
        else:
            continue
        break

for i in range(n):
    if a3[0] == int(lines[4+i].rstrip()):
        for j in range(n):
            if a3[1] == int(lines[4+j].rstrip()):
                for k in range(n):
                    if a3[2] == int(lines[4+k].rstrip()):
                        counter += 1
                        break
                else:
                    continue
                break
        else:
            continue
        break

for i in range(n):
    if a1[0] == int(lines[4+i].rstrip()):
        for j in range(n):
            if a2[0] == int(lines[4+j].rstrip()):
                for k in range(n):
                    if a3[0] == int(lines[4+k].rstrip()):
                        counter += 1
                        break
                else:
                    continue
                break
        else:
            continue
        break

for i in range(n):
    if a1[1] == int(lines[4+i].rstrip()):
        for j in range(n):
            if a2[1] == int(lines[4+j].rstrip()):
                for k in range(n):
                    if a3[1] == int(lines[4+k].rstrip()):
                        counter += 1
                        break
                else:
                    continue
                break
        else:
            continue
        break

for i in range(n):
    if a1[2] == int(lines[4+i].rstrip()):
        for j in range(n):
            if a2[2] == int(lines[4+j].rstrip()):
                for k in range(n):
                    if a3[2] == int(lines[4+k].rstrip()):
                        counter += 1
                        break
                else:
                    continue
                break
        else:
            continue
        break

for i in range(n):
    if a1[0] == int(lines[4+i].rstrip()):
        for j in range(n):
            if a2[1] == int(lines[4+j].rstrip()):
                for k in range(n):
                    if a3[2] == int(lines[4+k].rstrip()):
                        counter += 1
                        break
                else:
                    continue
                break
        else:
            continue
        break

for i in range(n):
    if a1[2] == int(lines[4+i].rstrip()):
        for j in range(n):
            if a2[1] == int(lines[4+j].rstrip()):
                for k in range(n):
                    if a3[0] == int(lines[4+k].rstrip()):
                        counter += 1
                        break
                else:
                    continue
                break
        else:
            continue
        break

if counter > 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

A1 = LIST()
A2 = LIST()
A3 = LIST()
N = INT()
B = np.ones(N)
for i in range(N):
  B[i] = INT()
  
B = list(B)

def bingo_array(A, B):
  for i in range(3):
    for x in B:
      if A[i] == x:
        A[i] *= 0
       
bingo_array(A1, B)
bingo_array(A2, B)
bingo_array(A3, B)

if sum(A1) == 0 or sum(A2) == 0 or sum(A3) == 0:
  print("Yes")
elif 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")
elif 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:
A = list(map(int,input().split()))
A += list(map(int,input().split()))
A += list(map(int,input().split()))
Z = [False]*9

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

for i in range(N):
  for j in range(9):
    if A[j] == B[i]:
      Z[j] = True
      
if (Z[0] and Z[1] and Z[2]) or (Z[3] and Z[4] and Z[5]) or (Z[6] and Z[7] and Z[8]) or (Z[0] and Z[3] and Z[6]) or (Z[1] and Z[4] and Z[7]) or (Z[2] and Z[5] and Z[8]) or (Z[0] and Z[4] and Z[8]) or (Z[2] and Z[4] and Z[6]):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
li=[]
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 num in range(n):
  j=int(input())
  li.append(j)
bingo=0
yoko1=(a in li) and (b in li) and (c in li)
yoko2=(d in li) and (e in li) and (f in li)
yoko3=(g in li) and (h in li) and (i in li)
yoko=yoko1 or yoko2 or yoko3
tate1=(a in li) and (d in li) and (g in li)
tate2=(b in li) and (e in li) and (h in li)
tate3=(c in li) and (f in li) and (i in li)
tate=tate1 or tate2 or tate3
nana1=(a in li) and (e in li) and (i in li)
nana2=(c in li) and (e in li) and (g in li)
nana=nana1 or nana2
if yoko or tate or nana:
    bingo=1
print("Yes" if bingo==1 else "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()))
a = [a_1, a_2, a_3]
n = int(input())
for i in range(n):
    number = int(input())
    for j in range(3):
        if a_1[j] == number:
            a_1[j] = 0
            break
        elif a_2[j] == number:
            a_2[j] = 0
            break
        elif a_3[j] == number:
            a_3[j] = 0
            break
if (a[0][0]+a[1][1]+a[2][2])*(a[0][2]+a[1][1]+a[2][0])*(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[0][1]+a[0][2])*(a[1][0]+a[1][1]+a[1][2])*(a[2][0]+a[2][1]+a[2][2]) == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#B

A = []

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

import copy

B = copy.deepcopy(A)

for i in range(3):
  B += [[A[0][i], A[1][i], A[2][i]]]
B += [[A[0][0], A[1][1], A[2][2]]]
B += [[A[0][2], A[1][1], A[2][0]]]

B = [set(b) for b in B]

N = int(input())

bs = []

for _ in range(N):
  bs += [int(input())]

bs = set(bs)

flag = "No"

for b in B:
  if b.issubset(bs):
    flag = "Yes"

print(flag)

Submission status: Accepted

Solution code:
a=[list(map(int,input().split())) for i in range(3)]
n=int(input())
b=[int(input()) for j in range(n)]
for j in range(n):
  for i in range(3):
    for k in range(3):
      if b[j] == a[i][k]:
        a[i][k]=0
x="yet"
sum=0
for i in range(3):
  sum+=a[i][i]
if sum==0:
  print("Yes")
  x="done"  

if x=="yet":
  sum=0
  for i in range(3):
    sum+=a[2-i][i]
  if sum==0:
    print("Yes")
    x="done"
    
if x=="yet":
  for i in range(3): 
    sum=0
    for k in range(3):  
      sum+=a[i][k]
    if sum==0:
      print("Yes")
      x="done"
      break

if x=="yet":
  for k in range(3): 
    sum=0
    for i in range(3):  
      sum+=a[i][k]
    if sum==0:
      print("Yes")
      x="done"
      break
if x=="yet":
      print("No")

Submission status: Accepted

Solution code:
def bingo(line):
    for num in line:
        if not num in b:
            return False
    return True

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

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

lines = []
lines.append([A[0][0], A[0][1], A[0][2]])
lines.append([A[1][0], A[1][1], A[1][2]])
lines.append([A[2][0], A[2][1], A[2][2]])

lines.append([A[0][0], A[1][0], A[2][0]])
lines.append([A[0][1], A[1][1], A[2][1]])
lines.append([A[0][2], A[1][2], A[2][2]])

lines.append([A[0][0], A[1][1], A[2][2]])
lines.append([A[0][2], A[1][1], A[2][0]])

for line in lines:
    for num in line:
        if bingo(line):
            print('Yes')
            exit(0)

print('No')
exit(0)

Submission status: Accepted

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

yoko = [[(i,j) for j in range(3)] for i in range(3)]
tate = [[(i,j) for i in range(3)] for j in range(3)]
naname = [[(i,i) for i in range(3)], [(i,2 - i) for i in range(3)]]

atari = set()
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            atari.add((i, j))

if len(atari) < 3:
    print('No')
else:        
    for i in yoko:
        if i[0] in atari and i[1] in atari and i[2] in atari:
            print('Yes')
            exit()

    for i in tate:
        if i[0] in atari and i[1] in atari and i[2] in atari:
            print('Yes')
            exit()

    for i in naname:
        if i[0] in atari and i[1] in atari and i[2] in atari:
            print('Yes')
            exit()
    
    print('No')

Submission status: Accepted

Solution code:
import sys
a1=[int(i) for i in input().split()]
a2=[int(i) for i in input().split()]
a3=[int(i) for i in input().split()]
for l in sys.stdin:
  if int(l) in a1:
    a1[a1.index(int(l))]=0
  elif int(l) in a2:
    a2[a2.index(int(l))]=0
  elif int(l) in a3:
    a3[a3.index(int(l))]=0
m=sum(a1)*sum(a2)*sum(a3)
for i in range(3):
  m*=a1[i]+a2[i]+a3[i]
  m*=a1[i]+a2[1]+a3[2-i]
print('Yes' if m==0 else 'No')

Submission status: Accepted

Solution code:
import sys
a = [list(map(int,input().split())) for _ in range(3)]
check = [[0]*3 for _ in range(3)]
n = int(input())
for i in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                check[i][j] = 1
#たて
for j in range(3):
    ch = 0
    for i in range(3):
        if check[i][j] == 1:
            ch += 1
    else:
        if ch == 3:
            print('Yes')
            sys.exit()
#よこ
for i in range(3):
    ch = 0
    for j in range(3):
        if check[i][j] == 1:
            ch += 1
    else:
        if ch == 3:
            print('Yes')
            sys.exit()
#斜め
if check[0][0] + check[1][1] + check[2][2] == 3:
    print('Yes')
    sys.exit()
if check[0][2] + check[1][1] + check[2][0] == 3:
    print('Yes')
    sys.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()))
n=int(input())
b=[0]*n
for i in range(n):
    b[i]=int(input())
for i in range(n):
    for j in range(3):
        if a1[j]==b[i]:
            a1[j]=-1
        if a2[j]==b[i]:
            a2[j]=-1
        if a3[j]==b[i]:
            a3[j]=-1
if sum(a1)==-3 \
    or sum(a2)==-3 \
    or sum(a3)==-3 \
    or (a1[0],a2[0],a3[0])==(-1,-1,-1) \
    or (a1[1],a2[1],a3[1])==(-1,-1,-1) \
    or (a1[2],a2[2],a3[2])==(-1,-1,-1) \
    or (a1[0], a2[1], a3[2]) == (-1, -1, -1) \
    or (a1[2], a2[1], a3[0]) == (-1, -1, -1) :
    print("Yes")

else:
    print("No")
    #print(a1)
    #print(a2)
    #print(a3)

Submission status: Accepted

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

while n > 0:
    b = int(input())
    for i in range(3):
        for j in range(3):
            if b == a[i][j]:
                a[i][j] = "Yes"
    n -= 1
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[0][2] == a[1][1] == a[2][0]:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

while n > 0:
    b = int(input())
    for i in range(3):
        if b == a[0][i]:
            a[0][i] = "Yes"
    for j in range(3):
        if b == a[1][j]:
            a[1][j] = "Yes"
    for k in range(3):
        if b == a[2][k]:
            a[2][k] = "Yes"
    n -= 1
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[0][2] == a[1][1] == a[2][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())
b = []
for i in range(n):
    x = int(input())
    b.append(x)


for i in b:
    if i in a1:
        a1[a1.index(i)] = 'X'
    if i in a2:
        a2[a2.index(i)] = 'X'
    if i in a3:
        a3[a3.index(i)] = 'X'

if len(set(a1)) == 1 and a1[0] == 'X' or len(set(a2)) == 1 and a2[0] == 'X' or len(set(a3)) == 1 and a3[0] == 'X':
    print('Yes')
elif a1[0] == 'X' and a1[0] == a2[0] == a3[0] or a1[1] == 'X' and a1[1] == a2[1] == a3[1] or a1[2] == 'X' and a1[2] == a2[2] == a3[2]:
    print('Yes')
elif a1[0] == 'X' and a1[0] == a2[1] == a3[2] or a1[2] == 'X' and a1[2] == a2[1] == a3[0]:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
A = list()
for _ in range(3):
  for i in map(int, input().split()):
    A.append(i)
N = int(input())
B = list()
for i in range(N):
  B.append(int(input()))
c = [0 for i in range(9)]
for i in range(N):
  for j in range(9):
    if B[i] == A[j]:
      c[j] += 1
#print(c)
if (c[0]*c[1]*c[2] != 0) or (c[3]*c[4]*c[5] != 0) or (c[6]*c[7]*c[8] != 0) or (c[0]*c[3]*c[6] != 0) or (c[1]*c[4]*c[7] != 0) or (c[2]*c[5]*c[8] != 0) or (c[0]*c[4]*c[8] != 0) or (c[2]*c[4]*c[6] != 0):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
P = [list(map(int,input().split())) for i in range(3)]
Q=[P[i][j] for i in range(3) for j in range(3)]
N=int(input())
B=[int(input()) for i in range(N)]
TF_list=[(Q[i] in B) for i in range(9)]
if TF_list[0]+TF_list[1]+TF_list[2] ==3 or \
TF_list[3]+TF_list[4]+TF_list[5] ==3 or \
TF_list[6]+TF_list[7]+TF_list[8] ==3 or \
TF_list[0]+TF_list[3]+TF_list[6] ==3 or \
TF_list[1]+TF_list[4]+TF_list[7] ==3 or \
TF_list[2]+TF_list[5]+TF_list[8] ==3 or \
TF_list[0]+TF_list[4]+TF_list[8] ==3 or \
TF_list[2]+TF_list[4]+TF_list[6] ==3:
  print ('Yes')
else:
  print('No')

Submission status: Accepted

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

  n = int(input())

  data_map = []
  for _ in range(3):
    data_map.append([0, 0, 0])

  for _ in range(n):
    x = int(input())
    if x == data[0][0]:
      data_map[0][0] = 1
    if x == data[0][1]:
      data_map[0][1] = 1
    if x == data[0][2]:
      data_map[0][2] = 1
    if x == data[1][0]:
      data_map[1][0] = 1
    if x == data[1][1]:
      data_map[1][1] = 1
    if x == data[1][2]:
      data_map[1][2] = 1
    if x == data[2][0]:
      data_map[2][0] = 1
    if x == data[2][1]:
      data_map[2][1] = 1
    if x == data[2][2]:
      data_map[2][2] = 1

  # for i in range(3):
  #   print(*data_map[i])

  # 横
  if sum(data_map[0]) == 3 or sum(data_map[1]) == 3 or sum(data_map[2]) == 3:
    print("Yes")
    return
  
  # ななめ(左->右)
  if data_map[0][0] + data_map[1][1] + data_map[2][2] == 3:
    print("Yes")
    return
  # ななめ(右->左)
  if data_map[0][2] + data_map[1][1] + data_map[2][0] == 3:
    print("Yes")
    return

  # 縦
  if data_map[0][0] + data_map[1][0] + data_map[2][0] == 3:
    print("Yes")
    return
  if data_map[0][1] + data_map[1][1] + data_map[2][1] == 3:
    print("Yes")
    return
  if data_map[0][2] + data_map[1][2] + data_map[2][2] == 3:
    print("Yes")
    return

  print("No")

if __name__ == "__main__":
  main()

Submission status: Accepted

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

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

if A[0]==A[1]==A[2]==0 or A[3]==A[4]==A[5]==0 or A[6]==A[7]==A[8]==0 or A[0]==A[3]==A[6]==0 or A[1]==A[4]==A[7]==0 or A[2]==A[5]==A[8]==0 or  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)]
for i in range(3):
  for j in range(3):
    for k in range(n):
      if b[k]==a[i][j]:
        a[i][j]=0
if (a[0][0]==0 and a[1][0]==0 and a[2][0]==0) or (a[0][1]==0 and a[1][1]==0 and a[2][1]==0) or (a[0][2]==0 and a[1][2]==0 and a[2][2]==0) or a[0]==[0,0,0] or a[1]==[0,0,0] or a[2]==[0,0,0] or (a[0][0]==0 and a[1][1]==0 and a[2][2]==0) or (a[0][2]==0 and a[1][1]==0 and a[2][0]==0):
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

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

# calc
f = [[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:
            f[i][j] = 1 

for i in range(3):
    s = 0 
    u = 0 
    for j in range(3):
        s += f[i][j]
        u += f[j][i]
    if s == 3 or u == 3:
        print('Yes')
        sys.exit()

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

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

for i in range(3):
    if 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')
    exit()

if A[0][2] == 0 and A[1][1] == 0 and A[2][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())
    if b in A1:
        A1[A1.index(b)] = 0
    elif b in A2:
        A2[A2.index(b)] = 0
    elif b in A3:
        A3[A3.index(b)] = 0

if all([x == 0 for x in A1]):
    print('Yes')
    exit()
if all([y == 0 for y in A2]):
    print('Yes')
    exit()
if all([z == 0 for z in A3]):
    print('Yes')
    exit()

for t in range(3):
    if A1[t] == A2[t] == A3[t]:
        print('Yes')
        exit()

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

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

print('No')

Submission status: Accepted

Solution code:
bingo = []
b = []

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

n = int(input())

while True:
  try:
    b.append(int(input()))
  except EOFError:
    break

lis1 = [bingo[0][0],bingo[0][1],bingo[0][2]]
lis2 = [bingo[1][0],bingo[1][1],bingo[1][2]]
lis3 = [bingo[2][0],bingo[2][1],bingo[2][2]]

lis4 = [bingo[0][0],bingo[1][0],bingo[2][0]]
lis5 = [bingo[0][1],bingo[1][1],bingo[2][1]]
lis6 = [bingo[0][2],bingo[1][2],bingo[2][2]]

lis7 = [bingo[0][0],bingo[1][1],bingo[2][2]]
lis8 = [bingo[0][2],bingo[1][1],bingo[2][0]]

allList = [lis1,lis2,lis3,lis4,lis5,lis6,lis7,lis8]

for i in allList:
  cnt = 0
  for _ in range(3):
    if i[_] in b:
      cnt +=1
  if cnt ==3:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

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

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

c=0
for i in range(3):
    if a[0][i]==a[1][i] and a[0][i]==a[2][i]:
        c += 1
if a[0]==[0,0,0] or a[1]==[0,0,0] or a[2]==[0,0,0]:
    print("Yes")
elif c!= 0:
    print("Yes")
elif (a[0][0]==0 and a[1][1]==0 and a[2][2]==0) or (a[0][2]==0 and a[1][1]==0 and a[2][0]==0):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

for i in range(N):
    b=int(input())
    
    for x in range(3):
        for y in range(3):
            if A[x][y]==b:
                S[x][y]=1

flag=False
for i in range(3):
    if S[i]==[1,1,1]:
        flag=True

for i in range(3):
    s=[]
    for k in range(3):
        s.append(S[k][i])
    if s==[1,1,1]:
        flag=True

s=[]
for i in range(3):
    s.append(S[i][i])

if s==[1,1,1]:
    flag=True
        
s=[]
for i in range(3):
    s.append(S[i][2-i])

if s==[1,1,1]:
    flag=True

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

Submission status: Accepted

Solution code:
a_list = [input().split(" "),input().split(" "),input().split(" ")]
N = int(input())
for i in range(N):
    b = input()
    for j in range(3):
        for k in range(3):
            if a_list[j][k] == b:
                a_list[j][k] = ""
bingo = False
if a_list[0][0] =="" and  a_list[1][1] =="" and  a_list[2][2] == "":
    bingo = True
if a_list[0][2] =="" and  a_list[1][1] =="" and  a_list[2][0] == "":
    bingo = True
for i in range(3):
    if a_list[i][0] == "" and a_list[i][1] == "" and a_list[i][2] == "":
        bingo = True
    elif a_list[0][i] == "" and a_list[1][i] == "" and a_list[2][i] == "":
        bingo = True
if bingo:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np
a_list=[]
for i in range(3):
  tmp=list(map(int,input().split()))
  a_list.append(tmp)
a_list=np.array(a_list)
num=int(input())
for i in range(num):
  tmp=int(input())
  a_list[a_list==tmp]=-1
  
yes_no=False
for i in range(3):
  if sum(a_list[i])==-3:
    yes_no=True
    break
  tmp=0
  for j in range(3):
    tmp+=a_list[j][i]
  if tmp==-3:
    yes_no=True
    break
else:
  yes_no=False
tmp=0
tmp2=0
for i in range(3):
  tmp+=a_list[i][i]
  tmp2+=a_list[i][2-i]
if tmp==-3 or tmp2==-3:
  yes_no=True

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

Submission status: Accepted

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

# input
a = [['' for _ in range(3)] for _ in range(3)]
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):
    tmp = int(input())
    b.append(tmp)

# calc
f = [['' for _ in range(3)] for _ in range(3)]
for i in range(3):
    for j in range(3): f[i][j] = 0

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

for i in range(3):
    s = 0
    for j in range(3):
        s += f[i][j]
    if s == 3:
        print('Yes')
        sys.exit()

for i in range(3):
    s = 0
    for j in range(3):
        s += f[j][i]
    if s == 3:
        print('Yes')
        sys.exit()

if f[0][0] + f[1][1] + f[2][2] == 3:
    print('Yes')
    sys.exit()
if f[0][2] + f[1][1] + f[2][0] == 3:
    print('Yes')
    sys.exit()

print('No')

Submission status: Accepted

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

for _ in range(n):
    x = int(input())
    for i in range(3):
        for j in range(3):
            if al[i][j]==x:
                al[i][j] = -1

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

    if -3==sum([al[j][i] for j in range(3)]):
        print("Yes")
        exit()

if al[0][0]+al[1][1]+al[2][2]==-3:
    print("Yes")
    exit()
if al[0][2]+al[1][1]+al[2][0]==-3:
    print("Yes")
    exit()

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 = False
for i in range(3):
    if all(a[i][j] in b for j in range(3)): #bの中にa[i][j]があるかどうか
        flag = True
    if all(a[j][i] in b for j in range(3)):
        flag = True
if all(a[i][i] in b for i in range(3)) or all(a[i][2-i] in b for i in range(3)):
    flag = True
 
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

hit = np.zeros_like(A)

for n in b:
	hit[A == n] = 1
if np.sum(np.sum(hit, 0) == 3):
	print('Yes')
elif np.sum(np.sum(hit, 1) == 3):
	print('Yes')
elif hit[0, 0] + hit[1, 1] + hit[2, 2] == 3:
	print('Yes')
elif hit[2, 0] + hit[1, 1] + hit[0, 2] == 3:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
def myAnswer(A: list, B: list, N: int) -> str:
    clomn = [0, 0, 0]
    bingoCard = [[0, 0, 0] for i in range(3)]
    row = [0, 0, 0]
    # マスが空くがどうかの判定
    for b in B:
        for i, a in enumerate(A):
            if(b in a):
                bingoCard[i][a.index(b)] = 1
                clomn[i] += 1
                row[a.index(b)] += 1
                break
   #  for n, b in enumerate(bingoCard):
   #      if(sum(b) == 3):
   #          return "Yes"  # 横の判定

    # 縦の判定(列ごとの合計が3である列があったかどうか)
    if(3 in row or 3 in clomn):
        return "Yes"

    # 斜めの判定
    if(bingoCard[1][1]):
        if((bingoCard[0][0] and bingoCard[2][2]) or (bingoCard[0][2] and bingoCard[2][0])):
            return "Yes"

    # 縦、横、斜めに当てはまらなければ,No
    return "No"


def modelAnswer():
    tmp = 1


def main():
    A = []
    B = []
    for _ in range(3):
        A.append(list(map(int, input().split())))
    N = int(input())
    for _ in range(N):
        B.append(int(input()))
    print(myAnswer(A[:], B[:], N))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def myAnswer(A: list, B: list, N: int) -> str:
    bingoCard = [[0, 0, 0] for i in range(3)]
    row = [0, 0, 0]
    # マスが空くがどうかの判定
    for b in B:
        for i, a in enumerate(A):
            if(b in a):
                bingoCard[i][a.index(b)] = 1
                row[a.index(b)] += 1
                break
    for n, b in enumerate(bingoCard):
        if(sum(b) == 3):
            return "Yes"  # 横の判定

    # 縦の判定(列ごとの合計が3である列があったかどうか)
    if(3 in row):
        return "Yes"

    # 斜めの判定
    if(bingoCard[1][1]):
        if((bingoCard[0][0] and bingoCard[2][2]) or (bingoCard[0][2] and bingoCard[2][0])):
            return "Yes"

    # 縦、横、斜めに当てはまらなければ,No
    return "No"


def modelAnswer():
    tmp = 1


def main():
    A = []
    B = []
    for _ in range(3):
        A.append(list(map(int, input().split())))
    N = int(input())
    for _ in range(N):
        B.append(int(input()))
    print(myAnswer(A[:], B[:], N))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A=[[int(_) for _ in input().split()] for i in range(3)]
flag=[[0]*3 for i in range(3)]
n=int(input())
for k in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                flag[i][j]=1
import numpy as np
if (3 in np.sum(flag,axis=0)) or (3 in np.sum(flag,axis=1)) or (((flag[0][0]==flag[1][1] and flag[1][1]==flag[2][2]) or (flag[0][2]==flag[1][1] and flag[1][1]==flag[2][0])) and flag[1][1]==1):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:

def myAnswer(A:list,B:list,N:int) -> str:
   bingo=[[0,0,0] for i in range(3)]
   for b in B:
      for i,a in enumerate(A):
         if(b in a):
            bingo[i][a.index(b)] = 1
            break
   tate=[0,0,0]
   for n,b in enumerate(bingo):
      if(sum(b) == 3):
         return "Yes"
      for i in range(3):
         tate[i] += b[i]
   if(3 in tate): return "Yes"
   if(bingo[1][1] == 1):
      if((bingo[0][0] == 1 and bingo[2][2] == 1) or (bingo[0][2]==1 and bingo[2][0]==1)):
         return "Yes"
   return "No"

def modelAnswer():
   tmp=1
def main():
   A=[]
   B=[]
   for _ in range(3):
      A.append(list(map(int,input().split())))
   N = int(input())
   for _ in range(N):
      B.append(int(input()))
   print(myAnswer(A[:],B[:],N))

if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
A = []*3

for i in range(3):
    A.append(list(map(int, input().split())))
N = int(input())
flag = 0

for i in range(N):
    aaa = int(input())
    for m in range(3):
        for n in range(3):
            if A[m][n] == aaa:
                A[m][n] = 0

    for k in range(3):
        if A[0][k] == A[1][k] and A[0][k] == A[2][k]:
            flag = 1
            break
        if A[k][0] == A[k][1] and A[k][0] == A[k][2]:
            flag = 1
            break
    if A[0][0] == A[1][1] and A[0][0] == A[2][2]:
        flag = 1
        break
    if A[0][2] == A[1][1] and A[0][2] == A[2][0]:
        flag = 1
        break


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