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:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


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


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    A = []
    B = []
    for i in range(3):
        A.append(LI())
        B.append([False] * 3)


    N = I()

    b = []
    for i in range(N):
        b.append(I())

    for t in range(N):
        for i in range(3):
            for j in range(3):
                if b[t] == A[i][j]:
                    B[i][j] = True

    for i in range(3):
        if B[i][0] is True and B[i][1] is True and B[i][2] is True:
            print('Yes')
            return

    for i in range(3):
        if B[0][i] is True and B[1][i] is True and B[2][i] is True:
            print('Yes')
            return

    if B[0][0] is True and B[1][1] is True and B[2][2] is True:
        print('Yes')
        return

    if B[0][2] is True and B[1][1] is True and B[0][2] is True:
        print('Yes')
        return

    print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
B=list(map(int,input().split()))
B = B+list(map(int,input().split()))
B = B+list(map(int,input().split()))
A = [0 for i in range(9)]
N = int(input())
for i in range(N):
    b = int(input())
    for j in range(9):
        if B[j] == b:
            A[j] = 1
if A[0]==A[3] and A[3] == A[6] and A[0] == 1:
    print("Yes")
elif A[0]==A[1] and A[1] == A[2] and A[0] == 1:
    print("Yes")
elif A[0]==A[4] and A[4] == A[8] and A[0] == 1:
    print("Yes")
elif A[1]==A[4] and A[4] == A[7] and A[1] == 1:
    print("Yes")
elif A[2]==A[5] and A[5] == A[8] and A[2] == 1:
    print("Yes")
elif A[3]==A[4] and A[4] == A[5] and A[5] == 1:
    print("Yes")
elif A[7]==A[6] and A[7] == A[8] and A[8] == 1:
    print("Yes")
elif A[2]==A[4] and A[4] == A[6] and A[2] == 1:
    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 _ in range(N)]
f = [[False]*3 for _ in range(3)]
for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                f[i][j] = True
for i in range(3):
    if all(f[i]):
        break
    if f[0][i] and f[1][i] and f[2][i]:
        break
    if f[0][0] and f[1][1] and f[2][2]:
        break
    if f[0][2] and f[1][1] and f[2][0]:
        break
else:
    print('No')
    exit()
print("Yes")

Submission status: Accepted

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

n = int(input())
B = [int(input()) for _ in range(n)]

y = []
for i in range(3):
    tmp = []
    for j in range(3):
        tmp.append(lst[i][j])
    y.append(tmp)
for i in range(3):
    tmp = []
    for j in range(3):
        tmp.append(lst[j][i])
    y.append(tmp)

y.append([lst[0][0], lst[1][1], lst[2][2]])
y.append([lst[0][2], lst[1][1], lst[2][0]])

res = False
for i in range(len(y)):
    a,b,c = y[i][0], y[i][1], y[i][2]
    if (a in B) and (b in B) and (c in B):
        res = True
print('Yes' if res 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()))
n=int(input())
for i in range(n):
    b=int(input())
    for j in range(3):
        if a1[j]==b:
            a1[j]='o'
        if a2[j]==b:
            a2[j]='o'
        if a3[j]==b:
            a3[j]='o'

if a1.count('o')==3 or a2.count('o')==3 or a3.count('o')==3:
    print('Yes')
elif a1[0]==a2[0]==a3[0]=='o':
    print('Yes')
elif a1[1]==a2[1]==a3[1]=='o':
    print('Yes')
elif a1[2]==a2[2]==a3[2]=='o':
    print('Yes')
elif a1[0]==a2[1]==a3[2]=='o':
    print('Yes')
elif a1[2]==a2[1]==a3[0]=='o':
    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())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                a[j][k] = -1
if a[0][0] == -1 and a[0][1] == -1 and a[0][2] == -1:
    print("Yes")
elif a[1][0] == -1 and a[1][1] == -1 and a[1][2] == -1:
    print("Yes")
elif a[2][0] == -1 and a[2][1] == -1 and a[2][2] == -1:
    print("Yes")
elif a[0][0] == -1 and a[1][0] == -1 and a[2][0] == -1:
    print("Yes")
elif a[0][1] == -1 and a[1][1] == -1 and a[2][1] == -1:
    print("Yes")
elif a[0][2] == -1 and a[1][2] == -1 and a[2][2] == -1:
    print("Yes")
elif a[0][0] == -1 and a[1][1] == -1 and a[2][2] == -1:
    print("Yes")
elif a[0][2] == -1 and a[1][1] == -1 and a[2][0] == -1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Check = [[0 for _ in range(3)] for _ in range(3)]

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

ans = 'No'
for i in range(3):
    if sum(Check[i]) == 3:
        ans = 'Yes'
for i in range(3):
    now = 0
    for j in range(3):
        now += Check[j][i]
    if now == 3:
        ans = 'Yes'
now = 0
for i in range(3):
    now += Check[i][i]
if now == 3:
    ans = 'Yes'

if Check[2][0] + Check[1][1] + Check[0][2] == 3:
    ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
A = input().split()
a1 = [int(a) for a in A]
A = input().split()
a2 = [int(a) for a in A]
A = input().split()
a3 = [int(a) for a in A]
ass = set(a1+a2+a3)

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

bs = set(Bs)

c = list(ass & bs)

if len(c) < 3:
  print('No')
else:
  if a1[0] in bs and a1[1] in bs and a1[2] in bs:
    print('Yes')
  elif a2[0] in bs and a2[1] in bs and a2[2] in bs:
    print('Yes')
  elif a3[0] in bs and a3[1] in bs and a3[2] in bs:
    print('Yes')
  elif a1[0] in bs and a2[0] in bs and a3[0] in bs:
    print('Yes')
  elif a1[1] in bs and a2[1] in bs and a3[1] in bs:
    print('Yes')
  elif a1[2] in bs and a2[2] in bs and a3[2] in bs:
    print('Yes')
  elif a1[0] in bs and a2[1] in bs and a3[2] in bs:
    print('Yes')
  elif a1[2] in bs and a2[1] in bs and a3[0] in bs:
    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,False,False] for i 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:
                bingo[j][k] = True

ans = False
for i in range(3):
    q = True
    for j in range(3):
        if  not bingo[i][j]:
            q = False
            break
    if q:
        print("Yes")
        exit()
for i in range(3):
    q = True
    for j in range(3):
        if  not bingo[j][i]:
            q = False
            break
    if q:
        print("Yes")
        exit()
q = True
for i in range(3):
    if not bingo[i][i]:
        q = False
        break
if q:
    print("Yes")
    exit()

q = True
for i in range(3):
    if not bingo[i][2-i]:
        q = False
        break
if q:
    print("Yes")
    exit()

print("No")

Submission status: Accepted

Solution code:
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())

get_list1 = []
get_list2 = []
get_list3 = []
for n in range(N):
  _ = int(input())
  for idx,a1 in enumerate(A1):
    if a1 == _:
      get_list1.append(idx)

  for idx,a2 in enumerate(A2):
    if a2 == _:
      get_list2.append(idx)
      
  for idx,a3 in enumerate(A3):
    if a3 == _:
      get_list3.append(idx)
    

ans = 'No'
# OKなパターンを一つづつ
# 縦
if 0 in get_list1:
  if 0 in get_list2:
    if 0 in get_list3:
      ans = 'Yes'
if 1 in get_list1:
  if 1 in get_list2:
    if 1 in get_list3:
      ans = 'Yes'      
if 2 in get_list1:
  if 2 in get_list2:
    if 2 in get_list3:
      ans = 'Yes'      

# 横      
if len(get_list1) == 3:
  ans = 'Yes'
if len(get_list2) == 3:
  ans = 'Yes'
if len(get_list3) == 3:
  ans = 'Yes'

# 斜め
if 0 in get_list1:
  if 1 in get_list2:
    if 2 in get_list3:
      ans = 'Yes'
if 2 in get_list1:
  if 1 in get_list2:
    if 0 in get_list3:
      ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
A = []
for _ in range(3):
    A.append(list(map(int, input().split())))
N = int(input())
B = [int(input()) for _ in range(N)]
bingo = [[False for _ in range(3)] for _ in range(3)]
for b in B:
    for h in range(3):
        for w in range(3):
            if A[h][w] == b:
                bingo[h][w] = True

for w in range(3):
    flag = True
    for h in range(3):
        if not bingo[h][w]:
            flag = False
            break
    if flag:
        print("Yes")
        exit()

for h in range(3):
    flag = True
    for w in range(3):
        if not bingo[h][w]:
            flag = False
            break
    if flag:
        print("Yes")
        exit()

flag = True
for i in range(3):
    if not bingo[i][i]:
        flag = False
        break

if flag:
    print("Yes")
    exit()

flag = True
for i in range(3):
    if not bingo[i][2-i]:
        flag = False
        break
if flag:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
a=[]
for i in range(3):
    a.append(list(map(int,input().split())))
b=[[0 for i in range(3)] for j in range(3)]
n=int(input())
for i in range(n):
    p=int(input())
    for j in range(3):
        for k in range(3):
            if p==a[j][k]:
                b[j][k]=1
for i in range(3):
    x=0
    y=0
    for j in range(3):
        if b[i][j]==1:
            x+=1
        if b[j][i]==1:
            y+=1
    if x==3 or y==3:
        print('Yes')
        exit()
if b[0][0]==b[1][1]==b[2][2]==1:
    print('Yes')
    exit()
if b[2][0]==b[1][1]==b[0][2]==1:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

Solution code:
bingo = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
bingo_tf = [[False]*3 for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == b:
                bingo_tf[i][j] = True

def c(a, b, c):
    return bingo_tf[a[0]][a[1]] and bingo_tf[b[0]][b[1]] and bingo_tf[c[0]][c[1]]

if c((0, 0), (0, 1), (0, 2)) or c((1, 0), (1, 1), (1, 2)) or c((2, 0), (2, 1), (2, 2)) or c((0, 0), (1, 0), (2, 0)) or c((0, 1), (1, 1), (2, 1)) or c((0, 2), (1, 2), (2, 2)) or c((0, 0), (1, 1), (2, 2)) or c((0, 2), (1, 1), (2, 0)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
bingo = [[int(i) for i in input().split()] for _ in range(3)]
N= [int(i) for i in input().split()][0]
bn =[int(input()) for _ in range(N)]

array = [[0 for _ in range(3)] for _ in range(3)]

for i in range(3):
  for j in range(3):
    a = bingo[i][j]
    for b in bn:
      if a == b:
        array[i][j] = 1
bing = False
cor1 = 0
cor2 = 0
for i in range(3):
  cor1 += array[i][i]
  cor2 += array[i][2-i] 
  sum1 = 0
  sum2 = 0
  for j in range(3):
    sum1 += array[i][j]
    sum2 += array[j][i]
  if sum1 == 3 or sum2 == 3:
    bing = True
if cor1 == 3 or cor2 == 3:
  bing = True
    
print("Yes" if bing else "No")

Submission status: Accepted

Solution code:
import sys

a=[]
for i in range(3):
    a= a+[int(x) for x in input().split()]

# print(a)
n=int(input())
for i in range(n):
    b=int(input())
    for j in range(9):
        if a[j] == b:
            a[j]=-1
# print(a)
for i,k,j in [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]]:
    if a[i-1]==a[j-1]==a[k-1]==-1:
        print("Yes")
        sys.exit()
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 = []
for i in range(n):
  b.append(int(input()))

if (a11 in b) and (a12 in b) and (a13 in b):
  print('Yes')
  exit()
if (a21 in b) and (a22 in b) and (a23 in b):
  print('Yes')
  exit()
if (a31 in b) and (a32 in b) and (a33 in b):
  print('Yes')
  exit()
if (a11 in b) and (a21 in b) and (a31 in b):
  print('Yes')
  exit()
if (a12 in b) and (a22 in b) and (a32 in b):
  print('Yes')
  exit()
if (a13 in b) and (a23 in b) and (a33 in b):
  print('Yes')
  exit()
if (a11 in b) and (a22 in b) and (a33 in b):
  print('Yes')
  exit()
if (a13 in b) and (a22 in b) and (a31 in b):
  print('Yes')
  exit()
print('No')

Submission status: Accepted

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

hit = [[0]*3 for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                hit[i][j] = 1

for i in range(3):
    if sum(hit[i]) == 3:
        print('Yes')
        exit()

for i in range(3):
    if hit[0][i]*hit[1][i]*hit[2][i] == 1:
        print('Yes')
        exit()

if hit[0][0]*hit[1][1]*hit[2][2] == 1 or hit[0][2]*hit[1][1]*hit[2][0] == 1:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

Solution code:
a = list()
ans = "No"
for i in range(3):
  a += list(map(int, input().split()))
n = int(input())
c = [int(input()) for i in range(n)]
b = [0] * 9
for i in c:
  for k,j in enumerate(a):
    if i == j:
      b[k] = 1
if b[0] and b[1] and b[2]:
  ans = "Yes"
if b[3] and b[4] and b[5]:
  ans = "Yes"
if b[6] and b[7] and b[8]:
  ans = "Yes"
if b[0] and b[3] and b[6]:
  ans = "Yes"
if b[1] and b[4] and b[7]:
  ans = "Yes"
if b[2] and b[5] and b[8]:
  ans = "Yes"
if b[0] and b[4] and b[8]:
  ans = "Yes"
if b[2] and b[4] and b[6]:
  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)]

ans = 'No'
if A[0][0] in B and A[0][1] in B and A[0][2] in B:
    ans = 'Yes'
if A[1][0] in B and A[1][1] in B and A[1][2] in B:
    ans = 'Yes'
if A[2][0] in B and A[2][1] in B and A[2][2] in B:
    ans = 'Yes'
if A[0][0] in B and A[1][0] in B and A[2][0] in B:
    ans = 'Yes'
if A[0][1] in B and A[1][1] in B and A[2][1] in B:
    ans = 'Yes'
if A[0][2] in B and A[1][2] in B and A[2][2] in B:
    ans = 'Yes'
if A[0][0] in B and A[1][1] in B and A[2][2] in B:
    ans = 'Yes'
if A[2][0] in B and A[1][1] in B and A[0][2] in B:
    ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
import sys
range = xrange
input = raw_input

A = []
for _ in range(3):
    A.append([int(x) for x in input().split()])

C = [[False,False,False] for _ in range(3)]

n = int(input())
for _ in range(n):
    b = int(input())
    for x in range(3):
        for y in range(3):
            if A[x][y] == b:
                C[x][y] = True
def bingo():
    print 'Yes'
    sys.exit()

for x in range(3):
    if all(C[x]):
        bingo()

for y in range(3):
    if all(C[x][y] for x in range(3)):
        bingo()

if all(C[x][x] for x in range(3)):
    bingo()

if all(C[x][~x] for x in range(3)):
    bingo()

print 'No'

Submission status: Accepted

Solution code:
A=[list(map(int,input().split())) for i in range(3)]
N=int(input())
B=[int(input()) for i in range(N)]
for i in range(3):
  for j in range(3):
    if A[i][j] in B:
      A[i][j]=0
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')
    exit(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')
    exit(0)
print('No')

Submission status: Accepted

Solution code:
import numpy as np


def main():
  a=np.zeros((3,3))

  d={}
  for i in range(3):
    a[i]=list(map(int, input().split()))
    for j in range(3):
      d[a[i,j]]=(i,j)
  N=int(input())
  b=[]
  for i in range(N):
    b=int(input())
    if b in d:
      a[d[b]]=1
      
  for i in range(3):
    if a[i].sum()==3:
      print('Yes')
      return
  for i in range(3):
    if a[:,i].sum()==3:
      print('Yes')
      return
  if a[0,0]+a[1,1]+a[2,2]==3:
    print('Yes')
    return
  if a[0,2]+a[1,1]+a[2,0]==3:
    print('Yes')
    return
  
  print('No')
  return
main()

Submission status: Accepted

Solution code:
bingo = [[int(c) for c in input().split()] for _ 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 bingo[j][k] == b:
                bingo[j][k] = 0
# よこ
for i in bingo:
    if sum(i) == 0:
        print('Yes')
        exit()
# たて
for i in range(3):
    tmp = 0
    for j in range(3):
        tmp += bingo[j][i]
    if tmp == 0:
        print('Yes')
        exit()

# ななめ
n1 = 0
n2 = 0
for i in range(3):
    n1 += bingo[i][i]
    n2 += bingo[i][2-i]
if n1 == 0 or n2 == 0:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

Solution code:
bingo = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
num = [int(input()) for _ in range(n)]
ans = [[0]* 3 for _ in range(3)]
for x in num:
    for i, row in enumerate(bingo):
        for j, bn in enumerate(row):
            if bn == x:
                ans[i][j] = 1
w = "No"
for i in range(3):
    if ans[0][i] == ans[1][i] == ans[2][i] == 1:
        w = "Yes"
        break
for i in ans:
    if sum(i) == 3:
        w = "Yes"
        break

if ans[0][0] == ans[1][1] == ans[2][2] == 1:
    w = "Yes"

if ans[0][2] == ans[1][1] == ans[2][0] == 1:
    w = "Yes"

print(w)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

a = []
for _ in range(3):
    line = [int(item) for item in input().split()]
    a += line

n = int(input())
ok = [False] * 9
for _ in range(n):
    b = int(input())
    for i in range(9):
        if a[i] == b:
            ok[i] = True

        
if ok[0] and ok[3] and ok[6]:
    print("Yes")
elif ok[1] and ok[4] and ok[7]:
    print("Yes")
elif ok[2] and ok[5] and ok[8]:
    print("Yes")
elif ok[0] and ok[1] and ok[2]:
    print("Yes")
elif ok[3] and ok[4] and ok[5]:
    print("Yes")
elif ok[6] and ok[7] and ok[8]:
    print("Yes")
elif ok[0] and ok[4] and ok[8]:
    print("Yes")
elif ok[2] and ok[4] and ok[6]:
    print("Yes")
else:
    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]"):
    result_flag = False
    for i in range(3):
        if A[i][0] in b and A[i][1] in b and A[i][2] in b:
            result_flag = True
        if A[0][i] in b and A[1][i] in b and A[2][i] in b:
            result_flag = True
    if A[0][0] in b and A[1][1] in b and A[2][2] in b:
        result_flag = True
    if A[0][2] in b and A[1][1] in b and A[2][0] in b:
        result_flag = True

    if result_flag:
        print("Yes")
    else:
        print("No")
    return


# Generated by 1.1.6 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:
card = [list(map(int, input().split())) for _ in range(3)]
used = [[False for _ in range(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 card[i][j] == b:
				used[i][j] = True

ok = False
for i in range(3):
	if used[i][0] and used[i][1] and used[i][2]:
		ok = True
	if used[0][i] and used[1][i] and used[2][i]:
		ok = True
	if used[0][0] and used[1][1] and used[2][2]:
		ok = True
	if used[0][2] and used[1][1] and used[2][0]:
		ok = True
if ok:
	print("Yes")
else:
	print("No")

Submission status: Accepted

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

for b in B:
    for i, line in enumerate(A):
        for j, a in enumerate(line):
            if a == b:
                flag[i][j] = True

# yoko
for line in flag:
    if line[0] and line[1] and line[2]:
        print("Yes")
        exit()
for i in range(3):
    if flag[0][i] and flag[1][i] and flag[2][i]:
        print("Yes")
        exit()

if (flag[0][0] and flag[1][1] and flag[2][2]) or(flag[0][2] and flag[1][1] and flag[2][0]):
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for _ in range(3)]
B = [[0]*3 for _ in range(3)]
bingo = set(int(input()) for _ in range(int(input())))
for i in range(3):
    for j in range(3):
        if A[i][j] in bingo:
            B[i][j] = 1

ans = "No"
for i in range(3):
    if sum(B[i]) == 3: ans = "Yes"

for j in range(3):
    if B[0][j] + B[1][j] + B[2][j] == 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:

#####

import numpy as np
from numpy import newaxis, float32, float64, int32, int64, int16, int8, uint8, uint32, complex64, complex128
import itertools

#####

def getIntList(inp):
	return [int(_) for _ in inp]
	

from sys import stdin

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs

def v(on):
	for i in range(3):
		if on[i,:].all():
			return True
	for i in range(3):
		if on[:,i].all():
			return True
	
	if on[0,0] and on[1,1] and on[2,2]: return True
	if on[2,0] and on[1,1] and on[0,2]: return True
	return False

def main(inputs):
	a=np.empty((3,3),int32)
	aIndex={}
	on=np.zeros((3,3),np.bool)
	for i,j in itertools.product(range(3),range(3)):
		a[i,j]=int(inputs[i][j])
		aIndex[a[i,j]]=(i,j)
		
	n=int(inputs[3][0])
	for i in range(n):
		bi=int(inputs[i+4][0])
		if bi in aIndex:
			index=aIndex[bi]
			on[index[0],index[1]]=True
	
	vv=v(on)
	if vv: print("Yes")
	else: print("No")
	

if __name__=="__main__":
	inputs=getInputs()
# 	inputs=simInputs()
	main(inputs)

Submission status: Accepted

Solution code:

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


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


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret

def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max,mod=DIV):
    fac,finv,inv = [0]*max, [0]*max, [0]*max
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod -inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
    class CONV:
        def __init__(self):
            pass
        def ncr(self,n,k):
            if(n<k):
                return 0
            if(n<0 or k<0 ):
                return 0
            return fac[n]*(finv[k]*finv[n-k]%mod)%mod
    return CONV()


def main():
    As = [isRaw() for _ in range(3)]
    N = iRaw()
    bs = [iRaw() for _ in range(N)]
    for b in bs:
        for ridx,arow in enumerate(As):
            for cidx,a in enumerate(arow):
                if a==b:
                    As[ridx][cidx] = 0
    for ridx in range(3):
        if sum(As[ridx])==0:
            return "Yes"
        if sum([As[i][ridx] for i in range(3)])==0:
            return "Yes"
    if sum([As[i][i] for i in range(3)])==0:
        return "Yes"
    if sum([As[2-i][i] for i in range(3)])==0:
        return "Yes"
    return "No"
                    

if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
l = [list(map(int,input().split())) for i in range(3)]
n = int(input())
a = []
for i in range(n):
    s = int(input())
    a.append(s)
ans = [[0]*3 for i in range(3)]

for j in range(3):
    for k in range(3):
        if l[j][k] in a:
            ans[j][k] = 1

for i in ans:
    if sum(i) == 3:
        print("Yes")
        exit()
for i in range(3):
    count = 0
    for j in range(3):
        if ans[j][i] == 1:
            count += 1
    if count == 3:
        print("Yes")
        exit()
if ans[0][0] == ans[1][1] == ans[2][2]==1:
    print("Yes")
    exit()
if ans[0][2] == ans[1][1] == ans[2][0] == 1:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

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

N = int(input())
for k in range(N):
    t = int(input())
    for e in C:
        for l in range(3):
            if e[l] == t:
                e[l] = -1

f = 0
for e in C:
    if e == [-1,-1,-1]:
        f = 1
        break

for k in range(3):
    if C[0][k] == C[1][k] == C[2][k] == -1:
        f = 1
        break
if C[0][0] == C[1][1] == C[2][2] == -1:
    f = 1
if C[0][2] == C[1][1] == C[2][0] == -1:
    f = 1

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

Submission status: Accepted

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

N = int(input())

for _ in range(N):
    b = int(input())

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

for i in range(3):
    f = True
    for j in range(3):
        f &= A[i][j] == -1

    if f:
        print('Yes')
        exit()

for i in range(3):
    f = True
    for j in range(3):
        f &= A[j][i] == -1

    if f:
        print('Yes')
        exit()

f = True
for i in range(3):
    f &= A[i][i] == -1

if f:
    print('Yes')
    exit()

f = True
for i in range(3):
    f &= A[2-i][i] == -1

if f:
    print('Yes')
    exit()


print('No')

Submission status: Accepted

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

for i in range(3):
    for j in range(2):
        if A[i][j] != A[i][j+1]: break
    else:
        print('Yes')
        exit()

for j in range(3):
    for i in range(2):
        if A[i][j] != A[i+1][j]: break
    else:
        print('Yes')
        exit()

for i in range(2):
    if A[i][i] != A[i+1][i+1]: break
else:
    print('Yes')
    exit()

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

print('No')

Submission status: Accepted

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

for _ in range(N):
    b = int(input())
    for y in range(3):
        for x in range(3):
            if A[y][x] == b:
                A[y][x] = -1

for y in range(3):
    f = True
    for x in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()

for x in range(3):
    f = True
    for y in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()

f = True
for x in range(3):
    if A[x][x] != -1:
        f = False
if f:
    print('Yes')
    exit()

f = True
for x in range(3):
    if A[2 - x][x] != -1:
        f = False
if f:
    print('Yes')
    exit()

print('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]=-1
ans="No"
for i in range(3):
    if A[i]==[-1,-1,-1]:
        ans="Yes"
for i in range(3):
    if A[0][i]==-1 and A[1][i]==-1 and A[2][i]==-1:
        ans="Yes"
if A[0][0]==-1 and A[1][1]==-1 and A[2][2]==-1:
    ans="Yes"
if A[0][2]==-1 and A[1][1]==-1 and A[2][0]==-1:
    ans="Yes"
print(ans)

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)])
flag = False
for i in range(3):
  if A[i][0] in b and A[i][1] in b and A[i][2] in b:
    flag = True
  if A[0][i] in b and A[1][i] in b and A[2][i] in b:
    flag = True
if A[0][0] in b and A[1][1] in b and A[2][2] in b:
  flag = True
if A[0][2] in b and A[1][1] in b and A[2][0] in b:
  flag = True
print(['No','Yes'][flag])

Submission status: Accepted

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

B=[[0,0,0]for i in range(3)]
#print(B)
N=int(input())
for i in range(N):
    n=int(input())
    for h in range(3):
        for w in range(3):
            if L[h][w]==n:
                B[h][w]=1

F=0
for h in range(3):
    cnt=0
    for w in range(3):
        cnt+=B[h][w]
    if cnt==3:
        F=1

for w in range(3):
    cnt=0
    for h in range(3):
        cnt+=B[h][w]
    if cnt==3:
        F=1

if B[0][0]+B[1][1]+B[2][2]==3:
    F=1
if B[2][0]+B[1][1]+B[0][2]==3:
    F=1
if F==1:
    print("Yes")
else:
    print("No")