Problem:


Score : 200 points

Problem Statement

We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}.

The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet.

Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.

Constraints

All values in input are integers.

1 \leq A_{i, j} \leq 100

A_{i_1, j_1} \neq A_{i_2, j_2} ((i_1, j_1) \neq (i_2, j_2))

1 \leq N \leq 10

1 \leq b_i \leq 100

b_i \neq b_j (i \neq j)

Input

Input is given from Standard Input in the following format:

A_{1, 1} A_{1, 2} A_{1, 3}
A_{2, 1} A_{2, 2} A_{2, 3}
A_{3, 1} A_{3, 2} A_{3, 3}
N
b_1
\vdots
b_N

Output

If we will have a bingo, print Yes; otherwise, print No.

Sample Input 1

84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30

Sample Output 1

Yes

We will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3}, and complete the diagonal from the top-left to the bottom-right.

Sample Input 2

41 7 46
26 89 2
78 92 8
5
6
45
16
57
17

Sample Output 2

No

We will mark nothing.

Sample Input 3

60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34

Sample Output 3

Yes

We will mark all the squares.



Sample input:
84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30


Sample output:
Yes

Submission status: Accepted

Solution code:
from collections import defaultdict
dic = defaultdict(int)

for i in range(3):
    a,b,c = map(int,input().split())
    dic[a] = i*3+1
    dic[b] = i*3+2
    dic[c] = i*3+3
ansl = []
n = int(input())
for _ in range(n):
    k = int(input())
    if dic[k] and dic[k] not in ansl:
        ansl.append(dic[k])
if 1 in ansl and 2 in ansl and 3 in ansl:
    print("Yes")
    exit()
if 4 in ansl and 5 in ansl and 6 in ansl:
    print("Yes")
    exit()
if 7 in ansl and 8 in ansl and 9 in ansl:
    print("Yes")
    exit()
if 1 in ansl and 4 in ansl and 7 in ansl:
    print("Yes")
    exit()
if 2 in ansl and 5 in ansl and 8 in ansl:
    print("Yes")
    exit()
if 3 in ansl and 6 in ansl and 9 in ansl:
    print("Yes")
    exit()
if 1 in ansl and 5 in ansl and 9 in ansl:
    print("Yes")
    exit()
if 3 in ansl and 5 in ansl and 7 in ansl:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
import numpy as np
a = []
a.append([int(x) for x in input().split()])
a.append([int(x) for x in input().split()])
a.append([int(x) for x in input().split()])
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))

ans = 'No'
for i in range(3):
  if set(np.array(a)[:, i]) <= set(b) or set(np.array(a)[i, :]) <= set(b):
    ans = 'Yes'

if set([a[0][0], a[1][1], a[2][2]]) <= set(b) or set([a[2][0], a[1][1], a[0][2]]) <= set(b):
  ans = 'Yes'
print(ans)

Submission status: Accepted

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    for i in range(N):
        searchAndPut(A,b[i])

    # Horisonal
    if A[0][0] == A[0][1] == A[0][2] == -1:
            print(YES)
    elif A[1][0] == A[1][1] == A[1][2] == -1:
            print(YES)
    elif A[2][0] == A[2][1] == A[2][2] == -1:
            print(YES)
    # Vertical
    elif A[0][0] == A[1][0] == A[2][0] == -1:
            print(YES)
    elif A[0][1] == A[1][1] == A[2][1] == -1:
            print(YES)
    elif A[0][2] == A[1][2] == A[2][2] == -1:
            print(YES)
    # Cross
    elif A[0][0] == A[1][1] == A[2][2] == -1:
            print(YES)
    elif A[0][2] == A[1][1] == A[2][0] == -1:
            print(YES)
    else:
        print(NO)

def searchAndPut(A: "List[List[int]]",b):
    for i in range(3):
        list = A[i]
        if (b in list):
            list[list.index(b)] = -1
            break

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [[int(next(tokens)) for _ in range(3)] for _ in range(3)]  # type: "List[List[int]]"
    N = int(next(tokens))  # type: int
    b = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(A, N, b)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

N = int(input())

b=[]
ans = [[False]*3,[False]*3, [False]*3]
for i in range(N):
    b += [int(input())]

#print(ans)
#print(A)
for i in range(N):
    num = b[i]
    for j in range(3):
        for k in range(3):
            if A[j][k]==num:
                ans[j][k] = True;
                
#print(ans)

answer = ans[0][0] and ans[1][1] and ans[2][2]
answer = answer or (ans[0][2] and ans[1][1] and ans[2][0])

for i in range(3):
    answer = answer or (ans[i][0] and ans[i][1] and ans[i][2])
    answer = answer or (ans[0][i] and ans[1][i] and ans[2][i])

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

Submission status: Accepted

Solution code:
import numpy as np

A = np.array([[int(val) for val in input().split(" ")] for i in range(3)])
N = int(input())
b = np.array([int(input()) for i in range(N)])

A_ = np.zeros_like(A)
for bi in b:
    row, col = np.where(A == bi)
    if row.size and col.size:
        A_[row[0]][col[0]] = 1

ans1 = sum(np.sum(A_, axis=0) == 3)
ans2 = sum(np.sum(A_, axis=1) == 3)
ans3 = (sum([A_[i,i] for i in range(3)]) == 3).astype(int)
ans4 = (sum([A_[i,2-i] for i in range(3)]) == 3).astype(int)
if ans1 or ans2 or ans3 or ans4:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
b = []
b.append([int(s) for s in input().split()])
b.append([int(s) for s in input().split()])
b.append([int(s) for s in input().split()])

n = int(input())

for i in range(0, n):
    v = int(input())

    for i in range(0, 3):
        for j in range(0, 3):
            if b[i][j] == v:
                b[i][j] = 999

ans = 'No'

for i in range(0, 3):
    s = set(b[i])

    if len(s) == 1:
        ans = 'Yes'

for i in range(0, 3):
    s = set([b[0][i], b[1][i], b[2][i]])

    if len(s) == 1:
        ans = 'Yes'

c = set([b[0][0], b[1][1], b[2][2]])

if len(c) == 1:
    ans = 'Yes'

c = set([b[0][2], b[1][1], b[2][0]])

if len(c) == 1:
    ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
bingo = []

for _ in range(3):
	bingo.extend(list(map(int, input().split(' '))))

# print(bingo)

n = int(input())

nums = []
for _ in range(n):
  nums.append(int(input()))
  
# print(nums)
flag = [False for _ in range(9)]
for n in nums:
  for i in range(9):
    if bingo[i] == n:
      flag[i] = True
      
# print(flag)

result = False
for i in [0, 3, 6]:
  if (flag[i] and flag[i+1] and flag[i+2]):
    result = True
    
for i in [0, 1, 2]:
  if (flag[i] and flag[i+3] and flag[i+6]):
    result = True
    
if (flag[0] and flag[4] and flag[8]):
    result = True
    
if (flag[2] and flag[4] and flag[6]):
    result = True
    
if result:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

emp = [[0] * 3 for _ in range(3)]
#print(n, b)

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

x = [0, 1, 2, 0, 0, 0, 0, 2]
y = [0, 0, 0, 0, 1, 2, 0, 0]
dx = [0, 0, 0, 1, 1, 1, 1, -1]
dy = [1, 1, 1, 0, 0, 0, 1, 1]

flag = True
ans = False

for i in range(8) :
    xx = x[i]
    yy = y[i]
    flag = True
    for j in range(3) :
        #print(i, j, xx, yy, emp[xx][yy])
        if emp[xx][yy] != 1 :
            flag = False
            break
        xx += dx[i]
        yy += dy[i]
    if flag == True :
        ans = True
if ans :
    print('Yes')
else :
    print('No')

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy
import bisect


def dfs(s, prev, pre):
  val[s] += Ope[s] + prev
  for i in G[s]:
    if(i == pre):
      continue
    dfs(i, val[s], s)

#X = str(input()).split()
#a = [int(x) for x in input().split()]
#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())

A1 = [int(x) for x in input().split()]
A2 = [int(x) for x in input().split()]
A3 = [int(x) for x in input().split()]
A = ["x"]*9

N = int(input())
b = []
ans = "No"

for i in range(N):
  b.append(int(input()))
  for j in range(3):
    if(b[i]==A1[j]):
      A[j]="o"
    elif(b[i]==A2[j]):
      A[j+3]="o"
    elif(b[i]==A3[j]):
      A[j+6]="o"

for i in range(3):
  if(A[i*3]=="o" and A[i*3+1]=="o" and A[i*3+2]=="o"):
    ans = "Yes"
  if(A[i]=="o" and A[i+3]=="o" and A[i+6]=="o"):
    ans = "Yes"

if(A[0]=="o" and A[4]=="o" and A[8]=="o"):
  ans = "Yes"
if(A[2]=="o" and A[4]=="o" and A[6]=="o"):
  ans = "Yes"



print(ans)

Submission status: Accepted

Solution code:
A = list()
for i in range(3):
    A.append(list(map(int, input().split())))
N = int(input())
B = [int(input()) for _ in range(N)]
checkList = [[False, False, False], [False, False, False], [False, False, False]]
for b in B:
    for i in range(3):
        for j in range(3):
            if b == A[i][j]:
                checkList[i][j] = True
checkListT = [list(x) for x in zip(*checkList)]

ans = "No"
if all(checkList[0]):
   ans = "Yes"
if all(checkList[1]):
   ans = "Yes"
if all(checkList[2]):
   ans = "Yes"

if all(checkListT[0]):
   ans = "Yes"
if all(checkListT[1]):
   ans = "Yes"
if all(checkListT[2]):
   ans = "Yes"

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

print(ans)

Submission status: Accepted

Solution code:
import sys
bingo = [list(map(int, input().split())) for _ in range(3)]
input_num = int(input())
input_list = [int(input()) for _ in range(input_num)]
flag = False

for l in bingo:
	match_count = 0
	if [x for x in l if x in input_list]:
		match_count = len([x for x in l if x in input_list])
		if match_count == 3:
			print('Yes')
			sys.exit()


match_count = 0
for l in list(zip(*bingo)):
	match_count = 0
	if [x for x in l if x in input_list]:
		match_count = len([x for x in l if x in input_list])
		if match_count == 3:
			print('Yes')
			sys.exit()

match_count = 0
for n, l in zip([0,1,2], bingo):
	if l[n] in input_list:
		match_count += 1
	if match_count == 3:
		print('Yes')
		sys.exit()

match_count = 0
for n, l in zip([-1,-2,-3], bingo):
	if l[n] in input_list:
		match_count += 1
	if match_count == 3:
		print('Yes')
		sys.exit()

print('No')

Submission status: Accepted

Solution code:
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))

a = a1 + a2 + a3

n = int(input())

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

for i in b:
    for j in range(len(a)):
        if i == a[j]:
            a[j] = 0

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

Submission status: Accepted

Solution code:
a11,a12,a13 = map(int,input().split())
a21,a22,a23 = map(int,input().split())
a31,a32,a33 = map(int,input().split())
N=int(input())
i=0
B=[]
while i<N:
  B.append(int(input()))
  i+=1
ans=0
c11=c12=c13=c21=c22=c23=c31=c32=c33=0
  
for k in B:
  if k==a11:
    c11+=1
  elif k==a12:
    c12+=1
  elif k==a13:
    c13+=1
  elif k==a21:
    c21+=1
  elif k==a22:
    c22+=1
  elif k==a23:
    c23+=1
  elif k==a31:
    c31+=1
  elif k==a32:
    c32+=1
  elif k==a33:
    c33+=1
  
if c11>0 and c12>0 and c13>0:
  ans+=1
elif c21>0 and c22>0 and c23>0:
  ans+=1
elif c31>0 and c32>0 and c33>0:
  ans+=1
elif c11>0 and c21>0 and c31>0:
  ans+=1
elif c12>0 and c22>0 and c32>0:
  ans+=1
elif c13>0 and c23>0 and c33>0:
  ans+=1
elif c11>0 and c22>0 and c33>0:
  ans+=1
elif c31>0 and c22>0 and c13>0:
  ans+=1


if ans>0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
card = []
a,b,c = map(int,input().split())
card.append(a)
card.append(b)
card.append(c)
a,b,c = map(int,input().split())
card.append(a)
card.append(b)
card.append(c)
a,b,c = map(int,input().split())
card.append(a)
card.append(b)
card.append(c)
N = int(input())
for i in range(N):
    b = int(input())
    try:
        card[card.index(b)] = -1
    except:
        continue
if card[0] == card[1] == card[2] or card[3] == card[4] == card[5] or card[6] == card[7] == card[8] or card[0] == card[3] == card[6] or card[1] == card[4] == card[7] or card[2] == card[5] == card[8] or card[0] == card[4] == card[8] or card[2] == card[4] == card[6]:
    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())
b=[]
for i in range(0,N):
    d=int(input())
    b.append(d)
c1=[False,False,False]
c2=[False,False,False]
c3=[False,False,False]

for j in range(0,N):
    for k in range(0,3):
        if A1[k]==b[j]:
            c1[k]=True
        if A2[k]==b[j]:
            c2[k]=True
        if A3[k]==b[j]:
            c3[k]=True
if c1[0]==True and c1[1]==True and c1[2]==True:
    print("Yes")
elif c2[0]==True and c2[1]==True and c2[2]==True:
    print("Yes")
elif c3[0]==True and c3[1]==True and c3[2]==True:
    print("Yes")
elif c1[0]==True and c2[0]==True and c3[0]==True:
    print("Yes")
elif c1[1]==True and c2[1]==True and c3[1]==True:
    print("Yes")
elif c1[2]==True and c2[2]==True and c3[2]==True:
    print("Yes")
elif c1[0]==True and c2[1]==True and c3[2]==True:
    print("Yes")
elif c3[0]==True and c2[1]==True and c1[2]==True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def bingo(a):
    for i in range(3):
        if sum([a[j][i] for j in range(3)]) == 0:
            return 'Yes'
        if sum(a[i]) == 0:
            return 'Yes'
    if a[0][0] + a[1][1] + a[2][2] == 0:
        return 'Yes'
    if a[2][0] + a[1][1] + a[0][2] == 0:
        return 'Yes'
    return 'No'

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

for num in b:
    for i, ai in enumerate(a):
        for j, aij in enumerate(ai):
            if aij == num:
                a[i][j] = 0
print(bingo(a))

Submission status: Accepted

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

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

if a[0][0] == 0 and a[0][1] == 0 and a[0][2] == 0:
  print("Yes")
  exit()
if a[1][0] == 0 and a[1][1] == 0 and a[1][2] == 0:
  print("Yes")
  exit()
if a[2][0] == 0 and a[2][1] == 0 and a[2][2] == 0:
  print("Yes")
  exit()
if a[0][0] == 0 and a[1][0] == 0 and a[2][0] == 0:
  print("Yes")
  exit()
if a[0][1] == 0 and a[1][1] == 0 and a[2][1] == 0:
  print("Yes")
  exit()
if a[0][2] == 0 and a[1][2] == 0 and a[2][2] == 0:
  print("Yes")
  exit()
if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
  print("Yes")
  exit()
if a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0:
  print("Yes")
  exit()

print("No")

Submission status: Accepted

Solution code:
listA = []
import itertools
listB = [0] * 9
for i in range(3):
    listA.append(input().split())
listA = list(itertools.chain.from_iterable(listA))
N = int(input())
for i in range(N):
    B = input()
    if B in listA:
        listB[listA.index(B)] = 1
for i in range(3):
    if listB[i*3] == 1 and listB[i*3+1] == 1 and listB[i*3+2] == 1:
        print("Yes")
        exit()
for i in range(3):
    if listB[i] == 1 and listB[i+3] == 1 and listB[i+6] == 1:
        print("Yes")
        exit()
if listB[0] == 1 and listB[4] == 1 and listB[8] == 1:
    print("Yes")
    exit()
if listB[2] == 1 and listB[4] == 1 and listB[6] == 1:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

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

N = int(input())

grid = [[0] * 3] + [[0] * 3] + [[0] * 3]

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

    for j in range(3):
        for k in range(3):
            if b == A[j][k]:
                grid[j][k] = 1

ans = "No"

for j in range(3):
    if sum(grid[j]) == 3:
        ans = "Yes"


for k in range(3):
    tmp = 0
    for j in range(3):
        tmp += grid[j][k]
    if tmp == 3:
        ans = "Yes"

tmp = 0
for i in range(3):
    tmp += grid[i][i]
if tmp == 3:
    ans = "Yes"

tmp = 0
for i in range(3):
    tmp += grid[i][2-i]
if tmp == 3:
    ans = "Yes"


print(ans)

Submission status: Accepted

Solution code:
# ABC 157 B
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nms = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))
a=[list(map(int, input().split())) for i in range(3)]
n=int(input())
b=[]
for i in range(n):
    bb=int(input())
    b.append(bb)

mat=[[0]*3 for _ in range(3)]

for bb in b:
    for i in range(3):
        for j in range(3):
            if bb==a[i][j]:
                mat[i][j]=1
a1=mat[0][0]+mat[1][0]+mat[2][0]
a2=mat[0][1]+mat[1][1]+mat[2][1]
a3=mat[0][2]+mat[1][2]+mat[2][2]
# a1=mat[0][0]+mat[0][1]+mat[0][2]
# a2=mat[1][0]+mat[1][1]+mat[1][2]
# a3=mat[2][0]+mat[2][1]+mat[2][2]
a4=mat[0][0]+mat[1][1]+mat[2][2]
a5=mat[0][2]+mat[1][1]+mat[2][0]
if a1==3 or a2==3 or a3==3 or a4==3 or a5==3:
    print('Yes')
    exit()

# print(a)
# print(b)
# print(mat)
for mm in mat:
    if sum(mm)==3:
        print('Yes')
        exit()
print('No')

Submission status: Accepted

Solution code:
l = [list(map(int,input().split())) 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 l[j][k] == b:
                l[j][k] = -1

for i in range(3):
    flg = True
    for j in range(3):
        flg &= l[i][j] == -1
    if flg:
        print('Yes')
        exit()

for i in range(3):
    flg = True
    for j in range(3):
        flg &= l[j][i] == -1
    if flg:
        print('Yes')
        exit()

flg = True
for i in range(3):
    flg &= l[i][i] == l[0][0]
if flg:
    print('Yes')
    exit()

flg = True
for i in range(3):
    flg &= l[i][2 - i] == l[0][2]
if flg:
    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())

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

for i in range(3):
    if a[i] in x:
        a[i] = True
    else:
        a[i] = False
    if b[i] in x:
        b[i] = True
    else:
        b[i] = False
    if c[i] in x:
        c[i] = True
    else:
        c[i] = False

flag = False

if a[0] and a[1] and a[2]:
    flag = True
if b[0] and b[1] and b[2]:
    flag = True
if c[0] and c[1] and c[2]:
    flag = True

for i in range(3):
    if a[i] and b[i] and c[i]:
        flag = True

if a[0] and b[1] and c[2]:
    flag = True
if a[2] and b[1] and c[0]:
    flag = True

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

Submission status: Accepted

Solution code:
a = [0 for i in range(9)]
c = [0 for i in range(9)]
a[0],a[1],a[2] = map(int,input().split())
a[3],a[4],a[5] = map(int,input().split())
a[6],a[7],a[8] = map(int,input().split())

n = int(input())
for i in range(n):
    b= int(input())
    for j in range(9):
        if a[j] == b:
            c[j] = 1



ans = 'No'
for i in range(3):
    if c[3*i]+c[3*i+1]+c[3*i+2] == 3:
        ans = 'Yes'

for i in range(3):
    if c[i]+c[3+i]+c[6+i] == 3:
        ans = 'Yes'

if c[0]+c[4]+c[8] == 3:
    ans = 'Yes'
if c[2]+c[4]+c[6] == 3:
    ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
import sys

def judge(p, numList):
    for n in numList:
        if p[n] == False:
            return False
    return True

board = []
bingo = [False] * 9
for i in range(0, 3):
    board += list(map(int, input().split()))

N = int(input())
for i in range(0, N):
    n = int(input())
    for j in range(len(board)):
        if n == board[j]:
            bingo[j] = True

row = [[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 r in row:
    if judge(bingo, r):
        print("Yes")
        sys.exit()
print("No")

Submission status: Accepted

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

for i in b:
    for j in range(3):
        for k in range(3):
            if a[j][k] == i:
                a[j][k] = "o"

for i in range(3):
    tmp1 = ""
    tmp2 = ""
    for j in range(3):
        tmp1 += a[i][j]
        tmp2 += a[j][i]
    if tmp1 == "ooo" or tmp2 == "ooo":
        print("Yes")
        exit()

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

A = []
A += list(map(int, input().split()))
A += list(map(int, input().split()))
A += list(map(int, input().split()))

N = int(input())

for i in range(N):
    value = int(input())
    for j in range(len(A)):
        if value == A[j]:
            A[j] = 101
            break

msg = "No"
if (A[0] == 101 and A[1] == 101 and A[2] == 101):
    msg = "Yes"
elif (A[3] == 101 and A[4] == 101 and A[5] == 101):
    msg = "Yes"
elif (A[6] == 101 and A[7] == 101 and A[8] == 101):
    msg = "Yes"
elif (A[0] == 101 and A[3] == 101 and A[6] == 101):
    msg = "Yes"
elif (A[1] == 101 and A[4] == 101 and A[7] == 101):
    msg = "Yes"
elif (A[2] == 101 and A[5] == 101 and A[8] == 101):
    msg = "Yes"
elif (A[0] == 101 and A[4] == 101 and A[8] == 101):
    msg = "Yes"
elif (A[2] == 101 and A[4] == 101 and A[6] == 101):
    msg = "Yes"
print(msg)

Submission status: Accepted

Solution code:
bing1 = list(map(int, input().split()))
bing2 = list(map(int, input().split()))
bing3 = list(map(int, input().split()))

bingo = [bing1,bing2,bing3]
res = [[0,0,0],[0,0,0],[0,0,0]]

n = int(input())

for i in range(n):
    c = int(input())
    for j in range(3):
        for k in range(3):
            if bingo[j][k] == c:
                res[j][k] = 1
                break
                
ress = "No"
if sum(res[0]) == 3 or sum(res[1]) == 3 or sum(res[2]) == 3:
    ress = "Yes"
elif res[0][0] + res[1][0] + res[2][0] == 3 or res[0][1] + res[1][1] + res[2][1] == 3 or res[0][2] + res[1][2] + res[2][2] == 3:
    ress = "Yes"
elif res[0][0] + res[1][1] + res[2][2] == 3 or res[0][2] + res[1][1] + res[2][0] == 3:
    ress = "Yes"
print(ress)

Submission status: Accepted

Solution code:
A11, A12, A13 = map(int, input().split())
A21, A22, A23 = map(int, input().split())
A31, A32, A33 = map(int, input().split())
N = int(input())
bj = [int(input()) for i in range(N)]

result = []
result.append([A11, A12, A13])
result.append([A13, A23, A33])
result.append([A33, A32, A31])
result.append([A31, A21, A11])
result.append([A12, A22, A32])
result.append([A21, A22, A23])
result.append([A11, A22, A33])
result.append([A31, A22, A13])

flg = 'No'
for cmb in result:
	count = 0
	for i in bj:
		if i in cmb:
			count += 1
	if count == 3:
		flg = 'Yes'
print(flg)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

def initBingoCard():
    bingoCard = []
    for i in range(3):
        row = [int(i) for i in input().split()]
        bingoCard.append(row)
    return bingoCard

def generateBingoPatterns(bingo_card):
    bingo_patterns = []
    for row in bingo_card:
        bingo_patterns.append(row)
        
    for column in range(3):
        column_pattern = []
        for row in range(3):
            column_pattern.append(bingo_card[row][column])
            
        bingo_patterns.append(column_pattern)
        
    bingo_patterns.append([bingo_card[0][0],bingo_card[1][1],bingo_card[2][2]])
    bingo_patterns.append([bingo_card[2][0],bingo_card[1][1],bingo_card[0][2]])
    
    return bingo_patterns

bingo_card = initBingoCard()

bingo_patterns = generateBingoPatterns(bingo_card)
    
N = int(input())

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

combi = itertools.combinations(nums, 3)

flag = False
for c in combi:
    c = sorted(c)
    for pattern in bingo_patterns:
        if c == sorted(pattern):
            flag = True
            break
if flag :
    print('Yes')
else :
    print('No')

Submission status: Accepted

Solution code:
import sys 
x=[]
for i in range(3):
  a,b,c=map(int,input().split())
  x.append(a)
  x.append(b)
  x.append(c)
n=int(input())
p=[int(input()) for i in range(n)]
for i in range(9):
  if x[i] in p:
    x[i]=0
def ch(s,d):
  global x
  if x[s]==0 and x[s+d]==0 and x[s+d+d]==0:
    print('Yes')
    sys.exit()
d=1
ch(0,d)
ch(3,d)
ch(6,d)
d=3
for i in range(3):
  ch(i,d)
ch(2,2)
ch(0,4)
print('No')

Submission status: Accepted

Solution code:
a = []
for _ in range(3):
    a.append(list(map(int,input().split())))
n = int(input())
r = [[0,0,0],[0,0,0],[0,0,0]]
for b in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                r[i][j] = 1

s = 0

for i in range(3):
    if r[i][0] == r[i][1] == r[i][2] == 1:
        s += 1
        break
    elif r[0][i] == r[1][i] == r[2][i] == 1:
        s += 1
        break

if r[0][0] == r[1][1] == r[2][2] == 1:
    s += 1
elif r[2][0] == r[1][1] == r[0][2] == 1:
    s += 1

if s > 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
l1 = input().split()
l2 = input().split()
l3 = input().split()
l = [l1,l2,l3]
n = int(input())
b = [input() for i in range(n)]
for i in range(3):
    for j in range(3):
        if l[i][j] in b:
            l[i][j] = -1
if l[0] == [-1,-1,-1] or l[1] == [-1,-1,-1] or l[2] == [-1,-1,-1] or (l[0][0] == -1 and l[1][0] == -1 and l[2][0] == -1) or (l[0][1] == -1 and l[1][1] == -1 and l[2][1] == -1) or (l[0][2] == -1 and l[1][2] == -1 and l[2][2] == -1) or (l[0][0] == -1 and l[1][1] == -1 and l[2][2] == -1) or (l[2][0] == -1 and l[1][1] == -1 and l[0][2] == -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)]

ans=[set([a[0][0],a[0][1],a[0][2]]),set([a[1][0],a[1][1],a[1][2]]),set([a[2][0],a[2][1],a[2][2]]),set([a[0][0],a[1][0],a[2][0]]),set([a[0][1],a[1][1],a[2][1]]),set([a[0][2],a[1][2],a[2][2]]),set([a[0][0],a[1][1],a[2][2]]),set([a[0][2],a[1][1],a[2][0]])]
from itertools import combinations


for i in combinations(b, 3):
    if set(i) in ans:
        print('Yes')
        exit()
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()))

ans = "No"
flag = 0

#yoko
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            flag += 1
    if flag == 3:
        ans = "Yes"
    flag = 0

#tate
for j in range(3):
    for i in range(3):
        if a[i][j] in b:
            flag += 1
    if flag == 3:
        ans = "Yes"
    flag = 0

#naname1
for i in range(3):
    for j in range(3):
        if i == j:
            if a[i][j] in b:
                flag += 1
        if flag == 3:
            ans = "Yes"
flag = 0

#naname2
for i in range(3):
    for j in range(3):
        if i + j == 2 :
            if a[i][j] in b:
                flag += 1
        if flag == 3:
            ans = "Yes"
flag = 0

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    A = [list(map(int,input().split())) for i in range(3)]
    N = int(input())
    B = [int(input()) for i in range(N)]
    #print(A,N,B)
    for j in B:
        for k in range(3):
            for l in range(3):
                if j == A[k][l]:
                    A[k][l] = -1
    A1 = A[0]
    A2 = A[1]
    A3 = A[2]
    if A1.count(-1)==3 or A2.count(-1)==3 or A3.count(-1)==3:
        print('Yes')
        return
    for m in range(3):
        if A1[m] ==-1 and A2[m] == -1 and A3[m] == -1:
            print('Yes')
            return
    if A1[0]==-1 and A2[1]==-1 and A3[2]==-1:
        print('Yes')
        return
    if A1[2]==-1 and A2[1]==-1 and A3[0]==-1:
        print('Yes')
        return
    print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin

a = []
a1 = [int(x) for x in stdin.readline().rstrip().split()]
a2 = [int(x) for x in stdin.readline().rstrip().split()]
a3 = [int(x) for x in stdin.readline().rstrip().split()]
a4 = [a1[0], a2[0], a3[0]]
a5 = [a1[1], a2[1], a3[1]]
a6 = [a1[2], a2[2], a3[2]]
a7 = [a1[0], a2[1], a3[2]]
a8 = [a1[2], a2[1], a3[0]]
a.append(a1)
a.append(a2)
a.append(a3)
a.append(a4)
a.append(a5)
a.append(a6)
a.append(a7)
a.append(a8)

n = int(stdin.readline().rstrip())
b = []
for i in range(n):
    b.append(int(stdin.readline().rstrip()))

result = "No"
for aa in a:
    if (aa[0] in b and aa[1] in b and aa[2] in b):
        result = "Yes"

print(result)

Submission status: Accepted

Solution code:
import math as M
A=[]
for i in range(3):
    X=list(int(i) for i in input().split())
    A.append(X)
D=[[0 for i in range(3)]for j in range(3)]
n=int(input())
for _ in range(n):
    b=int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                D[i][j]=1
#row
#print(D)
bool=False
for i in range(3):
    sum=0
    for j in range(3):
        if D[i][j]==1:
            sum+=D[i][j]
    if sum==3:
        bool=True
        break
if bool is True:
    print("Yes")
elif bool is False:
    for i in range(3):
        sum=0
        for j in range(3):
            if D[j][i]==1:
                sum+=D[j][i]
        if sum==3:
            bool=True
            break
    if bool is True:
        print("Yes")
    else:
        if D[1][1]+D[2][2]+D[0][0]==3:
            print("Yes")
        elif D[1][1]+D[0][2]+D[2][0]==3:
            print("Yes")
        else:
            print("No")

Submission status: Accepted

Solution code:
#B - Bingo
A =[list(map(int, input().split())) for i in range(3)]
N = int(input())
b = [int(input()) for j in range(N)]
A_n = [[0 for a in range(3)] for c in range(3)]

for k in range(3):
    for l in range(3):
        for m in range(N):
            if A[k][l] == b[m]:
                A_n[k][l] = 1
            else:
                pass

if A_n[0][0]+A_n[0][1]+A_n[0][2]==3 or A_n[1][0]+A_n[1][1]+A_n[1][2] == 3 or A_n[2][0]+A_n[2][1]+A_n[2][2] == 3:
    print("Yes")
elif A_n[0][0]+A_n[1][0]+A_n[2][0]==3 or A_n[0][1]+A_n[1][1]+A_n[2][1] == 3 or A_n[0][2]+A_n[1][2]+A_n[2][2] == 3:
    print("Yes")
elif A_n[0][0]+A_n[1][1]+A_n[2][2]==3 or A_n[0][2]+A_n[1][1]+A_n[2][0]==3:
    print("Yes")
else:
    print("No")