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:
A = []
for i in range(3):
    a = list(input().split())
    A.append(a)
N = int(input())
B = []
for i in range(N):
    b = input()
    B.append(b)

bingo = [[False] * 3, [False] * 3, [False] * 3]

for i in range(3):
    for j in range(3):
        for x in range(N):
            if A[i][j] == B[x]:
                bingo[i][j] = True
ans = 'No'

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

print(ans)

Submission status: Accepted

Solution code:
size = 3
A_list = [[]] * size
A_list[0] = list(map(int, input().split(' ')))
A_list[1] = list(map(int, input().split(' ')))
A_list[2] = list(map(int, input().split(' ')))
N = int(input())
b_list = [int(input()) for _ in range(N)]
bingo_flag = False
for i in range(size):
    count = 0
    for j in range(size):
        if A_list[i][j] in b_list:
            count += 1
        else:
            break
    if count == size:
        bingo_flag = True
        break
if not bingo_flag:
    for j in range(size):
        count = 0
        for i in range(size):
            if A_list[i][j] in b_list:
                count += 1
            else:
                break
        if count == size:
            bingo_flag = True
            break
if not bingo_flag:
    count = 0
    for i in range(size):
        if A_list[i][i] in b_list:
            count += 1
        else:
            break
    if count == 3:
        bingo_flag = True
if not bingo_flag:
    count = 0
    for i in range(size):
        j = size - 1 - i
        if A_list[i][j] in b_list:
            count += 1
        else:
            break
    if count == size:
        bingo_flag = True
if bingo_flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
A = [[0]*3]*3
for i in range(3):
    A[i] = list(map(int,input().split()))
N = int(input())
for _ in range(N):
    a = int(input())
    for i in range(3):
        if a in A[i]:
            A[i][A[i].index(a)] = 0
for i in range(3):
    if A[i].count(0) == 3:
        print("Yes")
        exit()
for i in range(3):
    if A[0][i] == 0 and A[1][i] == 0 and A[2][i] == 0:
        print("Yes")
        exit()
for i in range(3):
    if A[i][i] != 0:
        break
    if i == 2:
        print("Yes")
        exit()
if A[2][0] == 0 and A[1][1] == 0 and A[0][2] == 0:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
from sys import exit, stdin
A = [list(map(int, stdin.readline().rstrip().split())) for _ in range(3)]
bin_A = [[0]*3 for _ in range(3)]
N = int(stdin.readline().rstrip())
B = [int(stdin.readline().rstrip()) for _ in range(N)]
for i in range(N):
    for j in range(3):
        for k in range(3): 
            if A[j][k] == B[i]:
                bin_A[j][k] = 1
ans = 'No'
for i in range(3):
    if bin_A[i][0] + bin_A[i][1] + bin_A[i][2] == 3:
        ans = 'Yes'
for j in range(3):
    if bin_A[0][j] + bin_A[1][j] + bin_A[2][j] == 3:
        ans = 'Yes'
if bin_A[0][0] + bin_A[1][1] + bin_A[2][2] == 3:
    ans = 'Yes'
if bin_A[0][2] + bin_A[1][1] + bin_A[2][0] == 3:
    ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
l=[list(map(int,input().split())) for i in range(3)]
n=int(input())
H=[0,0,0]
W=[0,0,0]
S=[0,0]

for i in range(n):
    b=int(input())
    for h in range(3):
        for w in range(3):
            if b==l[h][w]:
                H[h]+=1
                W[w]+=1
                if h==w:
                    S[0]+=1
                if h+w==2:
                    S[1]+=1

check=False
for h in H:
    if h==3:
        check=True
for w in W:
    if w==3:
        check=True
for s in S:
    if s==3:
        check=True

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

Submission status: Accepted

Solution code:
import numpy as np
N_1=list(map(int, input().split()))
N_2=list(map(int, input().split()))
N_3=list(map(int, input().split()))
N=int(input())
a=[int(input()) for i in range(N)]

n=np.array([N_1,N_2,N_3])

for a_n in a:
    if a_n in n:
        n[n==a_n]=0
    else:
        pass
i=0
    
if np.all(n[0:,0]==0)==True:
    i=+1
    
elif np.all(n[0:,1]==0)==True:
    i+=1
    
elif np.all(n[0:,2]==0)==True:
    i+=1
    
elif np.all(n[0,0:]==0)==True:
    i+=1
    
elif np.all(n[1,0:]==0)==True:
    i+=1

elif np.all(n[2,0:]==0)==True:
    i+=1

elif n[0,0]==0 and n[1,1]==0  and n[2,2] ==0:
    i+=1
    
elif n[0,2]==0 and n[1,1]==0 and n[2,0] ==0:
    i+=1
    
if i>0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# ビンゴカード
bingo_card = list()
for i in range(3):
    bingo_card.append(input().split(' '))
# 引いた回数
pick_count = int(input().strip())
# 引いた番号
picked_number = list()
for j in range(pick_count):
    picked_number.append(input().strip())

# ビンゴ成立条件
bingo_line = list()
# 横
for i in range(3):
    bingo_line.append(bingo_card[i-1])
# 縦
bingo_line.append([bingo_card[0][0], bingo_card[1][0], bingo_card[2][0]])
bingo_line.append([bingo_card[0][1], bingo_card[1][1], bingo_card[2][1]])
bingo_line.append([bingo_card[0][2], bingo_card[1][2], bingo_card[2][2]])
# 斜め
bingo_line.append([bingo_card[0][0], bingo_card[1][1], bingo_card[2][2]])
bingo_line.append([bingo_card[0][2], bingo_card[1][1], bingo_card[2][0]])

established_line = [line for line in bingo_line if len(set(line) & set(picked_number)) == 3]
print('Yes' if len(established_line) > 0 else 'No')

Submission status: Accepted

Solution code:
import sys

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

n = int(input())
bs = list()
for ii in range(0,n):
    bs.append(int(input()))

for b in bs:
    for ii in range(0,3):
        for jj in range(0,3):
            if bingo[ii][jj] == b:
                bingo[ii][jj] = 0

for ii in range(0,3):
    tmp_row = 0
    tmp_col = 0
    for jj in range(0,3):
        tmp_row = tmp_row + bingo[ii][jj]
        tmp_col = tmp_col + bingo[jj][ii]

    if (tmp_row == 0) or (tmp_col == 0):
        print('Yes')
        sys.exit()

ob1 = bingo[0][0] + bingo[1][1] + bingo[2][2]
ob2 = bingo[0][2] + bingo[1][1] + bingo[2][0]

if (ob1 == 0) or (ob2 == 0):
    print('Yes')
    sys.exit()

print('No')

Submission status: Accepted

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

X = []
X += [set(A[i]) for i in range(3)]
X += [set([A[j][i] for j in range(3)]) for i in range(3)]
X += [set([A[0][2], A[1][1], A[2][0]]), set([A[2][2], A[1][1], A[0][0]])]

for x in X:
  if x <= B:
    print('Yes')
    break
else:
  print('No')

Submission status: Accepted

Solution code:
def bingo(marked):
    for i in range(3):
        all_marked = True
        for j in range(3):
            if not marked[i][j]:
                all_marked = False
        if all_marked:
            return True
    
    for i in range(3):
        all_marked = True
        for j in range(3):
            if not marked[j][i]:
                all_marked = False
        if all_marked:
            return True
    
    all_marked = True
    for i in range(3):
        if not marked[i][i]:
            all_marked = False
    if all_marked:
        return True
    
    all_marked = True
    for i in range(3):
        if not marked[2 - i][i]:
            all_marked = False
    if all_marked:
        return True

    return False
            
A = [[] for i in range(3)]
marked=  [[False for i in range(3)] for j in range(3)]
for i in range(3):
    A[i] = list(map(int, input().split()))
N = int(input())
for i in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                marked[i][j] = True
                
if bingo(marked):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np

A = np.array([list(map(int, input().split())) for _ in range(3)])
N = int(input())
for _ in range(N):
    b = int(input())
    A[np.where(A == b)] = -1

if -3 in np.sum(A, axis=1) or -3 in np.sum(A, axis=0):
    print("Yes")
elif A[0, 0] + A[1, 1] + A[2, 2] == -3:
    print("Yes")
elif A[0, 2] + A[1, 1] + A[2, 0] == -3:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
bingoDict = {}
bingoList = []
pos = 0
mark = 0 

#Creates a list containing three lists for each row of numbers
for i in range(3):
  bingoList.append(list(map(int, input().split())))

#Iterates through list inside of list, adding them to a dictionary 
for row in range(len(bingoList)):
  for item in range(len(bingoList[row])):
    pos += 1
    tempList = [] 
    tempList.append(bingoList[row][item])
    tempList.append(0)
    bingoDict[pos] = tempList

#Number of numbers called 
N = int(input())

#If the number is mentioned, add one to value (could be more than 1)
for i in range(N):
  numCalled = int(input())
  for key in bingoDict:
    if numCalled == bingoDict[key][0]:
      bingoDict[key][1] += 1

#print('\n BingoDict: %s' % bingoDict)
  
for key in bingoDict:
  if (key == 1 or key == 4 or key == 7) and key + 2 <= 9:
    if bingoDict[key][1] and bingoDict[key + 1][1] and bingoDict[key + 2][1] >= 1:
      mark = 1
  if key + 6 <= 9:
    if bingoDict[key][1] and bingoDict[key + 3][1] and bingoDict[key + 6][1] >= 1:
      mark = 1
  if key == 1:
    if bingoDict[key][1] and bingoDict[key + 4][1] and bingoDict[key + 8][1] >= 1:
      mark = 1
  if key == 3:
    if bingoDict[key][1] and bingoDict[key + 2][1] and bingoDict[key + 4][1] >= 1:
      mark = 1

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

Submission status: Accepted

Solution code:
dic={}
a=[]
for i in range(1,100):
    dic[i]=[-1,-1]
for i in range(3):
    a.append(list(map(int,input().split())))
    for j in range(3):
        dic[a[i][j]]=[i,j]
n=int(input())
for i in range(n):
    x=int(input())
    if(dic[x]!=[-1,-1]):
        a[dic[x][0]][dic[x][1]]=0
flag=0
for i in range(3):
    if(max(a[i][1],a[i][2],a[i][0])==0):
        flag=1
        break
    elif(max(a[1][i],a[2][i],a[0][i])==0):
        flag=1
        break
if(max(a[0][0],a[1][1],a[2][2])==0):
    flag=1
elif(max(a[0][2],a[1][1],a[2][0])==0):
    flag=1
if(flag==1):
    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=[int(input()) for i in range(N)]
C=[[0]*3 for i in range(3)]

for i in range(3):
	for j in range(3):
		C[i][j]=False
		for k in range(N):
			if A[i][j]==B[k]:
				C[i][j]=True
answer="No"
for i in range(3):
	if (C[i][0] and C[i][1] and C[i][2]):
		answer="Yes"
	if (C[0][i] and C[1][i] and C[2][i]):
		answer="Yes"
if (C[0][0] and C[1][1] and C[2][2]):
	answer="Yes"
if (C[2][0] and C[1][1] and C[0][2]):
	answer="Yes"
print(answer)

Submission status: Accepted

Solution code:

def check(grid):
	bingo=False
	#row
	for i in range(3):
		count=0
		for j in range(3):
			if grid[i][j]==1:
				count+=1
		if count==3:
			bingo=True
	#col
	for i in range(3):
		count=0
		for j in range(3):
			if grid[j][i]==1:
				count+=1
		if count==3:
			bingo=True
	#left diag
	count=0
	for i in range(3):
		if grid[i][i]==1:
			count+=1
	if count==3:
		bingo=True
	#right diag
	count=0
	for i in range(3):
		if grid[i][2-i]==1:
			count+=1
	if count==3:
		bingo=True
		
	return bingo
		
pos={}
for i in range(3):
	temp=list(map(int,input().split(' ')))
	for j,t in enumerate(temp):
		pos[t]=[i,j]
grid=[[0 for i in range(3)] for j in range(3)]

n=int(input())
for i in range(n):
	t=int(input())
	if t in pos.keys():
		r,c=pos[t]
		grid[r][c]=1
bingo=check(grid)

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

Submission status: Accepted

Solution code:
def resolve():
    a, b, c = map(int, input().split())
    d, e, f = map(int, input().split())
    g, h, i = map(int, input().split())
    bingo = [a, b, c, d, e, f, g, h, i]
    n = int(input())
    s=0
    for i in range(n):
        z = int(input())
        if z in bingo:
            index = bingo.index(z)
            bingo[index] = 0

    a = bingo[0]
    b = bingo[1]
    c = bingo[2]
    d = bingo[3]
    e = bingo[4]
    f = bingo[5]
    g = bingo[6]
    h = bingo[7]
    i = bingo[8]

    if a + b + c == 0 or d + e + f == 0 or g + h + i == 0 or a + d + g == 0 or b + e + h == 0 or c + f + i == 0 or a + e + i == 0 or c + e + g == 0:
        print("Yes")
    else:
        print("No")
resolve()

Submission status: Accepted

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

N = int(input())

for i in range(N):
    b = int(input())
    if b in A:
        n = A.index(b)
        A[n] = '*'

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    A = [tuple(map(int, input().split())) for _ in range(3)]
    N = int(input())
    B = [int(input()) for _ in range(N)]

    ans = [[[] for _ in range(3)] for _ in range(3)]
    for i in range(3):
        for j, a in enumerate(A[i]):
            ans[i][j] = a in B

    yes = []
    for i in range(3):
        yes.append(all(ans[i]))
        yes.append(all([ans[0][i], ans[1][i], ans[2][i]]))
    yes.append(all([ans[0][0], ans[1][1], ans[2][2]]))
    yes.append(all([ans[2][0], ans[1][1], ans[0][2]]))

    if any(yes):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

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)]
    # print("A: {}".format(A))
    # print("n: {}".format(n))
    # print("b: {}".format(b))
    outs = [[False for _ in range(3)] for _ in range(3)]
    is_bingo = False
    for i in range(3):
        for j in range(3):
            outs[i][j] = A[i][j] in b
    
    # check row
    for i in range(3):
        is_bingo = outs[i][:] == [True for _ in range(3)]
        if is_bingo:
            return "Yes"

    # check column
    for i in range(3):
        is_bingo = [outs[j][i] for j in range(3)] == [True for _ in range(3)]
        if is_bingo:
            return "Yes"
    # check x
    is_bingo = [outs[i][i] for i in range(3)] == [True for _ in range(3)]
    if is_bingo:
        return "Yes"
    is_bingo = [outs[i][-i-1] for i in range(3)] == [True for _ in range(3)]
    if is_bingo:
        return "Yes"
    return "No"

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

Submission status: Accepted

Solution code:
a = [ list(map(int,input().split())) for i in range(3)]    # 二重リスト（配列）に標準入力　
n = int(input())                                           # 標準入力（整数）
d = [[0 for i in range(3)] for j in range(3)]              # 要素が全て0の３×３の二重リスト（配列）

for k in range(n):              #  n回繰り返す
    b = int(input())            #　標準入力（整数）
    for i in range(3):          
        for j in range(3):
            if a[i][j] == b:    #  aに、bと同じ数字があるか見る
                d[i][j] = 1     #　あれば、対応するdに1を代入

ans = 'No'                      #  最初はNoと仮定
count = 0

# 横でビンゴしているか確認
for i in range(3):
    if ans == 'Yes':            # もしYesだったら
        break;                  # ループを抜ける
    count = 0
    for j in range(3):
        count += d[i][j]
        if count == 3:          
            ans = 'Yes'         #  3つ１があればビンゴ

# 縦でビンゴしているか確認
for i in range(3):
    if ans == 'Yes':
        break;
    count = 0
    for j in range(3):
        count += d[j][i]
    if count == 3:
        ans = 'Yes'             #  3つ１があればビンゴ


# 左上から右下にかけて斜めにビンゴしているか確認
count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][i]
    if count == 3:
        ans = 'Yes'             #  3つ１があればビンゴ

#右上から左下にかけて斜めにビンゴしているか確認
count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][2 - i]
    if count == 3:              #  3つ１があればビンゴ
        ans = 'Yes'
            

print(ans)

Submission status: Accepted

Solution code:
a = [ list(map(int,input().split())) for i in range(3)]    # 二重リスト（配列）に標準入力　
n = int(input())                                           # 標準入力（整数）
d = [[0 for i in range(3)] for j in range(3)]              # 要素が全て0の３×３の二重リスト（配列）

for k in range(n):              #  n回繰り返す
    b = int(input())            #　標準入力（整数）
    for i in range(3):          
        for j in range(3):
            if a[i][j] == b:    #  aに、bと同じ数字があるか見る
                d[i][j] = 1     #　あれば、対応するdに1を代入

ans = 'No'                      #  最初はNoと仮定
count = 0

ans = 'No'
for i in range(3):
    if ans == 'Yes':
        break;
    count = 0
    for j in range(3):
        count += d[i][j]
        if count == 3:
            ans = 'Yes'
        
for i in range(3):
    if ans == 'Yes':
        break;
    count = 0
    for j in range(3):
        count += d[j][i]
    if count == 3:
        ans = 'Yes'


# 左上から右下にかけて斜めにビンゴしているか確認
count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][i]
    if count == 3:
        ans = 'Yes'

#右上から左下にかけて斜めにビンゴしているか確認
count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][2 - i]
    if count == 3:
        ans = 'Yes'
            

print(ans)

Submission status: Accepted

Solution code:

import collections


class Solution:
    def solve(self, A, N, B):
        mark = [[False for _ in range(3)] for _ in range(3)]
        bSet = set(B)

        for i, row in enumerate(A):
            for j, val in enumerate(row):
                if val in bSet:
                    mark[i][j] = True

        for row in mark:
            if all(row):
                return True

        for i in range(3):
            isMarked = True

            for j in range(3):
                isMarked &= isMarked & mark[j][i]

            if isMarked:
                return True

        isMarked = True

        # Top Left Diagonal
        for i in range(3):
            isMarked &= isMarked & mark[i][i]

        if isMarked:
            return True

        isMarked = True

        # Top Left Diagonal
        for i in range(3):
            isMarked &= isMarked & mark[i][3-i-1]

        return isMarked


sol = Solution()

A = []

for j in range(3):
    A.append(list(map(int, input().strip().split())))

N = int(input().strip())
B = []

for i in range(N):
    B.append(int(input().strip()))

print("Yes" if sol.solve(A, N, B) else "No")

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

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

chk = [[0]*3 for _ in range(3)]
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            chk[i][j] = 1

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

print(ans)

Submission status: Accepted

Solution code:
A = []

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

N = int(input())

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

judge = 0

#斜めがビンゴになる場合
if A[0][0] in b and A[1][1] in b and A[2][2] in b or A[0][2] in b and A[1][1] in b and A[2][0] in b:
    judge += 1

for i in range(3):
    #横がビンゴになる場合
    if A[i][0] in b and A[i][1] in b and A[i][2] in b:
        judge += 1
        break

    #縦がビンゴになる場合
    elif A[0][i] in b and A[1][i] in b and A[2][i] in b:
        judge += 1
        break

if judge >= 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def yoko(A):
    f = False
    for i in range(3):
        if len(set(A[i]))==1:f = True
    return f

def tate(A):
    f = False
    for i in range(3):
        B = [A[0][i],A[1][i],A[2][i]]
        if len(set(B))==1: f = True
    return f


def naname(A):
    f = False
    B = [A[0][0],A[1][1],A[2][2]]
    if len(set(B))==1: f = True
    B = [A[0][2], A[1][1], A[2][0]]
    if len(set(B))==1: f = True

    return f


A = []

A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))
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

F1 = tate(A)
F2 = yoko(A)
F3 = naname(A)


if F1 or F2 or F3: print('Yes')
else: print('No')

Submission status: Accepted

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

field = [[False for _ in range(3)] for _ in range(3)]
for x in b:
    for i in range(3):
        for j in range(3):
            if x == numbers[i][j]:
                field[i][j] = True

for i in range(3):
    bingo = True
    for j in range(3):
        bingo &= field[i][j]
    if bingo:
        print('Yes')
        exit()

for j in range(3):
    bingo = True
    for i in range(3):
        bingo &= field[i][j]
    if bingo:
        print('Yes')
        exit()

bingo = True
for i in range(3):
    bingo &= field[2-i][i]
if bingo:
    print('Yes')
    exit()
bingo = True
for i in range(3):
    bingo &= field[i][i]
if bingo:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

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

for k 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 ans == 'Yes':
        break;
    count = 0
    for j in range(3):
        count += d[i][j]
        if count == 3:
            ans = 'Yes'
            break;

count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count = 0
    for j in range(3):
        count += d[j][i]
    if count == 3:
        ans = 'Yes'
        break;

count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][i]
    if count == 3:
        ans = 'Yes'

count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][2 - i]
    if count == 3:
        ans = 'Yes'
            

print(ans)

Submission status: Accepted

Solution code:
a = []
for i in range(3):
  a.append([int(i) for i in input().split()])
n = int(input())
b = []
for i in range(n):
  x = int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k] == x:
        a[j][k] = 0
if 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")
elif a[0][0] == a[1][0] == a[2][0] == 0:
  print("Yes")
elif a[0][1] == a[1][1] == a[2][2] == 0:
  print("Yes")
elif a[0][2] == a[1][2] == a[2][2] == 0:
  print("Yes")
elif a[0][0] == a[0][1] == a[0][2] == 0:
  print("Yes")
elif a[1][0] == a[1][1] == a[1][2] == 0:
  print("Yes")
elif a[2][0] == a[2][1] == a[2][2] == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

for k 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 ans == 'Yes':
        break;
    count = 0
    for j in range(3):
        count += d[i][j]
        if count == 3:
            ans = 'Yes'
            break;

count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count = 0
    for j in range(3):
        count += d[j][i]
    if count == 3:
        ans = 'Yes'
        break;

count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][i]
    if count == 3:
        ans = 'Yes'

count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][2 - i]
    if count == 3:
        ans = 'Yes'
            

print(ans)

Submission status: Accepted

Solution code:
card = []

for _ in range(3):
  card.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 card[i][j] == b:
        card[i][j] = -1
        
def bingo(card):
  for row in card:
    if all(x == -1 for x in row):
      return True
  
  for j in range(3):
    if card[0][j] == -1 and card[1][j] == -1 and card[2][j] == -1:
      return True
    
  if card[0][0] == -1 and card[1][1] == -1 and card[2][2] == -1:
    return True
  
      
  if card[0][2] == -1 and card[1][1] == -1 and card[2][0] == -1:
    return True

  return False

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

Submission status: Accepted

Solution code:
a = []
for i in range(3):
  inp = [int(x) for x in input().split()]
  a.append(inp)
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))
for i in range(n):
  for j in range(3):
    for k in range(3):
      if a[j][k] == b[i]:
        a[j][k] = 0
if a[0][0] == 0 and a[0][1] == 0 and a[0][2] == 0:
  print('Yes')
elif a[1][0] == 0 and a[1][1] == 0 and a[1][2] == 0:
  print('Yes')
elif a[2][0] == 0 and a[2][1] == 0 and a[2][2] == 0:
  print('Yes')
    
elif 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 a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
  print('Yes')
elif a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:

a1, a2, a3 = [input().split() for l in range(3)]
n = int(input())
b = [input() for i in range(n)]

var1 = []
var2 = []
var3 = []

for bb in b:
    if bb in a1:
        var1.append(a1.index(bb))

    elif bb in a2:
        var2.append(a2.index(bb))
    elif bb in a3:
        var3.append(a3.index(bb))

#たて
if 0 in var1 and 0 in var2 and 0 in var3 or 1 in var1 and 1 in var2 and 1 in var3 or 2 in var1 and 2 in var2 and 2 in var3 :
    print("Yes")

#よこ
elif 0 in var1 and 1 in var1 and 2 in var1 or 0 in var2 and 1 in var2 and 2 in var2 or 0 in var3 and 1 in var3 and 2 in var3 :
    print("Yes")

#ななめ
elif 0 in var1 and 1 in var2 and 2 in var3 or 2 in var1 and 1 in var2 and 0 in var3:
    print("Yes")

else : 
    print("No")

Submission status: Accepted

Solution code:
import numpy as np
li = [list(map(int, input().split())) for i in range(3)] #ビンゴの取得
N = int(input())
B_list = [list(map(int, input().split())) for i in range(N)] #複数行の数値の入力を取得

arr = np.array(li)
arr2 = np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]])

# print(li)
# print(arr)
# print(B_list)
# print(B_list[1])

for i in range(N):
    for j in range(3):
        for k in range(3):
            if arr[j, k] == B_list[i]:
                arr2[j, k] = 0

# print(arr2)

if arr2[0, 0] == 0 and arr2[0, 1] == 0 and arr2[0, 2] == 0:
    print("Yes")
    exit()
elif arr2[1, 0] == 0 and arr2[1, 1] == 0 and arr2[1, 2] == 0:
    print("Yes")
    exit()
elif arr2[2, 0] == 0 and arr2[2, 1] == 0 and arr2[2, 2] == 0:
    print("Yes")
    exit()
elif arr2[0, 0] == 0 and arr2[1, 0] == 0 and arr2[2, 0] == 0:
    print("Yes")
    exit()
elif arr2[0, 1] == 0 and arr2[1, 1] == 0 and arr2[2, 1] == 0:
    print("Yes")
    exit()
elif arr2[0, 2] == 0 and arr2[1, 2] == 0 and arr2[2, 2] == 0:
    print("Yes")
    exit()
elif arr2[0, 0] == 0 and arr2[1, 1] == 0 and arr2[2, 2] == 0:
    print("Yes")
    exit()
elif arr2[0, 2] == 0 and arr2[1, 1] == 0 and arr2[2, 0] == 0:
    print("Yes")
    exit()
else:
    print("No")

Submission status: Accepted

Solution code:
mat=[]

for i in range(3):
    inp = [int(x) for x in input().split()]
    mat.append(inp)
    
n = int(input())

for _ in range(n):
    q = int(input())
    for i in range(3):
        if q in mat[i]:
            ind = mat[i].index(q)
            mat[i][ind] = '1'
            break
    
if mat[0][0]=='1' and mat[0][1]=='1' and mat[0][2]=='1':
    print('Yes')
    
elif mat[1][0]=='1' and mat[1][1]=='1' and mat[1][2]=='1':
    print('Yes')

elif mat[2][0]=='1' and mat[2][1]=='1' and mat[2][2]=='1':
    print('Yes')

#col
elif mat[0][0]=='1' and mat[1][0]=='1' and mat[2][0]=='1':
    print('Yes')

elif mat[0][1]=='1' and mat[1][1]=='1' and mat[2][1]=='1':
    print('Yes')

elif mat[0][2]=='1' and mat[1][2]=='1' and mat[2][2]=='1':
    print('Yes')

#diag
elif mat[0][0]=='1' and mat[1][1]=='1' and mat[2][2]=='1':
    print('Yes')

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

Submission status: Accepted

Solution code:
b=[]
for i in range(3):
  a = input().split()
  b.append(a)
n = int(input())
c=[0]*n
for i in range(n):
  c[i]=input()
hantei = "No"
for i in range(n):
  for x in range(3):
    for y in range(3):
      if b[y][x] == c[i]:
        b[y][x] = 101
for i in range(3):
  if b[i][0] == 101 and b[i][1] == 101 and b[i][2] == 101:
    hantei = "Yes"
  elif b[0][i] == 101 and b[1][i] == 101 and b[2][i] == 101:
    hantei = "Yes"
  elif b[0][0] == 101 and b[1][1] == 101 and b[2][2] == 101:
    hantei = "Yes"
  elif b[0][2] == 101 and b[1][1] == 101 and b[2][0] == 101:
    hantei = "Yes"
print(hantei)

Submission status: Accepted

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

n = int(input())
for i in range(n):
    num = int(input())
    for j in range(3):
        for k in range(3):
            if b[j][k] == num:
                a[j][k] = True

flag = 0
for i in range(3):
    f = 1
    for j in range(3):
        if not a[i][j]:
            f = 0
    if f == 1:
        flag = 1

for j in range(3):
    f = 1
    for i in range(3):
        if not a[i][j]:
            f = 0
    if f == 1:
        flag = 1

if a[0][0] and a[1][1] and a[2][2]:
    flag = 1
if a[2][0] and a[1][1] and a[0][2]:
    flag = 1

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