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:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: "List[List[int]]", N: int, B: "List[int]"):
    exists = []
    # fill
    for b in B:
        for i, row in enumerate(A):
            for j, col in enumerate(row):
                if b == col:
                    exists.append((i, j))
    bingo_pattern = (
        ((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),),
        ((2, 0), (1, 1), (0, 2),),
    )
    for bingo in bingo_pattern:
        ok = 0
        for pair in bingo:
            if pair in exists:
                ok += 1
            if ok == 3:
                print(YES)
                return

    print(NO)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = [
        [int(next(tokens)) for _ in range(3)] for _ in range(3)
    ]  # type: "List[List[int]]"
    N = int(next(tokens))  # type: int
    b = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(A, N, b)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

n=int(input())

for i in range(n):
  b=int(input())
  idx=np.where(A==b)
  if idx:
    A[idx]=0

yoko=0 in A.sum(axis=1)
tate=0 in A.sum(axis=0)
naname1=A[0,0]+A[1,1]+A[2,2]
naname2=A[0,2]+A[1,1]+A[2,0]

if yoko or tate or naname1*naname2==0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
A = [[] for _ in range(3)]

A[0] = list(map(int, input().split()))
A[1] = list(map(int, input().split()))
A[2] = list(map(int, input().split()))

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

if all(B[0]) or all(B[1]) or all(B[2]):
    print('Yes')
elif all([B[0][0], B[1][0], B[2][0]]) or all([B[0][1], B[1][1], B[2][1]]) or all([B[0][2], B[1][2], B[2][2]]):
    print('Yes')
elif all([B[0][0], B[1][1], B[2][2]]) or all([B[0][2], B[1][1], B[2][0]]):
    print('Yes')
else:
    print("No")

Submission status: Accepted

Solution code:
from sys import stdin

# read data
a_mat = []
for _ in range(3):
  a_mat.append([int(x) for x in stdin.readline().strip().split()])
n = int(stdin.readline().strip())
b_lst = []
for _ in range(n):
  b_lst.append(int(stdin.readline().strip()))
  
op_mat = []
for a in a_mat:
  op_mat.append([x in b_lst for x in a])
op_mat_t = list(map(list, zip(*op_mat)))
  
# tate
if(all(op_mat[0]) or all(op_mat[1]) or all(op_mat[2])):
  print("Yes")
# yoko
elif(all(op_mat_t[0]) or all(op_mat_t[1]) or all(op_mat_t[2])):
  print("Yes")
# naname
elif(all([op_mat[0][0], op_mat[1][1], op_mat[2][2]]) or all([op_mat[0][2], op_mat[1][1], op_mat[2][0]])):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
bingo=[]
karibingo=[]
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 j in range(3):
        for k in range(3):
            if bingo[j][k]==b:
                karibingo.append([j,k])
def bingohantei():
    count3 = 0
    if [0,2] in karibingo and [1,1] in karibingo and [2,0] in karibingo:
        return True
    for i in range(3):
        count=0
        count2=0
        if [i,i] in karibingo:
            count3+=1
        if count3==3:return True
        for j in range(3):
            if [i,j] in karibingo:
                count+=1
            if [j,i] in karibingo:
                count2+=1
            if count==3 or count2==3:return True
if bingohantei():
    print("Yes")
else:print("No")

Submission status: Accepted

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

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

ans = False
for i in range(3):
    if all(a[i][j] == 0 for j in range(3)) or all(a[j][i] == 0 for j in range(3)):
        ans = True
if a[0][0] == a[1][1] == a[2][2] or a[2][0] == a[1][1] == a[0][2]:
    ans = True

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

Submission status: Accepted

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

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

#bingo = False
for i in range(3):
  if card[i] == [0, 0, 0]:
    #bingo = True
    print("Yes")
    exit()
  elif [x[i] for x in card] == [0, 0, 0]:
    #bingo = True
    print("Yes")
    exit()
    
if [card[i][i] for i in range(3)] == [0, 0, 0]:
  #bingo = True
  print("Yes")
  exit()
elif [card[2-i][i] for i in range(3)] == [0, 0, 0]:
  #bingo = True
  print("Yes")
  exit()
else:
  #print("Yes" if bingo else "No")
  print("No")

Submission status: Accepted

Solution code:
def B():
    a = [list(map(int, input().split())) for i in range(3)]
    n = int(input())
    for b in (int(input()) for _ in range(n)):
        for i in range(3):
            for j in range(3):
                if a[i][j] == b:
                    a[i][j] = 1
    if ((a[0][0] == a[1][1] == a[2][2] == 1) or (a[0][2] == a[1][1] == a[2][0] == 1)):
        print('Yes')
        return
    for i in range(3):
        if all(a[i][j] == 1 for j in range(3)) or all(a[j][i] == 1 for j in range(3)):
            print('Yes')
            return
    print('No')
B()

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())
zennbu = {A11,A12,A13,A21,A22,A23,A31,A32,A33}
yoko1 = {A11,A12,A13}
yoko2 = {A21,A22,A23}
yoko3 = {A31,A32,A33}
tate1 = {A11,A21,A31}
tate2 = {A12,A22,A32}
tate3 = {A13,A23,A33}
naname1 = {A11,A22,A33}
naname2 = {A13,A22,A31}
N = int(input())
for i in range(N):
  b = int(input())
  if b in zennbu:
    yoko1.discard(b)
    yoko2.discard(b)
    yoko3.discard(b)
    tate1.discard(b)
    tate2.discard(b)
    tate3.discard(b)
    naname1.discard(b)
    naname2.discard(b)
if len(yoko1) ==0 or len(yoko2) ==0 or len(yoko3) ==0:
  print('Yes')
elif  len(tate1) ==0 or len(tate2) ==0 or len(tate3) ==0:
  print('Yes')
elif len(naname1) == 0 or len(naname2)==0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

for i in range(9):
  if a[i] in b:
    a[i] = 'x'
  else:
    next
if a[0]is a[1]is a[2] is 'x' or a[3]is a[4]is a[5]is 'x' or a[6]is a[7]is a[8]is 'x' or a[0]is a[3]is a[6]is 'x' or a[1]is a[4]is a[7]is 'x' or a[2]is a[5]is a[8]is 'x' or a[0]is a[4]is a[8]is 'x' or a[2]is a[4]is a[6]is 'x':
  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())

A = [[0,0,0],[0,0,0],[0,0,0]]

for _ in range(n):
    b = int(input())
    if b in A1:
        tmp = A1.index(b)
        A[0][tmp] = 1
    elif b in A2:
        tmp = A2.index(b)
        A[1][tmp] = 1
    elif b in A3:
        tmp = A3.index(b)
        A[2][tmp] = 1
'''
if A[0][0] + A[0][1] + A[0][2] == 3 or A[1][0] + A[1][1] + A[1][2] == 3 or A[2][0] + A[2][1] + A[2][2] == 3:
    print('Yes')
elif 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:
    print('Yes')
'''
ans = 'No'

for i in range(3):
    if A[0][i] == A[1][i] == A[2][i] == 1:
        ans = 'Yes'
    elif A[i][0] == A[i][1] == A[i][2]== 1:
        ans = 'Yes'
if A[0][0] + A[1][1] + A[2][2] == 3 or A[0][2] + A[1][1] + A[2][0] == 3:
    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())

A = [[0,0,0],[0,0,0],[0,0,0]]

for _ in range(n):
    b = int(input())
    if b in A1:
        tmp = A1.index(b)
        A[0][tmp] = 1
    elif b in A2:
        tmp = A2.index(b)
        A[1][tmp] = 1
    elif b in A3:
        tmp = A3.index(b)
        A[2][tmp] = 1

if A[0][0] + A[0][1] + A[0][2] == 3 or A[1][0] + A[1][1] + A[1][2] == 3 or A[2][0] + A[2][1] + A[2][2] == 3:
    print('Yes')
elif 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:
    print('Yes')
elif 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:
a = list(map(int,input().split()))
a += list(map(int,input().split()))
a += list(map(int,input().split()))
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))
index = 0
for i in a:
  if i in b:
    a[index] = 0
  else:
    next
  index += 1

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

Submission status: Accepted

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

n = int(input())
b = [int(input()) for _ in range(n)]
x = [[False, False, False] for _ in range(3)]

for i in range(n):
    for j in range(3):
        for k in range(3):
            if a[j][k] == b[i]:
                #print("b", x)
                x[j][k] = True
                #print("a", x)
                #print(a, b, a[j][k], b[i], x, j, k)



flag = False

for i in range(3):
    if x[i][0] and x[i][1] and x[i][2]:
        flag = True
    elif x[0][i] and x[1][i] and x[2][i]:
        flag = True

if x[0][0] and x[1][1] and x[2][2]:
    flag = True
elif x[2][0] and x[1][1] and x[0][2]:
    flag = True

#print(a, b, x)

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

Submission status: Accepted

Solution code:
import sys

# 再帰回数の制限
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7

def input():
    return sys.stdin.readline().strip()


import numpy as np

def main():
    A = []
    for i in range(3):
        A.extend(list(map(int, input().split())))

    N = int(input())
    for j in range(N):
        b = int(input())
        if b in A:
            bi = A.index(b)
            A[bi] = 0

    arr = np.array(A).reshape(3,3)

    row = arr.sum(axis=0)
    col = arr.sum(axis=1)
    diag = sum(arr.diagonal())
    diag_rev = arr[0, 2] + arr[1, 1] + arr[2, 0]

    for r, c in zip(row, col):
        if r == 0 or c == 0:
            print("Yes")
            return 0
    
    if diag == 0 or diag_rev == 0:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Submission status: Accepted

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

b = set(int(input()) for i in range(n))

def check():
    for i in range(3):
        if all(a[i][j] in b for j in range(3)):
            return True
        if all(a[j][i] in b for j in range(3)):
            return True
    return all(a[i][i] in b for i in range(3)) or all(a[2-i][i] in b for i in range(3))

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

Submission status: Accepted

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

N = int(input())

S = set(int(input()) for _ in range(N))

def check():
    for i in range(3):
        if all(grid[i][j] in S for j in range(3)):
            return True
        if all(grid[j][i] in S for j in range(3)):
            return True
    return all(grid[i][i] in S for i in range(3)) or all(grid[2-i][i] in S for i in range(3))

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

Submission status: Accepted

Solution code:
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
a3=list(map(int,input().split()))
a=[a1,a2,a3]
n=int(input())
q=[[0,0,0],[0,0,0],[0,0,0]]
for i in range(n):
    b=int(input())
    for c in range(3):
        for x in range(3):
            if b==a[c][x]:
                q[c][x]=1

result='No'
for t in range(3):
    if q[t][0]==q[t][1]==q[t][2]==1:
        result='Yes'
        break
    elif q[0][t]==q[1][t]==q[2][t]==1:
        result='Yes'
        break
if q[0][0]==q[1][1]==q[2][2]==1:
    result='Yes'
elif q[0][2]==q[1][1]==q[2][0]==1:
        result='Yes'

print(result)

Submission status: Accepted

Solution code:
def B():
    a = [list(map(int,input().split())) for i in range(3)]
    n = int(input())
    b = [int(input()) for i in range(n)]
    for bingo in b:
        for i in range(3):
            for j in range(3):
                if a[i][j] == bingo:
                    a[i][j] = 0
    if (a[0][0] == a[1][1] == a[2][2] == 0) or (a[0][2] == a[1][1] == a[2][0] == 0):
        print("Yes")
        return
    for i in range(3):
        if all(a[i][j] == 0 for j in range(3)) or all(a[j][i] == 0 for j in range(3)):
            print("Yes")
            return
    print("No")

B()

Submission status: Accepted

Solution code:
def B():
    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 bingo in  (int(input()) for _ in range(n)):
        for i in range(3):
            for j in range(3):
                if a[i][j] == bingo:
                    a[i][j] = 0
    if (a[0][0] == a[1][1] == a[2][2] == 0) or (a[0][2] == a[1][1] == a[2][0] == 0):
        print("Yes")
        return
    for i in range(3):
        if all(a[i][j] == 0 for j in range(3)) or all(a[j][i] == 0 for j in range(3)):
            print("Yes")
            return
    print("No")
B()

Submission status: Accepted

Solution code:
def B():
    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 bingo in  (int(input()) for _ in range(n)):
        for i in range(3):
            for j in range(3):
                if a[i][j] == bingo:
                    a[i][j] = 0
    if (a[0][0] == a[1][1] == a[2][2] == 0) or (a[0][2] == a[1][1] == a[2][0] == 0):
        print("Yes")
        return
    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")
            return
    print("No")
B()

Submission status: Accepted

Solution code:
def B():
    mat = [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 bingo in  (int(input()) for _ in range(n)):
        for i in range(3):
            for j in range(3):
                if mat[i][j] == bingo:
                    mat[i][j] = 0
    for i in range(3):
        if all(mat[i][j] == 0 for j in range(3)):
            print('Yes')
            break
        if all(mat[j][i] == 0 for j in range(3)):
            print('Yes')
            break
    else:
        if mat[0][0] == mat[1][1] == mat[2][2] == 0 or\
                mat[0][2] == mat[1][1] == mat[2][0] == 0:
            print('Yes')
        else:
            print('No')
B()

Submission status: Accepted

Solution code:
import numpy as np

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

n = int(input())

b = [0]*n

for i in range(n):
    b[i] = int(input())
    a = np.where(a == b[i], 0, a)

if np.any((a==0).all(axis=0)):
    print('Yes')

elif np.any((a==0).all(axis=1)):
    print('Yes')

elif a[1,1] == 0:
    if (a[0,0]==0) or (a[2,2]==0):
        print('Yes')
    elif (a[0,2]==0) or (a[2,0]==0):
        print('Yes')

else:
    print('No')

Submission status: Accepted

Solution code:
A,B,C=map(int,input().split())
D,E,F=map(int,input().split())
G,H,I=map(int,input().split())
N=int(input())
for i in range(N):
    b=int(input())
    if b==A:
        A=0
    if b==B:
        B=0
    if b==C:
        C=0
    if b==D:
        D=0
    if b==E:
        E=0
    if b==F:
        F=0
    if b==G:
        G=0
    if b==H:
        H=0
    if b==I:
        I=0



if A==0 and B==0 and C==0 or D==0 and E==0 and F==0 or G==0 and H==0 and I==0 or A==0 and D==0 and G==0 or B==0 and E==0 and H==0 or C==0 and F==0 and I==0 or A==0 and E==0 and I==0 or C==0 and E==0 and G==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A = []
for i in range(3):
  As = list(map(int, input().split()))
  A.append(As)
N = int(input())
bs = set()
for i in range(N):
  b = int(input())
  bs.add(b)
D = [[False]*3 for i in range(3)]
for i in range(3):
  for j in range(3):
    if A[i][j] in bs:
      D[i][j] = True
if D[0][0] and D[0][1] and D[0][2]:
  print("Yes")
elif D[1][0] and D[1][1] and D[1][2]:
  print("Yes")
elif D[2][0] and D[2][1] and D[2][2]:
  print("Yes")
elif D[0][0] and D[1][0] and D[2][0]:
  print("Yes")
elif D[0][1] and D[1][1] and D[2][1]:
  print("Yes")
elif D[0][2] and D[1][2] and D[2][2]:
  print("Yes")
elif D[0][0] and D[1][1] and D[2][2]:
  print("Yes")
elif D[2][0] and D[1][1] and D[0][2]:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, i = map(int, input().split())
L = []
L.append({a, b, c})
L.append({d, e, f})
L.append({g, h, i})
L.append({a, d, g})
L.append({b, e, h})
L.append({c, f, i})
L.append({a, e, i})
L.append({c, e, g})
N = int(input())
B = {int(input()) for i in range(N)}
if any(l <= B for l in L):
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

Bingo = [[A11, A12, A13], [A21, A22, A23], [A31, A32, A33], \
         [A11, A21, A31], [A12, A22, A32], [A13, A23, A33], \
         [A11, A22, A33], [A13, A22, A31]]

for j in Bingo:
  if set(j).issubset(b):
    print('Yes')
    exit()

print('No')

Submission status: Accepted

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


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    A = [list(readnums()) for _ in range(3)]
    c = [[False] * 3 for _ in range(3)]
    N = readint()
    for i in range(N):
        a = readint()
        pos = [(x, y) for y, row in enumerate(A) for x, elem in enumerate(row) if A[x][y] == a]
        if pos:
            x, y = pos[0]
        else:
            continue
        c[x][y] = True

    if all(c[0]) or all(c[1]) or all(c[2]) or all([x[0] for x in c]) or all([x[1] for x in c]) or all([x[2] for x in c]) or all([x[i] for i, x in enumerate(c)]) or all([x[2 - i] for i, x in enumerate(c)]):
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()

Submission status: Accepted

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


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    A = [list(readnums()) for _ in range(3)]
    c = [[False] * 3 for _ in range(3)]
    N = readint()
    for i in range(N):
        a = readint()
        pos = [(x, y) for y, row in enumerate(A) for x, elem in enumerate(row) if A[x][y] == a]
        if pos:
            x, y = pos[0]
        else:
            continue
        c[x][y] = True

    if all(c[0]) or all(c[1]) or all(c[2]) or all([c[0][0], c[1][0], c[2][0]]) or all([c[0][1], c[1][1], c[2][1]]) or all([c[0][2], c[1][2], c[2][2]]) or all([c[0][0], c[1][1], c[2][2]]) or all([c[2][0], c[1][1], c[0][2]]):
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
li2 = [input() for i in range(3)]
a = []
for i in range(3):
    a.append([int(x.strip()) for x in li2[i].split()])
bingo = [[0, 0, 0] for i in range(3)]

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


def atari(z):
    for x in range(3):
        for y in range(3):
            if a[x][y] == z:
                bingo[x][y] = 1


for i in range(n):
    atari(b[i])

ans = 0


def check(z1, z2, z3):
    if z1 == 1 and z2 == 1 and z3 == 1:
        global ans
        ans = 1




for i in range(3):
    check(bingo[i][0], bingo[i][1], bingo[i][2])
    check(bingo[0][i], bingo[1][i], bingo[2][i])

check(bingo[0][0], bingo[1][1], bingo[2][2])
check(bingo[2][0], bingo[1][1], bingo[0][2])


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

Submission status: Accepted

Solution code:
A = []
for i in range(3):
    a = list(map(int,input().split()))
    A.extend(a)
n = int(input())
B = [0]*9
for i in range(n):
    b = int(input())
    for i in range(9):
        if A[i] == b:
            B[i] = 1
ans = 0
for i in range(3):
    if B[i*3] == B[i*3+1] == B[i*3+2] == 1:
        ans = 1
    if B[i] == B[i+3] == B[i+6] == 1:
        ans = 1
    if B[0] == B[4] == B[8] == 1:
        ans = 1
    if B[2] == B[4] == B[6] == 1:
        ans = 1
if ans == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

for i in range(N):
    b = int(input())
    for j in range(3):
        A[j] = ["$" if num == b else num for num in A[j]]

if ["$"]*3 in A:
    print("Yes")
elif any( [A[j][i] for j in range(3)] == ["$"]*3 for i in range(3) ):
    print("Yes")
elif [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:
bingo = []
for i in range(3):
    bingo.append(input().split())

n = int(input())
for i in range(n):
    num = input()
    try:
        for y, row in enumerate(bingo):
            try:
                pos = (y, row.index(num))
                break
            except:
                pass
        bingo[pos[0]][pos[1]] = False
    except:
        pass

for i in range(3):
    if not any(bingo[i]):
        print("Yes")
        exit()
for i in range(3):
    if not (bingo[0][i] or bingo[1][i] or bingo[2][i]):
        print("Yes")
        exit()
if not(bingo[0][0] or bingo[1][1] or bingo[2][2]):
    print("Yes")
    exit()
if not(bingo[0][2] or bingo[1][1] or bingo[2][0]):
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
import numpy as np

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

def resolve():
    ansM = np.zeros((3,3))
    A1 = list(map(int,input().split()))
    A2 = list(map(int,input().split()))
    A3 = list(map(int,input().split()))
    A2.extend(A3)
    A1.extend(A2)
    N = int(input())
    for i in range(N):
        Bi = int(input())
        Q = my_index(A1,Bi)
        if Q >= 0:
            ansM[Q//3,Q%3] = 1
    bg = np.zeros(8)
    bg[0] = sum(ansM[0,:]) // 3
    bg[1] = sum(ansM[1,:]) // 3
    bg[2] = sum(ansM[2,:]) // 3
    bg[3] = sum(ansM[:,0]) // 3
    bg[4] = sum(ansM[:,1]) // 3
    bg[5] = sum(ansM[:,2]) // 3
    bg[6] = (ansM[0,0] + ansM[1,1] + ansM[2,2]) // 3
    bg[7] = (ansM[0,2] + ansM[1,1] + ansM[2,0]) // 3
    if sum(bg) > 0:
        print("Yes")
    else:
        print("No")
resolve()

Submission status: Accepted

Solution code:
import sys

def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))

A = []
B = [[0,0,0],[0,0,0],[0,0,0]]
ans = "No"
for i in range(3):A.append(ILI())
n = int(input())
for k in range(n):
	b = int(input())
	for i in range(3):
		for j in range(3):
			if A[i][j] == b:B[i][j]=1
B2 = list(zip(*B))
for i in range(3):
	if sum(B[i])==3 or sum(B2[i])==3:
		ans = "Yes"
if B[0][0]+B[1][1]+B[2][2]==3:ans="Yes"
if B[0][2]+B[1][1]+B[2][0]==3:ans="Yes"
print(ans)

Submission status: Accepted

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

    n = int(input())
    for i in range(n):
        b = int(input())
        for j in range(len(bingo)):
            if(bingo[j]==b):
                bingo[j] = 0

    flag = False

    for i in range(3):
        if (bingo[0+3*i]+bingo[1+3*i]+bingo[2+3*i])==0:
            flag = True

    for i in range(3):
        if (bingo[0+i]+bingo[3+i]+bingo[6+i])==0:
            flag = True

    if (bingo[0]+bingo[4]+bingo[8])==0:
        flag = True
    if (bingo[2]+bingo[4]+bingo[6])==0:
        flag = True

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

main()

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())
for i in range(n):
    k = int(input())
    for j in range(3):
        if k == a[j]:
            a[j] = 0
        if k == b[j]:
            b[j] = 0
        if k == c[j]:
            c[j] = 0

if (sum(a) == 0) or (sum(b) == 0) or (sum(c) == 0):
    print("Yes")
    exit(0)

for h in range(3):
    if a[h]+b[h]+c[h] == 0:
        print("Yes")
        exit(0)

hh = a[0]+b[1]+c[2]
ee = a[2]+b[1]+c[0]
if (hh == 0) or (ee == 0):
    print("Yes")
    exit(0)

print("No")

Submission status: Accepted

Solution code:
a = [[0 for j in range(3)] for w in range(3)]
s = [[0 for h in range(3)] for t in range(3)]
ans = 'No'

for i in range(3):
    a[i][0],a[i][1],a[i][2] = map(int,input().split())

n = int(input())

for k in range(n):
    b = int(input())
    for x in range(0,3,1):
        for y in range(0,3,1):
            if a[x][y] == b:
                s[x][y] = 1

if s[0][0] == 1 and s[0][1] == 1 and s[0][2] == 1:
    ans = 'Yes'
if s[1][0] == 1 and s[1][1] == 1 and s[1][2] == 1:
    ans = 'Yes'
if s[2][0] == 1 and s[2][1] == 1 and s[2][2] == 1:
    ans = 'Yes'
if s[0][0] == 1 and s[1][0] == 1 and s[2][0] == 1:
    ans = 'Yes'
if s[0][1] == 1 and s[1][1] == 1 and s[2][1] == 1:
    ans = 'Yes'
if s[0][2] == 1 and s[1][2] == 1 and s[2][2] == 1:
    ans = 'Yes'
if s[0][0] == 1 and s[1][1] == 1 and s[2][2] == 1:
    ans = 'Yes'
if s[2][0] == 1 and s[1][1] == 1 and s[0][2] == 1:
    ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
A = list(map(int, input().split()))
A += list(map(int, input().split()))
A += list(map(int, input().split()))
N = int(input())

bingo = [False]*9

for i in range(N):
    b = int(input())
    if b in A:
        bingo[A.index(b)] = True

for i in range(3):
    if bingo[i*3:(i+1)*3] == [True]*3:
        print("Yes")
        break
    elif bingo[i:7+i:3] == [True]*3:
        print("Yes")
        break
else:
    if ([bingo[0]] + [bingo[4]] + [bingo[8]]) == [True]*3:
        print("Yes")
    elif ([bingo[2]] + [bingo[4]] + [bingo[6]]) == [True]*3:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
A = [[int(i) for i in input().split()] for i in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]
 
d  = [[0]*3 for i in range(3)]
 
for B in b:
  for i in range(3):
    for j in range(3):
      if A[i][j]==B:
        d[i][j] = 1
 
ans = "No"
for i in range(3):
  if d[i][0]==d[i][1]==d[i][2]==1:
    ans = "Yes"
    break
  elif d[0][i]==d[1][i]==d[2][i]==1:
    ans = "Yes"
    break
if d[0][0]==d[1][1]==d[2][2]==1:
  ans ="Yes"
elif d[2][0]==d[1][1]==d[0][2]==1:
  ans ="Yes"
print(ans)

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)]
C = [[False]*3 for _ in range(3)]
for i in B:
    for j in range(3):
        for k in range(3):
            if A[j][k]==i:
                C[j][k]=True
def bingo(C):
    for i in range(3):
        if C[i][0]==C[i][1]==C[i][2]==True:
            return True
    for i in range(3):
        if C[0][i]==C[1][i]==C[2][i]==True:
            return True
    if C[0][0]==C[1][1]==C[2][2]==True:
        return True
    if C[2][0]==C[1][1]==C[0][2]==True:
        return True
if bingo(C):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

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

answer = "No"
for i in range(3):
  if data[i][0]==data[i][1]==data[i][2]==1:
    answer = "Yes"
    break
  elif data[0][i]==data[1][i]==data[2][i]==1:
    answer = "Yes"
    break
if data[0][0]==data[1][1]==data[2][2]==1:
  answer ="Yes"
elif data[2][0]==data[1][1]==data[0][2]==1:
  answer ="Yes"
print(answer)

Submission status: Accepted

Solution code:
def main():
    A = [[0]*3 for _ in range(3)]
    for i in range(3):
        A[i] = list(map(int, input().split()))
    N = int(input())
    hittable = [[False]*3 for _ in range(3)]
    for _ in range(N):
        b = int(input())
        for i in range(3):
            for j in range(3):
                if b==A[i][j]:
                    hittable[i][j]=True
    
    if hittable[0][0] and hittable[1][0] and hittable[2][0]:
        print("Yes")
    elif hittable[0][1] and hittable[1][1] and hittable[2][1]:
        print("Yes")
    elif hittable[0][2] and hittable[1][2] and hittable[2][2]:
        print("Yes")
    elif hittable[0][0] and hittable[0][1] and hittable[0][2]:
        print("Yes")
    elif hittable[1][0] and hittable[1][1] and hittable[1][2]:
        print("Yes")
    elif hittable[2][0] and hittable[2][1] and hittable[2][2]:
        print("Yes")
    elif hittable[0][0] and hittable[1][1] and hittable[2][2]:
        print("Yes")
    elif hittable[0][2] and hittable[1][1] and hittable[2][0]:
        print("Yes")
    else:
        print("No")

main()