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:
bingo = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
ans = []
for m in range(n):
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == b[m]:
                ans.append([i,j])
for i,j in ans:
    bingo[i][j] = -1
lists = []
cnt = 0

i = 0 
j = 0
if bingo[0][0] == -1 and bingo[0][1] == -1 and bingo[0][2] == -1:
                cnt = 1
if bingo[1][0] == -1 and bingo[1][1] == -1 and bingo[1][2] == -1:
                cnt = 1
if bingo[2][0] == -1 and bingo[2][1] == -1 and bingo[2][2] == -1:
                cnt = 1
if bingo[0][0] == -1 and bingo[1][0] == -1 and bingo[2][0] == -1:
                cnt = 1
if bingo[0][1] == -1 and bingo[1][1] == -1 and bingo[2][1] == -1:
                cnt = 1
if bingo[0][2] == -1 and bingo[1][2] == -1 and bingo[2][2] == -1:
    cnt = 1
if bingo[0][0] == -1 and bingo[1][1] == -1 and bingo[2][2] == -1:
                cnt = 1
if bingo[0][2] == -1 and bingo[1][1] == -1 and bingo[2][0] == -1:
                cnt = 1

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

Submission status: Accepted

Solution code:
import math
ind = 0
list = [[0 for i in range(3)] for j in range(3)]
for i in input().split():
  list[0][ind] = i
  ind+=1

ind = 0
for k in input().split():
  list[1][ind] = k
  ind+=1

ind = 0
for l in input().split():
  list[2][ind] = l
  ind+=1

ind = 0
kosu = int(input())
for kosu2 in range(kosu):
  p = int(input())
  for x in range(3):
    for y in range(3):
      if int(list[x][y]) == p:
        list[x][y] = -1

if list[0][0] == -1 and list[0][1] == -1 and list[0][2] == -1:
  print("Yes")
elif list[1][0] == -1 and list[1][1] == -1 and list[1][2] == -1:
  print("Yes")
elif list[2][0] == -1 and list[2][1] == -1 and list[2][2] == -1:
  print("Yes")
elif list[0][0] == -1 and list[1][0] == -1 and list[2][0] == -1:
  print("Yes")
elif list[0][1] == -1 and list[1][1] == -1 and list[2][1] == -1:
  print("Yes")
elif list[0][2] == -1 and list[1][2] == -1 and list[2][2] == -1:
  print("Yes")
elif list[0][0] == -1 and list[1][1] == -1 and list[2][2] == -1:
  print("Yes")
elif list[0][2] == -1 and list[1][1] == -1 and list[2][0] == -1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import numpy as np


card = np.array([list(map(int, input().split())) for _ in range(3)], dtype=np.int64)
n = int(input())
for _ in range(n):
    num = int(input())
    card[card == num] = 0
card = card == 0


def check_vertical(card):
    return np.all(card, axis=0).sum() >= 1


def check_horizon(card):
    return np.all(card, axis=1).sum() >= 1


def check_diagonal(card):
    check1 = np.diag(card).sum()
    check2 = np.diag(np.fliplr(card)).sum()
    return check1 == 3 or check2 == 3


if check_vertical(card) or check_horizon(card) or check_diagonal(card):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = 3
S = [list(map(int, input().split())) for _ in range(N)]
n_guess = int(input())
guesses = set([int(input()) for _ in range(n_guess)])
dic = {}
for r in range(N):
  for c in range(N):
    dic[S[r][c]]=(r,c)

for g in guesses:
  if g in dic:
    (r, c) = dic[g]
    S[r][c] = -1

ans = 'No'
for i in range(N):
  if sum(S[i]) == -3:
    ans='Yes'
    
for i in range(N):
  if sum([S[_][i] for _ in range(N)]) == -3:
    ans='Yes'
    
if all([S[i][N-i-1]==-1 for i in range(N)]) or \
   all([S[i][i]==-1 for i in range(N)]):
   	ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for i in range(3)]
A = A[0] + A[1] + A[2]
N = int(input())
for i in range(N):
    b = int(input())
    if b in A:
        A[A.index(b)] = 0
lines = [
            [A[0], A[3], A[6]],
            [A[1], A[4], A[7]],
            [A[2], A[5], A[8]],
            [A[0], A[1], A[2]],
            [A[3], A[4], A[5]],
            [A[6], A[7], A[8]],
            [A[0], A[4], A[8]],
            [A[2], A[4], A[6]],
        ]
if [0, 0, 0] in lines:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
array_1 = []
for i in range(3):
    line = input().rstrip().split(' ')
    array_1.append(line)
    
# print(array_1)

bool_array = []
for i in range(3):
    tmp = []
    for j in range(3):
        tmp.append(False)
    bool_array.append(tmp)

# print(bool_array)

num = int(input().rstrip())
for i in range(num):
    input_line = input().rstrip()
    for j in range(3):
        for k in range(3):
            if array_1[j][k] == input_line:
                bool_array[j][k] = True

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

for i in range(3):
    if bool_array[0][i] and bool_array[1][i] and bool_array[2][i]:
        ans = 'Yes'

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

if bool_array[0][2] and bool_array[1][1] and bool_array[2][0]:
    ans = 'Yes'
    
    
print(ans)

Submission status: Accepted

Solution code:
a=[];c=[];d=0;p=0;q=0;r=0;m=0;l=0
for i in range(3) :
    b=list(map(int,input().split()))
    a.append(b)
n=int(input())
for i in range(n) :
    z=int(input())
    c.append(z)
for i in range(len(a)) :
    for j in range(len(a)) :
        if a[i][j] in c :
            a[i][j]=1
for i in range(len(a)) :
    if a[i][0]+a[i][1]+a[i][2]==3 :
        d+=1
for i in range(len(a)) :
    p=p+a[i][0];q=q+a[i][1];r=r+a[i][2]
if p==3 or q==3 or r==3 :
    d+=1
for i in range(len(a)) :
    for j in range(len(a)) :
        if i==j :
            l=l+a[i][j]
        elif i+j==(len(a))-1 :
            m=m+a[i][j]
m=m+a[1][1]
if l==3 or m==3 :
    d+=1
if d==0 :
    print("No")
else :
    print("Yes")

Submission status: Accepted

Solution code:
list1 = input().split(" ")
list2 = input().split(" ")
list3 = input().split(" ")
count = int(input())
correct = ['o','o','o']
answer = "No"
for i in range(count):
	num = input()
	list1 = ['o' if i == num else i for i in list1]
	list2 = ['o' if i == num else i for i in list2]
	list3 = ['o' if i == num else i for i in list3]
	vlist1 = [list1[0],list2[0],list3[0]]
	vlist2 = [list1[1],list2[1],list3[1]]
	vlist3 = [list1[2],list2[2],list3[2]]
	xlist1 = [list1[0],list2[1],list3[2]]
	xlist2 = [list1[2],list2[1],list3[0]]
	if list1 == correct:
		answer = "Yes"
		break
	elif list2 == correct:
		answer = "Yes"
		break
	elif list3 == correct:
		answer = "Yes"
		break
	elif vlist1 == correct:
		answer = "Yes"
		break
	elif vlist2 == correct:
		answer = "Yes"
		break
	elif vlist3 == correct:
		answer = "Yes"
		break
	elif xlist1 == correct:
		answer = "Yes"
		break
	elif xlist2 == correct:
		answer = "Yes"
		break    
print(answer)

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
d = [[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:
        d[i][j] = 1
        
ans = "No"
 
for i in range(3):
  if sum(d[i]) == 3:
    ans = "Yes"
    break
  if sum([D[i] for D in d]) == 3:
    ans = "Yes"
    break
if sum([d[i][i] for i in range(3)]) == 3:
  ans = "Yes"
 
if sum([d[i][2 - i] for i in range(3)]) == 3:
  ans = "Yes"
  
print(ans)

Submission status: Accepted

Solution code:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def solve(l):
	n = len(l)
	

L = []
for i in range(3):
	l = list(map(int, stdin.readline().rstrip().split()))
	L.append(l)
# for i in L:
# 	print(i)
N = int(input())
for _ in range(N):
	q = int(input())
	for i in range(3):
		for j in range(3):
			if(L[i][j] == q):
				L[i][j] = -1
f = 0
for i in range(3):
	if(L[i] == [-1,-1,-1]):
		f = 1
if(not f):
	if(L[0][0] == L[1][0] == L[2][0] == -1):
		f = 1
	if(L[0][1] == L[1][1] == L[2][1] == -1):
		f = 1
	if(L[0][2] == L[1][2] == L[2][2] == -1):
		f = 1
	if(L[0][0] == L[1][1] == L[2][2] == -1):
		f = 1
	if(L[0][2] == L[1][1] == L[2][0] == -1):
		f = 1
	
# for i in L:
# 	print(i)
if(f):
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
a1=list(map(int, input().split()))
a2=list(map(int, input().split()))
a3=list(map(int, input().split()))
n=int(input())
a=[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for i in range(n):
  b = int(input())
  if b in a1:
    a[0][a1.index(b)] = 1
  elif b in a2:
    a[1][a2.index(b)] = 1
  elif b in a3:
    a[2][a3.index(b)] = 1
ans = 'No'
if a[0] == [1, 1, 1]:
  ans = 'Yes'
elif a[1] == [1, 1, 1]:
  ans = 'Yes'
elif a[2] == [1, 1, 1]:
  ans = 'Yes'
elif a[0][0]==1 and a[1][0]==1 and a[2][0]==1:
  ans = 'Yes'
elif a[0][1]==1 and a[1][1]==1 and a[2][1]==1:
  ans = 'Yes'
elif a[0][2]==1 and a[1][2]==1 and a[2][2]==1:
  ans = 'Yes'
elif a[0][0]==1 and a[1][1]==1 and a[2][2]==1:
  ans = 'Yes'
elif a[0][2]==1 and a[1][1]==1 and a[2][0]==1:
  ans = 'Yes'
print(ans)

Submission status: Accepted

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



N = int(input())

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

    for m in range(3):
        for n in range(3):
            if A[n][m] == b:
                A[n][m] = '○'

ans = 'No'

for i in range(3):
    if A[i][0] == A[i][1] and A[i][2] == A[i][1] and A[i][0] == '○':
        ans = 'Yes'
        
    if A[0][i] == A[1][i] and A[2][i] == A[1][i] and A[0][i] == '○':
        ans = 'Yes'

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

print(ans)

Submission status: Accepted

Solution code:
A=tuple(tuple(int(i) for i in input().split()) for j in range(3))
TF=[[False for i in range(3)] for j in range(3)]
N=int(input())
for i in range(N):
  b=int(input())
  for p in range(3):
    for q in range(3):
      if A[p][q] == b:
        TF[p][q]=True
ans=False
for i in range(3):
  if all(TF[i][j] for j in range(3)):
    ans=True
  if all(TF[j][i] for j in range(3)):
    ans=True
if all(TF[j][j] for j in range(3)):
  ans=True
if all(TF[j][-(j+1)] for j in range(3)):
  ans=True
print('Yes' if ans else 'No')

Submission status: Accepted

Solution code:
def main():
    a = [list(map(int, input().split())) for _ in range(3)]
    n = int(input())
    b = [int(input()) for _ in range(n)]
    card = [[False]*3 for _ in range(3)]
    for i in range(3):
        for j in range(3):
            if a[i][j] in b:
                card[i][j] = True

    ans = "No"
    for i in range(3): #横に見てる
        if card[i][0] and card[i][1] and card[i][2]:
            ans = "Yes"
    for i in range(3): # 縦に見てる
        if card[0][i] and card[1][i] and card[2][i]:
            ans = "Yes"
    if card[0][0] and card[1][1] and card[2][2]:
        ans = "Yes"
    if card[0][2] and card[1][1] and card[2][0]:
        ans = "Yes"
    print(ans)

    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a = [list(map(int,input().split())) for _ in range(3)]
for i in range(int(input())):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k]==b:a[j][k]=0
ans="No"
for i in range(3):
  if a[i][0]==a[i][1]==a[i][2]==0:ans="Yes"
  if a[0][i]==a[1][i]==a[2][i]==0:ans="Yes"
if a[0][0]==a[1][1]==a[2][2]==0:ans="Yes"
if a[2][0]==a[1][1]==a[0][2]==0:ans="Yes"
print(ans)

Submission status: Accepted

Solution code:
def ii():return int(input())
def mi():return map(int,input().split())

a=[]
for _ in range(3):
  a+=list(mi())
n=ii()
b=[]
for i in range(n):
  b+=ii(),

def ana(x):
  if x in b:
    return 1
  else:
    return 0

c=[ana(aa) for aa in a]

oks="012 345 678 036 147 258 048 246".split()

for ok in oks:
  res=1
  for j in list(ok):
    res*=c[int(j)]
  if res==1:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
tab = [a, b, c]
tab += [[a[0], b[0], c[0]]]
tab += [[a[1], b[1], c[1]]]
tab += [[a[2], b[2], c[2]]]
tab += [[a[0], b[1], c[2]]]
tab += [[a[2], b[1], c[0]]]

n = int(input())
p = []
for _ in range(n):
  x = int(input())
  p.append(x)

for v in tab:  
  x = 0
  for i in v:
    if i in p:
      x += 1
  if x == 3:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

Solution code:
C = []
C.append(list(map(int, input().split())))
C.append(list(map(int, input().split())))
C.append(list(map(int, input().split())))

B = [[0,0,0],[0,0,0],[0,0,0]]
N = int(input())
for i in range(N):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if C[j][k]==b:
        B[j][k]=1
  
ans = 'No'
#Row
for j in range(3):
  if B[j][0] == 1 and B[j][1] == 1 and B[j][2] == 1:
    ans = "Yes"

#Col
for j in range(3):
  if B[0][j] == 1 and B[1][j] == 1 and B[2][j] == 1:
    ans = "Yes"

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

print(ans)

Submission status: Accepted

Solution code:
A = []
for i in range(3):
    a = input().split()
    a = [int(x) for x in a]
    A.append(a)
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
T = 'No'
for i in range(3):
    if sum(A[i]) == 0:
        T = 'Yes'
        break
    s = 0
    for j in range(3):
        s += A[j][i]
    if s == 0:
        T = "Yes"
if A[0][0]+A[1][1]+A[2][2] == 0 or A[0][2]+A[1][1]+A[2][0] == 0:
    T = 'Yes'
print(T)

Submission status: Accepted

Solution code:
A = [input().split() for i in range(3)]
B = [[False]*3 for i in range(3)]
n = int(input())
for i in range(n) :
    b = input()
    for j in range(3) :
        for k in range(3) :
            if A[j][k] == b :
                B[j][k] = True

res = "No"
for i in range(3) :
    if B[i][0] == B[i][1] == B[i][2] == True :
        res = "Yes"
    elif B[0][i] == B[1][i] == B[2][i] == True :
        res = "Yes"

if B[0][0] == B[1][1] == B[2][2] == True :
    res = "Yes"
elif B[2][0] == B[1][1] == B[0][2] == True :
    res = "Yes"

print(res)

Submission status: Accepted

Solution code:
(lambda A:(lambda N:(lambda
C:(lambda d:(lambda B:print
(["No","Yes"][3 in{sum(B[2:
8:2]),sum(B[::4])}|{sum(B[i
*3:i*3+3])for i in range(3)
} | { sum(B[i::3] )for i in
range(3)} ] ) ) ( list(map(
lambda x:d[x],A))))([x in C
for x in range(101)]))({int
(input())for x in range(N)}
))(int(input())))(list(map(
int,input().split()))+list(
map(int,input().split())) +
list(map(int,input().split())))

Submission status: Accepted

Solution code:
import numpy as np
import sys

#入力処理、Aは行列、Bはリスト
A = []
for i in range(3):
    A.append([int(a) for a in input().split()])

B = []
for l in sys.stdin:
    if l == '\n':
        break
    l = l.rstrip('\n')
    B.append(int(l))

#穴あきか判定
for i in B:
    A = np.where(A == i, 0, A)
#なんか0番目を判定してくれないから個別に判定
A = np.where(A == B[0], 0, A)

#ビンゴ判定
bingo = False
#ななめ
if A[0][0]+A[1][1]+A[2][2] == 0 or A[0][2]+A[1][1]+A[2][0] == 0:
    bingo = True

for i in range(3):
    #よこ
    if sum(A[i]) == 0:
        bingo = True
        break

    #たて
    if A[0][i]+A[1][i]+A[2][i]==0:
        bingo = True
        break

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

Submission status: Accepted

Solution code:
# def print_sheet(sheet):
#     for i in range(3):
#         print(sheet[3*i:3*(i+1)])

sheet = []
for i in range(3):
    sheet += list(map(int, input().split()))
answer = [False for i in range(9)]

# print_sheet(sheet)
# print_sheet(answer)

n = int(input())

# print("n, ", n)

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

# print("B: ", bs)

for b in bs:
    for i in range(9):
        if sheet[i] == b:
            answer[i] = True

# print_sheet(answer)

res = "No"

for i in range(3):
    if answer[i] and answer[i+3] and answer[i+6]:
        res = "Yes"
    elif answer[3*i] and answer[1+3*i] and answer[2+3*i]:
        res = "Yes"

if answer[0] and answer[4] and answer[8]:
    res= "Yes"
if answer[2] and answer[4] and answer[6]:
    res = "Yes"

print(res)

Submission status: Accepted

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


def rotate_counterclockwise(matrix):
    """2次元リストを反時計回りに回転"""
    return list(map(list, zip(*matrix)))[::-1]


for b in B:
    for row in range(SIZE):
        for col in range(SIZE):
            if A[row][col] == b:
                A[row][col] = 0
ans = 'No'
for _ in range(2):
    # 行と対角成分のそれぞれについて、和が 0 になったらビンゴとなる
    for row in range(SIZE):
        if sum(A[row]) == 0:
            ans = 'Yes'
    if sum(A[k][k] for k in range(SIZE)) == 0:
        ans = 'Yes'
    # カードを回転させることで、同じ処理を使い回す
    A = rotate_counterclockwise(A)

print(ans)

Submission status: Accepted

Solution code:
A=[]
B=[False]*9
for i in range(3):
    A+=[int(i) for i in input().split()]
n=int(input())
for _ in range(n):
    b=int(input())
    for i in range(9):
        if b==A[i]:
            B[i]=True
C=[[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]]
ans=False
for a,b,c in C:
    if B[a-1] and B[b-1] and B[c-1]:
        ans=True
print("Yes" if ans else "No")

Submission status: Accepted

Solution code:
from collections import defaultdict
def a():
    A = []
    A += list(map(int,input().split()))
    A += list(map(int,input().split()))
    A += list(map(int,input().split()))
    N = int(input())
    d = defaultdict(int)
    for _ in range(N):
        d[int(input())] = 1

    B = list(map(lambda x:d[x],A))

    if sum(B[::4]) == 3:
        return 1
    
    if sum(B[2:8:2]) == 3:
        return 1
    
    for i in range(3):
        if sum(B[i*3:i*3+3]) == 3:
            return 1
        if sum(B[i::3]) == 3:
            return 1
    
    return 0

print(["No","Yes"][a()])

Submission status: Accepted

Solution code:
a,b,c  = map(int, input().split())
d,e,f  = map(int, input().split())
g,h,i  = map(int, input().split())
n=int(input())
A = []
for j in range(n):
    A.append(int(input()))
if (a in A) and (b in A) and (c in A):
    print("Yes")
elif d in A and e in A and f in A:
    print("Yes")
elif g in A and h in A and i in A:
    print("Yes")
elif a in A and d in A and g in A:
    print("Yes")
elif b in A and e in A and h in A:
    print("Yes")
elif c in A and f in A and i in A:
    print("Yes")
elif a in A and e in A and i in A:
    print("Yes")
elif c in A and e in A and g in A:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


def main():
	A=[]
	for i in range(3):
		A+=list(map(int,input().split()))
	n=int(input())
	
	for i in range(n):
		b=int(input())
		for j in range(9):
			if b==A[j]:
				A[j]=0
	
	ans="No"
	
	for i in range(3):
		if A[i]==A[i+3]==A[i+6]==0:
			ans="Yes"
		if A[i*3]==A[i*3+1]==A[i*3+2]==0:
			ans="Yes"
	
	if A[0]==A[4]==A[8]==0 or A[2]==A[4]==A[6]==0:
		ans="Yes"
		
	print(ans)
	
	
	
	
	
	
	
	

if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
li_a = list(map(int,input().split()))
li_b = list(map(int,input().split()))
li_c = list(map(int,input().split()))
n = int(input())
li_num=[int(input()) for i in range(n)]
 
li_card = [li_a, li_b, li_c]
 
ans = False
 
#print(li_card)
#print(li_b)
#print(li_c)
#print(n)
#print(li_num)
 
for m in li_num:
    for i in range(3):
        for j in range(3):
          if li_card[i][j] == m:
              li_card[i][j] = 0
 
for i in range(3):
    if li_card[i][0] == li_card[i][1] == li_card[i][2]:
        ans = True
        break
    elif li_card[0][i] == li_card[1][i] == li_card[2][i]:
        ans = True
        break
 
if not ans:
  if li_card[0][0] == li_card[1][1] == li_card[2][2]:
      ans = True
  elif li_card[0][2] == li_card[1][1] == li_card[2][0]:
      ans = True
 
if ans:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
a = [list(map(int,input().split()))for i in range(3)]
raw = []
for i in range(3):
    raw.append([a[i][0],a[i][1],a[i][2]])
    raw.append([a[0][i],a[1][i],a[2][i]])
raw.append([a[0][0],a[1][1],a[2][2]])
raw.append([a[0][2],a[1][1],a[2][0]])
cnt = [0]*8
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(8):
        if b in raw[j]:cnt[j]+=1
cnt.sort()
if cnt[-1] == 3:print("Yes")
else:print("No")

Submission status: Accepted

Solution code:
bingo = []
for _ in range(3):
    x,y,z = map(int,input().split())
    bingo.append((x,y,z))
n=int(input())
appear=[[False]*3 for i in range(3)]
b=[]
for _ in range(n):
    b.append(int(input()))
for i in range(3):
    for j in range(3):
        for k in range(len(b)):
            if bingo[i][j] == b[k]:
                appear[i][j] = True
ans = "No"
for i in range(3):
    if appear[i][0] and appear[i][1] and appear[i][2]:
        ans = "Yes"
for i in range(3):
    if appear[0][i] and appear[1][i] and appear[2][i]:
        ans = "Yes"
isdia = True
for i in range(3):
    if not appear[i][i]:
        isdia = False
if isdia:
    ans = "Yes"
isdia = True
j = 2
for i in range(3):
    if not appear[i][j-i]:
        isdia = False
if isdia:
    ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
li_a = list(map(int,input().split()))
li_b = list(map(int,input().split()))
li_c = list(map(int,input().split()))
n = int(input())
li_num=[int(input()) for i in range(n)]
 
li_card = [li_a, li_b, li_c]
 
ans = False
 
#print(li_card)
#print(li_b)
#print(li_c)
#print(n)
#print(li_num)
 
for m in li_num:
    for i in range(3):
        for j in range(3):
          if li_card[i][j] == m:
              li_card[i][j] = 0
 
for i in range(3):
    if li_card[i][0] == li_card[i][1] == li_card[i][2] == 0:
        ans = True
        break
    elif li_card[0][i] == li_card[1][i] == li_card[2][i] == 0:
        ans = True
        break
 
if not ans:
  if li_card[0][0] == li_card[1][1] == li_card[2][2] == 0:
      ans = True
  elif li_card[0][2] == li_card[1][1] == li_card[2][0] == 0:
      ans = True
 
if ans:
  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],[0,0,0],[0,0,0]]

def my_index(L, x):
    return L.index(x) if x in L else -1

for k in b:
    for i in range(3):
        if my_index(A[i], k) != -1:
            bingo[i][my_index(A[i], k)] = 1
            
ans = 0
for i in range(3):
    if bingo[i] == [1,1,1]:
        ans = 1
    if bingo[0][i] * bingo[1][i] * bingo[2][i]:
        ans = 1
    if bingo[0][0] * bingo[1][1] * bingo[2][2]:
        ans = 1
    if bingo[0][2] * bingo[1][1] * bingo[2][0]:
        ans = 1
        
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# coding: utf-8


def main():
    bingo = []
    bingo.append(list(map(int, input().split())))
    bingo.append(list(map(int, input().split())))
    bingo.append(list(map(int, input().split())))
    
    list1 = [bingo[0][0], bingo[1][0], bingo[2][0]]
    list2 = [bingo[0][1], bingo[1][1], bingo[2][1]]
    list3 = [bingo[0][2], bingo[1][2], bingo[2][2]]
    list4 = [bingo[0][0], bingo[1][1], bingo[2][2]]
    list5 = [bingo[0][2], bingo[1][1], bingo[2][0]]
    
    bingo += list1, list2, list3, list4, list5
    
    n = int(input())
    num = list()
    for _ in range(n):
        num.append(int(input()))
        
    counter = 0   
    for i in range(8):
        for j in range(3):
            if bingo[i][j] in num:
                counter += 1
        if counter == 3:
            print('Yes')
            break
        else:
            counter = 0
            
    if counter != 3:
        print('No')
    
    
    return 0


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    called = [0] * (100 + 1)  # 読み上げられた番号

    a = []
    for _ in range(3):
        *row, = map(int, input().split())
        a.append(row)

    n = int(input())
    for _ in range(n):
        b = int(input())
        called[b] = 1

    for r in range(3):
        for c in range(3):
            number = a[r][c]
            if not called[number]:
                break
        else:
            print('Yes')
            return

    for c in range(3):
        for r in range(3):
            number = a[r][c]
            if not called[number]:
                break
        else:
            print('Yes')
            return

    for i in range(3):
        number = a[i][i]
        if not called[number]:
            break
    else:
        print('Yes')
        return

    for i in range(3):
        number = a[i][2 - i]
        if not called[number]:
            break
    else:
        print('Yes')
        return

    print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A = []
out = []
for x in range(3):
    A.append(list(map(int, input().split())))
    out.append([0, 0, 0])
N = int(input())
b = []
for B in range(N):
    b.append(int(input()))
for pick in b:
    for y in range(3):
        for x in range(3):
            if pick == A[y][x]:
                out[y][x] = 1

bingo = False
for x in range(3):
    if out[x][0] == 1 and out[x][1] == 1 and out[x][2] == 1:
        bingo = True

for x in range(3):
    if out[0][x] == 1 and out[1][x] == 1 and out[2][x] == 1:
        bingo = True

for x in range(3):
    if out[0][0] == 1 and out[1][1] == 1 and out[2][2] == 1:
        bingo = True

    if out[2][0] == 1 and out[1][1] == 1 and out[2][0] == 1:
        bingo = True

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

Submission status: Accepted

Solution code:
#Input
l_A =  [[0 for i in range(3)] for j in range(3)]
l_A[0] = list(map(int, input().split()))
l_A[1] = list(map(int, input().split()))
l_A[2] = list(map(int, input().split()))

def detect_BINGO(l_Atf):
    #print(l_Atf)
    #横
    for i in range(3):
        f_detect = True
        for j in range(3):
            #print(f_detect, l_Atf[i][j])
            f_detect = f_detect and l_Atf[i][j]
        if(f_detect):
            #print("横" + str(i))
            return True
    #縦
    for i in range(3):
        f_detect = True
        for j in range(3):
            f_detect = f_detect and l_Atf[j][i]
        if(f_detect):
            #print("縦" + str(i))
            return True
    #斜
    f_detect = True
    for i in range(3):
        f_detect = f_detect and l_Atf[i][i]
    if(f_detect):
        #print("斜＼")
        return True
    f_detect = True
    for i in range(3):
        f_detect = f_detect and l_Atf[i][3-1-i]
    if(f_detect):
        #print("斜／")
        return True
    
    #BINGOなし
    return False

#Process
l_Atf = [[False for i in range(3)] for j in range(3)]
for i in range(int(input())):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if(l_A[j][k] == b):
                l_Atf[j][k] = True
    #print(l_Atf)

f_bingo = detect_BINGO(l_Atf)

#Output
if(f_bingo):
    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()))
A = [[0, 0, 0],[0, 0, 0],[0, 0, 0]]

N = int(input())

# 印の箇所を1とする
for i in range(N):
    b = int(input())
    if b in A1:
        A[0][A1.index(b)] = 1
    elif b in A2:
        A[1][A2.index(b)] = 1
    elif b in A3:
        A[2][A3.index(b)] = 1

# ビンゴの有無を判定
ans = "No"
a = max(sum(A[0]), sum(A[1]), sum(A[2]), (A[0][0] + A[1][0] + A[2][0]), (A[0][1] + A[1][1] + A[2][1]), (A[0][2] + A[1][2] + A[2][2]), (A[0][0] + A[1][1] + A[2][2]), (A[0][2] + A[1][1] + A[2][0]))
if a == 3:
    ans = "Yes"

print(ans)

Submission status: Accepted

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

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

for i in range(len(bingo)):
    if bingo[i] in b_list:
        bingo[i] = 'X'

pattern_list =[[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
flag = 0
for i in range(len(pattern_list)):
    if bingo[pattern_list[i][0]] == 'X' and bingo[pattern_list[i][1]] == 'X' and bingo[pattern_list[i][2]] == 'X':
        flag = 1
        break

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

Submission status: Accepted

Solution code:
X = [[0 for i in range(3)] for j in range(3)]
for x in range(3):
    Y = list(map(int,input().split()))
#    print(Y)
    #print(Y[0])
    for y in range(3):
        X[x][y] = Y[y]
#        print(x,y,X[x][y],Y[y])
#print(X)


N = int(input())
B = []
for x in range(N):
    B.append(int(input()))
#print(X)
#print(B)
for x in B:
    for y in range(3):
        for z in range(3):
            if(X[y][z] == x):
                X[y][z] = True
ans = "No"
for x in range(3):
    if(X[x][0] == True and X[x][1] == True and X[x][2] == True):
        ans = "Yes"
    if(X[0][x] == True and X[1][x] == True and X[2][x] == True):
        ans = "Yes"
if(X[0][0] == True and X[1][1] == True and X[2][2] == True):
    ans = "Yes"
if(X[0][2] == True and X[1][1] == True and X[2][0] == True):
    ans = "Yes"
print(ans)