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:
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
bingo_num = []
judge = False
N = int(input())
for i in range(N):
  bingo_num.append(int(input()))
for i in bingo_num:
  for a in range(len(A1)):
    if A1[a] == i:
      A1[a] = -1
  for b in range(len(A2)):
    if A2[b] == i:
      A2[b] = -1
  for c in range(len(A3)):
    if A3[c] == i:
      A3[c] = -1
if sum(A1) == -3 or sum(A2) == -3 or sum(A3) == -3:
  judge = True
for i in range(len(A1)):
  if A1[i] + A2[i] + A3[i] == -3:
    judge = True
if A1[0] + A2[1] + A3[2] == -3 or A1[2] + A2[1] + A3[0] == -3:
  judge = True
if judge:
  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  = list(map(int,input().split()) for i in range(n))
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if b == a[j][k]:
                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:
import sys
table = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
for _ in range(N):
    cmd = int(input())
    for i in range(3):
        for j in range(3):
            if table[i][j] == cmd:
                table[i][j] = -1
                break
for i in range(3):
    if (table[i][0]==-1 and table[i][1]==-1 and table[i][2]==-1) or \
        (table[0][i]==-1 and table[1][i]==-1 and table[2][i]==-1):
        print("Yes")
        sys.exit()
if (table[0][0]==-1 and table[1][1]==-1 and table[2][2]==-1) or \
    (table[0][2]==-1 and table[1][1]==-1 and table[2][0]==-1):
    print("Yes")
    sys.exit()
print("No")

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for i in range(3)]  #数字、複数行複数列
N = int(input())  #数字
T = list(int(input()) for i in range(N))  #複数行１列を一つのリストにする

#print(A)
#print(N)
#print(T)

for i in range(3):
    for j in range(3):
        if A[i][j] in T:
            A[i][j] = 999

#print(A)

for i in range(3):
    if A[i][0] + A[i][1] + A[i][2] == 999 * 3:
        print("Yes")
        exit()
    if A[0][i] + A[1][i] + A[2][i] == 999 * 3:
        print("Yes")
        exit()

if A[0][0] + A[1][1] + A[2][2] == 999 * 3:
    print("Yes")
    exit()
if A[2][0] + A[1][1] + A[0][2] == 999 * 3:
    print("Yes")
    exit()

print("No")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    A = tuple(tuple(map(int, input().split())) for i in range(3)) #改行行列
    N = int(input())
    B = tuple(int(input()) for i in range(N))
    tset=set()
    for b in B:
        for i in range(3):
            for j in range(3):
                if A[i][j]==b:
                    tset.add(i*4+j)
    flag=False
    for i in range(3):
        if i*4 in tset and i*4+1 in tset and i*4+2 in tset:
            flag=True
        elif i in tset and 4+i in tset and 8+i in tset:
            flag=True
    if 0 in tset and 5 in tset and 10 in tset:
        flag=True
    elif 2 in tset and 5 in tset and 8 in tset:
        flag=True

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





if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
card=[]
for i in range(3):
  card.append(list(map(int,input().split())))
n = int(input())
for i in range(n):
  k = int(input())
  for i in range(3):
    for j in range(3):
      if k == card[i][j]:
        card[i][j] = -1

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

Submission status: Accepted

Solution code:
card = [0]*3
for i in range(3):
    a = input().split()
    card[i] = [int(s) for s in a]
for i in range(int(input())):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if b == card[j][k]:
                card[j][k] = 0
if (card[0][0] == 0 and card[1][0] == 0 and card[2][0] == 0) or (card[0][1] == 0 and card[1][1] == 0 and card[2][1] == 0) or (card[0][2] == 0 and card[1][2] == 0 and card[2][2] == 0) or(card[0][0] == 0 and card[0][1] == 0 and card[0][2] == 0) or (card[1][0] == 0 and card[1][1] == 0 and card[1][2] == 0) or (card[2][0] == 0 and card[2][1] == 0 and card[2][2] == 0) or (card[0][0] == 0 and card[1][1] == 0 and card[2][2] == 0) or (card[0][2] == 0 and card[1][1] == 0 and card[2][0] == 0):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')
import numpy as np

def solve():
    A = LLI(3)
    # print(A)
    n = II()
    C = np.array([[0, 0, 0] for _ in range(3)])
    # print(C)
    for i in range(n):
        b = II()
        for j in range(3):
            for k in range(3):
                if A[j][k] == b:
                    C[j][k] = 1

    # print(C)
    # tate, yoko
    for i in range(3):
        # print(C[i, :])
        # print(C[:, i])
        if sum(C[:, i]) == 3 or sum(C[i, :]) == 3:
            print('Yes')
            return

    # naname
    if C[0][0] + C[1][1] + C[2][2] == 3 or C[0][2] + C[1][1] + C[2][0] == 3:
        print('Yes')
        return

    print('No')



if __name__ == '__main__':
    solve()

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())
    a = [0 if b == a[i] else a[i] for i in range(9)]

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

Submission status: Accepted

Solution code:
dic = {}
for i in range(3):
  arr = input().split()
  for j in range(3):
    dic[arr[j]] = (i,j)
    
n = int(input())
appear=[[False for _ in range(3)] for __ in range(3)]

for _ in range(n):
  b = input()
  if b in dic:
    i, j = dic[b]
    appear[i][j] = True

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

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 i in range(n):
  b = int(input())
  A = np.where(A == b, -1, A)

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

Submission status: Accepted

Solution code:

A = [input().split() for i in range(3)]
N = int(input())

B = [input() for _ in range(N)]

result = False

for x in range(len(B)):
    for y in range(3):
        for z in range(3):
            #print(A)
            #print(B[x])
            if A[y][z] == B[x]:
                A[y][z] = 0

for i in range(3):
        if A[i][0] == A[i][1] == A[i][2]:
            result = True
            break

for i in range(3):
        if A[0][i] == A[1][i] == A[2][i]:
            result = True
            break

if A[0][0] == A[1][1] == A[2][2] or A[0][2] == A[1][1] == A[2][0]:
    result = True
    
#print(A)

if result == False:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
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())
dic = {0:False,1:False,2:False,3:False,4:False,5:False,6:False,7:False,8:False}
for i in range(N):
    called = int(input())
    for j in range(9):
        if called == A[j//3][j%3]:
            dic[j] = True
            continue
if dic[0] == dic[1] == dic[2] == True or dic[3] == dic[4] == dic[5] == True or dic[6] == dic[7] == dic[8] == True or dic[0] == dic[3] == dic[6] == True or dic[1] == dic[4] == dic[7] == True or dic[2] == dic[5] == dic[8] == True or dic[0] == dic[4] == dic[8] == True or dic[2] == dic[4] == dic[6] == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A1 = [int(_) for _ in input().split()]
A2 = [int(_) for _ in input().split()]
A3 = [int(_) for _ in input().split()]
P = [A1, A2, A3]
for i in range(3):
    P.append([A1[i], A2[i], A3[i]])
P.append([A1[0], A2[1], A3[2]])
P.append([A1[2], A2[1], A3[0]])


N = int(input())
B = []
for i in range(N):
    b = int(input())
    B.append(b)
for p in P:
    if len(set(p) & set(B)) == 3:
        print('Yes')
        break
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
A = [[int(i) for i in readline().split()] for _ in range(3)]
n = int(readline())
b = [int(readline()) for _ in range(n)]

for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            A[i][j] = 0
        
if A[0][0]+A[1][1]+A[2][2] == 0 \
or A[0][2]+A[1][1]+A[2][0] == 0 \
or 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 :
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
seat=[list(map(int,input().split())) for _ in range(3)]
n = int(input())
for i in range(n):
    x = int(input())
    for j in range(3):
        if x in seat[j]:
            seat[j][seat[j].index(x)]=0
#print(seat)

f = False
for i in range(3):
    if seat[i][0]==0 and seat[i][1]==0 and seat[i][2]==0:
        f = True
    if seat[0][i] == 0 and seat[1][i] == 0 and seat[2][i] == 0:
        f = True
if seat[0][0]==0 and seat[1][1]==0 and seat[2][2]==0:
    f = True
if seat[0][2]==0 and seat[1][1]==0 and seat[0][2]==0:
    f = True

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

Submission status: Accepted

Solution code:
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=q
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)

a = readInts()+readInts()+readInts()

n = readInt()
b = []
for i in range(n):
	b = readInt()
	if b in a:
		c = a.index(b)
		a[c] = 0

for i in [0,3,6]:
	if a[i]+a[i+1]+a[i+2]==0:
		print("Yes")
		exit()
for i in [0,1,2]:
	if a[i]+a[i+3]+a[i+6]==0:
		print("Yes")
		exit()
if a[0]+a[4]+a[8]==0 or a[2]+a[4]+a[6]==0:
	print("Yes")
	exit()

print("No")

Submission status: Accepted

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

num = [[0] * 3 for _ in range(3)]
for i in range(n):
    x = int(input())
    for j in range(3):
        for k in range(3):
            if x == a[j][k]:
                num[j][k] = 1


ans = False
for i in range(3):
    cnt = 0
    for j in range(3):
        if num[i][j] == 1:
            cnt += 1
    if cnt == 3:
        ans = True

for i in range(3):
    cnt = 0
    for j in range(3):
        if num[j][i] == 1:
            cnt += 1
    if cnt == 3:
        ans = True

if num[0][0] == 1 and num[1][1] == 1 and num[2][2] == 1:
    ans = True
if num[0][2] == 1 and num[1][1] == 1 and num[2][0] == 1:
    ans = True

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A = np.array([lr() for _ in range(3)])
N = ir()
B = np.zeros_like(A, np.bool)
for _ in range(N):
    b = ir()
    if np.any(A==b):
        i = np.where(A==b)
        B[i[0], i[1]] = True

bl = np.any([np.all(row) for row in B])
if np.any(np.all(B, axis=0)):
    bl = True
if np.all(np.diag(B)):
    bl = True
B = B[:, ::-1]
if np.all(np.diag(B)):
    bl = True
print('Yes' if bl else 'No')

Submission status: Accepted

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

if 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[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][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:
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
g,h,i=map(int,input().split())
N=int(input())
L=[int(input()) for i in range(N)]
if a in L and b in L and c in L:
  print('Yes')
elif d in L and e in L and  f in L:
  print('Yes')
elif g in L and h in L and  i in L:
  print('Yes')
elif a in L and d in L and  g in L:
  print('Yes')
elif b in L and e in L and  h in L:
  print('Yes')
elif c in L and f in L and  i in L:
  print('Yes')
elif a in L and e in L and  i in L:
  print('Yes')
elif c in L and e in L and  g in L:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
a = [list(int(i) for i in input().split()) for i in range(3)]
f = [[0 for i in range(3)] for i in range(3)]
n = int(input())
b = []
flag = False

for i in range(n):
  b.append(int(input()))
  
for i in b:
  for j in range(3):
    for k in range(3):
      if i == a[j][k]:
        f[j][k] = 1

if sum(f[0]) == 3 or sum(f[1]) == 3 or sum(f[2]) == 3:
  flag = True

for i in range(3):
  tmp = []
  for j in range(3):
    tmp.append(f[j][i])
  if sum(tmp) == 3:
    flag = True
    
if f[0][0] == 1 and f[1][1] == 1 and f[2][2] == 1:
  flag = True

if f[0][2] == 1 and f[1][1] == 1 and f[2][0] == 1:
  flag = True

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

Submission status: Accepted

Solution code:

# -*- coding: utf-8 -*-
# 157b
a = []
b = []
check_list = [False] * 9
for _ in range(3):
  a.extend(list(map(int, input().split())))
n = int(input())
for _ in range(n):
  b.append(int(input()))

for _b in b:
  if _b in a:
    check_list[a.index(_b)] = True

if check_list[0] and check_list[1] and check_list[2]\
  or check_list[3] and check_list[4] and check_list[5]\
  or check_list[6] and check_list[7] and check_list[8]\
  or check_list[0] and check_list[3] and check_list[6]\
  or check_list[1] and check_list[4] and check_list[7]\
  or check_list[2] and check_list[5] and check_list[8]\
  or check_list[0] and check_list[4] and check_list[8]\
  or check_list[2] and check_list[4] and check_list[6]:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
def main():
    num=[0]*9
    num[0],num[1],num[2]= map(int,input().split())
    num[3],num[4],num[5]= map(int,input().split())
    num[6],num[7],num[8]= map(int,input().split())

    n=int(input())
    li=[int(input()) for i in range(n)]
    flg = 0
    cnt = 0
    bg = [0]*9


    for i in num:
        if i in li:
            # print('okay')
            bg[cnt]=1

        cnt+=1

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

    # print(bg)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a1,a2,a3= map(int,input().split())
a4,a5,a6= map(int,input().split())
a7,a8,a9= map(int,input().split())
n=int(input())
b=[int(input()) for _ in range(n)]
bing = [(a1,a2,a3),(a4,a5,a6),(a7,a8,a9),
        (a1,a4,a7),(a2,a5,a8),(a3,a6,a9),
        (a1,a5,a9),(a3,a5,a7)]
for cs in bing:
    for c in cs:
        if not c in b:break
    else:
        print('Yes')
        break
else:print('No')

Submission status: Accepted

Solution code:
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
g,h,i=map(int,input().split())
N=int(input())
L=[int(input()) for i in range(N)]
if a in L and b in L and c in L:
  print('Yes')
elif d in L and e in L and  f in L:
  print('Yes')
elif g in L and h in L and  i in L:
  print('Yes')
elif a in L and d in L and  g in L:
  print('Yes')
elif b in L and e in L and  h in L:
  print('Yes')
elif c in L and f in L and  i in L:
  print('Yes')
elif a in L and e in L and  i in L:
  print('Yes')
elif c in L and e in L and  g in L:
  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()))
B1 = [0,0,0]
B2 = [0,0,0]
B3 = [0,0,0]
N = int(input())
for i in range(N):
  x = int(input())
  if(x in A1):
    tmp = A1.index(x)
    B1[tmp] = 1
  if(x in A2):
    tmp = A2.index(x)
    B2[tmp] = 1
  if(x in A3):
    tmp = A3.index(x)
    B3[tmp] = 1
if(B1[0]==1 and B1[1]==1 and B1[2]==1):
  print("Yes")
  exit()
if(B2[0]==1 and B2[1]==1 and B2[2]==1):
  print("Yes")
  exit()
if(B3[0]==1 and B3[1]==1 and B3[2]==1):
  print("Yes")
  exit()
if(B1[0]==1 and B2[0]==1 and B3[0]==1):
  print("Yes")
  exit()
if(B1[1]==1 and B2[1]==1 and B3[1]==1):
  print("Yes")
  exit()
if(B1[2]==1 and B2[2]==1 and B3[2]==1):
  print("Yes")
  exit()
if(B1[0]==1 and B2[1]==1 and B3[2]==1):
  print("Yes")
  exit()
if(B1[2]==1 and B2[1]==1 and B3[0]==1):
  print("Yes")
  exit()
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)]
#print(A,N,b)
for i in range(3):
  for j in range(3):
    for k in b:
      if A[i][j]==k:
         A[i][j]=0
  
flag=0
for i in range(3):
  if A[i].count(0)==3:
    flag=1
    #print('yoko')
    break
  elif A[0][i]==0 and A[1][i]==0 and A[2][i]==0:
    flag=1
    #print('tate')
    break    
else:
  if A[0][0]==0 and A[1][1]==0 and A[2][2]==0:
    #print('naname1')
    flag=1
  elif A[0][2]==0 and A[1][1]==0 and A[2][0]==0:
    #print('naname2')
    flag=1
print('Yes' if flag==1 else 'No')

Submission status: Accepted

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

def is_bingo(A, B):
    is_called = []
    for i in range(3):
        is_called.append([True if A[i][j] in B else False for j in range(3)])
    for i in range(3):
        if not(False in [is_called[i][j] for j in range(3)]): return True
    for j in range(3):
        if not(False in [is_called[i][j] for i in range(3)]): return True
    if not(False in [is_called[i][j] for i in range(3) for j in range(3) if i + j == 2]): return True
    if not(False in [is_called[i][j] for i in range(3) for j in range(3) if i - j == 0]): return True
    return False

def main():
    A = []
    B = []
    for _ in range(3):
        A.append(list(map(int, input().split())))
    N = int(input())
    for _ in range(N):
        B.append(int(input()))
    if is_bingo(A, B):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    try:
        assert is_bingo([[84, 97, 66], [79, 89, 11], [61, 59, 7]], [89, 7, 87, 79, 24, 84, 30]) == True
        assert is_bingo([[41, 7, 46], [26, 89, 2], [78, 92, 8]], [5, 6, 45, 16, 57, 17]) == False
        assert is_bingo([[60, 88, 34], [92, 41, 43], [65, 73, 48]], [10, 60, 43, 88, 11, 48, 73, 65, 41, 92, 34]) == True
    except:
        import traceback
        traceback.print_exc()
        exit()
    main()

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[0],a1[1],a1[2],a2[0],a2[1],a2[2],a3[0],a3[1],a3[2]]
#print(A)
n=int(input())
b=[]
for i in range(n):
    b.append(int(input()))

for i in range(n):
    for j in range(9):
        if b[i]==A[j]:
            A[j]="atari"
#print(A)
if A[0]==A[3]==A[6]:
    print("Yes")
elif A[1]==A[4]==A[7]:
    print("Yes")
elif A[2]==A[5]==A[8]:
    print("Yes")
elif A[0]==A[1]==A[2]:
    print("Yes")
elif A[3]==A[4]==A[5]:
    print("Yes")
elif A[6]==A[7]==A[8]:
    print("Yes")
elif A[0]==A[4]==A[8]:
    print("Yes")
elif A[2]==A[4]==A[6]:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A=[[int(i) for i in input().split(" ")]for k in range(3)]
N=int(input())
for i in range(N):
    b=int(input())
    for x,y in [(x,y) for x in range(3) for y in range(3) if A[x][y]==b]:
        A[x][y]=0

M=1
for k in range(3):
    M*=sum(A[i][k] for i in range(3))
    M*=sum(A[k][i] for i in range(3))
M*=sum(A[i][i] for i in range(3))
M*=sum(A[i][2-i] for i in range(3))
if M==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np
a1 = np.zeros(3, dtype=int)
a2 = np.zeros(3, dtype=int)
a3 = np.zeros(3, dtype=int)

for i in range(3):
    a1[i], a2[i], a3[i] = map(int, input().split())

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

a = np.array([a1, a2, a3]).T.flatten()

for i in range(n):
    a[np.where(a == b[i])] = 0
a = a.reshape(3, -1)

print("Yes") if a[0].sum()==0 or a[1].sum()==0 or a[2].sum()==0 or a[:, 0].sum()==0 or a[:, 1].sum()==0 or a[:, 2].sum()==0 or np.diag(a).sum()==0 or np.diag(a[::-1]).sum()==0 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 i in range(3):
        for j in range(3):
            if a[i][j] == b:
                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_list = [0]*3
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())
#print(a_list)
for k in range(n):
    dum = int(input())
    for i in range(3):
        for j in range(3):
            if a_list[i][j] == dum:
                a_list[i][j] = 0
#print(a_list[0][0])
if a_list[0][0] == 0 and a_list[0][1] == 0 and a_list[0][2] == 0:
    print("Yes")
elif a_list[1][0] == 0 and a_list[1][1] == 0 and a_list[1][2] == 0:
    print("Yes")
elif a_list[2][0] == 0 and a_list[2][1] == 0 and a_list[2][2] == 0:
    print("Yes")
elif a_list[0][0] == 0 and a_list[1][0] == 0 and a_list[2][0] == 0:
    print("Yes")
elif a_list[0][1] == 0 and a_list[1][1] == 0 and a_list[2][1] == 0:
    print("Yes")
elif a_list[0][2] == 0 and a_list[1][2] == 0 and a_list[2][2] == 0:
    print("Yes")
elif a_list[0][0] == 0 and a_list[1][1] == 0 and a_list[2][2] == 0:
    print("Yes")
elif a_list[0][2] == 0 and a_list[1][1] == 0 and a_list[2][0] == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A1=[int(i) for i in input().split()]
A2=[int(i) for i in input().split()]
A3=[int(i) for i in input().split()]
N=int(input())
b=[int(input()) for i in range (N)]
for t in b:
    if t in A1:
        A1[A1.index(t)]="#"
    elif t in A2:
        A2[A2.index(t)]="#"
    elif t in A3:
        A3[A3.index(t)]="#"
ans='No'
if len(set(A1))==1 or len(set(A2))==1 or len(set(A3))==1:
    ans='Yes'
if (A1[0]==A2[0]==A3[0]) or (A1[1]==A2[1]==A3[1]) or (A1[2]==A2[2]==A3[2]):
    ans='Yes'
if (A1[0]==A2[1]==A3[2]) or (A1[2]==A2[1]==A3[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)]

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

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

B = [[False for i in range(0,3,1)]for i in range(0,3,1)]
for i in range(0,N):
    n = int(input())
    for j in range(0,3):
        for k in range(0,3):
            if n == A[j][k]:
                B[j][k]=True

if (B[0][0]and B[0][1]and B[0][2])or(B[1][0]and B[1][1]and B[1][2])or(B[2][0]and B[2][1]and B[2][2])or(B[0][0]and B[1][0]and B[2][0])or(B[0][1]and B[1][1]and B[2][1])or(B[0][2]and B[1][2]and B[2][2])or(B[0][0]and B[1][1]and B[2][2])or(B[2][0]and B[1][1]and B[0][2]):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a0,a1,a2=map(int,input().split())
a3,a4,a5=map(int,input().split())
a6,a7,a8=map(int,input().split())
N=int(input())
b=[int(input()) for _ in range(N)]
A=[a0,a1,a2,a3,a4,a5,a6,a7,a8]

for i in range(N):
  for p in range(9):
    if b[i]==A[p]:
      A[p]=0
  
if A[0]==A[1]==A[2]==0 or A[3]==A[4]==A[5]==0 or A[6]==A[7]==A[8]==0 or A[0]==A[3]==A[6]==0 or A[1]==A[4]==A[7]==0 or A[2]==A[5]==A[8]==0 or A[0]==A[4]==A[8]==0 or A[2]==A[4]==A[6]==0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import numpy as np
A = np.zeros((3,3), dtype=int)
for i in range(3):
    A[i,:] = list(map(int, input().split()))
N = int(input())
B = [int(input()) for _ in range(N)]

A = A.flatten()
for a in range(len(A)):

    for b in range(N):
        if A[a] == B[b]:
            A[a] = -1



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

Submission status: Accepted

Solution code:
d = {}

for i in range(3):
    a = input().split()
    for j in range(3):
        d[a[j]] = (i,j)
t = [[0 for _ in range(3)] for _ in range(3)]
n = int(input())
for i in range(n):
    b = input()
    if(b in d):t[d[b][0]][d[b][1]] = 1
for i in range(3):
    if(t[0][i] + t[1][i] + t[2][i] == 3):
        print('Yes')
        exit()
    if(t[i][0] + t[i][1] + t[i][2] == 3):
        print('Yes')
        exit()
if(t[0][0]+t[1][1]+t[2][2] == 3):
    print('Yes')
    exit()
if(t[0][2]+t[1][1]+t[2][0] == 3):
    print('Yes')
    exit()
print('No')