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:
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 _ in range(n)]

for i in b:
    for j in range(3):
        if a1[j] == i:
            a1[j] = 0
        if a2[j] == i:
            a2[j] = 0
        if a3[j] == i:
            a3[j] = 0

for i in range(3):
    if a1[i] == a2[i] == a3[i] == 0:
        print('Yes')
        exit()

if a1[0] == a1[1] == a1[2] == 0:
    print('Yes')
    exit()
if a2[0] == a2[1] == a2[2] == 0:
    print('Yes')
    exit()
if a3[0] == a3[1] == a3[2] == 0:
    print('Yes')
    exit()

if a1[0] == a2[1] == a3[2] == 0:
    print('Yes')
    exit()
if a3[0] == a2[1] == a1[2] == 0:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
A=[list(map(int,input().split())) for _  in range(3)]
N=int(input())
b=[int(input()) for _ in range(N)]
l=[[0 for _ in range(3)] for _ in range(3)]
flag=0
#print(A,b,l)

for i in range(N):
    for j in range(3):
        for k in range(3):
            if b[i]==A[j][k]:
                l[j][k]=1
#print(l)
for i in range(3):
    if (l[i][0]+l[i][1]+l[i][2])==3:
        flag=1
        break
    if (l[0][i]+l[1][i]+l[2][i])==3:
        flag=1
        break
if (l[0][0]+l[1][1]+l[2][2]==3)or(l[2][0]+l[1][1]+l[0][2]==3):
    flag=1
if flag==0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys
# list(map(int,input().split()))

#n = int(input())

#print((n+1)//2)

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

for j in range(3):
  if a[j][0] in b and a[j][1] in b and a[j][2] in b:
    print('Yes')
    sys.exit()
  
for j in range(3):
  if a[0][j] in b and a[1][j] in b and a[2][j] in b:
    print('Yes')
    sys.exit()

if a[0][0] in b and a[1][1] in b and a[2][2] in b:
  print('Yes')
  sys.exit()

if a[0][2] in b and a[1][1] in b and a[2][0] in b:
  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)]

lines = [set(x) for x in a] + [set(x) for x in zip(*a)] + [set([a[0][0], a[1][1], a[2][2]]), set([a[0][2], a[1][1], a[2][0]])]
bs = set(b)

if any(line.issubset(bs) for line in lines):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
hoge=[0,0,0,0,0,0,0,0,0]
for i in range(3):
  a,b,c=map(int,input().split())
  hoge[i*3],hoge[i*3+1],hoge[i*3+2]=a,b,c
huga=[0,0,0,0,0,0,0,0,0]


n=int(input())
for i in range(n):
  a=int(input())
  for j in range(9):
    if(hoge[j]==a):
      huga[j]+=1

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

Submission status: Accepted

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

for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            A[i][j] = 'X'

if A[0][0] == A[1][1] == A[2][2] == 'X':
    print('Yes')
    exit()

if A[0][2] == A[1][1] == A[2][0] == 'X':
    print('Yes')
    exit()

if A[0][0] == A[0][1] == A[0][2] == 'X':
    print('Yes')
    exit()

if A[1][0] == A[1][1] == A[1][2] == 'X':
    print('Yes')
    exit()

if A[2][0] == A[2][1] == A[2][2] == 'X':
    print('Yes')
    exit()

# t
if A[0][0] == A[1][0] == A[2][0] == 'X':
    print('Yes')
    exit()
if A[0][1] == A[1][1] == A[2][1] == 'X':
    print('Yes')
    exit()
if A[0][2] == A[1][2] == A[2][2] == 'X':
    print('Yes')
    exit()
print('No')

Submission status: Accepted

Solution code:
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
N = int(input())
b = list()
flag = False
for i in range(N):
  b.append(int(input()))
for i in range(N):
  for j in range(3):
    if b[i] == A[j]:
      A[j] = 0
for i in range(N):
  for j in range(3):
    if b[i] == B[j]:
      B[j] = 0
for i in range(N):
  for j in range(3):
    if b[i] == C[j]:
      C[j] = 0
for i in range(3):
  if A[i] == B[i] == C[i] ==0:
    flag = True
if A[0] == A[1] == A[2] == 0:
  flag = True
if B[0] == B[1] == B[2] == 0:
  flag = True  
if C[0] == C[1] == C[2] == 0:
  flag = True
  
if A[0] == B[1] == C[2] ==0:
  flag = True
if C[0] == B[1] == A[2] ==0:
  flag = True

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

Submission status: Accepted

Solution code:
import sys
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
A = [A1, A2, A3]
n = int(input())
for i in range(n):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if A[j][k] == b:
        A[j][k] = 0
#print(A)
#横
for i in range(3):
  if A[i].count(0) == 3:
    print("Yes")
    sys.exit()
#縦
for i in range(3):
  if A1[i] == 0 and A2[i] == 0 and A3[i] == 0:
    print("Yes")
    sys.exit()
#斜め
if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
    print("Yes")
    sys.exit()
if A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0:
    print("Yes")
    sys.exit()

print("No")

Submission status: Accepted

Solution code:
a = []
for _ in range(3):
    a.append([int(x) for x in input().split()])
n = int(input())
b = []
for _ in range(n):
    b.append(int(input()))
for i, aa in enumerate(a):
    for j, aaa in enumerate(aa):
        if aaa in b:
            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[2][0] == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
class Bar:
    def __init__(self, a, b, c):
        self.a = a
        self.b = b
        self.c = c
        self.left = False
        self.center = False
        self.right = False

    def open(self, v):
        if v == self.a:
            self.left = True
        elif v == self.b:
            self.center = True
        elif v == self.c:
            self.right = True

    def bingo(self):
        return all([self.left, self.right, self.center])


top = Bar(*map(int, input().split()))
center = Bar(*map(int, input().split()))
bottom = Bar(*map(int, input().split()))
for x in range(int(input())):
    value = int(input())
    top.open(value)
    center.open(value)
    bottom.open(value)


def ok():
    print("Yes")
    exit()


if top.bingo() or center.bingo() or bottom.bingo():
    ok()

if top.left == center.left == bottom.left == True:
    ok()

if top.center == center.center == bottom.center == True:
    ok()

if top.right == center.right == bottom.right == True:
    ok()

if top.left == center.center == bottom.right == True:
    ok()

if top.right == center.center == bottom.left == True:
    ok()

print('No')

Submission status: Accepted

Solution code:
a = []

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

ans = [[0,0,0], [0,0,0], [0,0,0]]
for num_b in range(n):
    for i in range(3):
        for j in range(3):
            if b[num_b] == a[i][j]:
                ans[i][j] = 1

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

Submission status: Accepted

Solution code:
def main():
    A = []
    for _ in range(3):
        a1,a2,a3 = map(int, input().split()) 
        AA = [[a1,0],[a2,0],[a3,0]]
        A.append(AA)
    N = int(input())
    # print(A)

    for _ in range(N):
        b = int(input())
        for i in range(3):
            for j in range(3):
                if A[i][j][0] == b:
                    A[i][j][1] = 1
        
        # row
        for i in range(3):
            if 3 == sum([v[1] for v in A[i]]):
                print('Yes')
                return
        # column
        for j in range(3):
            if 3 == sum([a[j][1] for a in A]):
                print('Yes')
                return
        # cross
        if 3 == (A[0][0][1]+A[1][1][1]+A[2][2][1]):
            print('Yes')
            return
        if 3 == (A[0][2][1]+A[1][1][1]+A[2][0][1]):
            print('Yes')
            return

    print('No')
        

main()

Submission status: Accepted

Solution code:

r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))

#%%
N = int(input())
for _ in range(N):
    b = int(input())
    for i in range(3):
        if r1[i] == b:
            r1[i] = 0
        if r2[i] == b:
            r2[i] = 0
        if r3[i] == b:
            r3[i] = 0

#%%
flag = False
if sum(r1) == 0:
    flag = True
if sum(r2) == 0:
    flag = True
if sum(r3) == 0:
    flag = True
for i in range(3):
    if sum([r1[i], r2[i], r3[i]]) == 0:
        flag = True
if sum([r1[0], r2[1], r3[2]]) == 0:
    flag = True
if sum([r1[2], r2[1], r3[0]]) == 0:
    flag = True

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter
a_ls = []
_dict = {}
for i in range(3):
    a = [int(i) for i in sys.stdin.readline().split()]
    for j, _a in enumerate(a):
        _dict[_a] = [i, j]
    a_ls.append(a)
n = int(input())
i_ls = Counter()
j_ls = Counter()
res = []
for i in range(n):
    b = int(input())
    _b = _dict.get(b)
    if _b is not None:
        res.append(_b)
flg = False
for i in range(3):
    if [i,0] in res and  [i,1] in res and [i,2] in res:
        flg = True
        break
    if [0,i] in res and [1,i] in res and [2,i] in res:
        flg = True
        break
if [0,0] in res and [1,1] in res and [2,2] in res:
    flg = True
if [2,0] in res and [1,1] in res and [0,2] in res:
    flg = True
if flg:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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


n=int(input())

for i in range(n):
    b=int(input())
    if b in a:
        a[a.index(b)]=-1
        
check=[[0,1,2],[3,4,5],[6,7,8],
       [0,3,6],[1,4,7],[2,5,8],
       [0,4,8],[2,4,6]]

flag=False
for c in check:
    if a[c[0]]==-1 and a[c[1]]==-1 and a[c[2]] ==-1:
        flag=True
    if flag:
        break
    
if flag:
    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())
for i in range(n):
    num = int(input())
    for j in range(3):
        for k in range(3):
            if num == bingo[j][k]:
                bingo[j][k] = 0
for i in range(3):
    if bingo[i] == [0, 0, 0]:
        print("Yes")
        exit()
for i in range(3):
    cnt = 0
    for j in range(3):
        cnt += bingo[j][i]
    if cnt == 0:
        print("Yes")
        exit()
if bingo[0][0] == bingo[1][1] == bingo[2][2] == 0:
    print("Yes")
    exit()
if bingo[0][2] == bingo[1][1] == bingo[2][0] == 0:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
import numpy as np
A1 = [int(i) for i in input().split()]
A2 = [int(i) for i in input().split()]
A3 = [int(i) for i in input().split()]
A = np.array([A1,A2,A3])
N = int(input())
B = []
for i in range(N):
  B.append(int(input()))
#print(A1,A2,A3,A,N,B)

start = np.zeros((3,3))
flag = "No"
for i in range(3):
  for j in range(3):
    if A[i,j] in B:
      start[i,j] = 1
for i in range(3):
  if sum(start[i]) == 3:
    flag = "Yes"
  elif sum(start[:,i])==3:
    flag = "Yes"

if start[0,0]==1 and start[1,1]==1 and start[2,2]==1:
  flag = "Yes"
if start[2,0]==1 and start[1,1]==1 and start[0,2]==1:
  flag = "Yes"
print(flag)

Submission status: Accepted

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

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

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

print("Yes" if flg==1 else "No")

Submission status: Accepted

Solution code:
bingo = []
card = [[0,0,0],[0,0,0],[0,0,0]]
ans = 0
for i in range(3):
    A = list(map(int,input().split()))
    bingo.append(A)
N = int(input())
for i in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == b:
                card[i][j] += 1
if card[0][0]+card[0][1]+card[0][2] >= 3:
    ans += 1
if card[0][0]+card[1][0]+card[2][0] >= 3:
    ans += 1
if card[1][0]+card[1][1]+card[1][2] >= 3:
    ans += 1
if card[2][0]+card[2][1]+card[2][2] >= 3:
    ans += 1
if card[0][1]+card[1][1]+card[2][1] >= 3:
    ans += 1
if card[0][2]+card[1][2]+card[2][2] >= 3:
    ans += 1
if card[0][0]+card[1][1]+card[2][2] >= 3:
    ans += 1
if card[0][2]+card[1][1]+card[2][0] >= 3:
    ans += 1
if ans > 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A=[[-1 for i in range(3)] for j in range(3)]

for i in range(3):
    A[i] = map(int, raw_input().split())

#print A

N = int(raw_input())
B = [-1 for i in range(N)]

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

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

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

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

Submission status: Accepted

Solution code:
A11, A12, A13 = map(int, input().split())
A21, A22, A23 = map(int, input().split())
A31, A32, A33 = map(int, input().split())

N = int(input())
A = [0]*N
for i in range(N):
    A[i] = int(input())

for i in A:
    if A11 == i:
        A11 = 0
    elif A12 == i:
        A12 = 0
    elif A13 == i:
        A13 = 0
    elif A21 == i:
        A21 = 0
    elif A22 == i:
        A22 = 0
    elif A23 == i:
        A23 = 0
    elif A31 == i:
        A31 = 0
    elif A32 == i:
        A32 = 0
    elif A33 == i:
        A33 = 0

ans = 0
if A11+A12+A13==0:
    ans += 1
if A21+A22+A23==0:
    ans += 1
if A31+A32+A33==0:
    ans += 1
if A11+A21+A31==0:
    ans += 1
if A12+A22+A32==0:
    ans += 1
if A13+A23+A33==0:
    ans += 1
if A11+A22+A33==0:
    ans += 1
if A13+A22+A31==0:
    ans += 1
    
if ans == 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys

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

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

for i in range(3):
    for j in range(3):
        if A[i][j] != -1:
            break
    else:
        print('Yes')
        sys.exit(0)

for i in range(3):
    for j in range(3):
        if A[j][i] != -1:
            break
    else:
        print('Yes')
        sys.exit(0)

for i in range(3):
    if A[i][i] != -1:
        break
else:
    print('Yes')
    sys.exit(0)

for i in range(3):
    if A[i][2-i] != -1:
        break
else:
    print('Yes')
    sys.exit(0)

print('No')

Submission status: Accepted

Solution code:
#  --*-coding:utf-8-*--


def bingo(M):
    for i in range(3):
        if M[i][0] and M[i][1] and M[i][2]:
            return True
    
        if M[0][i] and M[1][i] and M[2][i]:
            return True

    if (M[0][0] and M[1][1] and M[2][2] or
        M[0][2] and M[1][1] and M[2][0]):
        return True

    return False


P = {}

for i in range(3):
    for j, a in enumerate(map(int, input().split())):
        P[a] = (i,j)


N = int(input())
M = [[False]*3 for _ in range(3)]

for _ in range(N):
    b = int(input())
    if b in P:
        p = P[b]
        M[p[0]][p[1]] = True

print('Yes' if bingo(M) else 'No')

Submission status: Accepted

Solution code:
a = [[0 for i in range(3)] for j in range(3)]
s = [[False for i in range(3)] for j in range(3)]

for i in range(3):
    t = list(map(int, input().split()))
    for j in range(3):
        a[i][j] = t[j]

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] = True

ans = 'No'
# yoko
if s[0][0] and s[0][1] and s[0][2]: ans = 'Yes'
if s[1][0] and s[1][1] and s[1][2]: ans = 'Yes'
if s[2][0] and s[2][1] and s[2][2]: ans = 'Yes'
# tate
if s[0][0] and s[1][0] and s[2][0]: ans = 'Yes'
if s[0][1] and s[1][1] and s[2][1]: ans = 'Yes'
if s[0][2] and s[1][2] and s[2][2]: ans = 'Yes'
# naname
if s[0][0] and s[1][1] and s[2][2]: ans = 'Yes'
if s[0][2] and s[1][1] and s[2][0]: ans = 'Yes'

print(ans)

Submission status: Accepted

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

B = []
while True:
    try:
        B.append(int(input()))
    except:
        break;

for i in range(3):
  if (A[0][i] in B and A[1][i] in B and A[2][i] in B) or (A[i][0] in B and A[i][1] in B and A[i][2] in B):
    print("Yes")
    import sys; sys.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")
  import sys; sys.exit()

print("No")

Submission status: Accepted

Solution code:
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    a = [list(input().split()) for i in range(3)]
    n = int(input())
    b = [input() for i in range(n)]

    for i in range(3):
        for j in range(3):
            if a[i][j] in b:
                a[i][j] = "o"

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	A = []
	S = [[False,False,False] for i in range(3)]
	for i in range(3):
		a=LI()
		A.append(a)
	N = II()
	for _ in range(N):
		b = II()
		for i in range(3):
			for j in range(3):
				if(A[i][j]==b):
					S[i][j]=True
	if((S[0][2]==S[1][2]==S[2][2]==True) or(S[0][1]==S[1][1]==S[2][1]==True) or(S[0][0]==S[1][0]==S[2][0]==True) or(S[0][0]==S[0][1]==S[0][2]==True) or (S[1][0]==S[1][1]==S[1][2]==True) or (S[2][0]==S[2][1]==S[2][2]==True) or (S[0][0]==S[1][1]==S[2][2]==True) or (S[2][0]==S[1][1]==S[0][2]==True)):
		print("Yes")
	else:
		print("No")

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    a1 = [int(i) for i in input().split()]
    a2 = [int(i) for i in input().split()]
    a3 = [int(i) for i in input().split()]
    a =[]
    a.extend(a1)
    a.extend(a2)
    a.extend(a3)
    n = int(input())

    for  i in range(n):
        b = int(input())
        if b in a:
            a[a.index(b)] = 0
    ans = []
    ans.append(a[0] + a[1] + a[2] )
    ans.append(a[3] + a[4] + a[5] )
    ans.append(a[6] + a[7] + a[8] )

    ans.append(a[0] + a[3] + a[6] )
    ans.append(a[1] + a[4] + a[7] )
    ans.append(a[2] + a[5] + a[8] )

    ans.append(a[0] + a[4] + a[8] )
    ans.append(a[2] + a[4] + a[6] )

    if 0 in ans:
        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())
    for i in range(3):
        if a1[i]==b:
            a1[i]=0
    for i in range(3):
        if a2[i]==b:
            a2[i]=0
    for i in range(3):
        if a3[i]==b:
            a3[i]=0
            
flag = 0
if sum(a1)==0:
    flag = 1
if sum(a2)==0:
    flag = 1
if sum(a3)==0:
    flag = 1
    
if a1[0]+a2[0]+a3[0]==0:
    flag = 1
if a1[1]+a2[1]+a3[1]==0:
    flag = 1
if a1[2]+a2[2]+a3[2]==0:
    flag = 1
    
    
if a1[0]+a2[1]+a3[2]==0:
    flag = 1
if a1[2]+a2[1]+a3[0]==0:
    flag = 1
    
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np

a_matrix = []
for i in range(3):
    a_matrix.extend(list(map(int,input().split())))
flag_list = [0 for i in range(9)]

N = int(input())
for i in range(N):
    b = int(input())
    if b in a_matrix:
        pos = a_matrix.index(b)
        flag_list[pos] = 1

ans = 'No'
flag_matrix = np.array(flag_list).reshape(3,3)
for i in range(3):
    c = sum(flag_matrix[:,i])
    d = sum(flag_matrix[i,:])
    if (c==3 or d==3):
        ans = 'Yes'

c = flag_matrix[0,0]+flag_matrix[1,1]+flag_matrix[2,2]
d = flag_matrix[0,2]+flag_matrix[1,1]+flag_matrix[2,0]
if (c==3 or d==3):
    ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

A = []
for i in range(3):
    a1, a2, a3 = (input_nums())
    A.append(a1)
    A.append(a2)
    A.append(a3)

def my_index(l, x, default=False):
    return l.index(x) if x in l else default

n = int(input())
for i in range(n):
    b = int(input())
    idx = my_index(A, b, -1)
    if idx == -1:
        continue
    A[idx] = 0

bingo = False
# 横のチェック
for i in range(3):
    if sum(A[i*3:i*3+3]) == 0:
        bingo = True
        break
# 縦のチェック
for i in range(3):
    if A[i] + A[i+3] + A[i+6] == 0:
        bingo=True
        break

# 斜めのチェック
if A[0] + A[4] + A[8] == 0:
    bingo = True
if A[2] + A[4] + A[6] == 0:
    bingo = True

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

Submission status: Accepted

Solution code:
import sys
a=[ [int(i) for i in input().split() ]for _ in range(3)]
#print(a)
n=int(input())
mat=[([0]*3) for _ in range(3) ]
#print(mat)
b=[]
for _ in range(n):
  x=int(input())
  for i in range(3):
    for j in range(3):
      if x==a[i][j] and mat[i][j]==0:
        mat[i][j]=1
#print(mat)
flag=False
for i in range(3):
  s=0
  for j in range(3):
    s+=mat[i][j]
  if s==3:
    print("Yes")
    sys.exit()
for j in range(3):
  s=0
  for i in range(3):
    s+=mat[i][j]
  if s==3:
    print("Yes")
    sys.exit()
if mat[0][0]+mat[1][1]+mat[2][2]==3 or mat[0][2]+mat[1][1]+mat[2][0]==3:
  print("Yes")
  sys.exit()
print("No")

Submission status: Accepted

Solution code:
# coding:utf-8

A_pairs = []
bs = []

for _ in range(3):
    As = list(map(int, input().split(' ')))
    A_pairs.append(As)
N = int(input())
for _ in range(N):
    b = int(input())
    bs.append(b)

for idx in range(3):
    A_pairs.append([A_pairs[0][idx], A_pairs[1][idx], A_pairs[2][idx]])

A_pairs.append([A_pairs[0][0], A_pairs[1][1], A_pairs[2][2]])
A_pairs.append([A_pairs[2][0], A_pairs[1][1], A_pairs[0][2]])

for As in A_pairs:
    if As[0] in bs and As[1] in bs and As[2] in bs:
        print('Yes')
        exit(0)
print('No')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
d = {}
for i in range(n):
    d[int(input())] = 1

cand = [
    [[0, 0], [0, 1], [0,2]],
    [[1,0],[1,1],[1,2]],
    [[2,0],[2,1],[2,2]],
    [[0,0],[1,0],[2,0]],
    [[0,1],[1,1],[2,1]],
    [[0,2],[1,2],[2,2]],
    [[0,0],[1,1],[2,2]],
    [[0,2],[1,1],[2,0]],
]

f = 0
for item in cand:
    t = 0
    for x, y in item:
        if a[x][y] in d:
            t += 1
    if t == 3:
        f = 1
if f:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a = [list(map(int,input().split())) 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 b == a[i][j]:
                a[i][j] = 0
for i in a:
    if sum(i) == 0:
        print('Yes')
        exit()
for i in range(3):
    sum_tate = a[0][i]+a[1][i]+a[2][i]
    if sum_tate == 0:
        print('Yes')
        exit()
if a[0][0]+a[1][1]+a[2][2] == 0:
    print('Yes')
    exit()
if a[0][2]+a[1][1]+a[2][0] == 0:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

TF = [[False, False, False] for _ in range(3)]
for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                TF[i][j] = True

TF = (np.array(TF)).flatten()

C = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]])

for a, b, c in C:
    if TF[a] and TF[b] and TF[c]:
        print('Yes')
        sys.exit()

else:
    print('No')

Submission status: Accepted

Solution code:
#B
import numpy as np
a = np.zeros((4,4),np.int32)
A = np.zeros((4,4),np.int32)
a0 = list(map(int, input().strip().split()))
a1 = list(map(int, input().strip().split()))
a2 = list(map(int, input().strip().split()))
a[1,1:4] = a0
a[2,1:4] = a1
a[3,1:4] = a2
N = int(input())
b = []
for n in range(N):
    b = int(input())

    for j in range(1,4):
        for i in range(1,4):
            if a[j][i] == b:
                A[j][i] = 1

if sum(A[1,:])==3 or sum(A[2,:])==3 or sum(A[3,:])==3 or sum(A[:,1])==3 or sum(A[:,2])==3 or sum(A[:,3])==3 or A[1][1] + A[2][2] + A[3][3]==3 or A[1][3] + A[2][2] + A[3][1]==3:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np
A = [list(map(int, input().split())) for _ in range(3)]
A = A[0]+A[1]+A[2]
N = int(input())
for _ in range(N):
    b = int(input())
    if b in A:
        A[A.index(b)] = -1

C = [A[:3], A[3:6], A[6:]]
C = np.array(C)

ans = "No"
for i in range(3):
    if (C[i] == -1).all():
        ans = "Yes"
    if (C[:, i] == -1).all():
        ans = "Yes"

if C[0][0] == C[1][1] == C[2][2] == -1:
    ans = "Yes"
if C[2][0] == C[1][1] == C[0][2] == -1:
    ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
A = [[0 for i in range(3)]for i2 in range(3)]
c = [[False for i in range(3)]for i2 in range(3)]
A[0] = list(map(int,input().rstrip().split(" ")))
A[1] = list(map(int,input().rstrip().split(" ")))
A[2] = list(map(int,input().rstrip().split(" ")))
int_inp = int(input())
s = 0
for i in range(int_inp):
  s = int(input())
  for i2 in range(9):
    if A[int(i2 / 3)][i2 % 3] == s:
      c[int(i2 / 3)][i2 % 3] = True
ans = False
for i in range(3):
  if c[i][0] and c[i][1] and c[i][2]:ans = True
for i in range(3):
  if c[0][i] and c[1][i] and c[2][i]:ans = True
if c[0][0] and c[1][1] and c[2][2]:ans = True
if c[2][0] and c[1][1] and c[0][2]:ans = True
if ans:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

n=int(input())
for i in range(n):
    b=int(input())
    for g in range(3):
        for l in range(3):
            if b==a[g][l]:
                c[g][l]=True

if c[0][0] is True and c[1][1] is True and c[2][2] is True:
    print("Yes")
    exit()

if c[0][2] is True and c[1][1] is True and c[2][0] is True:
    print("Yes")
    exit()

for i in range(3):
    if c[i]==[True]*3:
        print("Yes")
        exit()

for i in range(3):
    if c[0][i] is True and c[1][i] is True and c[2][i] is True:
        print("Yes")
        exit()
print("No")