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:
# input
A = []
for i in range(3):
    A.append(list(map(int, input().split())))

N = int(input())

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

# process
A2 = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A2[i][j] = 1
                break

# ビンゴの判定
result = False 

# 横
for i in range(3):
    if A2[i][0]==1 and A2[i][1]==1 and A2[i][2]==1:
        result = True
# 縦
if not result:
    for i in range(3):
        if A2[0][i]==1 and A2[1][i]==1 and A2[2][i]==1:
            result = True

# 斜め
if not result:
    if A2[0][0]==1 and A2[1][1]==1 and A2[2][2]==1:
        result = True
    elif A2[0][2]==1 and A2[1][1]==1 and A2[2][0]==1:
        result = True

# output
print("Yes" if result else "No")

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for _ in range(3)]
C=[0]*9
e=0
N=int(input())
for i in range(N):
  b=int(input())
  for j in range(3):
    for k in range(3):
    	if(A[j][k]==b):
          C[j*3+k]=1
          break
for j in range(3):
    if(C[j*3]==1 and C[j*3+1]==1 and C[j*3+2]==1):
         e=1
         break
    if(C[j]==1 and C[j+3]==1 and C[j+6]==1):
         e=1
         break
if(C[0]==1 and C[4]==1 and C[8]==1):
     e=1
if(C[2]==1 and C[4]==1 and C[6]==1):
     e=1
if(e==0):
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
Bingo = [ list(map(int,input().split())) for i in range(3)]
n = int(input())
num = [int(input()) for i in range(n)]
Bingo.append([Bingo[0][0] , Bingo[1][1],Bingo[2][2] ])
Bingo.append([Bingo[0][2] , Bingo[1][1],Bingo[2][0] ])
for k in range(3):
  Bingo.append([Bingo[0][k] , Bingo[1][k],Bingo[2][k] ])
k=0
re = 'No'
for l in range(len(Bingo)):
  if len(list(set(num) & set(Bingo[l]))) == 3:
    re = 'Yes'
    break
print(re)

Submission status: Accepted

Solution code:
a1=list(map(int, input().split()))
a2=list(map(int, input().split()))
a3=list(map(int, input().split()))
n=input()
b=[int(input())]
for i in range(int(n)-1):
    b.append(int(input()))


if b.count(a1[0])==1 and b.count(a1[1])==1 and b.count(a1[2])==1:
    print("Yes")
    exit()
if b.count(a2[0])==1 and b.count(a2[1])==1 and b.count(a2[2])==1:
    print("Yes")
    exit()
if b.count(a3[0])==1 and b.count(a3[1])==1 and b.count(a3[2])==1:
    print("Yes")
    exit()
if b.count(a1[0])==1 and b.count(a2[0])==1 and b.count(a3[0])==1:
    print("Yes")
    exit()
if b.count(a1[1])==1 and b.count(a2[1])==1 and b.count(a3[1])==1:
    print("Yes")
    exit()
if b.count(a1[2])==1 and b.count(a2[2])==1 and b.count(a3[2])==1:
    print("Yes")
    exit()
if b.count(a1[0])==1 and b.count(a2[1])==1 and b.count(a3[2])==1:
    print("Yes")
    exit()
if b.count(a1[2])==1 and b.count(a2[1])==1 and b.count(a3[0])==1:
    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 = [list(map(int,input().split())) for i in range(N)]

for i in range(3):
    for j in range(3):
        for k in range(N):
            if A[i][j] in B[k]:
                A[i][j] = 0
if A[0][0] == 0 and A[0][1] == 0 and A[0][2] == 0 or A[1][0] == 0 and A[1][1] == 0 and A[1][2] == 0 or A[2][0] == 0 and A[2][1] == 0 and A[2][2] == 0 or 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 and A[1][1] == 0 and A[2][2] == 0 or A[0][2] == 0 and A[1][1] == 0 and A[0][2] == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
  
bingo_card = []

for i in range(3):
    bingo_card.append(list(map(int, input().split())))
    
n = int(input())
called_num = set()
for i in range(n):
    called_num.add(int(input()))
    
    
for i in range(3):
    for j in range(3):
        if bingo_card[i][j] in called_num:
            bingo_card[i][j] = -1
            
bingo = False

if bingo_card[0][0] + bingo_card[0][1] + bingo_card[0][2] == -3:
    bingo = True
if bingo_card[1][0] + bingo_card[1][1] + bingo_card[1][2] == -3:
    bingo = True
if bingo_card[2][0] + bingo_card[2][1] + bingo_card[2][2] == -3:
    bingo = True
if bingo_card[0][0] + bingo_card[1][0] + bingo_card[2][0] == -3:
    bingo = True
if bingo_card[0][1] + bingo_card[1][1] + bingo_card[2][1] == -3:
    bingo = True
if bingo_card[0][2] + bingo_card[1][2] + bingo_card[2][2] == -3:
    bingo = True
if bingo_card[0][0] + bingo_card[1][1] + bingo_card[2][2] == -3:
    bingo = True
if bingo_card[2][0] + bingo_card[1][1] + bingo_card[0][2] == -3:
    bingo = True
    
if bingo:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

n = int(input())
b_s = []
for i in range(n):
    b_s.append(int(input()))
ans = "No"


for i in range(n):
    for j in range(3):
        for k in range(3):
            if b_s[i] == bingo[j][k]:
                bingo[j][k] = "o"

if bingo[1][1] == "o":
    if bingo[0][0] == "o" and bingo[2][2] == "o":
        ans = "Yes"
    elif bingo[0][2] == "o" and bingo[2][0] == "o":
        ans = "Yes"
    elif bingo[1][0] == "o" and bingo[1][2] == "o":
        ans = "Yes"
    elif bingo[0][1] == "o" and bingo[2][1] == "o":
        ans = "Yes"

elif bingo[1][1] != "o":
    if bingo[0][0] == "o" and bingo[0][1] == "o" and bingo[0][2] == "o":
        ans = "Yes"
    elif bingo[0][0] == "o" and bingo[1][0] == "o" and bingo[2][0] == "o":
        ans = "Yes"
    elif bingo[0][2] == "o" and bingo[1][2] == "o" and bingo[2][2] == "o":
        ans = "Yes"
    elif bingo[2][0] == "o" and bingo[2][1] == "o" and bingo[2][2] == "o":
        ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

a = []
for _ in range(3):
    a.append([int(i) for i in input().split()])
a = [e for row in a for e in row]
for i in range(int(input())):
    b = int(input())
    if b in a:
        a[a.index(b)] = 0
bingo = [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
flg = 0
for i in range(len(bingo)):
    c = 0
    for j in bingo[i]:
        c += a[j]
    if c==0:
        flg = 1
        break
print('Yes' if flg==1 else 'No')

Submission status: Accepted

Solution code:
hyo = []
x = []
ans = 0
for i in range(3):
    x = [int(e) for e in input().split()]
    hyo.extend(x)
    
kaz = int(input())

for j in range(kaz):
    num = int(input())
    for k in range(9):
        if hyo[k] == num:
            hyo[k] = 0
            break
for l in range(3):
    if hyo[3*l] == 0 and hyo[3*l+1] == 0 and hyo[3*l+2] == 0:
        ans = 1
    elif hyo[l] == 0 and hyo[3+l] == 0 and hyo[6+l] == 0:
        ans = 1
if hyo[0] ==0 and hyo[4] == 0 and hyo[8] == 0:
    ans =1
elif hyo[2] == 0 and hyo[4] == 0 and hyo[6] == 0:
    ans = 1
    
if ans == 1:
    print("Yes")
elif ans == 0:
    print("No")

Submission status: Accepted

Solution code:
def jud(l):
  for i in range(3):
    for j in range(3):
      if l[i][j] != 0:
        break
      if j == 2:
        return 1
  for i in range(3):
    for j in range(3):
      if l[j][i] != 0:
        break
      if j == 2:
        return 1
  for i in range(3):
      if l[i][i] != 0:
          break
      if i == 2:
          return 1
  for i in range(3):
      if l[i][2-i] != 0:
          break
      if i == 2:
          return 1
  return 0
          
       
def op(l,a):
  for i in range(3):
    for j in range(3):
      if l[i][j] == a:
        l[i][j] = 0
  return l

l = []
for i in range(3):
  l.append(input())
  l[i] = l[i].split()
  for j in range(3):
    l[i][j] = int(l[i][j])
num = int(input())
for i in range(num):
  a = int(input())
  l = op(l,a)
if jud(l) == 1:
  print('Yes')
else:
  print('No')

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
if sum(a[0]) == 0 or sum(a[1]) == 0 or sum(a[2]) == 0:
    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")
elif a[0][0] + a[1][0] + a[2][0] == 0 or a[0][1] + a[1][1] + a[2][1] == 0 or a[0][2] + a[1][2] + a[2][2] == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

def check():
    if np.count_nonzero(card[0] == 0) == 3:
        return True
    elif np.count_nonzero(card[1] == 0) == 3:
        return True
    elif np.count_nonzero(card[2] == 0) == 3:
        return True
    elif np.count_nonzero(card.T[0] == 0) == 3:
        return True
    elif np.count_nonzero(card.T[1] == 0) == 3:
        return True
    elif np.count_nonzero(card.T[2] == 0) == 3:
        return True
    elif [card[0][0],card[1][1],card[2][2]].count(0) == 3:
        return True
    elif [card[0][2],card[1][1],card[2][0]].count(0) == 3:
        return True
for i in range(len(num)):
    for x in [0,1,2]:
        for y in [0,1,2]:
            if card[x][y] == num[i]:
                card[x][y] = 0
                if check():
                    print("Yes")
                    exit()

print("No")

Submission status: Accepted

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


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


A = read_matrix(3)

import numpy as np
A = np.array(A)
idx_dict = {}
for i in range(3):
    for j in range(3):
        idx_dict[A[i, j]] = (i, j)
N = read_a_int()
B = read_col(N, 1)[0]

for b in B:
    if b not in idx_dict.keys():
        continue
    i, j = idx_dict[b]
    A[i, j] = -1

# print(A)
cnt = 0
for i in range(3):
    if (A[:, i] == -1).sum() == 3:
        print('Yes')
        exit()
    if (A[i, :] == -1).sum() == 3:
        print('Yes')
        exit()
    cnt += A[i, i] == -1

if cnt == 3:
    print('Yes')
    exit()

if A[0, 1] == -1 and A[1, 1] == -1 and A[2, 0] == -1:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

Solution code:
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
a1=[0]*3
b1=[0]*3 
c1=[0]*3
n=int(input())
flag=0
for j in range(n):
  x=int(input())
  for i in range(3):
    if(a[i]==x):
      a1[i]=1
    elif(b[i]==x):
      b1[i]=1
    elif(c[i]==x):
      c1[i]=1 
  if(n>=3):
    s1,s2,s3=0,0,0
    cl1,cl2,cl3=0,0,0
    d1,d2=0,0
    d1=a1[0]+b1[1]+c1[2]
    d2=a1[2]+b1[1]+c1[0]
    for i in range(3):
      s1=s1+a1[i] 
      s2=s2+b1[i]
      s3=s3+c1[i]
      cl1=a1[i]+b1[i]+c1[i]
      if(cl1==3 or s1==3 or s2==3 or s3==3 or d1==3 or d2==3):
        flag=1 
        break
if(flag==0):
  print("No")
else:
  print("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 x in b:
    for i in range(3):
        for j in range(3):
            if a[i][j] == x:
                a[i][j] = 'x'
for x in range(3):
    if (a[x][0] == a[x][1] == a[x][2] == 'x') or (a[0][x] == a[1][x] == a[2][x] == 'x'):
        print('Yes')
        exit()
if (a[0][0] == a[1][1] == a[2][2] == 'x') or (a[0][2] == a[1][1] == a[2][0] == 'x'):
    print('Yes')
    exit()
print('No')

Submission status: Accepted

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

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

for j in range(N):
  if B[j] in A:
    A[A.index(B[j])] = 0
ans = 'No'

for k in range(3):
  if A[k] == A[k+3] == A[k+6]:
    ans = 'Yes'
  elif A[3*k] == A[3*k+1] == A[3*k+2]:
    ans = 'Yes'
  elif A [0] == A[4] == A[8]:
    ans = 'Yes'
  elif A [2] == A[4] == A[6]:
    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())
b = []
for i in range(N):
    inputItem = int(input())
    b.append(inputItem)
check = {'first':[False,False,False],'second':[False,False,False],'third':[False,False,False]}
for j in b:
    if j in A1:
        pos = A1.index(j)
        check['first'][pos] = True
    elif j in A2:
        pos = A2.index(j)
        check['second'][pos] = True
    elif j in A3:
        pos = A3.index(j)
        check['third'][pos] = True

bingo = False
for k in range(3):
    if check['first'][k]==check['second'][k]==check['third'][k]==True:
        bingo = True
        break
if check['first'][0]==check['first'][1]==check['first'][2]==True:
    bingo = True
elif check['second'][0]==check['second'][1]==check['second'][2]==True:
    bingo = True
elif check['third'][0]==check['third'][1]==check['third'][2]==True:
    bingo = True
if check['first'][0]==check['second'][1]==check['third'][2]==True or check['first'][2]==check['second'][1]==check['third'][0]==True:
    bingo = True
if bingo:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#B
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

N = int(input())
b = []
for i in range(N):
    b.append(int(input()))
bingo = False
if A[0] in b:
    if A[1] in b:
        if A[2] in b:
            bingo = True

if B[0] in b:
    if B[1] in b:
        if B[2] in b:
            bingo = True


if C[0] in b:
    if C[1] in b:
        if C[2] in b:
            bingo = True

if A[0] in b:
    if B[1] in b:
        if C[2] in b:
            bingo = True


if A[2] in b:
    if B[1] in b:
        if C[0] in b:
            bingo = True

if A[0] in b:
    if B[0] in b:
        if C[0] in b:
            bingo = True

if A[1] in b:
    if B[1] in b:
        if C[1] in b:
            bingo = True

if A[2] in b:
    if B[2] in b:
        if C[2] in b:
            bingo = True

if bingo == False:
    print('No')
else:
    print('Yes')

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_list = []
count_list = []

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

for i in range(3):
    for j in range(3):
        for b in b_list:
            if a[i][j] == b:
                count_list.append(str(i) + str(j))

if ((("00" in count_list) and ("01" in count_list) and ("02" in count_list)) or
   (("10" in count_list) and ("11" in count_list) and ("12" in count_list)) or
   (("20" in count_list) and ("21" in count_list) and ("22" in count_list))):
        print("Yes")
elif ((("00" in count_list) and ("10" in count_list) and ("20" in count_list)) or
   (("01" in count_list) and ("11" in count_list) and ("21" in count_list)) or
   (("02" in count_list) and ("12" in count_list) and ("22" in count_list))):
        print("Yes")
elif ((("00" in count_list) and ("11" in count_list) and ("22" in count_list)) or
   (("02" in count_list) and ("11" in count_list) and ("20" in count_list))):
        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):
    c = int(input())
    b.append(c)
ref = [[0]*3 for i in range(3)]
for i in b:
    if i in a1:
        j = a1.index(i)
        ref[0][j] = 1
    elif i in a2:
        j = a2.index(i)
        ref[1][j] = 1
    elif i in a3:
        j = a3.index(i)
        ref[2][j] = 1
    else: pass

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

Submission status: Accepted

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

answers = []
for _ in range(3):
  answers.append([False for _ in range(3)])

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

for number in numbers:
  for y in range(3):
    # 同じ列に複数個要素が含まれている場合ができていない
    if number in A[y]:
      answers[y][A[y].index(number)] = True 

flg = False

# たてチェック
for i in range(3):
  if answers[0][i] and answers[1][i] and answers[2][i]:
    flg = True

# 横チェック
for i in range(3):
  if answers[i][0] and answers[i][1] and answers[i][2]:
    flg = True

# 斜めチェック
if answers[0][0] and answers[1][1] and answers[2][2]:
  flg = True

if answers[2][0] and answers[1][1] and answers[0][2]:
  flg = True

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

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
a = []
for _ in range(3):
  temp = list(map(int,input().split()))
  a.append(temp)
  
m1 = dd(int)
n = int(input())

for _ in range(n):
  temp = int(input())
  m1[temp]+=1
  
cnt=0
flag=0
for i in range(3):
  cnt=0
  for j in range(3):
    if m1[a[i][j]]==1:
      cnt+=1
  if cnt==3:
    print("Yes")
    flag=1
    break

if flag==0:
  for i in range(3):
    cnt=0
    for j in range(3):
      if m1[a[j][i]]==1:
        cnt+=1
        
    if cnt==3:
      print("Yes")
      flag=1
      break
      
if flag==0:
  cnt=0
  for i in range(3):
    if m1[a[i][i]]==1:
      cnt+=1
  if cnt==3:
    print("Yes")
    flag=1
    
if flag==0:
  cnt=0;j=2
  for i in range(3):
    if m1[a[i][j]]==1:
      cnt+=1
    j-=1
  if cnt==3:
    print("Yes")
    flag=1
    
if flag==0:
  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(len(b)):
    for j in range(len(a)):
        for k in range(3):
            if b[i]==a[j][k]:
                a[j][k]='o'
ans=0
for i in range(3):
    if a[i][0]=='o' and a[i][1]=='o' and a[i][2]=='o':
        ans+=1
    if a[0][i]=='o' and a[1][i]=='o' and a[2][i]=='o':
        ans+=1
if a[0][0]=='o' and a[1][1]=='o' and a[2][2]=='o':
    ans+=1
if a[0][2]=='o' and a[1][1]=='o' and a[2][0]=='o':
    ans+=1
if ans>=1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

a_true = [[False for i in range(3)] for j in range(3)]

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

#print(a_true)
#exit()
                
for i in range(3):
    for j in range(3):
        if a_true[i][j] == False:
            bingo = False
            break
    if bingo == True:
        #print(i,j)
        print('Yes')
        exit()
    bingo = True

bingo = True

for i in range(3):
    for j in range(3):
        if a_true[j][i] == False:
            bingo = False
            break
    if bingo == True:
        print('Yes')
        exit()
    bingo = True

if a_true[1][1] == True:
    if a_true[0][0] == True:
        if a_true[2][2] == True:
            print('Yes')
            exit()
    elif a_true[0][2] == True:
        if a_true[2][0] == True:
            print('Yes')
            exit()
else:
    print('No')
    exit()

print('No')

Submission status: Accepted

Solution code:


A_List_1 = list(map(int,input().split()))
A_List_2 = list(map(int,input().split()))
A_List_3 = list(map(int,input().split()))



N = int(input())
#B_List = []
for i in range(N):
    n = int(input())
    for j in range(3):
        if n == A_List_1[j]:
            A_List_1[j] = 0
        if n == A_List_2[j]:
            A_List_2[j] = 0
        if n == A_List_3[j]:
            A_List_3[j] = 0


sum_1 = A_List_1[0] + A_List_1[1] + A_List_1[2]
sum_2 = A_List_2[0] + A_List_2[1] + A_List_2[2]
sum_3 = A_List_3[0] + A_List_3[1] + A_List_3[2]
naname_1 = A_List_1[0] + A_List_2[1] + A_List_3[2]
naname_2 = A_List_1[2] + A_List_2[1] + A_List_3[0]
tate_0 = A_List_1[0] + A_List_2[0] + A_List_3[0]
tate_1 = A_List_1[1] + A_List_2[1] + A_List_3[1]
tate_2 = A_List_1[2] + A_List_2[2] + A_List_3[2]

if sum_1 == 0 or sum_2 == 0 or sum_3 == 0 or naname_1 == 0 or naname_2 == 0 or tate_0 == 0 or tate_1 == 0 or tate_2 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

#print(A[0][0])

A_new = []
for bi in b:
  #print(bi)
  for i in range(3):
    #print(A[1][1])
    A_ = [0 if bi==A[i][j] else A[i][j] for j in range(3)]
    #print(A_)
    A[i] = A_

import numpy as np
A = np.array(A)
t = np.sum(A, axis=0)
y = np.sum(A, axis=1)
n1 = A[0][0]+A[1][1]+A[2][2]
n2 = A[0][2]+A[1][1]+A[2][0]

if 0 in t:
  print('Yes')
elif 0 in y:
  print('Yes')
elif n1==0 or n2==0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
from itertools import product

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

N = int(input())

B = []
for _ in range(N):
    b = int(input())
    for i, j in product(range(3), repeat=2):
        if A1[i][j] == b:
            A1[i][j] = 0
            continue

A2 = [
    [A1[0][0], A1[1][0], A1[2][0]],
    [A1[0][1], A1[1][1], A1[2][1]],
    [A1[0][2], A1[1][2], A1[2][2]]
]

A3 = [
    [A1[0][0], A1[1][1], A1[2][2]],
    [A1[2][0], A1[1][1], A1[0][2]]
]

AA = A1 + A2 + A3

R = 'No'
for aa in AA:
    if sum(aa) == 0:
        R = 'Yes'
        break

print(R)

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):
    c=int(input())
    b.append(c)
flag=False
tmp1=0
tmp2=0
tmp3=0
for i in range(3):
    for j in range(N):
        if b[j]==a1[i]:
            tmp1+=1
        if b[j]==a2[i]:
            tmp2+=1
        if b[j]==a3[i]:
            tmp3+=1
if tmp1==3:
    flag=True
if tmp2==3:
    flag=True
if tmp3==3:
    flag=True
tmp=0
for i in range(3):
    tmp=0
    for j in range(N):
        if b[j]==a1[i]:
            tmp+=1
        if b[j]==a2[i]:
            tmp+=1
        if b[j]==a3[i]:
            tmp+=1
    if tmp==3:
        flag=True
tmp=0
for i in range(N):
    if b[i]==a1[0]:
        tmp+=1
    if b[i]==a2[1]:
        tmp+=1
    if b[i]==a3[2]:
        tmp+=1
if tmp==3:
    flag=True
tmp=0
for i in range(N):
    if b[i]==a1[2]:
        tmp+=1
    if b[i]==a2[1]:
        tmp+=1
    if b[i]==a3[0]:
        tmp+=1
if tmp==3:
    flag=True
if flag:
    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())
b = []
flag = 0
for i in range(n):
    b.append(int(input()))
for i in range(n):
    if b[i] in a[0]:
        a[0][a[0].index(b[i])]=0
    elif b[i] in a[1]:
        a[1][a[1].index(b[i])]=0
    elif b[i] in a[2]:
        a[2][a[2].index(b[i])]=0
if a[0][0] == a[0][1] == a[0][2] == 0:
    print('Yes')
elif  a[1][0] == a[1][1] == a[1][2] == 0:
    print('Yes')
elif  a[2][0] == a[2][1] == a[2][2] == 0:
    print('Yes')
elif  a[0][0] == a[1][0] == a[2][0] == 0:
    print('Yes')
elif  a[0][1] == a[1][1] == a[2][1] == 0:
    print('Yes')
elif  a[0][2] == a[1][2] == a[2][2] == 0:
    print('Yes')
elif  a[0][0] == a[1][1] == a[2][2] == 0:
    print('Yes')
elif  a[0][2] == a[1][1] == a[2][0] == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
list1 = []
for x in range(3):
    list1.append([int(i)for i in input().split()])
n = int(input())
indices = []
for x in range(n):
    val = int(input())
    if val in list1[0]:
        indices.append([list1[0].index(val),0])
    elif val in list1[1]:
        indices.append([list1[1].index(val),1])
    elif val in list1[2]:
        indices.append([list1[2].index(val),2])
    else:
        indices.append(-1)
if [0,0] in indices and [0,1] in indices and [0,2] in indices:
    print("Yes")
elif [1,0] in indices and [1,1] in indices and [1,2] in indices:
    print("Yes")
elif [2,0] in indices and [2,1] in indices and [2,2] in indices:
    print("Yes")
elif [0,0] in indices and [1,0] in indices and [2,0] in indices:
    print("Yes")
elif [0,1] in indices and [1,1] in indices and [2,1] in indices:
    print("Yes")
elif [0,2] in indices and [1,2] in indices and [2,2] in indices:
    print("Yes")
elif [0,0] in indices and [1,1] in indices and [2,2] in indices:
    print("Yes")
elif [0,2] in indices and [1,1] in indices and [2,0] in indices:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a = []
for i in range(3):
    i = list(map(int, input().split()))
    a.append(i)
n = int(input())
b = [int(input()) for i 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] = -100

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

if a[0][0] == a[1][1] == a[2][2] == -100:
    print("Yes")
    exit(0)
if a[0][2] == a[1][1] == a[2][0] == -100:
    print("Yes")
    exit(0)

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)]
han=[]
for i in range(3):
    for j in range(3):
        for k in range(N):
            if A[i][j]==B[k]:
                A[i][j]=0
if A[0][0]==A[0][1]==A[0][2]==0 or A[1][0]==A[1][1]==A[1][2]==0 or A[2][0]==A[2][1]==A[2][2]==0:
    print("Yes")
    exit()
if A[0][0]==A[1][0]==A[2][0]==0 or A[0][1]==A[1][1]==A[2][1]==0 or A[0][2]==A[1][2]==A[2][2]==0:
    print("Yes")
    exit()
if A[0][0]==A[1][1]==A[2][2]==0 or A[0][2]==A[1][1]==A[2][0]:
    print("Yes") 
    exit()
print("No")

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)






def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
     
#input
"""
def resolve():
    N,M=pin()
    ans=[1]+[0]*(N-1)
    check=[False]*3
    for i in range(M):
        p,m=pin()
        if p==1 and m!=0:
            if check[p-1]==False:
                ans[0]=m
                check[p-1]=True
            else:
                if ans[0]!=m:
                    print(-1)
                    return
        elif p==1 and m==0:
            print(-1)
            return
        elif p!=1:
            if check[p-1]==False:
                ans[p-1]=m
                check[p-1]=True
            else:
                if ans[p-1]!=m:
                    print(-1)
                    return
    a=""
    for i in range (M):
        a+=str(ans[i])
    print(int(a))
    #print(hint)
    
    #print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
#if __name__=="__main__":resolve()
"""
def resolve():
    bingo=[list(pin()) for i in range(3)]
    check=[[0]*3 for j in range(3)]
    N=int(input())
    for i in range(N):
        b=int(input())
        for h in range(3):
            for w in range(3):
                if bingo[h][w]==b:
                    check[h][w]=1
    for i in range(3):
        a=check[i][0]*check[i][1]*check[i][2]
        b=check[0][i]*check[1][i]*check[2][i]
        if a or b:
            print("Yes")
            return
    c,d=1,1
    for i in range(3):
        c*=check[i][i]
        d*=check[i][2-i]
    if c or d:
        print("Yes")
        return
    print("No")
    return
"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""

import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30"""
        output = """Yes"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """41 7 46
26 89 2
78 92 8
5
6
45
16
57
17"""
        output = """No"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34"""
        output = """Yes"""
        self.assertIO(input, output)

if __name__=="__main__":resolve()