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 = [[0 for j in range(3)] for i in range(3)]
for i in range(3):
    A[i][0], A[i][1], A[i][2] = map(int, input().split())

N = int(input())

s = [[False for j in range(3)] for i in range(3)]
for k in range(N):
    b_k = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b_k:
                s[i][j] = True

bingo = False
if s[0][0] and s[0][1] and s[0][2]:
    bingo = True
if s[1][0] and s[1][1] and s[1][2]:
    bingo = True
if s[2][0] and s[2][1] and s[2][2]:
    bingo = True
if s[0][0] and s[1][0] and s[2][0]:
    bingo = True
if s[0][1] and s[1][1] and s[2][1]:
    bingo = True
if s[0][2] and s[1][2] and s[2][2]:
    bingo = True
if s[0][0] and s[1][1] and s[2][2]:
    bingo = True
if s[2][0] and s[1][1] and s[0][2]:
    bingo = True

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

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) for i in range(3)]
d = [[0] * 3 for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
def bingo(l1, l2):
    global d
    for i in l2:
        for j in range(3):
            for k in range(3):
                if l1[j][k] == i:
                    d[j][k] = 1
    for i in range(3):
        if d[i][0] == 1 and d[i][1] == 1 and d[i][2] == 1:
            return "Yes"
        elif d[0][i] == 1 and d[1][i] == 1 and d[2][i] == 1:
            return "Yes"
    if d[0][0] == 1 and d[1][1] == 1 and d[2][2]:
        return "Yes"
    elif d[2][0] == 1 and d[1][1] == 1 and d[0][2]:
        return "Yes"
    else:
        return "No"
print(bingo(a,b))

Submission status: Accepted

Solution code:
line_0 = list(map(int, input().split()))
line_1 = list(map(int, input().split()))
line_2 = list(map(int, input().split()))
num = int(input())

is_open = [[False, False, False], [False, False, False], [False, False, False]]
for i in range(num):
    open_num = int(input())
    for j in range(3):
        if line_0[j] == open_num:
            is_open[0][j] = True
        if line_1[j] == open_num:
            is_open[1][j] = True
        if line_2[j] == open_num:
            is_open[2][j] = True

clear = "No"

if is_open[0] == [True, True, True]:
    clear = "Yes"
if is_open[1] == [True, True, True]:
    clear = "Yes"
if is_open[2] == [True, True, True]:
    clear = "Yes"

for i in range(3):
    if is_open[0][i] == is_open[1][i] == is_open[2][i] == True:
        clear = "Yes"

if is_open[0][0] == is_open[1][1] == is_open[2][2] == True:
    clear = "Yes"
if is_open[0][2] == is_open[1][1] == is_open[2][0] == True:
    clear = "Yes"

print(clear)

Submission status: Accepted

Solution code:
array= []
for i in range(3):
    array.append(list(map(int,input().split())))
n= int(input())
number=[]
answer = "No"
for i in range(n):
    number.append(input())

for i in range (3):
    for j in range(3):
        for k in range(n):
            if int(array[i][j]) == int(number[k]):
                array[i][j] = 8101919

for i in range (3):
    if array[i][0] & array[i][1] & array[i][2] == 8101919:        
        answer = "Yes"

for i in range(3):
    if array[0][i] & array[1][i] & array[2][i] == 8101919:
        answer = "Yes"

if array[0][0] & array[1][1] & array[2][2] == 8101919:
    answer = "Yes"
           
if array[2][0] & array[1][1] & array [0][2] == 8101919:
    answer = "Yes"

print(answer)

Submission status: Accepted

Solution code:
Field = [list(map(int, input().split(" "))) for i in range(3)]
N = int(input())
num =[]
for i in range(N):
    t = int(input())
    num.append(t)
count=0
for i in Field:
    for t in range(3):
        if i[t] in num:
            i[t] = 0

for i in Field:
    if sum(i) == 0:
        count+=1

for i in range(3):
    if Field[0][i] == 0 and Field[1][i] == 0 and Field[2][i] == 0:
        count+=1

if Field[0][0] == 0 and Field[1][1] == 0 and Field[2][2] == 0:
    count+=1
if Field[0][2] == 0 and Field[1][1] == 0 and Field[2][0] == 0:
    count+=1

if count != 0:
    print("Yes")
else:
    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] = 0

if a[0][0] == a[0][1] == a[0][2] == 0 or a[1][0] == a[1][1] == a[1][2] == 0 or a[2][0] == a[2][1] == a[2][2] == 0 \
   or a[0][0] == a[1][0] == a[2][0] == 0 or a[0][1] == a[1][1] == a[2][1] == 0 or a[0][2] == a[1][2] == a[2][2] == 0 \
   or a[0][0] == a[1][1] == a[2][2] == 0 \
   or a[0][2] == a[1][1] == a[2][0] == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
a3 = list(map(int,input().split()))
n = int(input())
for i in range(n):
  b = int(input())
  if b in a1:
    #vは穴が空いたということ
    num = a1.index(b)
    a1[num] = "v"
  elif b in a2:
    num = a2.index(b)
    a2[num] = "v"
  elif b in a3:
    num = a3.index(b)
    a3[num] = "v"
if a1.count("v")==3 or a2.count("v")==3 or a3.count("v")==3 or a1[0]==a2[0]==a3[0]=="v" or a1[1]==a2[1]==a3[1]=="v" or a1[2]==a2[2]==a3[2]=="v" or a1[0]==a2[1]==a3[2]=="v" or a1[2]==a2[1]==a3[0]=="v":
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
a = []
for i in range(3):
    a += list(map(int, input().split()))
bg = [False]*9
n = int(input())
for i in range(n):
    b = int(input())
    if b in a:
        bg[a.index(b)] = True

num = [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
for x, y, z in num:
    if bg[x] and bg[y] and bg[z]:
        print('Yes')
        exit()
print('No')

Submission status: Accepted

Solution code:
class BingoCard:
    def __init__(self, bingolist):
        self.bingocard = bingolist

    def call(self, b):
        for i in range(3):
            for j in range(3):
                if b == self.bingocard[i][j]:
                    self.bingocard[i][j] = 0

    def check_bingo(self):
        bingo = False
        # check row
        for row in self.bingocard:
            if row[0] + row[1] + row[2] == 0:
                bingo = True
        # check column
        for i in range(3):
            if self.bingocard[0][i] == 0:
                if self.bingocard[1][i] + self.bingocard[2][i] == 0:
                    bingo = True
        # check diagonal
        if self.bingocard[1][1] == 0:
            if self.bingocard[0][0] + self.bingocard[2][2] == 0 or\
                self.bingocard[0][2] + self.bingocard[2][0] == 0:
                bingo = True
        return bingo

# prepare bingo card
bingo0 = list(map(int, input().split(" ")))
bingo1 = list(map(int, input().split(" ")))
bingo2 = list(map(int, input().split(" ")))

bc = BingoCard([bingo0, bingo1, bingo2])

# get N
n = int(input())

while n:
    b = int(input())
    bc.call(b)
    n -= 1

if bc.check_bingo():
    print("Yes")
else:
    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 x in range(3):
        for y in range(3):
            if A[x][y] == b:
                A[x][y] = -1

for x in range(3):
    f = True
    for y in range(3):
        if A[x][y] != -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=[list(map(int,input().split())) for i in range(3)]
n=int(input())

for i in range(n):
  o=int(input())
  for x in range(3):
    for y in range(3):
      if o == A[y][x]:
        A[y][x]=-1

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

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


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


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

print('No')

Submission status: Accepted

Solution code:
import sys
import math
from io import StringIO
import unittest

lines = [[0,1,2], [3,4,5], [6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]

def resolve():
    table = [int(s) for s in input().split()]
    table += [int(s) for s in input().split()]
    table += [int(s) for s in input().split()]

    lis = [int(input()) for _ in range(int(input()))]

    ans = [ n in lis for n in table ]

    for line in lines:
        valid = True
        for num in line:
            if not ans[num] :
                valid = False
                break

        if valid:
            print('Yes')
            return

    print('No')
resolve()

Submission status: Accepted

Solution code:
sheet=[list(map(int,input().split())) for i in range(3)]
n=int(input())
number=[int(input()) for i in range(n)]
answer="No"

for i in range(3):
   for j in range(3):
      if sheet[i][j] in number:
        sheet[i][j]=0

if sheet[0][0]+sheet[1][1]+sheet[2][2]==0 or sheet[2][0]+sheet[1][1]+sheet[0][2]==0:
  answer="Yes"
else:        
  for i in range (3):
    if sheet[i]==[0,0,0]:
      answer="Yes"
    elif sheet[0][i]==0 and sheet[1][i]==0 and sheet[2][i]==0:
      answer="Yes"

print(answer)

Submission status: Accepted

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

n = int(input())

for i in range(n):
    b = int(input())
    if b in a_list:
        place = a_list.index(b)
        check_list[place] = True

bingo = False
while True:
    for i in range(3):
        if check_list[i*3] and check_list[i*3+1] and check_list[i*3+2]:
            bingo = True
            break
        if check_list[i] and check_list[i+3] and check_list[i+6]:
            bingo = True
            break
    if check_list[0] and check_list[4] and check_list[8]:
        bingo = True
        break
    if check_list[2] and check_list[4] and check_list[6]:
        bingo = True
        break
    break

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

Submission status: Accepted

Solution code:
s = 3
arr =[]
for _ in range(s):
        arr.append(list(map(int, input().rstrip().split())))
#print(arr)
 
check = [[0,0,0],[0,0,0],[0,0,0]]
#print(check)
 
#check データ
N = int(input())
#print(N)
 
for i in range(N):
    data = int(input())
    for k in range(3):
        for j in range(3):
            if data == arr[j][k]:
                check[j][k]= 1
#print(check)
 
#chek ビンゴ
answer = "No"
for k in range(3):
    if check[k][0] == 1 and check[k][1]== 1 and check[k][2] == 1:
        answer = "Yes"
 
for j in range(3):
    if check[0][j] == 1 and check[1][j] == 1 and check[2][j] == 1:
        answer = "Yes"
 
if check[0][0] == 1 and check[1][1] == 1 and check[2][2] == 1:
    answer = "Yes"
 
if check[0][2] == 1 and check[1][1] == 1 and check[2][0] == 1:
    answer = "Yes"
 
 
print(answer)

Submission status: Accepted

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

buf = [[-1,-1,-1] for i in range(3)]
n = int(input())
for i in range(n):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if b==a[j][k]:
        buf[j][k]=1

bingo = buf
for i in range(3):
	bingo = bingo+[[buf[0][i],buf[1][i],buf[2][i]]]
bingo = bingo + [[buf[0][0],buf[1][1],buf[2][2]]] + [[buf[2][0],buf[1][1],buf[0][2]]]
flag = False
for i in range(8):
  if bingo[i]==[1,1,1]:
    flag = True
    print("Yes")
    break
if flag==False:
  print("No")

Submission status: Accepted

Solution code:
op = [list(map(int, inp.split())) for inp in open(0)]
a = [op[0], op[1], op[2]]
n = int(op[3][0])
b = []
for i in range(n):
  b.append(int(op[4 + i][0]))
  for j in range(3):
    for k in range(3):
      if a[j][k] == b[i]:
        a[j][k] = -1
res = 'No'
for i in range(3):
  if a[0][i] == a[1][i] == a[2][i] == -1:
    res = 'Yes'
  if a[i][0] == a[i][1] == a[i][2] == -1:
    res = 'Yes'
if a[0][0] == a[1][1] == a[2][2] == -1:
  res = 'Yes'
if a[2][0] == a[1][1] == a[0][2] == -1:
  res = 'Yes'
print(res)

Submission status: Accepted

Solution code:
data_list = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
bingo_list = [int(input()) for _ in range(N)]
mark = [[False, False, False] for _ in range(3)]
for i in range(3):
    for j in range(3):
        if data_list[i][j] in bingo_list:
            mark[i][j] = True
ans = "No"
for i in range(3):
    if all(mark[i]):
        ans = "Yes"
        break
for j in range(3):
    if mark[0][j] and mark[1][j] and mark[2][j]:
        ans = "Yes"
        break
if (mark[0][0] and mark[1][1] and mark[2][2]) or (mark[2][0] and mark[1][1] and mark[0][2]) :
    ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
a = [list(map(int, input().split()))for _ in range(3)]
n = int(input())
b = [list(map(int, input().split()))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][0]:
                a[j][k] = 0

ans = "No"

for i in range(3):
    if a[0][i] == a[1][i] == a[2][i] == 0:
        ans = "Yes"
    if a[i][0] == a[i][1] == a[i][2] == 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:
row1=list(map(int,input().split()))
row2=list(map(int,input().split()))
row3=list(map(int,input().split()))
bingo=row1+row2+row3
num=int(input())
num_list=set()
for i in range(num):
  num_list.add(int(input()))

bingo_list=[[0,3,6],[1,4,7],[2,5,8],[0,1,2],[3,4,5],[6,7,8],[0,4,8],[2,4,6]]
num_list=list(num_list)
for i in num_list:
  if i in bingo:
    bingo[bingo.index(i)] = True

for i in bingo_list:
  if bingo[i[0]] ==True and bingo[i[1]] == True and bingo[i[2]] == True:
    print('Yes')
    break
  if i == [2,4,6]:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np

A = []
for _ in range(3):
    A.append(list(map(int, input().split())))
N = input()
N = int(N)
B = []
for _ in range(N):
    b = input()
    B.append(int(b))
npA = np.array(A)
check = 'No'
for a in npA:
    if a[0] in B and a[1] in B and a[2] in B:
        check = 'Yes'
for a in npA.T:
    if a[0] in B and a[1] in B and a[2] in B:
        check = 'Yes'
dia = np.diag(npA)
if dia[0] in B and dia[1] in B and dia[2] in B:
    check = 'Yes'
diaT = np.diag(np.fliplr(npA))
if diaT[0] in B and diaT[1] in B and diaT[2] in B:
    check = 'Yes'
print(check)

Submission status: Accepted

Solution code:

a = [None for i in range(9)]
b = [False for i in range(9)]

a[0], a[1], a[2] = input().split()
a[3], a[4], a[5] = input().split()
a[6], a[7], a[8] = input().split()

N = int(input())

for i in range(N):
    target = input()
    for j in range(9):
        if a[j] == target:
            b[j] = True

bl = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]

ret = "No"
for i in bl:
    for j in i:
        if b[j] is False:
            break
    else:
        ret = "Yes"

print(ret)

Submission status: Accepted

Solution code:
#coding:utf-8
import copy

a1 = input().split()
a2 = input().split()
a3 = input().split()
n = int(input())
binhot = [0,0,0,0,0,0,0,0,0]
memo = [0,0,0,0,0,0,0,0,0]
ans = "No"

for i in range(n):
  b = str(input())
  count = 0
  for f in a1:
    if(b == f):
      binhot[count] = 1
    count += 1
  for f in a2:
    if(b == f):
      binhot[count] = 1
    count += 1
  for f in a3:
    if(b == f):
      binhot[count] = 1
    count += 1

saver = binhot
teacher = [[1,1,1,0,0,0,0,0,0],
           [0,0,0,1,1,1,0,0,0],
           [0,0,0,0,0,0,1,1,1],
           [1,0,0,1,0,0,1,0,0],
           [0,1,0,0,1,0,0,1,0],
           [0,0,1,0,0,1,0,0,1],
           [1,0,0,0,1,0,0,0,1],
           [0,0,1,0,1,0,1,0,0]]

for i in teacher:
  memo = copy.deepcopy(saver)
  for j in range(9):
    memo[j] = i[j] * memo[j]
  if(memo == i):
    ans = "Yes"

print("{}".format(ans))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    a = []
    b = []
    a.append(list(map(int, input().split())))
    a.append(list(map(int, input().split())))
    a.append(list(map(int, input().split())))
    n = int(input().strip())
    for i in range(n):
        b.append(int(input().strip()))

    n_to_k = {}
    for i in range(3):
        for j in range(3):
            n_to_k[a[i][j]] = (i, j)

    board = set()
    for i in b:
        if i not in n_to_k:
            continue
        board.add(n_to_k[i])

    # check
    for i in range(3):
        if (i, 0) in board and (i, 1) in board and (i, 2) in board:
            print("Yes")
            return
        if (0, i) in board and (1, i) in board and (2, i) in board:
            print("Yes")
            return
    if (0, 0) in board and (1, 1) in board and (2, 2) in board:
        print("Yes")
        return
    if (2, 0) in board and (1, 1) in board and (0, 2) in board:
        print("Yes")
        return

    print("No")

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
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()))

for i,a in enumerate(A):
  for j,x in enumerate(a):
    if x in B:
      A[i][j] = 0

def bingo(x):
  if sum(x) == 0:
    print('Yes')
    exit()

for x in A:
  bingo(x)

AT = [list(x) for x in zip(*A)]
for x in AT:
  bingo(x)

AD = [A[i][i] for i in range(3)]
bingo(AD)

AD = [A[i][2-i] for i in range(3)]
bingo(AD)

print('No')

Submission status: Accepted

Solution code:
import numpy as np
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()))

for i,a in enumerate(A):
  for j,x in enumerate(a):
    if x in B:
      A[i][j] = 0
ans = 'No'
def bingo(x):
  if sum(x) == 0:
    print('Yes')
    exit()

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:
A = []
b = []
for i in range(3):
    A.extend(list(map(int, input().split())))
N = int(input())
for i in range(N):
    num = int(input())
    if num in A:
        idx = A.index(num)
        A[idx] = 0
        if A.count(0) >= 3:
            if (A[0] == A[3] and A[0] == A[6]
              or A[1] == A[4] and A[1] == A[7]
              or A[2] == A[5] and A[2] == A[8]
              or A[0] == A[1] and A[0] == A[2]
              or A[3] == A[4] and A[3] == A[5]
              or A[6] == A[7] and A[6] == A[8]
              or A[0] == A[4] and A[0] == A[8]
              or A[2] == A[4] and A[2] == A[6]):
                print("Yes")
                exit()
print("No")

Submission status: Accepted

Solution code:
import numpy as np
A = np.array([])
f=False
B= np.zeros((3,3))

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

n=int(input())

for i in range(n):
  x=int(input())
  B+=(A==x)*1
  
for i,j in zip(sum(B),sum(B.T)):
  f=f or (i//3) or (j//3) 
f = f or (sum(np.diag(B))//3)
f = f or (sum(np.diag(np.fliplr(B)))//3)
print("Yes" if f else "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 i in range(3):
    if set(A[i]) <= set(b):
        print("Yes")
        exit()
    if set([A[0][i], A[1][i], A[2][i]]) <= set(b):
        print("Yes")
        exit()
if set([A[0][0], A[1][1], A[2][2]]) <= set(b) or set([A[0][2], A[1][1], A[2][0]]) <= set(b):
    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 b==A[i][j]:
                A[i][j]=0
for k in range(3):
    ans=A[0][k]+A[1][k]+A[2][k]
    if ans==0:
        print("Yes");exit()
for k in range(3):
    ans=A[k][0]+A[k][1]+A[k][2]
    if ans==0:
        print("Yes");exit()
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")
else:
    print("No")

Submission status: Accepted

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

for i in range(N):
    bi = int(input())
    
    for j in range(3):
        if bi in A[j]:
            A[j][A[j].index(bi)] = 0
            
judge = False
for i in range(3):
    if A[i] == [0, 0, 0]:
        judge = True
    if A[0][i] == A[1][i] == A[2][i] == 0:
        judge = True
if A[0][0] == A[1][1] == A[2][2] == 0 or A[0][2] == A[1][1] == A[2][0] == 0:
    judge = True
    
if judge == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

for i in range(N):
    for j in range(3):
        for k in range(3):
            if a[i] == num[j][k]:
                num[j][k] = False
bingo = 0
for m in range(3):
    if num[0][m] == num[1][m] == num[2][m] == False:bingo = 1

for n in range(3):
    if num[n][0] ==  num[n][1] ==  num[n][2] == 0:bingo = 1 
if num[0][0] == num[1][1] == num[2][2] == 0 :bingo = 1
if num[0][2] == num[1][1] == num[2][0] == 0 :bingo = 1

if bingo == 1:print("Yes")
elif bingo == 0:print("No")

Submission status: Accepted

Solution code:
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
t = []
t.append(A);t.append(B);t.append(C)
N = int(input()) 
num = [(int(input())) for x in range(N)]
for i in range(3):
  if t[i][0] in num and t[i][1] in num and t[i][2] in num:
    print('Yes')
    exit()
  if t[0][i] in num and t[1][i] in num and t[2][i] in num:
    print('Yes')
    exit()
if (t[0][0] in num and t[1][1] in num and t[2][2] in num) or (t[0][2] in num and t[1][1] in num and t[2][0] in num):
  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()))
N = int(input())
numbers = list()
for i in range(N):
    numbers.append(int(input()))

bingo = False
for a in A:
    if a not in numbers:
        break
else:
    bingo = True

for b in B:
    if b not in numbers:
        break
else:
    bingo = True

for c in C:
    if c not in numbers:
        break
else:
    bingo = True

columnA = [A[0],B[0],C[0]]
for i in columnA:
    if i not in numbers:
        break
else:
    bingo = True

columnB = [A[1],B[1],C[1]]
for i in columnB:
    if i not in numbers:
        break
else:
    bingo = True

columnC = [A[2],B[2],C[2]]
for i in columnC:
    if i not in numbers:
        break
else:
    bingo = True

diagA = [A[0],B[1],C[2]]
for i in diagA:
    if i not in numbers:
        break
else:
    bingo = True

diagB = [A[2],B[1],C[0]]
for i in diagB:
    if i not in numbers:
        break
else:
    bingo = True

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

Submission status: Accepted

Solution code:
B = []
for i in range(3):
    B += list(map(int,input().split()))
# print(B)
N = int(input())
Y = []
for i in range(N):
    b = int(input())
    if b in B:
        Y.append(B.index(b)+1)
# print(Y)
if 1 in Y and 5 in Y and 9 in Y:
    print("Yes")
elif 3 in Y and 5 in Y and 7 in Y:
    print("Yes")
    
elif 1 in Y and 2 in Y and 3 in Y:
    print("Yes")
elif 4 in Y and 5 in Y and 6 in Y:
    print("Yes")
elif 7 in Y and 8 in Y and 9 in Y:
    print("Yes")
    
elif 1 in Y and 4 in Y and 7 in Y:
    print("Yes")
elif 2 in Y and 5 in Y and 8 in Y:
    print("Yes")
elif 3 in Y and 6 in Y and 9 in Y:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

for k in range(0,n):
  for i in range(0,3):
    for j in range(0,3):
      if a[i][j]==b[k]:
        a[i][j]=0
for k in range(0,3):
  if (a[k][0]==0)and(a[k][1]==0)and(a[k][2]==0):
    bingo=bingo+1
for k in range(0,3):
  if (a[0][k]==0)and(a[1][k]==0)and(a[2][k]==0):
    bingo=bingo+1   
if (a[0][0]==0)and(a[1][1]==0)and(a[2][2]==0):
  bingo=bingo+1 
  
if (a[2][0]==0)and(a[1][1]==0)and(a[2][0]==0):
  bingo=bingo+1
if bingo>0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import numpy as np
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
a3 = list(map(int,input().split()))
n = int(input())
t = np.zeros(8,dtype=int)
count = 0
for i in range(n):
    b = int(input())
    for j in range(3):
        if a1[j] == b:
            a1[j] = 0
        if a2[j] == b:
            a2[j] = 0
        if a3[j] == b:
            a3[j] = 0
if a1[0] + a2[0] + a3[0] == 0:
    count +=1
if a1[1] + a2[1] + a3[1] == 0:
    count +=1
if a1[2] + a2[2] + a3[2] == 0:
    count +=1
if a1[0] + a1[1] + a1[2] == 0:
    count +=1
if a2[0] + a2[1] + a2[2] == 0:
    count +=1
if a3[0] + a3[1] + a3[2] == 0:
    count +=1
if a1[0] + a2[1] + a3[2] == 0:
    count +=1
if a3[0] + a2[1] + a1[2] == 0:
    count +=1
if count == 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

p = []
p += a
p += [list(a_) for a_ in zip(*a)]
p += [[a[x][x] for x in range(3)]]
p += [[a[x][2-x] for x in range(3)]]

for p_ in p:
    for x in p_:
        if x in b:
            continue
        else:
            break
    else:
        print('Yes')
        break
else:
    print('No')

Submission status: Accepted

Solution code:
row1 = list(map(int, input().split()))
row2 = list(map(int, input().split()))
row3 = list(map(int, input().split()))
N = int(input())
b = [int(input()) for n in range(N)]

col1 = [row1[0], row2[0], row3[0]]
col2 = [row1[1], row2[1], row3[1]]
col3 = [row1[2], row2[2], row3[2]]

diagonal1 = [row1[0], row2[1], row3[2]]
diagonal2 = [row1[2], row2[1], row3[0]]

all = row1 + row2 + row3

x = []
for i in b:
    if i in all:
        x.append(i)
    
if len(list(set(row1) & set(x))) == 3 or\
    len(list(set(row2) & set(x))) == 3 or\
    len(list(set(row3) & set(x))) == 3 or\
    len(list(set(col1) & set(x))) == 3 or\
    len(list(set(col2) & set(x))) == 3 or\
    len(list(set(col3) & set(x))) == 3 or\
    len(list(set(diagonal1) & set(x))) == 3 or\
    len(list(set(diagonal2) & set(x))) == 3:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

bingo = []

for i, a_li in enumerate(a_li_li):
    for j, a in enumerate(a_li):
        if a in b:
            bingo.append(i + j * 10)

if 0 in bingo and 10 in bingo and 20 in bingo:
    ans = 'Yes'
elif 1 in bingo and 11 in bingo and 21 in bingo:
    ans = 'Yes'
elif 2 in bingo and 12 in bingo and 22 in bingo:
    ans = 'Yes'
elif 0 in bingo and 1 in bingo and 2 in bingo:
    ans = 'Yes'
elif 10 in bingo and 11 in bingo and 12 in bingo:
    ans = 'Yes'
elif 20 in bingo and 21 in bingo and 22 in bingo:
    ans = 'Yes'
elif 0 in bingo and 11 in bingo and 22 in bingo:
    ans = 'Yes'
elif 2 in bingo and 11 in bingo and 20 in bingo:
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

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

Submission status: Accepted

Solution code:
bingo = [list(map(int, input().split())) for i 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 bingo[j][k] == num:
                bingo[j][k] = 0
                break;
res = 'No'
for i in range(3):
    if bingo[i][0] == bingo[i][1] == bingo[i][2] == 0:
        res = 'Yes'
        break
    elif bingo[0][i] == bingo[1][i] == bingo[2][i] == 0:
        res = 'Yes'
        break
if bingo[0][2] == bingo[1][1] == bingo[2][0] == 0:
    res = 'Yes'
elif bingo[0][0] == bingo[1][1] == bingo[2][2] == 0:
    res = 'Yes'
print(res)