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:
# problem B

A = []
for i in range(1,4):
    x = map(int,input().split())
    A.append(list(x))

N = int(input())

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

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


tate = []
yoko = []
naname = []

for i in range(0,3):
    tate.append(A[0][i]*A[1][i]*A[2][i])
for i in range(0,3):
    yoko.append(A[i][0]*A[i][1]*A[i][2])
    

naname.append(A[0][0]*A[1][1]*A[2][2])
naname.append(A[0][2]*A[1][1]*A[2][0])

ans = sum(tate)+sum(yoko)+sum(naname)
if ans == 0:
    print('No')
else:
    print('Yes')

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())

card=[a11,a12,a13,a21,a22,a23,a31,a32,a33]
def isBingo():
   if ( (card[0] == -1 and card[1] == -1 and card[2] == -1) \
      or (card[3] == -1 and card[4] == -1 and card[5] == -1) \
      or (card[6] == -1 and card[7] == -1 and card[8] == -1) \
      or (card[0] == -1 and card[3] == -1 and card[6] == -1) \
      or (card[1] == -1 and card[4] == -1 and card[7] == -1) \
      or (card[2] == -1 and card[5] == -1 and card[8] == -1) \
      or (card[0] == -1 and card[4] == -1 and card[8] == -1) \
      or (card[2] == -1 and card[4] == -1 and card[6] == -1) \
      ):
      return True
   else:
      return False
    
for i in range(n):
  i= int(input())
  if i in card:
    card[card.index(i)]=-1
if( isBingo()):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
def getInput():
    return [int(i) for i in input().rstrip().split(' ')]
def checkBingo(holes):
    holes_x = [list(x) for x in zip(*holes)]
    _a,_b = True,True
    for i in range(3):
        if not None in holes[i] or not None in holes_x[i]:# 縦横
            return True
        #斜め
        if None is holes[i][i]:_a=False
        if None is holes[i][2-i]: _b=False
    return (_a ==True or _b == True)
bingo = []
holes = []
for i in range(3):
    bingo += [getInput()]
for i in bingo:
    holes += [[None for n in i]]
N = getInput()[0]
for i in range(N):
    num = getInput()[0]
    for h in range(3):
        for w in range(3):
            if num == bingo[h][w]:
                holes[h][w] = 1
                break
    if checkBingo(holes):
        print('Yes')
        sys.exit()
print('No')

Submission status: Accepted

Solution code:
a11,a12,a13=map(int,input().split())
a21,a22,a23=map(int,input().split())
a31,a32,a33=map(int,input().split())
n=int(input())

card = [a11,a12,a13,a21,a22,a23,a31,a32,a33]
def isBingo() :
    if ( (card[0] == -1 and card[1] == -1 and card[2] == -1) \
      or (card[3] == -1 and card[4] == -1 and card[5] == -1) \
      or (card[6] == -1 and card[7] == -1 and card[8] == -1) \
      or (card[0] == -1 and card[3] == -1 and card[6] == -1) \
      or (card[1] == -1 and card[4] == -1 and card[7] == -1) \
      or (card[2] == -1 and card[5] == -1 and card[8] == -1) \
      or (card[0] == -1 and card[4] == -1 and card[8] == -1) \
      or (card[2] == -1 and card[4] == -1 and card[6] == -1) \
      ) :
        return True
    else :
        return False

ans = "No"
for x in range(n) :
    s = int(input())
    if s in card :
        card[card.index(s)] = -1
    if( isBingo() ) :
        ans = "Yes"

print(ans)

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)]
a = [[False]*3 for i in range(3)]
for i in range(3):
    for j in range(3):
        for b in B:
            if A[i][j]==b:
                a[i][j]=True

bingo=False
for i in range(3):
    if a[i][0] and a[i][1] and a[i][2]:
        bingo=True
for j in range(3):
    if a[0][j] and a[1][j] and a[2][j]:
        bingo=True
if a[0][0] and a[1][1] and a[2][2]:
    bingo=True
if a[2][0] and a[1][1] and a[0][2]:
    bingo=True
print("Yes" if bingo else "No")

Submission status: Accepted

Solution code:
import numpy as np
card = np.array([list(map(int,input().split())),\
                 list(map(int,input().split())),\
                 list(map(int,input().split()))])
N = int(input())
for i in range(N):
  card[card == int(input())] = 0
print('No' if str(np.all(card == 0, axis = 0)) == '[False False False]' and\
              str(np.all(card == 0, axis = 1)) == '[False False False]' and\
              sum(np.diag(card)) != 0 and\
			  sum(np.choose([2, 1, 0], card)) != 0 else 'Yes')

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 i in range(3):
  for j in b:
    if a[i].count(j) > 0:
      a[i][a[i].index(j)] = -1

if (sum(a[0]) == -3) or (sum(a[1]) == -3) or (sum(a[2]) == -3) or (a[0][0] + a[1][0] + a[2][0] == -3) or (a[0][1] + a[1][1] + a[2][1] == -3) or (a[0][2] + a[1][2] + a[2][2] == -3) or (a[0][0] + a[1][1] + a[2][2] == -3) or (a[0][2] + a[1][1] + a[2][0] == -3):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
l = []
for i in range(3):
  a = [int(x) for x in input().split()]
  l.append(a)
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))
for x in range(3):
  for y in range(3):
    for i in range(n):
      if l[x][y] == b[i]:
        l[x][y] = 0
hantei = "No"
for i in range(3):
  if l[i][0] == l[i][1] and l[i][1] == l[i][2]:
    hantei = "Yes"
    break
  elif l[0][i] == l[1][i] and l[1][i] == l[2][i]:
    hantei = "Yes"
    break
if l[0][2] == l[1][1] and l[1][1] == l[2][0]:
  hantei = "Yes"
elif l[0][0] == l[1][1] and l[1][1] == l[2][2]:
  hantei ="Yes"
print(hantei)

Submission status: Accepted

Solution code:
def judge(A):
    if A[0][0]==A[1][1]==A[2][2]=="o" or A[0][2]==A[1][1]==A[2][0]=="o":
        return "Yes"
    for i in range(3):
        if A[i][0]==A[i][1]==A[i][2]=="o" or A[0][i]==A[1][i]==A[2][i]=="o":
            return "Yes"
    return "No"
a1=input().split()
a2=input().split()
a3=input().split()
A=[a1,a2,a3]
N=int(input())
for n in range(N):
    p=0
    b=input()
    for i in range(3):
        for j in range(3):
            if b==A[i][j]:
                A[i][j]="o"
                p=1
                break
        if p==1:
            break
print(judge(A))

Submission status: Accepted

Solution code:
a_1_1, a_1_2, a_1_3 = map(int, input().split())
a_2_1, a_2_2, a_2_3 = map(int, input().split())
a_3_1, a_3_2, a_3_3 = map(int, input().split())
n = int(input())
b = [int(input()) for _ in range(n)]
a = []
a.extend((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))
for _ in range(len(a)):
    if a[_] in b:
        a[_] = 0

def is_bingo(num_1, num_2, num_3):
    if num_1 == num_2 == num_3:
        return True

if is_bingo(a[0], a[1], a[2]) or is_bingo(a[3], a[4], a[5]) or is_bingo(a[6], a[7], a[8]) or is_bingo(a[0], a[3], a[6]) or is_bingo(a[1], a[4], a[7]) or is_bingo(a[2], a[5], a[8]) or is_bingo(a[0], a[4], a[8]) or is_bingo(a[2], a[4], a[6]):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np

A = np.zeros((3, 3), dtype=int)
for i in range(3):
    A[i, :] = [int(x) for x in input().split()]
N = int(input())
b = np.zeros(N, dtype=int)
for i in range(N):
    b[i] = int(input())

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

is_bingo = False
for i in range(3):
    if np.sum(A[i, :]) == 0:
        is_bingo = True

for j in range(3):
    if np.sum(A[:, j]) == 0:
        is_bingo = True

if A[1, 1] == 0:
    if A[0, 0] == 0 and A[2, 2] == 0:
        is_bingo = True
    elif A[0, 2] == 0 and A[2, 0] == 0:
        is_bingo = True

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

Submission status: Accepted

Solution code:
A=[list(map(int,input().split())) for i in range(3)]
A1=list(zip(*A))
A2=[A[0][0], A[1][1], A[2][2]]
A3=[A[2][0], A[1][1], A[0][2]]
N=int(input())
b=[int(input()) for i in range(N)]

count=0
for i in range(3):
  for j in range(3):
    if A[i][j] in b:
      count+=1
  if count==3:
    print('Yes')
    exit()
  else:
    count=0

for i in range(3):
  for j in range(3):
    if A1[i][j] in b:
      count+=1
  if count==3:
    print('Yes')
    exit()
  else:
    count=0

for i in range(3):
  if A2[i] in b:
    count+=1
if count==3:
  print('Yes')
  exit()
else:
  count=0
  
for i in range(3):
  if A3[i] in b:
    count+=1
if count==3:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
import numpy as np

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()))

a = np.array(a)
b = np.array(b)
  
for i in range(n) :
  num = b[i]
  for j in range(3) :
    for k in range(3) :
      if num == a[j][k] :
        a[j][k] = 0
        break
        
ans = 'No'
for i in range(3) :
  if all(j==0 for j in a[:,i]) or all(j==0 for j in a[i,:]) :
    ans = 'Yes'
    
af = np.fliplr(a)
if all(j==0 for j in np.diag(a)) or all(j==0 for j in np.diag(af)) :
  ans = 'Yes'

print(ans)

Submission status: Accepted

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

N = int(input())
for _ in range(N):
    bn = int(input())
    for i in range(3):
        for j in range(3):
            if bn == data[i][j]:
                data[i][j] = 0
ans = "No"
for i in range(3):
    if data[i][0] == data[i][1] == data[i][2] == 0:ans = "Yes"
    if data[0][i] == data[1][i] == data[2][i] == 0:ans = "Yes"
if data[0][0] == data[1][1] == data[2][2]==0:ans ="Yes"
if data[0][2] == data[1][1] == data[2][0] == 0 :ans="Yes"
print(ans)

Submission status: Accepted

Solution code:
A = [list(map(int,input().split())) for i in range(3)]
A = sum(A,[])
N = int(input())
flag = 0
for i in range(N):
    b = int(input())
    for j in range(9):
        if A[j] == b:
            A[j] = 0

for i in range(3):
    if A[i]==A[i+3] and A[i+3]==A[i+6] and A[i]==0 or\
        A[i*3] == A[i*3+1] and A[i*3+1] == A[i*3+2] and A[i*3] == 0:
        flag = 1
if A[0]==A[4] and A[4]==A[8] and A[0]==0 or\
     A[2]==A[4] and A[4]==A[6] and A[2]==0:
     flag = 1

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

Submission status: Accepted

Solution code:
card = {}
bingo = {1:False,2:False,3:False,4:False,5:False,6:False,7:False,8:False,9:False}
for i in range(3):
    row = list(map(int, input().split()))
    card[i * 3 + 1] = row[0]
    card[i * 3 + 2] = row[1]
    card[i * 3 + 3] = row[2]

n = int(input())
for i in range(n):
    num = int(input())
    keys = [k for k, v in card.items() if v == num]
    if len(keys) > 0:
        bingo[keys[0]] = True

hit_keys = [k for k, v in bingo.items() if v]
if len(hit_keys) >= 3 and ((1 in hit_keys and 2 in hit_keys and 3 in hit_keys) or \
    (4 in hit_keys and 5 in hit_keys and 6 in hit_keys) or\
    (7 in hit_keys and 8 in hit_keys and 9 in hit_keys) or\
    (1 in hit_keys and 4 in hit_keys and 7 in hit_keys) or\
    (2 in hit_keys and 5 in hit_keys and 8 in hit_keys) or\
    (3 in hit_keys and 6 in hit_keys and 9 in hit_keys) or\
    (1 in hit_keys and 5 in hit_keys and 9 in hit_keys) or\
    (3 in hit_keys and 5 in hit_keys and 7 in hit_keys)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

bingo=[[0,0,0],[0,0,0],[0,0,0]]
for i in num:
    for j in range(3):
        for k in range(3):
            if i==A[j][k]:
                bingo[j][k]=1
#行がビンゴ
for i in range(3):
    if sum(bingo[i])==3:
        print("Yes")
        exit()
#列がビンゴ
if bingo[0][0]+bingo[1][0]+bingo[2][0]==3 or bingo[0][1]+bingo[1][1]+bingo[2][1]==3 or bingo[0][2]+bingo[1][2]+bingo[2][2]==3:
        print("Yes")
        exit()
#斜めがビンゴ
elif bingo[0][0]+bingo[1][1]+bingo[2][2]==3 or bingo[0][2]+bingo[1][1]+bingo[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)}

for i in range(3):
    if A[i][0] in b and A[i][1] in b and A[i][2] in b:
        print('Yes')
        exit()
    elif A[0][i] in b and A[1][i] in b and A[2][i] in b:
        print('Yes')
        exit()
if (A[0][0] in b and A[1][1] in b and A[2][2] in b) or (A[0][2] in b and A[1][1] in b and A[2][0] in b):
    print('Yes')
    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 i in range(3):
    for j in range(3):
        if (A[i][j] in B):
            A[i][j] = True
        else:
            A[i][j] = False


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

    if 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]:
    print("Yes")
    exit()

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

print("No")

Submission status: Accepted

Solution code:
import sys

bng=[[0]*3 for i in range(3)]

for i in range(3):

  a,b,c=map(int,input().split())

  bng[i][0]=a
  bng[i][1]=b
  bng[i][2]=c

n=int(input())

for j in range(n):

  k=int(input())

  for a in range(3):
    for b in range(3):
      if bng[a][b]==k:
        bng[a][b]=-1

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

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

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

if bng[2][0]==-1 and bng[1][1]==-1 and bng[0][2]==-1:
  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)]
flag=0
for i in range(3):
  if (A[0][i] in b)and(A[1][i] in b)and(A[2][i] in b):
    flag=1
  elif (A[i][0] in b)and(A[i][1] in b)and(A[i][2] in b):
    flag=1
if (A[0][0] in b)and(A[1][1] in b)and(A[2][2] in b):
  flag=1
elif (A[0][2] in b)and(A[1][1] in b)and(A[2][0] in b):
  flag=1
print("Yes" if flag==1 else "No")

Submission status: Accepted

Solution code:
A11, A12, A13 = map(int, input().split())
A21, A22, A23 = map(int, input().split())
A31, A32, A33 = map(int, input().split())
A = [A11, A12, A13, A21, A22, A23, A31, A32, A33]
N = int(input())
for _ in range(N):
  b = int(input())
  if b in A:
    A[A.index(b)] = 0

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:
A1 = list(input().split())
A2 = list(input().split())
A3 = list(input().split())
A = [A1,A2,A3]
N = int(input())
for i in range(N):
  C = input()
  for j in range(3):
    if C == A[0][j]:
      A[0][j] = 'AC'
    if C == A[1][j]:
      A[1][j] = 'AC'
    if C == A[2][j]:
      A[2][j] = 'AC'
for l in range(3):
    if A[l][0] == A[l][1] == A[l][2] == 'AC':
      print('Yes')
      exit()
    if A[0][l] == A[1][l] == A[2][l] == 'AC':
      print('Yes')
      exit()
if A[0][0] == A[1][1] == A[2][2] == 'AC':
  print('Yes')
  exit()
if A[0][2] == A[1][1] == A[2][0] == 'AC':
  print('Yes')
  exit()
print('No')

Submission status: Accepted

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

A = [list(map(int, input().split())) for a 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] = -1

is_bingo = False
is_bingo = is_bingo or (A[0][0] == -1 and A[0][1] == -1 and A[0][2] == -1)
is_bingo = is_bingo or (A[1][0] == -1 and A[1][1] == -1 and A[1][2] == -1)
is_bingo = is_bingo or (A[2][0] == -1 and A[2][1] == -1 and A[2][2] == -1)
is_bingo = is_bingo or (A[0][0] == -1 and A[1][0] == -1 and A[2][0] == -1)
is_bingo = is_bingo or (A[0][1] == -1 and A[1][1] == -1 and A[2][1] == -1)
is_bingo = is_bingo or (A[0][2] == -1 and A[1][2] == -1 and A[2][2] == -1)
is_bingo = is_bingo or (A[0][0] == -1 and A[1][1] == -1 and A[2][2] == -1)
is_bingo = is_bingo or (A[0][2] == -1 and A[1][1] == -1 and A[2][0] == -1)

if is_bingo:
    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=[int(input()) for i in range(N)]
if A1[0] in b and A2[0] in b and A3[0] in b:
    print('Yes')
    exit()
elif A1[1] in b and A2[1] in b and A3[1] in b:
    print('Yes')
    exit()
elif A1[2] in b and A2[2] in b and A3[2] in b:
    print('Yes')
    exit()
elif A1[0] in b and A1[1] in b and A1[2] in b:
    print('Yes')
    exit()
elif A2[0] in b and A2[1] in b and A2[2] in b:
    print('Yes')
    exit()
elif A3[0] in b and A3[1] in b and A3[2] in b:
    print('Yes')
    exit()
elif A1[0] in b and A2[1] in b and A3[2] in b:
    print('Yes')
    exit()
elif A1[2] in b and A2[1] in b and A3[0] in b:
    print('Yes')
    exit()
else:
    print('No')

Submission status: Accepted

Solution code:
A = []
for i in range(3):
    A += list(map(int, input().split()))
N = int(input())
for i in range(N):
    b = int(input())
    if b in A:
        A = [0 if num == b else num for num in A]
bingo_check = [[0, 1, 2],
               [0, 3, 6],
               [0, 4, 8],
               [1, 4, 7],
               [2, 4, 6],
               [2, 5, 8],
               [3, 4, 5],
               [6, 7, 8]]
no_check = 1
for check in bingo_check:
    row = [A[i] for i in check]
    if not sum(row):
        print("Yes")
        no_check = 0
        break
if no_check:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np
S = np.array([list(map(int, input().split())) for _ in range(3)])
n = int(input())
for _ in range(n):
    S = np.where(S==int(input()), 0, S)
    HBingo = min(np.sum(S, axis=0)) == 0
    WBingo = min(np.sum(S, axis=1)) == 0
    SBingo = S[2][0] == 0 and S[1][1] == 0 and S[0][2] == 0
    BSBingo = S[0][0] == 0 and S[1][1] == 0 and S[2][2] == 0
if HBingo or WBingo or SBingo or BSBingo:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

Solution code:
def columnCheck(a):
  result = False
  for i in a:
    if i == [0, 0, 0]:
      result = True
  return result

def rowCheck(a):
  result = False
  for j in range(3):
    if a[0][j] == 0 and a[1][j] == 0 and a[2][j] == 0:
      result = True
  return result

def crossCheck(a):
  result = False
  if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
    result = True
  if a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0:
    result = True
  return result

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

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

print("Yes" if columnCheck(a) or rowCheck(a) or crossCheck(a) else "No")

Submission status: Accepted

Solution code:
import numpy as np
S = np.array([list(map(int, input().split())) for _ in range(3)])
n = int(input())
for _ in range(n):
    S = np.where(S==int(input()), 0, S)
if min(np.sum(S, axis=0))==0 or min(np.sum(S, axis=1))==0:
    print('Yes')
    exit()
if (S[0][0] == 0 and S[1][1] == 0 and S[2][2] == 0) or (S[2][0] == 0 and S[1][1] == 0 and S[0][2] == 0):
    print('Yes')
    exit()
print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A = []

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


N = int(input())
nums = set()
for _ in range(N):
  n = int(input())
  nums.add(n)

for row in A:
  if len(set(row).difference(nums)) == 0:
    print('Yes')
    exit()
for col in range(len(A[0])):
  nums_in_col = set()
  for row in range(len(A)):
    nums_in_col.add(A[row][col])
  if len(nums_in_col.difference(nums)) == 0:
    print('Yes')
    exit()

nums_ = set()
for i in range(len(A)):
  nums_.add(A[i][i])
if len(nums_.difference(nums)) == 0:
  print('Yes')
  exit()

nums_ = set()
for i, j in zip(range(len(A)-1, -1, -1), range(len(A))):
  nums_.add(A[i][j])

if len(nums_.difference(nums)) == 0:
  print('Yes')
  exit()

print('No')

Submission status: Accepted

Solution code:
a = []
[a.append(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 a[j][k] == i:
        a[j][k] = 1
ans = 0
count =0
for j in range(3):
  if a[j].count(1) == 3:
    ans += 1
  elif (a[0][j] == a[1][j] == a[2][j]) == 1:
    ans += 1
  elif (a[0][0] == a[1][1] == a[2][2]) == 1:
    ans += 1
  elif (a[0][2] == a[1][1] == a[2][0]) == 1:
    ans += 1
if ans > 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
bingoboard = list()
for x in range(3):
    bingoboard.append([int(x) for x in input().split()])
trials = int(input())

for t in range(trials):
    bingno = int(input())
    for i in range(3):
        for j in range(3):
            if bingno == bingoboard[i][j]:
                bingoboard[i][j] = 0

bingoBool = False
diag = 0
diag2 = 0
for i in range(3):
    col= 0
    row = 0
    for j in range(3):
        row += bingoboard[i][j]
        col += bingoboard[j][i]
        diag += bingoboard[i][i]
        diag2 += bingoboard[i][2-i]
    if row == 0 or col == 0:
        bingoBool = True
        break

if diag == 0 or diag2 == 0:
    bingoBool = True

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

Submission status: Accepted

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

N = int(input())
B = []
for _ in range(N):
  B.append(int(input()))
  
# judge
flg = False

for i in range(3):
  if A[i][0] in B and A[i][1] in B and A[i][2] in B:
    flg = True
  if A[0][i] in B and A[1][i] in B and A[2][i] in B:
    flg = True
  
if A[0][0] in B and A[1][1] in B and A[2][2] in B:
  flg = True
if A[2][0] in B and A[1][1] in B and A[0][2] in B:
  flg = True
  
print("Yes" if flg else "No")

Submission status: Accepted

Solution code:
al=list(map(int,input().split()))+list(map(int,input().split()))+list(map(int,input().split()))
n=int(input())
bl=[int(input()) for _ in [0]*n]
for i in bl:
  for j in range(9):
    if al[j] == i:
      al[j] = 0
nobingo = (al[0]+al[1]+al[2])*(al[3]+al[4]+al[5])*(al[6]+al[7]+al[8])*(al[0]+al[3]+al[6])*(al[1]+al[4]+al[7])*(al[2]+al[5]+al[8])*(al[0]+al[4]+al[8])*(al[2]+al[4]+al[6])
if nobingo:
  print('No')
else:
  print('Yes')

Submission status: Accepted

Solution code:
bingo = [list(map(int,input().split())) for i in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]
cnt = [0]*8
for i in range(3):
    for j in range(3):
        if bingo[i][j] in b:
            cnt[i] += 1
            cnt[j+3] += 1
            if i == j:
                cnt[-1] += 1
            if i+j == 2:
                cnt[-2] += 1
ans = "No"
for i in cnt:
    if i >= 3:
        ans = "Yes"
        break
print(ans)

Submission status: Accepted

Solution code:
# 初期入力
a_list = [input().split() for i in range(3)]
N = int(input())
call_num = [input() for i in range(N)]

bingo =""
# 横がそろっているか
bingo = "No"
yoko = [i for i in a_list if set(i) & set(call_num) ==set(i)]
if 0 < len(yoko):
    bingo ="Yes"

# 縦がそろっているか
a_tate =[]
for i,v in enumerate(a_list):
    ta =[]
    for j in range(3):
        ta.append(a_list[j][i])
    a_tate.append(ta)

tate =""
for i in a_tate:
    if len(set(i) & set(call_num) ) ==3 :
        tate +="ss"
if 0 < len(tate):
    bingo ="Yes"

# 斜め
a_naname_1 = set([a_list[0][0],a_list[1][1],a_list[2][2] ])
a_naname_2 = set([a_list[0][2],a_list[1][1],a_list[2][0] ])
if a_naname_1 & set(call_num) == a_naname_1:
    bingo = "Yes"
if a_naname_2 & set(call_num) == a_naname_2:
    bingo = "Yes"
print(bingo)

Submission status: Accepted

Solution code:
def check_line(start, dxy):
    x, y = start
    dx, dy = dxy
    flg = bingo[x][y]
    for _ in range(2):
        x += dx
        y += dy
        flg &= bingo[x][y]
    return flg

Alist = [list(map(int, input().split())) for _ in range(3)]
Aset = set()
for line in Alist:
    Aset |= set(line)
bingo = [[False] * 3 for i in range(3)]
N = int(input())
br = False
for _ in range(N):
    b = int(input())
    if b in Aset:
        for x in range(3):
            for y in range(3):
                if Alist[x][y] == b:
                    bingo[x][y] = True

ans = False
for i in range(3):
    ans |= check_line((0, i), (1, 0))
    ans |= check_line((i, 0), (0, 1))
ans |= check_line((0, 0), (1, 1))
ans |= check_line((0, 2), (1, -1))
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
a = [[int(i) for i in input().split()] for l in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

for target in b:
    for i in range(len(a)):
        for j in range(len(a[0])):
            if a[i][j] == target:
                a[i][j]=0

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

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

print("No")

Submission status: Accepted

Solution code:
a = []
a_bool = [False for i in range(9)]
for j in range(3):[a.append(i) for i in list(map(int, input().split()))]
n = int(input())
for i in range(n):
    b = int(input())
    if b in a:
        a_bool[a.index(b)] = True
if (a_bool[0] and a_bool[1] and a_bool[2]) or (a_bool[3] and a_bool[4] and a_bool[5]) or (a_bool[6] and a_bool[7] and a_bool[8]) or (a_bool[0] and a_bool[3] and a_bool[6]) or (a_bool[1] and a_bool[4] and a_bool[7]) or (a_bool[2] and a_bool[5] and a_bool[8]) or (a_bool[0] and a_bool[4] and a_bool[8]) or (a_bool[2] and a_bool[4] and a_bool[6]):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
data = []
for j in range(3):
  data.extend([int (i) for i in input().split()])

bingo_dic = {}
for i, d in enumerate(data):
  bingo_dic[d] = i
  
N = int(input())

bingo = [0,0,0,0,0,0,0,0,0]
for _ in range(N):
  i = int(input())
  if i in bingo_dic.keys():
    bingo[bingo_dic[i]] = 1
    
if bingo[0] + bingo[1] + bingo[2] == 3:
  print('Yes')
  exit()
  
if bingo[3] + bingo[4] + bingo[5] == 3:
  print('Yes')
  exit()
  
if bingo[6] + bingo[7] + bingo[8] == 3:
  print('Yes')
  exit()
  
if bingo[0] + bingo[3] + bingo[6] == 3:
  print('Yes')
  exit()

if bingo[1] + bingo[4] + bingo[7] == 3:
  print('Yes')
  exit()
  
if bingo[2] + bingo[5] + bingo[8] == 3:
  print('Yes')
  exit()
  
if bingo[0] + bingo[4] + bingo[8] == 3:
  print('Yes')
  exit()

if bingo[2] + bingo[4] + bingo[6] == 3:
  print('Yes')
  exit()

print('No')

Submission status: Accepted

Solution code:
import numpy as np
a = list(map(int,input().split(' ')))
b = list(map(int,input().split(' ')))
c = list(map(int,input().split(' ')))
x = [a,b,c]
hit = []
zero = np.zeros((3,3))
count = int(input())
for i in range(count):
  hit.append(int(input()))

  
#print(x,hit)
flag = np.zeros((3,3))
for j in hit:
  for n,i in enumerate(x):
    if j in i:
      one = i.index(j)
      zero[n][one] = 1


#print(zero)
point = np.sum(zero,axis=0)
point2 = np.sum(zero,axis=1)
apoint =      np.append(point,point2,)
hnaname = zero[0][0]+zero[1][1]+zero[2][2] 
mnaname = zero[0][2]+zero[1][1]+zero[2][0] 
apoint = np.append(apoint,hnaname)
apoint = np.append(apoint,mnaname)
#print(apoint)       
if 3 in apoint:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
import sys
# input = sys.stdin.buffer.readline
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

A = [[int(i) for i in input().split()] for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
# print(A)
# print(b)

done = [[0] * 3 for _ in range(3)]
for k in range(N):
    for i in range(3):
        for j in range(3):
            if b[k] == A[i][j]:
                done[i][j] = 1
# print(done)

ans = "No"
for i in range(3):
    flg = True
    for j in range(3):
        if done[i][j] == 0:
            flg = False
    if flg:
        ans = "Yes"
for i in range(3):
    flg = True
    for j in range(3):
        if done[j][i] == 0:
            flg = False
    if flg:
        ans = "Yes"

flg = True
for j in range(3):
    if done[j][j] == 0:
        flg = False
if flg:
    ans = "Yes"
flg = True
for j in range(3):
    if done[2-j][j] == 0:
        flg = False
if flg:
    ans = "Yes"

print(ans)

Submission status: Accepted

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

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

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

flg = False

for i in range(3):
    if sum([result[i][j] for j in range(3)]) == 3:
        flg = True

for j in range(3):
    if sum([result[i][j] for i in range(3)]) == 3:
        flg = True

if sum([result[i][i] for i in range(3)]) == 3:
    flg = True

if sum([result[i][2-i] for i in range(3)]) == 3:
    flg = True

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