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:
import sys

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

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

h = [[0, 0, 0],
     [0, 0, 0],
     [0, 0, 0]]

a = []

for l in sys.stdin:
    a.append(int(l))

for i in a:
    for j in range(3):
        for k in range(3):
            if card[j][k] == i:
                h[j][k] = 1

if max(sum(h[0]), sum(h[1]), sum(h[2])) == 3:
    print("Yes")
elif max((h[0][0] + h[1][0] + h[2][0]), (h[0][1] + h[1][1] + h[2][1]), (h[0][2] + h[1][2] + h[2][2])) == 3:
    print("Yes")
elif max((h[0][0] + h[1][1] + h[2][2]), (h[0][2] + h[1][1] + h[2][0])) == 3:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

# スペース区切りの整数の入力
A1,B1,C1 = map(int, input().split())
A2,B2,C2 = map(int, input().split())
A3,B3,C3 = map(int, input().split())

np_arr = np.array([[A1,B1,C1], [A2,B2,C2],[A3,B3,C3]])

bingo_list=(np_arr==-1)

K= int(input())

for num in range(K):
    Z = int(input())
    bingo_list+=(np_arr==Z)





if sum(bingo_list[:,0])==3 or sum(bingo_list[:,1])==3 or sum(bingo_list[:,2])==3 or sum(bingo_list[0,:])==3 or sum(bingo_list[1,:])==3 or sum(bingo_list[2,:])==3 or (bingo_list[0,0]*1+bingo_list[1,1]*1+bingo_list[2,2]*1)==3 or (bingo_list[2,0]*1+bingo_list[1,1]*1+bingo_list[0,2]*1)==3:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

for b in B:
    A = [["hit" if i==b else i for i in a] for a in A]

for w in range(3):
    if all(a=="hit" for a in A[w]):
        print("Yes")
        quit()

for h in range(3):
    if all(A[i][h]=="hit" for i in range(3)):
        print("Yes")
        quit()

if A[0][0]=="hit" and A[1][1]=="hit" and A[2][2]=="hit":
    print("Yes")
    quit()

if A[0][-1]=="hit" and A[1][-2]=="hit" and A[2][-3]=="hit":
    print("Yes")
    quit()

print("No")

Submission status: Accepted

Solution code:
listA1 = input().split(" ")
listA2 = input().split(" ")
listA3 = input().split(" ")

matrix = [listA1, listA2, listA3]

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

n = int(input())
bingo = False
for i in range(n):
    a = input()

    for l in range(3):
        for j in range(3):

            if matrix[l][j] == a:
                matrixBool[l][j] = True

for l in range(3):
    c = 0
    for i in range(3):
        if matrixBool[l][i] == True:
            c = c+1

    if c == 3:
        bingo = True
        break

for l in range(3):
    c = 0
    for i in range(3):
        if matrixBool[i][l] == True:
            c = c + 1

    if c == 3:
        bingo = True
        break

if (matrixBool[0][0] == True) and (matrixBool[1][1] == True) and (matrixBool[2][2] == True):
    bingo = True


if (matrixBool[0][2] == True) and (matrixBool[1][1] == True) and (matrixBool[2][0] == True):
    bingo = True

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

Submission status: Accepted

Solution code:
list1=list(map(int,input().split()))
list2=list(map(int,input().split()))
list3=list(map(int,input().split()))
n=int(input())
nums = list()
for i in range(n):
    temp = int(input())
    nums.append(temp)

a=list1
a.extend(list2)
a.extend(list3)

a=[i in nums for i in a]
if (a[0] and a[1] and a[2])or \
   (a[3] and a[4] and a[5])or \
   (a[6] and a[7] and a[8])or \
   (a[0] and a[3] and a[6])or \
   (a[1] and a[4] and a[7])or \
   (a[2] and a[5] and a[8])or \
   (a[0] and a[4] and a[8])or \
   (a[2] and a[4] and a[6]):
    print("Yes")
else:
    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()))

a.extend(b)
a.extend(c)

n = int(input())
nums = []
for i in range(n):
  nums.append(int(input()))
  
a = [ i in nums for i in a]
if((a[0] and a[1] and a[2])  or
   (a[3] and a[4] and a[5])  or
   (a[6] and a[7] and a[8])  or
   (a[0] and a[3] and a[6])  or
   (a[1] and a[4] and a[7])  or
   (a[2] and a[5] and a[8])  or
   (a[0] and a[4] and a[8])  or
   (a[2] and a[4] and a[6])):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
list1 = list(map(int,input().split()))
list2 = list(map(int,input().split()))
list3 = list(map(int,input().split()))
n=int(input())
b_list=list(map(int,[input() for i in range(4,n+4)]))


list_all=[list1,list2,list3]

for i in b_list:
    sub={i:'t'}
    list_all = [[sub.get(x,x) for x in inner] for inner in list_all]

if list_all[1][1]=='t':
    if list_all[0][0]=='t' and list_all[2][2]=='t':
        print('Yes')
    elif list_all[0][2]=='t' and list_all[2][0]=='t':
        print('Yes')
    elif list_all[0][1]=='t' and list_all[2][1]=='t':
        print('Yes')
    elif list_all[1][0]=='t' and list_all[1][2]=='t':
        print('Yes')

else:
    if list_all[0][0]=='t' and list_all[1][0]=='t' and list_all[2][0]=='t':
        print('Yes')
    elif list_all[0][0]=='t' and list_all[0][1]=='t' and list_all[0][2]=='t':
        print('Yes')
    elif list_all[0][2]=='t' and list_all[1][2]=='t' and list_all[2][2]=='t':
        print('Yes')
    elif list_all[2][0]=='t' and list_all[2][1]=='t' and list_all[2][2]=='t':
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
ar = []
br = [[],[],[]]
cr = [[],[]]
for i in range(3):
    r = list(map(int,input().split(" ")))
    for i in range(3):
        br[i].append(r[i])
    ar.append(r)
cr[0].append(ar[0][0])
cr[0].append(ar[1][1])
cr[0].append(ar[2][2])
cr[1].append(ar[2][0])
cr[1].append(ar[1][1])
cr[1].append(ar[0][2])
a = int(input())
dr = []
for i in range(a):
    l = int(input())
    dr.append(l)
for rr in ar:
    count = 0
    for r in rr:
        if r in dr:
            count += 1
    if count == 3:
        print("Yes")
        exit()
for rr in br:
    count = 0
    for r in rr:
        if r in dr:
            count += 1
    if count == 3:
        print("Yes")
        exit()
for rr in cr:
    count = 0
    for r in rr:
        if r in dr:
            count += 1
    if count == 3:
        print("Yes")
        exit()
print("No")

Submission status: Accepted

Solution code:
a1_1, a1_2, a1_3 = map(int, input().split())
a2_1, a2_2, a2_3 = map(int, input().split())
a3_1, a3_2, a3_3 = map(int, input().split())
a_list=[a1_1, a1_2, a1_3, a2_1, a2_2, a2_3, a3_1, a3_2, a3_3]
n = int(input())
b=[]
for i in range(n):
  b_i = int(input())
  b.append(b_i)
  for j in range(len(a_list)):
    if a_list[j] == b_i:
      a_list[j] = -1
if ((a_list[0]==-1 and a_list[1] == -1 and a_list[2] == -1) or
    (a_list[3]==-1 and a_list[4] == -1 and a_list[5] == -1) or
    (a_list[6]==-1 and a_list[7] == -1 and a_list[8] == -1) or
    (a_list[0]==-1 and a_list[3] == -1 and a_list[6] == -1) or
    (a_list[1]==-1 and a_list[4] == -1 and a_list[7] == -1) or
    (a_list[2]==-1 and a_list[5] == -1 and a_list[8] == -1) or
    (a_list[0]==-1 and a_list[4] == -1 and a_list[8] == -1) or
	(a_list[2]==-1 and a_list[4] == -1 and a_list[6] == -1)):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
card = [input().split() for _ in range(3)]
n = int(input())

hit = set()
for _ in range(n):
    b = input()
    for i in range(3):
        for j in range(3):
            if b == card[i][j]:
                hit.add(i * 3 + j + 1)

bingo = [
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9},
    {1, 4, 7},
    {2, 5, 8},
    {3, 6, 9},
    {1, 5, 9},
    {3, 5, 7}
]

for b in bingo:
    if b.issubset(hit):
        print("Yes")
        break
else:
    print("No")

Submission status: Accepted

Solution code:
A=[]
for i in range(3):
  a,b,c=map(int,input().split())
  A+=[a,b,c]
  
n=int(input())
T=[0]*9
for i in range(n):
  p=int(input())
  if p in A:
    T[A.index(p)]=1
    
if [1,1,1] in [T[0:3],T[3:6],T[6:9],T[0:7:3],T[1:9:3],T[2:9:3],T[0:10:4],T[2:7:2]]:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

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

res = np.array([int(i in B) for i in A.ravel()]).reshape(3, 3)
diag_sum = res[0, 0] + res[1, 1] + res[2, 2]
diag_sum2 = res[0, 2] + res[1, 1] + res[2, 0]
if (res.sum(axis=0) == 3).any() or (res.sum(axis=1) == 3).any() or diag_sum == 3 or diag_sum2 == 3:
    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)]
ans = [-1] * 9
for i in range(n):
    if b[i] in a[0]:
        ans[a[0].index(b[i])] = 0
    elif b[i] in a[1]:
        ans[a[1].index(b[i]) + 3] = 0
    elif b[i] in a[2]:
        ans[a[2].index(b[i]) + 6] = 0
if (ans[0] == 0 and ans[1] == 0 and ans[2] == 0) or\
   (ans[0] == 0 and ans[3] == 0 and ans[6] == 0) or\
   (ans[3] == 0 and ans[4] == 0 and ans[5] == 0) or\
   (ans[6] == 0 and ans[7] == 0 and ans[8] == 0) or\
   (ans[1] == 0 and ans[4] == 0 and ans[7] == 0) or\
   (ans[2] == 0 and ans[5] == 0 and ans[8] == 0) or\
   (ans[0] == 0 and ans[4] == 0 and ans[8] == 0) or\
   (ans[2] == 0 and ans[4] == 0 and ans[6] == 0):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    a = [list(map(int, input().split())) for e in range(3)]
    n = int(input())
    b = [int(input()) for _ in range(n)]
    c = 'No'
    for i in range(len(a)):
        for j in range(len(a)):
            if a[i][j] in b:
                a[i][j] = 0

    for i in range(len(a)):
         if {a[i][j] for j in range(len(a))} == {0}:
             c = 'Yes'
         if {a[j][i] for j in range(len(a))} == {0}:
            c = 'Yes'
    if {a[j][j] for j in range(len(a))} == {0}:
        c = 'Yes'
    if {a[-(j+1)][j] for j in range(len(a))} == {0}:
        c = 'Yes'
    print(c)

Submission status: Accepted

Solution code:
import sys

def main():
    bingo = []
    for i in range(3):
        line = sys.stdin.readline().rstrip('\n').split()
        bingo.append(line[0])
        bingo.append(line[1])
        bingo.append(line[2])

    line = sys.stdin.readline().rstrip('\n')
    N = int(line)

    inputs = []
    for i in range(N):
        line = sys.stdin.readline().rstrip('\n')
        inputs.append(line)

    for i in [0, 3, 6]:
        if (bingo[i] in inputs) and (bingo[i+1] in inputs) and (bingo[i+2] in inputs):
            print('Yes')
            return

    for i in [0, 1, 2]:
        if (bingo[i] in inputs) and (bingo[i+3] in inputs) and (bingo[i+6] in inputs):
            print('Yes')
            return

    if (bingo[0] in inputs) and (bingo[4] in inputs) and (bingo[8] in inputs):
        print('Yes')
        return

    if (bingo[2] in inputs) and (bingo[4] in inputs) and (bingo[6] in inputs):
        print('Yes')
        return

    print('No')

main()

Submission status: Accepted

Solution code:
B=[];bingo=0
import numpy as np
A=np.zeros((3,3),dtype=int)
for i in range(3):
  a,b,c=map(int,input().split())
  A[i][0]=a
  A[i][1]=b
  A[i][2]=c
N=int(input())
for i in range(N):
  B.append(int(input()))
#print(A)
#print(B)
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
#print(A)
for i in range(3):
  if sum(A[i][:])==0:
    bingo=bingo+1
for i in range(3):
  if A[0][i]+A[1][i]+A[2][i]==0:
    bingo=bingo+1
if A[0][0]+A[1][1]+A[2][2]==0:
  bingo=bingo+1
if A[2][0]+A[1][1]+A[0][2]==0:
  bingo=bingo+1
print("Yes" if bingo>=1 else "No")

Submission status: Accepted

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

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

for i in range(3):
    f = True
    for j in range(3):
        if a[i][j] != 0:
            f = False
            break
    if f:
        print("Yes")
        exit(0)
    
    f = True
    for j in range(3):
        if a[j][i] != 0:
            f = False
            break
    if f:
        print("Yes")
        exit(0)

f = True
for i in range(3):
    if a[i][i] != 0:
        f = False
        break
if f:
    print("Yes")
    exit(0)

f = True
for i in range(3):
    if a[i][2 - i] != 0:
        f = False
        break
if f:
    print("Yes")
    exit(0)

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())
lb = []
for i in range(N):
  lb.append(int(input()))
res = "No"

for i in range(N):
  if A11 == lb[i]:
    A11 = 0
  if A12 == lb[i]:
    A12 = 0
  if A13 == lb[i]:
    A13 = 0
  if A21 == lb[i]:
    A21 = 0
  if A22 == lb[i]:
    A22 = 0
  if A23 == lb[i]:
    A23 = 0
  if A31 == lb[i]:
    A31 = 0
  if A32 == lb[i]:
    A32 = 0
  if A33 == lb[i]:
    A33 = 0
    
if A11 + A12 + A13 == 0 or A21 + A22 + A23 == 0 or A31 + A32 + A33 == 0 or A11 + A21 + A31 == 0 or A12 + A22 + A32 == 0 or A13 + A23 + A33 == 0 or A11 + A22 + A33 == 0 or A13 + A22 + A31 == 0:
    res = "Yes"
    
print(res)

Submission status: Accepted

Solution code:
from __future__ import print_function

import array
import bisect
import collections
import copy
import fractions
import functools
import heapq
import itertools
import math
import operator
import random
import re
import string
import sys
import time
from collections import Counter, deque
from fractions import Fraction, gcd
from functools import reduce
from heapq import heapify, heappop, heappush, heappushpop, heapreplace
from itertools import accumulate
from operator import mul
from queue import PriorityQueue as pq
from queue import Queue
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    # variants
    s1 = set()
    s2 = set()
    matrix = []
    matrix_check = [[0 for i in range(3)] for j in range(3)]

    # input
    for i in range(3):
        l = list(map(int, input().strip().split()))
        s1.update(l)
        matrix.append(l)
    n = int(input().strip())
    a = [0 for i in range(n)]
    for i in range(n):
        a[i] = int(input().strip())
        s2.add(a[i])
    s_union = s1 & s2

    # processing
    for i in range(len(matrix)):
        for j in range(len(matrix[i])):
            if matrix[i][j] in s_union:
                matrix_check[i][j] = 1
    eprint('matrix_check ', end=':\n')
    eprint(matrix_check) 

    # check
    for i in range(len(matrix_check)):
        if matrix_check[i] == [1, 1, 1] or [row[i] for row in matrix_check] == [1, 1, 1]:
            print("Yes")
            return

    if [matrix_check[i][i] for i in range(3)] == [1,1,1] or [matrix_check[i][-(i+1)] for i in range(3)] == [1,1,1]:
        print("Yes")
        return

    print("No")
    return
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A = []
for i in range(3):
    A.append(list(input().split()))
N = int(input())
B = []
for i in range(N):
    B.append(input())
B=set(B)
if set(A[0]) <= B or set(A[1]) <= B or set(A[2]) <= B or {A[0][0], A[1][0], A[2][0]} <= B or\
{A[0][1], A[1][1], A[2][1]} <= B or {A[0][2], A[1][2], A[2][2]} <= B \
or {A[0][0], A[1][1], A[2][2]} <= B or {A[0][2], A[1][1], A[2][0]} <= B:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def resolve():
    a = [input().split() for i in range(3)]
    n = int(input())
    b = [input() for i in range(n)]
    
    r=[[0] * 3 for i in range(3)]
    for i in range(n):
        for j in range(3):
            for k in range(3):
                if b[i]==a[j][k]:
                    r[j][k] = 1
    # print(res)
    for i in range(3):
        if r[0][i] + r[1][i] + r[2][i] == 3:
            print("Yes")
            return
    for i in range(3):
        if r[i][0] + r[i][1] + r[i][2] == 3:
            print("Yes")
            return
    if r[0][0] + r[1][1] + r[2][2] == 3:
        print("Yes")
        return
    if r[0][2] + r[1][1] + r[2][0] == 3:
        print("Yes")
        return
    print("No")

resolve()

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)]
b = set(b)
g = [0]*9
for i in range(3):
  for j in range(3):
    if a[i][j] in b:
      g[i*3+j] = 1
for i,j,k in [[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6],[0,1,2],[3,4,5],[6,7,8]]:
  if g[i]==g[j]==g[k]==1:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

Solution code:
a = []
for i in range(3):
    a.append(list(map(int, input().split())))
d = []
for _ in range(int(input())):
    d.append(int(input()))
for i in range(3):
    t = 0
    t2 = 0
    for j in range(3):
        if a[i][j] in d:
            t += 1
        if a[j][i] in d:
            t2 += 1
        if t == 3 or t2 == 3:
            print("Yes")
            exit()
t = 0
t2 = 0
for i in range(3):
    for j in range(3):
        if i == j and a[i][j] in d:
            t += 1
        if i + j == 2  and a[i][j] in d:
            t2 += 1
if t == 3 or t2 == 3:
    print("Yes")
    exit()

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())
x=[a, b, c, d, e, f, g, h, i]
y=[False, False, False, False, False, False, False, False, False]
z=[[0, 1, 2], [3, 4, 5], [6, 7, 8],[0,3,6], [1, 4 ,7], [2, 5, 8], [0, 4, 8], [2, 4,6]]

N = int(input())
for p in range(N):
  n = int(input())
  for q in range(9):
    if n == x[q]:
      y[q]=True
  for r in range(8):
    if y[z[r][0]] and y[z[r][1]] and y[z[r][2]]:
      print('Yes')
      exit()
print('No')

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]"):
    import numpy as np

    CARD = np.array(A,dtype=np.int8)

    for i in range(N):
        CARD[CARD==b[i]] = 0   

    CARD = CARD==0

    # 行が揃っているかチェック
    if np.all(CARD,axis=0).sum() > 0:
        print(YES)
        return
    
    if np.all(CARD,axis=1).sum()>0:
        print(YES)
        return
    
    if np.all(np.diag(CARD)):
        print(YES)
        return
    
    if np.all(np.diag(np.fliplr(CARD))):
        print(YES)
        return
    
    print(NO)
    return


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:
import itertools
A = [ list(map(int, input().split())) for i in range(3)]
a = list(itertools.chain.from_iterable(A))

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

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

for i in [0, 1, 2]:
    if a[i] + a[i + 3] + a[i + 6] == 0:
        flag = True
    elif a[i * 3] + a[i * 3 + 1] + a[i * 3 + 2] == 0:
        flag = True
    elif i == 0 and (a[0] + a[4] + a[8] == 0 or a[2] + a[4] + a[6] == 0):
        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 = []
for i in range(N):
  b.append(int(input()))
if A[0][0] in b and A[0][1] in b and A[0][2] in b:
  print("Yes")
elif A[1][0] in b and A[1][1] in b and A[1][2] in b:
  print("Yes")
elif A[2][0] in b and A[2][1] in b and A[2][2] in b:
  print("Yes")
elif A[0][0] in b and A[1][0] in b and A[2][0] in b:
   print("Yes")
elif A[0][1] in b and A[1][1] in b and A[2][1] in b:
  print("Yes")
elif A[0][2] in b and A[1][2] in b and A[2][2] in b:
  print("Yes")
elif A[0][0] in b and A[1][1] in b and A[2][2] in b:
  print("Yes")
elif A[0][2] in b and A[1][1] in b and A[2][0] in b:
  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 = []
for i in range(N):
  b.append(int(input()))
Bingo = [[(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),(0,2)]]
for L in Bingo:
  f = True
  for x,y in L:
    if A[x][y] not in b:
      f = False
  if f:
    print ("Yes")
    break
else:
  print ("No")

Submission status: Accepted

Solution code:
li_1 = list(map(int,input().split()))
li_2 = list(map(int,input().split()))
li_3 = list(map(int,input().split()))
ans = []
n = int(input())
li_b = []
for i in range(n):
  b= int(input())
  if b in li_1:
    id = li_1.index(b)
    ans.append(id)
  if b in li_2:
    id = li_2.index(b) + 3
    ans.append(id)
  if b in li_3:
    id = li_3.index(b) + 6
    ans.append(id)
tf = False
ans.sort()
for i in ans:
  if i ==0 or i==3 or i==6:
    if i+1 in ans:
      if i+2 in ans:
        tf = True
  if i==0 or i==1 or i==2:
    if i+3 in ans:
      if i+6 in ans:
        tf = True
  if 0 in ans:
    if 4 in ans:
      if 8 in ans:
        tf = True
  if 2 in ans:
    if 4 in ans:
      if 6 in ans:
        tf = True
if tf==True:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
bingo = [input().split() for i in range(3)]
card = [[0, 0, 0] for i in range(3)]
n = int(input())
for i in range(n):
    num = str(input())
    for rowNum in range(3):
        for colNum in range(3):
            if bingo[rowNum][colNum] == num:
                card[rowNum][colNum] = 1

#holizonal
for i in range(3):
    s = 0
    for item in card[i]:
        s += int(item)
    if s == 3:
        print('Yes')
        exit()

#vertical
for colNum in range(3):
    s = 0
    for rowNum in range(3):
        s += int(card[rowNum][colNum])
    if s == 3:
        print('Yes')
        exit()
        
#diagonal
if int(card[0][0]) + int(card[1][1]) + int(card[2][2]) == 3:
    print('Yes')
    exit()
elif int(card[0][2]) + int(card[1][1]) + int(card[2][0]) == 3:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

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

n = int(input())

k = [int(input()) for p in range(n)]
for s in range(3):
    if a[s][0] in k and a[s][1] in k and a[s][2] in k:
        print("Yes")
        exit()

for t in range(3):
    if a[0][t] in k and a[1][t] in k and a[2][t] in k:
        print("Yes")
        exit()

if a[0][0] in k and a[1][1] in k and a[2][2] in k:
    print("Yes")
    exit()

if a[0][2] in k and a[1][1] in k and a[2][0] in k:
    print("Yes")
    exit()

print("No")

Submission status: Accepted

Solution code:
a0,a1,a2=map(int,input().split())
a3,a4,a5=map(int,input().split())
a6,a7,a8=map(int,input().split())
N=int(input())
b=[int(input()) for i in range(N)]

s=range(9)
lists=[]
lists.append(a0)
lists.append(a1)
lists.append(a2)
lists.append(a3)
lists.append(a4)
lists.append(a5)
lists.append(a6)
lists.append(a7)
lists.append(a8)

listb=[]
for j in range(N):
  listb.append(b[j])
t=0
for il in range(9):
  for ib in range(N):
    if b[ib]==lists[il]:
      lists[il]=0
            
if lists[0]==lists[1] and lists[2]==lists[1] and lists[0]==0:
  print ('Yes')
elif lists[3]==lists[4] and lists[5]==lists[4] and lists[3]==0:
  print ('Yes')
elif lists[6]==lists[7] and lists[8]==lists[7] and lists[6]==0:
  print ('Yes')
elif lists[0]==lists[3] and lists[3]==lists[6] and lists[0]==0:
  print ('Yes')
elif lists[1]==lists[4] and lists[4]==lists[7] and lists[1]==0:
  print ('Yes')
elif lists[2]==lists[5] and lists[5]==lists[8] and lists[2]==0:
  print ('Yes')
elif lists[0]==lists[4] and lists[4]==lists[8] and lists[0]==0:
  print ('Yes')
elif lists[2]==lists[4] and lists[4]==lists[6] and lists[2]==0:
  print ('Yes')
else:
  print ('No')

Submission status: Accepted

Solution code:
bingo = [[int(j) for j in input().split()] for i in range(3)]
N = int(input())
for k in range(N):
  flag = 0
  hole = int(input())
  for i in range(3):
    for j in range(3):
      if bingo[i][j] == hole:
        bingo[i][j] = -1
        flag = 1
        break
    if flag == 1:
      break
        
if bingo[0][0] * bingo[0][1] * bingo[0][2] == -1:
  print("Yes")
elif bingo[1][0] * bingo[1][1] * bingo[1][2] == -1:
  print("Yes")
elif bingo[2][0] * bingo[2][1] * bingo[2][2] == -1:
  print("Yes")
elif bingo[0][0] * bingo[1][0] * bingo[2][0] == -1:
  print("Yes")
elif bingo[0][1] * bingo[1][1] * bingo[2][1] == -1:
  print("Yes")
elif bingo[0][2] * bingo[1][2] * bingo[2][2] == -1:
  print("Yes")
elif bingo[0][0] * bingo[1][1] * bingo[2][2] == -1:
  print("Yes")
elif bingo[0][2] * bingo[1][1] * bingo[2][0] == -1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
A = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
bingo = False
def bingo_check(A,b):
	for i in range(3):
		for j in range(3):
			if A[i][j] == b:
				A[i][j] = -1
	return A

for i in range(n):
	s = int(input())
	A = bingo_check(A,s)

s,t = 0,0
for i in range(3):
	s += A[i][i]
	t += A[i][2-i]
if s == -3 or t == -3:
	bingo = True
if not bingo:
	for i in range(3):
		u,p = 0,0
		for j in range(3):
			u += A[i][j]
			p += A[j][i]
		if u == -3 or p == -3:
			bingo = True
if bingo:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
n11, n12, n13 = map(int,input().split())
n21, n22, n23 = map(int,input().split())
n31, n32, n33 = map(int,input().split())
lines = [[n11,n12,n13],
         [n21,n22,n23],
         [n31,n32,n33],
         [n11,n21,n31],
         [n12,n22,n32],
         [n13,n23,n33],
         [n11,n22,n33],
         [n13,n22,n31]]
nums = {}
r = input()
for i in range(int(r)):
  nums[int(input())] = 0
flag = False
for l in lines:
  if l[0] in nums:
    if l[1] in nums:
      if l[2] in nums:
        flag = True
if flag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
a1,a2,a3 = input().split()
a4,a5,a6 = input().split()
a7,a8,a9 = input().split()
alist = [a1,a2,a3,a4,a5,a6,a7,a8,a9]
N = int(input())
for i in range(N):
  b = input()
  acnt = 0
  for a in alist:
    if a==b:
      alist[acnt] = -1
      break
    acnt += 1 
if (alist[0]==alist[4]==alist[8]
    or alist[2]==alist[4]==alist[6]
    or alist[0]==alist[1]==alist[2]
    or alist[3]==alist[4]==alist[5]
    or alist[6]==alist[7]==alist[8]
    or alist[0]==alist[3]==alist[6]
    or alist[1]==alist[4]==alist[7]
    or alist[2]==alist[5]==alist[8]):
  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())
_A = [[0, 0, 0] for _ in range(3)]
for i in range(N):
    num = int(input())
    for j in range(3):
        if num in A[j]:
            idx = A[j].index(num)
            _A[j][idx] = 1
if sum(_A[0]) == 3 or sum(_A[1]) == 3 or sum(_A[2]) == 3:
    print('Yes')
elif sum([a[0] for a in _A]) == 3 or sum([a[1] for a in _A]) == 3 or sum([a[2] for a in _A]) == 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:
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())

A = A1 + A2 + A3

while(N != 0):
    b = int(input())
    if b in A:
        A[A.index(b)] = 0
    N = N - 1

while(N != 0):
    b = int(input())
    if b in A:
        A[A.index(b)] = 0
    N = N - 1

if(A[0:3] == [0,0,0] or A[3:6] == [0,0,0] or A[6:9] == [0,0,0]):
    print('Yes')
    
elif(A[0::3] == [0,0,0] or A[1::3] == [0,0,0] or A[2::3] == [0,0,0]):
    print('Yes')

elif(A[0] + A[4] + A[8] == 0 or A[2] + A[4] + A[6] ==0):
    print('Yes')
    
else:
    print('No')

Submission status: Accepted

Solution code:
bingo = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
l = [int(input()) for _ in range(n)]
for i in range(3):
    if bingo[i][0] in l and bingo[i][1] in l and bingo[i][2] in l:
        print("Yes")
        exit()
for i in range(3):
    if bingo[0][i] in l and bingo[1][i] in l and bingo[2][i] in l:
        print("Yes")
        exit()
if bingo[0][0] in l and bingo[1][1] in l and bingo[2][2] in l:
    print("Yes")
    exit()
if bingo[0][2] in l and bingo[1][1] in l and bingo[2][0] in l:
    print("Yes")
    exit()
print("No")