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())
int_list=[int(input()) for i in range(n)]

check = [0]*9
tmp = 0

for j in range(3):
    for i in range(n):
        if(int_list[i] == a1[j]):
                check[tmp] = 1
    tmp += 1

for j in range(3):
    for i in range(n):
        if(int_list[i] == a2[j]):
                check[tmp] = 1
    tmp += 1

for j in range(3):
    for i in range(n):
        if(int_list[i] == a3[j]):
                check[tmp] = 1
    tmp += 1

test = 0

if(check[0] == 1 and check[1] == 1 and check[2] == 1):
        test = 1
if(check[3] == 1 and check[4] == 1 and check[5] == 1):
        test = 1
if(check[6] == 1 and check[7] == 1 and check[8] == 1):
        test = 1
if(check[0] == 1 and check[3] == 1 and check[6] == 1):
        test = 1
if(check[1] == 1 and check[4] == 1 and check[7] == 1):
        test = 1
if(check[2] == 1 and check[5] == 1 and check[8] == 1):
        test = 1
if(check[0] == 1 and check[4] == 1 and check[8] == 1):
        test = 1
if(check[2] == 1 and check[4] == 1 and check[6] == 1):
        test = 1


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

Submission status: Accepted

Solution code:
import numpy as np
first = [int(item) for item in input().split()]
second = [int(item) for item in input().split()]
third = [int(item) for item in input().split()]

grid = np.array([first, second, third])
# print(grid)

N = int(input())

num_list = [int(input()) for _ in range(N)]
# print(num_list)

flg_list = [0,0,0]

is_bingo = False

for i in range(3):
    flg_list = [0,0,0]
    for j in range(3):
        if grid[i,j] in num_list:
            flg_list[j] = 1

    if flg_list == [1,1,1]:
        is_bingo = True

for i in range(3):
    flg_list = [0,0,0]
    for j in range(3):
        if grid[j,i] in num_list:
            flg_list[j] = 1

    if flg_list == [1,1,1]:
        is_bingo = True


flg_list = [0,0,0]
for i in range(3):
    if grid[i,i] in num_list:
        flg_list[i] = 1

    if flg_list == [1,1,1]:
        is_bingo = True

flg_list = [0,0,0]
for i in range(3):

    if grid[2-i,i] in num_list:
        flg_list[i] = 1

    if flg_list == [1,1,1]:
        is_bingo = True

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

Submission status: Accepted

Solution code:
l=[]
for i in range(3):
  a1,a2,a3=map(int,input().split())
  l.append(a1)
  l.append(a2)
  l.append(a3)
n=int(input())
for i in range(n):
  try:
    ind=l.index(int(input()))
    l[ind]=0
  except:
    pass
for i in range(0,9,3):
  if l[i+0]==l[i+1]==l[i+2]==0:
    print('Yes')
    exit(0)
for i in range(3):
  if l[i]==l[i+3]==l[i+6]==0:
    print('Yes')
    exit(0)
if l[0]==l[4]==l[8]==0:
  print('Yes')
  exit(0)
if l[2]==l[4]==l[6]==0:
  print('Yes')
  exit(0)
print('No')

Submission status: Accepted

Solution code:
A = [0]*3
for i in range(0, 3):
    A[i] = list(map(int, input().split()))
N = int(input())
b = [0]*N
for i in range(0, N):
    b[i] = int(input())
for i in range(0, 3):
    for j in range(0, 3):
        for k in range(0, N):
            if A[i][j] == b[k]:
                A[i][j] = 0
if A[0] == [0, 0, 0] or A[1] == [0, 0, 0] or A[2] == [0, 0, 0]:
    print ("Yes")
elif A[0][0] == A[1][0] == A[2][0] == 0:
    print ("Yes")
elif A[0][1] == A[1][1] == A[2][1] == 0:
    print ("Yes")
elif A[0][2] == A[1][2] == A[2][2] == 0:
    print ("Yes")
elif A[0][0] == A[1][1] == A[2][2] == 0:
    print ("Yes")
elif A[0][2] == A[1][1] == A[2][0] == 0:
    print ("Yes")
else:
    print ("No")

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for _ in range(3)]
S = [[False, False, False], [False, False, False], [False, False, False]]
N = int(input())
for _ in range(N):
    B = int(input())
    # print(B in A[0])
    if B in A[0]:
        S[0][A[0].index(B)] = True
    elif B in A[1]:
        S[1][A[1].index(B)] = True
    elif B in A[2]:
        S[2][A[2].index(B)] = True

if S[0][0] and S[0][1] and S[0][2] or \
    S[1][0] and S[1][1] and S[1][2] or \
    S[2][0] and S[2][1] and S[2][2] or \
    S[0][0] and S[1][0] and S[2][0] or \
    S[0][1] and S[1][1] and S[2][1] or \
    S[0][2] and S[1][2] and S[2][2] or \
    S[0][0] and S[1][1] and S[2][2] or \
    S[0][2] and S[1][1] and S[0][2]:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
B = [[0 for i in range(3)] for j in range(3)]
for i in range(N):
  a = int(input())
  for m in range(3):
    for n in range(3):
      if a == A[m][n]:
        B[m][n] = 1
p = 'No'
for i in range(3):
  cnt1 = 0
  cnt2 = 0
  for j in range(3):
    if B[i][j] == 1:
      cnt1 += 1
    if B[j][i] == 1:
      cnt2 += 1
  if cnt1 == 3 or cnt2 == 3:
    p = 'Yes'
    break
cnt3, cnt4 = 0, 0
for i in range(3):
  if B[i][i] == 1:
    cnt3 += 1
  if B[i][2-i] == 1:
    cnt4 += 1
if cnt3 == 3 or cnt4 == 3:
  p = 'Yes'
print(p)

Submission status: Accepted

Solution code:
ans = []
A = [int(i) for i  in input().split()] + [int(i) for i  in input().split()] + [int(i) for i  in input().split()]
A = {v:i for i, v in enumerate(A)}
N = int(input())
for i in range(N):
    b = int(input())
    if b in A.keys():
        ans.append(A[b])
        
if ((0 in ans) and (1 in ans) and (2 in ans)) or\
((3 in ans) and (4 in ans) and (5 in ans)) or\
((6 in ans) and (7 in ans) and (8 in ans)) or\
((0 in ans) and (3 in ans) and (6 in ans)) or\
((1 in ans) and (4 in ans) and (7 in ans)) or\
((2 in ans) and (5 in ans) and (8 in ans)) or\
((0 in ans) and (4 in ans) and (8 in ans)) or\
((2 in ans) and (4 in ans) and (6 in ans)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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


def main():
    A = [list(map(int, input().split())) for _ in range(3)]
    a = [[False] * 3 for _ in range(3)]
    n = int(input())
    for _ in range(n):
        b = int(input())
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    a[i][j] = True
    for i in range(3):
        if all(a[i]):
            print("Yes")
            return
    for j in range(3):
        if all([a[0][j], a[1][j], a[2][j]]):
            print("Yes")
            return
    if a[0][0] and a[1][1] and a[2][2]:
        print("Yes")
        return
    if a[0][2] and a[1][1] and a[2][0]:
        print("Yes")
        return
    print("No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
ary = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
n = int(input())
while n > 0:
    num = int(input())
    if num == a1[0]:
        ary[0][0] = 1
    if num == a1[1]:
        ary[0][1] = 1
    if num == a1[2]:
        ary[0][2] = 1
    if num == a2[0]:
        ary[1][0] = 1
    if num == a2[1]:
        ary[1][1] = 1
    if num == a2[2]:
        ary[1][2] = 1
    if num == a3[0]:
        ary[2][0] = 1
    if num == a3[1]:
        ary[2][1] = 1
    if num == a3[2]:
        ary[2][2] = 1
    n = n - 1
if (ary[0][0] == 1 and ary[0][1] == 1 and ary[0][2] == 1) or\
   (ary[1][0] == 1 and ary[1][1] == 1 and ary[1][2] == 1) or\
   (ary[2][0] == 1 and ary[2][1] == 1 and ary[2][2] == 1) or\
   (ary[0][0] == 1 and ary[1][0] == 1 and ary[2][0] == 1) or\
   (ary[0][1] == 1 and ary[1][1] == 1 and ary[2][1] == 1) or\
   (ary[0][2] == 1 and ary[1][2] == 1 and ary[2][2] == 1) or\
   (ary[0][0] == 1 and ary[1][1] == 1 and ary[2][2] == 1) or\
   (ary[0][2] == 1 and ary[1][1] == 1 and ary[2][0] == 1):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    A = [list(map(int, input().split())) for _ in [0] * 3]
    N = int(input())
    B = [int(input()) for _ in [0] * N]

    for i, (a1, a2, a3) in enumerate(A):
        if a1 in B:
            A[i][0] = 0
        if a2 in B:
            A[i][1] = 0
        if a3 in B:
            A[i][2] = 0
    for a in A:
        if not sum(a):
            print('Yes')
            return
    for i in range(3):
        a = [A[0][i], A[1][i], A[2][i]]
        if not sum(a):
            print('Yes')
            return
    if any((A[0][0] == A[1][1] == A[2][2] == 0,
            A[0][2] == A[1][1] == A[2][0] == 0)):
            print('Yes')
            return
    print('No')


main()

Submission status: Accepted

Solution code:
import itertools

bingo = []

for _ in range(3):
    array = list(map(int, input().split()))
    bingo.append(array)

bingo = list(itertools.chain.from_iterable(bingo))

bingo_bi = [False for _ in range(9)]

n = int(input())

nums = []

for _ in range(n):
    num = int(input())
    if num in bingo:
        bingo_bi[bingo.index(num)] = True

correct = [True, True, True]

if bingo_bi[0:3] == correct or bingo_bi[3:6] == correct or bingo_bi[6:9] == correct:
    print('Yes')
elif bingo_bi[0::3] == correct or bingo_bi[1::3] == correct or bingo_bi[2::3] == correct:
    print('Yes')
elif bingo_bi[0] == True and bingo_bi[4] == True and bingo_bi[8] == True:
    print('Yes')
elif bingo_bi[2:8:2] == correct:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N = int(input())
B = [int(input()) for i in range(N)]

ans = []
for i in range(3):
    a = [A1[i],A2[i],A3[i]]
    ans.append(a)
ans.append(A1)
ans.append(A2)
ans.append(A3)
ans.append([A1[0],A2[1],A3[2]])
ans.append([A3[0],A2[1],A1[2]])

for i in range(len(ans)):
    for j in range(N):
        if B[j] in ans[i]:
            ans[i].remove(B[j])

# print(ans)
if [] in ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def main():
    A = [int(e) for e in input().split()]
    A.extend([int(e) for e in input().split()])
    A.extend([int(e) for e in input().split()])
    n = int(input())
    B = [int(input()) for i in range(n)]

    S = set()
    for ai, a in enumerate(A):
        if a in B:
          S.add(ai + 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 bi in bingo:
        if S.issuperset(set(bi)):
            print('Yes')
            exit()

    print('No')

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
lis1 = list(map(str, input().split()))
lis2 = list(map(str, input().split()))
lis3 = list(map(str, input().split()))
n = int(input())
lisn = [input() for i in range(n)]
for i in lisn:
    if i in lis1:
        lis1[lis1.index(i)] = 1000
    if i in lis2:
        lis2[lis2.index(i)] = 1000
    if i in lis3:
        lis3[lis3.index(i)] = 1000
if lis1.count(1000)==3 or lis2.count(1000)==3 or lis3.count(1000)==3 or (lis1[0]==1000 and lis2[0]==1000 and lis3[0]==1000) or (lis1[1]==1000 and lis2[1]==1000 and lis3[1]==1000) or (lis1[2]==1000 and lis2[2]==1000 and lis3[2]==1000) or (lis1[0]==1000 and lis2[1]==1000 and lis3[2]==1000) or (lis1[2]==1000 and lis2[1]==1000 and lis3[0]==1000):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np

def check(A):
    for i in range(3):
        if A[i,0] == 0 and A[i,1] == 0 and A[i,2] == 0:
            return True
        if A[0,i] == 0 and A[1,i] == 0 and A[2,i] == 0:
            return True
    if A[0,0] == 0 and A[1,1] == 0 and A[2,2] == 0:
        return True
    if A[0,2] == 0 and A[1,1] == 0 and A[2,0] == 0:
        return True

    return False



a = list(map(int, input().split()))
A = a
a = list(map(int, input().split()))
A = np.vstack((A, a))
a = list(map(int, input().split()))
A = np.vstack((A, a))
N = int(input())
b = []
for i in range(N):
    b.append(int(input()))

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

if check(A):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
bingo_list=[list(map(int,input().split())) for i in range(3)]
n = int(input())
number_li=[int(input()) for i in range(n)]
ans = "No"

for i in range(len(bingo_list)):
    for j in number_li:
        if j in bingo_list[i]:
            bingo_list[i][bingo_list[i].index(j)] = "x"

for k in range(len(bingo_list)):
    if bingo_list[0][k] == bingo_list[1][k] == bingo_list[2][k]:
        ans = "Yes"
for l in bingo_list:
    if l[0] == l[1] == l[2]:
        ans = "Yes"
if bingo_list[0][0] == bingo_list[1][1] == bingo_list[2][2]:
    ans = "Yes"
if bingo_list[0][2] == bingo_list[1][1] == bingo_list[2][0]:
    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())
for i in range(N):
    ii=int(input())
    if ii in A1:
        A1[A1.index(ii)]=0
    if ii in A2:
        A2[A2.index(ii)]=0
    if ii in A3:
        A3[A3.index(ii)]=0
ans="No"
l=[0,0,0]
if A1[0]==0 and A2[1]==0 and A3[2]==0:
    ans="Yes"
elif A1[2]==0 and A2[1]==0 and A3[0]==0:
    ans="Yes"
elif A1==l or A2==l or A3==l:
    ans="Yes"
elif A1[0]==0 and A2[0]==0 and A3[0]==0:
    ans="Yes"
elif A1[1]==0 and A2[1]==0 and A3[1]==0:
    ans="Yes"
elif A1[2]==0 and A2[2]==0 and A3[2]==0:
    ans="Yes"
print(ans)

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 i in range(N):
    b = int(input())
    for j in range(3):
        if R1[j] == b:
            R1[j] = 0
        if R2[j] == b:
            R2[j] = 0
        if R3[j] == b:
            R3[j] = 0
C1 = [R1[0], R2[0], R3[0]]
C2 = [R1[1], R2[1], R3[1]]
C3 = [R1[2], R2[2], R3[2]]
D1 = [R1[0], R2[1], R3[2]]
D2 = [R1[2], R2[1], R3[0]]

judge = "No"
if R1[0] == 0 and R1[1] == 0 and R1[2] == 0:
    judge = "Yes"
if R2[0] == 0 and R2[1] == 0 and R2[2] == 0:
    judge = "Yes"
if R3[0] == 0 and R3[1] == 0 and R3[2] == 0:
    judge = "Yes"
if C1[0] == 0 and C1[1] == 0 and C1[2] == 0:
    judge = "Yes"
if C2[0] == 0 and C2[1] == 0 and C2[2] == 0:
    judge = "Yes"
if C3[0] == 0 and C3[1] == 0 and C3[2] == 0:
    judge = "Yes"
if D1[0] == 0 and D1[1] == 0 and D1[2] == 0:
    judge = "Yes"
if D2[0] == 0 and D2[1] == 0 and D2[2] == 0:
    judge = "Yes"
print(judge)

Submission status: Accepted

Solution code:
a=[[] for i in range(3)]
a[0]=list(map(int,input().split()))
a[1]=list(map(int,input().split()))
a[2]=list(map(int,input().split()))
dic={}
for i in range(3):
    for j in range(3):
        dic[a[i][j]]=0
n=int(input())
for i in range(n):
    b=int(input())
    if b in dic:
        dic[b]=1

def ans():
    for i in range(3):
        y=0
        t=0
        for j in range(3):
            if dic[a[i][j]]:
                y+=1
                
            if dic[a[j][i]]:
                t+=1
        if y==3 or t==3:
            print("Yes")
            return
    if dic[a[0][0]]+dic[a[1][1]]+dic[a[2][2]]==3 or dic[a[0][2]]+dic[a[1][1]]+dic[a[2][0]]==3:
        print("Yes")
        return
    print("No")
    
ans()

Submission status: Accepted

Solution code:
l1 = input().split()
l2 = input().split()
l3 = input().split()
n = int(input())
b = [input() for _ in range(n)]
if l1[0] in b and l1[1] in b and l1[2] in b:
    print('Yes')
elif l2[0] in b and l2[1] in b and l2[2] in b:
    print('Yes')
elif l3[0] in b and l3[1] in b and l3[2] in b:
    print('Yes')
elif l1[0] in b and l2[0] in b and l3[0] in b:
    print('Yes')
elif l1[1] in b and l2[1] in b and l3[1] in b:
    print('Yes')
elif l1[2] in b and l2[2] in b and l3[2] in b:
    print('Yes')
elif l1[0] in b and l2[1] in b and l3[2] in b:
    print('Yes')
elif l1[2] in b and l2[1] in b and l3[0] in b:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

ans = "No"
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") or (a[2][0]==a[1][1]==a[0][2]=="x"):
  print("Yes")
  exit()
  
if (a[0][0]==a[1][0]==a[2][0]=="x")or(a[0][1]==a[1][1]==a[2][1]=="x")or(a[0][2]==a[1][2]==a[2][2]=="x"):
  print("Yes")
  exit()
  
if (a[0][0]==a[0][1]==a[0][2]=="x")or(a[1][0]==a[1][1]==a[1][2]=="x")or(a[2][0]==a[2][1]==a[2][2]=="x"):
  print("Yes")
  exit()
  
  
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
a = []
for _ in range(3):
  a_ = list(map(int, input().split()))
  a=a+a_
c = [0]*9
n = int(input())
for _ in range(n):
  b = int(input())
  if b in a:
    c[a.index(b)]=1
c = np.reshape(c, [3,3])
if 3 in np.sum(c, axis=0):
  print("Yes")
elif 3 in np.sum(c, axis=1):
  print("Yes")
elif c[0][0]+c[1][1]+c[2][2]==3 or c[0][2]+c[1][1]+c[2][0]==3:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd

mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
arr=[]
for i in range(3):
    mm=limii()
    arr.append(mm)

n=ii()

b=lin(n)

for i in range(3):
    for j in range(3):
        if arr[i][j] in b:
            arr[i][j]=0
chk=False

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

if chk==True:
    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 _ in range(N):
  b = int(input())
  for i in range(3):
    if A1[i] == b:
      A1[i] = 0
  for j in range(3):
    if A2[j] == b:
      A2[j] = 0
  for k in range(3):
    if A3[k] == b:
      A3[k] = 0

if A1[0] == 0:
  if (A1[1]==0 and A1[2]==0) or (A2[0]==0 and A3[0]==0) or (A2[1]==0 and A3[2]==0):
    print('Yes')
    exit()
if A2[0] == 0:
  if (A2[1]==0 and A2[2]==0):
    print('Yes')
    exit()
if A3[0] == 0:
  if (A3[1]==0 and A3[2]==0) or (A2[1]==0 and A1[2]==0):
    print('Yes')
    exit()
if A1[1] == 0:
  if (A2[1]==0 and A3[1]==0):
    print('Yes')
    exit()
if A1[2] == 0:
  if (A2[2]==0 and A3[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()))

A_all = A1
A_all.extend(A2)
A_all.extend(A3)


N = int(input())


def get_index(l, x, default=-1):
    if x in l:
        return l.index(x)
    else:
        return default
        
for i in range(N):
    b = int(input())
    suffix = get_index(A_all, b)
    if suffix >= 0:
        A_all[suffix] = 0

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

Submission status: Accepted

Solution code:
a=[]
m=0
for i in range(3):
  b=list(map(int,input().split()))
  a.append(b)
n=int(input())
for i in range(n):
  k=int(input())
  for q in range(3):
    for p in range(3):
      if a[q][p]==k:
        a[q][p]=0
for i in range(3):
  if a[i][0]==0 and a[i][1]==0 and a[i][2]==0:
    print("Yes")
    m+=1
    break
  if a[0][i]==0 and a[1][i]==0 and a[2][i]==0:
    print("Yes")
    m+=1
    break
  if a[0][0]==0 and a[1][1]==0 and a[2][2]==0:
    print("Yes")
    m+=1
    break
  if a[0][2]==0 and a[1][1]==0 and a[2][0]==0:
    print("Yes")
    m+=1
    break
if m==0:
  print("No")

Submission status: Accepted

Solution code:
a_list = []
for i  in range(3):
  a_list.append(list(map(int,input().split())))
n = int(input())
b_list = []
result_list = [[0,0,0] for i in range(3)]
for i in range(n):
  b_list.append(int(input()))
for s in range(3):
  for m in range(3):
    if a_list[s][m] in b_list:
      result_list[s][m] = 1
check = False
if result_list[0][0] == result_list[1][1] and result_list[0][0] == result_list[1][1] and result_list[1][1] ==1:
  check = True
elif result_list[0][2] == result_list[1][1] and result_list[2][0] == result_list[1][1] and result_list[1][1] ==1:
    check = True
elif result_list[0][1] == result_list[0][2] and result_list[0][2] == result_list[0][0] and result_list[0][0] ==1:
    check = True
elif result_list[1][1] == result_list[1][2] and result_list[1][2] == result_list[1][0] and result_list[1][0] ==1:
    check = True 
elif result_list[2][1] == result_list[2][2] and result_list[2][2] == result_list[2][0] and result_list[2][0] ==1:
    check = True
elif result_list[0][0] == result_list[1][0] and result_list[1][0] == result_list[2][0] and result_list[2][0] ==1:
    check = True
elif result_list[0][1] == result_list[1][1] and result_list[1][1] == result_list[2][1] and result_list[2][1] ==1:
    check = True
elif result_list[0][2] == result_list[1][2] and result_list[1][2] == result_list[2][2] and result_list[2][2] ==1:
    check = True
if check == True:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import numpy as np

A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))

N = int(input())

card = np.zeros((3, 3))
for i in range(N):
    t = int(input())
    if t in A1:
        card[0][A1.index(t)] = 1
    if t in A2:
        card[1][A2.index(t)] = 1
    if t in A3:
        card[2][A3.index(t)] = 1
f = False
s = np.sum(card, axis=0)
if s[0] == 3 or s[1] == 3 or s[2] == 3:
    f = True

if card[0][0] + card[1][1] + card[2][2] == 3 or card[0][2] + card[1][1] + card[2][0] == 3:
    f = True
s = np.sum(card, axis=1)
if s[0] == 3 or s[1] == 3 or s[2] == 3:
    f = True

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

Submission status: Accepted

Solution code:
a = [0] * 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())

bingo = [[0,0,0],
        [0,0,0],
        [0,0,0]]
for i in range(N):
    b = int(input())

    for j in range(3):
        for k in range(3):
            if(a[j][k] == b): bingo[j][k] = 1

if(bingo[0][0] == bingo[1][1] == bingo[2][2] == 1 or
   bingo[0][2] == bingo[1][1] == bingo[2][0] == 1 or
   bingo[0][0] == bingo[0][1] == bingo[0][2] == 1 or
   bingo[1][0] == bingo[1][1] == bingo[1][2] == 1 or
   bingo[2][0] == bingo[2][1] == bingo[2][2] == 1 or
   bingo[0][0] == bingo[1][0] == bingo[2][0] == 1 or
   bingo[0][1] == bingo[1][1] == bingo[2][1] == 1 or
   bingo[0][2] == bingo[1][2] == bingo[2][2] == 1) :
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
A = [ [0]*3 for i in range(3)];

for i in range(3) :
	s = input().split(' ');
	for j in range(3) :
		A[i][j] = int(s[j]);

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

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 :
				Check[j][k] = 1;
ans = 0;
for i in range(3) :
	bingo = 0;
	for j in range(3) :
		bingo += Check[i][j];
		if bingo == 3 :
			ans = 1;

for i in range(3) :
	bingo = 0;
	for j in range(3) :
		bingo += Check[j][i];
		if bingo == 3 :
			ans = 1;

bingo = 0;
for i in range(3) :
	bingo += Check[i][i];
	if bingo == 3 :
			ans = 1;

bingo = 0;
for i in range(3) :
	bingo += Check[i][2-i];
	if bingo == 3 :
			ans = 1;

if ans :
	print('Yes');
else :
	print('No');

Submission status: Accepted

Solution code:
a = []
b = []

for i in range(3):
    a.append(list(map(int, input().split())))

n = int(input())

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

# yoko
for i in range(3):
    yoko = set(a[i])
    if yoko <= set(b):
        print("Yes")
        exit()

# tate
for i in range(3):
    tate = set([a[0][i], a[1][i], a[2][i]])
    if tate <= set(b):
        print("Yes")
        exit()

# naname
naname1 = {a[0][0], a[1][1], a[2][2]}
naname2 = {a[0][2], a[1][1], a[2][0]}

if naname1 <= set(b):
    print("Yes")
    exit()
elif naname2 <= set(b):
    print("Yes")
    exit()
else:
    print("No")

Submission status: Accepted

Solution code:
a=[]
for i in range(3):
  *x,=map(int,input().split())
  a+=x
n=int(input())
b=[]
for i in range(n):
    b.append(int(input()))
ans=[False for _ in range(9)]
for i in b:
    for j in a:
        if i==j:
            ans[a.index(i)]=True
if all(ans[0:3]) or all(ans[3:6]) or all(ans[6:9]):
    print("Yes")
elif all(ans[0:7:3]) or all(ans[1:8:3]) or all(ans[2:9:3]):
    print("Yes")
elif all(ans[0:5:4]) or all(ans[2:7:2]):
    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())
A = [A11, A12, A13, A21, A22, A23, A31, A32, A33]
bingo = [0, 0, 0, 0, 0, 0, 0, 0, 0]
N = int(input())
B = []
for _ in range(N):
    B.append(int(input()))

for i, b in enumerate(B):
    for j, a in enumerate(A):
        if a == b:
            bingo[j] = 1

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

Submission status: Accepted

Solution code:
ans = "No"
c = []
for i in range(3):
    t = list(map(int, input().split()))
    c.append(t)

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

for i in range(3):
    x = []
    for j in range(3):
        x.append(c[j][i])
    else:
        c.append(x)


for i in range(1):
    x = []
    for j in range(3):
        x.append(c[j][j])
    else:
        c.append(x)

for i in range(1):
    x = []
    for j in range(3):
        x.append(c[j][2-j])
    else:
        c.append(x)

for i in range(8):
    for j in range(3):
        if c[i][j] not in b:
            break
    else:
        ans = "Yes"
        break

print(ans)

Submission status: Accepted

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

C = [[0 for i in range(3)] for j in range(3)]

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

flag = 0
for i in range(3):
    for j in range(3):
        if A[0][0]*A[0][1]*A[0][2] == 101**3 \
        or A[1][0]*A[1][1]*A[1][2] == 101**3 \
        or A[2][0]*A[2][1]*A[2][2] == 101**3 \
        or A[0][0]*A[1][0]*A[2][0] == 101**3 \
        or A[0][1]*A[1][1]*A[2][1] == 101**3 \
        or A[0][2]*A[1][2]*A[2][2] == 101**3 \
        or A[0][0]*A[1][1]*A[2][2] == 101**3 \
        or A[2][0]*A[1][1]*A[0][2] == 101**3:
            flag = 1
            break

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