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=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))
A = [a,b,c]
N = int(input())
b = []
temp = []
for _ in range(N):
    inp = int(input())
    for y, row in enumerate(A):
        try:
            temp.append([y, row.index(inp)])
            break
        except ValueError:
            pass
if ([0,0] in temp and [1,0] in temp and [2,0] in temp) or([0,1] in temp and [1,1] in temp and [2,1] in temp)or([0,2] in temp and [1,2] in temp and [2,2] in temp)or([0,0] in temp and [0,1] in temp and [0,2] in temp)or([1,0] in temp and [1,1] in temp and [1,2] in temp)or([2,0] in temp and [2,1] in temp and [2,2] in temp)or([0,0] in temp and [1,1] in temp and [2,2] in temp)or([0,2] in temp and [1,1] in temp and [2,0] in temp):
	print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A11, A12, A13=list(map(int,input().split()))
A21, A22, A23=list(map(int,input().split()))
A31, A32, A33=list(map(int,input().split()))
N=int(input())
b=[int(input()) for i in range(N)]
if A11 in b and A12 in b and A13 in b:
    print('Yes')
elif A21 in b and A22 in b and A23 in b:
    print('Yes')
elif A31 in b and A32 in b and A33 in b:
    print('Yes')
elif A11 in b and A21 in b and A31 in b:
    print('Yes')
elif A12 in b and A22 in b and A32 in b:
    print('Yes')
elif A13 in b and A23 in b and A33 in b:
    print('Yes')
elif A11 in b and A22 in b and A33 in b:
    print('Yes')
elif A13 in b and A22 in b and A31 in b:
    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 l in range(n)]
a = a[0] + a[1] + a[2]
A = [False]*9
for h in range(len(a)):
  A[h] = a[h] in b
flag = 'No'
for k in range(3):
  if A[k*3] ==  A[k*3+1] ==  A[k*3+2] == True:
    flag = 'Yes'
  if A[k] == A[k+3] ==  A[k+6] == True:
    flag = 'Yes'
  if A[0] ==  A[4] == A[8] == True:
    flag = 'Yes'
  if A[2] ==  A[4] ==  A[6] == True:
    flag = 'Yes'
print(flag)

Submission status: Accepted

Solution code:
data=[]
for i in range(3):
    a=list(map(int,input().split()))
    data.append(a)
n=int(input())
cnt=[0]*8
for i in range(n):
    b=int(input())
    for j in range(3):
        for k in range(3):
            if b==data[j][k]:
                cnt[j]+=1
                cnt[k+3]+=1
                if j==k:
                    cnt[6]+=1
                if j+k==2:
                    cnt[7]+=1
ans="No"
for i in range(8):
    if cnt[i]==3:
        ans="Yes"
        break
print(ans)

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()))
A = np.array([A1, A2, A3])

N = int(input())
for i in range(N):
    B = int(input())
    A[A==B] = 0
    
result = 'No'
for i in range(3):
    if A[i].sum()==0:
        result = 'Yes'
        break
    elif A[:, i].sum()==0:
        result = 'Yes'
    else:
        pass
if np.diag(A).sum()==0:
    result = 'Yes'
elif (A[0, 2]+A[1, 1]+A[2, 0])==0:
    result = 'Yes'

print(result)

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
b = []
for i in range(N):
	b.append(int(input()))
	
yoko = A
tate = [[], [], []]
for row in A:
	for i in range(3):
		tate[i].append(row[i])
naname = [[A[0][0], A[1][1], A[2][2]], [A[0][2], A[1][1], A[2][0]]]

all = yoko + tate + naname

y = 0
chk = 0
for kumi in all:
	for k in kumi:
		if k in b:
			chk += 1
		else:
			continue
	if chk == 3:
		print("Yes")
		y = 1
		break
	else:
		chk = 0
		
if y == 0:
	print("No")

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] = "x"
      else:
        pass
if A[0] == ["x","x","x"]:
  print("Yes")
elif A[1] == ["x","x","x"]:
  print("Yes")
elif A[2] == ["x","x","x"]:
  print("Yes")
elif A[0][0] == "x" and A[1][0] == "x" and A[2][0] == "x":
  print("Yes")
elif A[0][1] == "x" and A[1][1] == "x" and A[2][1] == "x":
  print("Yes")
elif A[0][2] == "x" and A[1][2] == "x" and A[2][2] == "x":
  print("Yes")
elif A[0][0] == "x" and A[1][1] == "x" and A[2][2] == "x":
  print("Yes")
elif A[0][2] == "x" and A[1][1] == "x" and A[2][0] == "x":
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from functools import *
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def Golf():
    *a,=map(int,open(0))
def S_():
    return input()
def IS():
    return input().split()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['YES','NO']
Yn=['Yes','No']
 
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
#ts=time.time()
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a


class UnionFind:
    def __init__(self, n):
        # 負  : 根であることを示す。絶対値はランクを示す
        # 非負: 根でないことを示す。値は親を示す
        self.table = [-1] * n
        self.cnt = [1] * n
 
    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            # 経路の圧縮
            self.table[x] = self._root(self.table[x])
            return self.table[x]
 
    def find(self, x, y):
        return self._root(x) == self._root(y)
 
    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        # ランクの取得
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.cnt[r1]+=self.cnt[r2]
            if d1 == d2:
                self.table[r1] -= 1
                
        else:
            self.table[r1] = r2
            self.cnt[r2]+=self.cnt[r1]
    
    def __str__(self):
        rt=[i if j<0 else j for i,j in enumerate(self.table)]
        return str(rt)

show_flg=False
show_flg=True

mr={}
mc={}
A=[[0]*3 for i in range(3)]
for i in range(3):
    a=LI()
    for j in range(3):
        mr[a[j]]=i
        mc[a[j]]=j

n=I()
for i in range(n):
    b=I()
    if b in mr:
        A[mr[b]][mc[b]]=1

for i in range(3):
    if sum(A[i])==3:
        print('Yes')
        exit()


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

for j in range(3):
    if A[0][j]+A[1][j]+A[2][j]==3:
        print('Yes')
        exit()

print('No')

Submission status: Accepted

Solution code:
import sys
import math
sys.setrecursionlimit(int(1e6))

A = [[0]*3]*3
A[0] = list(map(int, input().split()))
A[1] = list(map(int, input().split()))
A[2] = list(map(int, input().split()))

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

c = [[0]*3 for i in range(3)]
for bn in b:
    for m in range(3*3):
        i = m % 3
        j = m // 3
        if (A[i][j] == bn):
            c[i][j] = 1
            break

ans = 'No'
for i in range(3):
    if sum(c[i]) == 3:
        ans = 'Yes'
        break
    if sum([c[0][i], c[1][i], c[2][i]]) == 3:
        ans = 'Yes'
        break
else:
    if sum([c[0][0], c[1][1], c[2][2]]) == 3:
        ans = 'Yes'
    elif sum([c[2][0], c[1][1], c[0][2]]) == 3:
        ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
# B
import sys
a_list = []
a = []
c = [False for i in range(9)]
for i in range(3):
    a_list = list(map(int, input().split()))
    for num in a_list:
        a.append(num)
n = int(input())
for i in range(n):
    num = int(input())
    if num in a:
        index = a.index(num)
        c[index] = True

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

Submission status: Accepted

Solution code:
mt = [[0, 0, 0] for i in range(3)]
bf = [[0, 0, 0] for i in range(3)]
res = 'No'
for i in range(3):
    mt[i] = list(map(int, input().split(' ')))
n = int(input())
b = []
for i in range(n):
    b.append(int(input()))
for i in b:
    for j in range(3):
        if i in mt[j]:
            bcol = mt[j].index(i)
            bf[j][bcol] = 1
            if sum(bf[j]) == 3 or bf[0][bcol] == 1 and bf[1][bcol] == 1 and bf[2][bcol] == 1:
                res = 'Yes'
            if bf[0][0] == 1 and bf[1][1] == 1 and bf[2][2] == 1 or bf[0][2] == 1 and bf[1][1] == 1 and bf[0][2] == 1:
                res = 'Yes'
print(res)

Submission status: Accepted

Solution code:
listA = []
while True:
    try:
        listA.append(list(map(int,input().split())))
    except:
        break;

listB = []
listB = listA[:3]
n = listA[3][0]

listC = []
for i in range(0,n):
	listC.append(listA[i+4][0])


for i in range(0,n):
  for j in range(0,3):
    for k in range(0,3):
      if listB[j][k]==listC[i]:
        listB[j][k] = -1

kekka = 0
for i in range(0,3):
  if listB[i][0]==-1 and listB[i][1]==-1 and listB[i][2]==-1:
    kekka = 1
for i in range(0,3):
  if listB[0][i]==-1 and listB[1][i]==-1 and listB[2][i]==-1:
    kekka = 1
if listB[0][0]==-1 and listB[1][1]==-1 and listB[2][2]==-1:
  kekka = 1
if listB[0][2]==-1 and listB[1][1]==-1 and listB[2][0]==-1:
  kekka = 1

if kekka == 1:
  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()))

A = [A1,A2,A3]
a = np.array(A)

N = int(input())
for i in range(N):
    tmp = int(input())
    a = np.where(a==tmp, 0,a)

ans = 'Yes' if ((a[0][0]==0)and(a[0][1]==0)and(a[0][2]==0)) or ((a[1][0]==0)and(a[1][1]==0)and(a[1][2]==0)) or ((a[2][0]==0)and(a[2][1]==0)and(a[2][2]==0)) or ((a[0][0]==0)and(a[1][0]==0)and(a[2][0]==0)) or ((a[0][1]==0)and(a[1][1]==0)and(a[2][1]==0)) or ((a[0][2]==0)and(a[1][2]==0)and(a[2][2]==0)) or ((a[0][0]==0)and(a[1][1]==0)and(a[2][2]==0)) or ((a[0][2]==0)and(a[1][1]==0)and(a[2][0]==0)) else 'No'
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))

N = int(input())

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

card_nums = r1 + r2 + r3

bingo_list = set()
for b in bs:
    if b in card_nums:
        index = card_nums.index(b)
        bingo_list.add(index)

bingo_candidates = [
    [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 main():
    for bingo_candidate in bingo_candidates:
        result = set(bingo_candidate) & bingo_list

        if len(result) == 3:
            print("Yes")
            return
        else:
            continue
    print("No")

main()
# if (3 in bingo_list.sum(axis=1)) or (3 in bingo_list.sum(axis=0)):
#     print('Yes')
# elif np.diag(bingo_list).sum() == 3:
#     print('Yes')
# else:
#     print('No')

Submission status: Accepted

Solution code:
import sys

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

a1.extend(a2)
a1.extend(a3)
result = []

for target_list in b:
    try:
        result.append(a1.index(target_list)+1)
    except:
        continue        

ans = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 4, 7],[2, 5, 8], [3, 6, 9], [1, 5, 9], [3, 5, 7]]


for target_list in ans:
    tmp = set(target_list) & set(result)
    if len(tmp)>=3:
        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())
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:
    f=True
elif a[1][0]==0 and a[1][1]==0 and a[1][2]==0:
    f= True
elif a[2][0]==0 and a[2][1]==0  and a[2][2]==0:
    f= True
elif a[0][0]==0 and a[1][0]==0 and a[2][0]==0:
    f= True
elif a[0][1]==0 and a[1][1]==0 and a[2][1]==0:
    f= True
elif a[0][2]==0 and a[1][2]==0 and a[2][2]==0:
    f= True
elif a[1][1]==0 and a[2][2]==0 and a[0][0]==0:
    f= True
elif a[0][2]==0 and a[1][1]==0 and a[2][0]==0:
    f= True
else:
    f= False

if f == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a,b,c = map(int, input().split())
d,e,f = map(int, input().split())
l,m,k = map(int, input().split())
g = [a, b, c, d, e, f, l, m, k]
a1 = [a, b, c]
a2 = [d, e, f]
a3 = [l, m, k]
a4 = [a, d, l]
a5 = [b, e, m]
a6 = [c, f, k]
a7 = [a, e, k]
a8 = [c, e, l]
lis1 = []
n = int(input())
for i in range(n):
    op = int(input())
    lis1.append(op)
    
if set(a1) <= set(lis1) or set(a2) <= set(lis1) or set(a3) <= set(lis1) or set(a4) <= set(lis1) or set(a5) <= set(lis1) or set(a6) <= set(lis1) or set(a7) <= set(lis1) or set(a8) <= set(lis1):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
l = []
b = []
for i in range(3):
    l.append(input().split())
# for t in range(int(input())):
r = int(input())
for v in range(r):
    b.append(input())
for i in range(3):
    for a in range(3):
        for t in range(r):
            if l[i][a] == b[t]:
                l[i][a] = '@'
if l[0][0] == '@' and l[0][1] == '@' and l[0][2] == '@':
    print('Yes')
elif l[1][0] == '@' and l[1][1] == '@' and l[1][2] == '@':
    print('Yes')
elif l[2][0] == '@' and l[2][1] == '@' and l[2][2] == '@':
    print('Yes')
elif l[0][0] == '@' and l[1][0] == '@' and l[2][0] == '@':
    print('Yes')
elif l[0][1] == '@' and l[1][1] == '@' and l[2][1] == '@':
    print('Yes')
elif l[0][2] == '@' and l[1][2] == '@' and l[2][2] == '@':
    print('Yes')
elif l[0][0] == '@' and l[1][1] == '@' and l[2][2] == '@':
    print('Yes')
elif l[0][2] == '@' and l[1][1] == '@' and l[2][0] == '@':
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
b = []
for _ in range(N):
  b.append(int(input()))
for n in range(N):
  for i in range(3):
    for j in range(3):
      if b[n]==A[i][j]:
        A[i][j]=0
a=A[0][0]+A[0][1]+A[0][2]
b=A[1][0]+A[1][1]+A[1][2]
c=A[2][0]+A[2][1]+A[2][2]
d=A[0][0]+A[1][0]+A[2][0]
e=A[0][1]+A[1][1]+A[2][1]
f=A[0][2]+A[1][2]+A[2][2]
g=A[0][0]+A[1][1]+A[2][2]
h=A[0][2]+A[1][1]+A[2][0]
if a==0 or b==0 or c==0 or d==0 or e==0 or f==0 or g==0 or h==0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
r1 = [int(str) for str in input().split()]
r2 = [int(str) for str in input().split()]
r3 = [int(str) for str in input().split()]
n = int(input())

for i in range(n):
  b = int(input())
  r1 = [0 if x == b else x for x in r1]
  r2 = [0 if x == b else x for x in r2]
  r3 = [0 if x == b else x for x in r3]

c1 = [r1[0],r2[0],r3[0]]
c2 = [r1[1],r2[1],r3[1]]
c3 = [r1[2],r2[2],r3[2]]
s1 = [r1[0],r2[1],r3[2]]
s2 = [r1[2],r2[1],r3[0]]

s = [sum(r1),sum(r2),sum(r3),sum(c1),sum(c2),sum(c3),sum(s1),sum(s2)]

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

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=[]
for i in range(n):
    b.append(int(input()))
    
c=[]   
for j1 in range(3):
    c.append([0,0,0])

for i in range(n):
    for j1 in range(3):
        for j2 in range(3):
            if b[i]==a[j1][j2]:
                c[j1][j2]=1

csum1=0                
csum2=0                
csum3=0                
for j1 in range(3):
    csum1=csum1+c[j1][0]                
    csum2=csum2+c[j1][1]                
    csum3=csum3+c[j1][2]
                
csum4=0                
csum5=0                
csum6=0                
for j1 in range(3):
    csum4=csum4+c[0][j1]                
    csum5=csum5+c[1][j1]                
    csum6=csum6+c[2][j1]

csum7=c[0][0]+c[1][1]+c[2][2]                
csum8=c[2][0]+c[1][1]+c[0][2]  

if csum1==3 or csum2==3 or csum3==3:
    print("Yes")
elif csum4==3 or csum5==3 or csum6==3:
    print("Yes")
elif csum7==3 or csum8==3 :
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

N = int(input())

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

# 縦のビンゴがある
def isExistTatePair():
    # すべての当選番号を調べる
    for i in range(3):
            sum = 0
            for j in range(3):
                sum += A[3 * j + i]
            
            # ビンゴか調べる
            if sum == 0:
                return True
    return False
    
# 横のビンゴがある
def isExistYokoPair():
    # すべての当選番号を調べる
    for i in range(3):
            sum = 0
            for j in range(3):
                sum += A[3 * i + j]
            
            # ビンゴか調べる
            if sum == 0:
                return True
    return False
    
# ななめのビンゴがある
def isExistNanamePair():
    # 左上から右下へのななめ
    naname1 = A[0] + A[4] + A[8]
    
    if naname1 == 0:
        return True
    
    # 右上から左下へのななめ
    naname2 = A[2] + A[4] + A[6]
    
    if naname2 == 0:
        return True
    
    return False

# 当選番号を見てビンゴカードに穴をあける
for b in B:
    for index in range(len(A)):
        a = A[index]
        if a == b:
            A[index] = 0
    
isExistBingo = isExistTatePair() or isExistYokoPair() or isExistNanamePair()
print('Yes' if isExistBingo else 'No')

Submission status: Accepted

Solution code:
A = [input().split() for a in range(3)]
N = int(input())
B = [input() for b in range(N)]

for i in range(N):
  for j in range(3):
    for k in range(3):
      if A[j][k] == B[i]:
        A[j][k] = 'ok'
        
if A[0][0] == 'ok' and A[0][1] == 'ok' and A[0][2] == 'ok':
  print('Yes')
  exit
elif A[1][0] == 'ok' and A[1][1] == 'ok' and A[1][2] == 'ok':
  print('Yes')
  exit
elif A[2][0] == 'ok' and A[2][1] == 'ok' and A[2][2] == 'ok':
  print('Yes')
  exit
elif A[0][0] == 'ok' and A[1][0] == 'ok' and A[2][0] == 'ok':
  print('Yes')
  exit
elif A[0][1] == 'ok' and A[1][1] == 'ok' and A[2][1] == 'ok':
  print('Yes')
  exit
elif A[0][2] == 'ok' and A[1][2] == 'ok' and A[2][2] == 'ok':
  print('Yes')
  exit
elif A[0][0] == 'ok' and A[1][1] == 'ok' and A[2][2] == 'ok':
  print('Yes')
  exit
elif A[0][2] == 'ok' and A[1][1] == 'ok' and A[2][0] == 'ok':
  print('Yes')
  exit
else :
  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())

a = a + b + c

list = []

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

b = [0,0,0,0,0,0,0,0,0]

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

sum = 0
for i in range(len(b)):
    sum = sum + b[i]

if sum == 0:
    print("No")
elif b[2]+b[4]+b[6] ==3:
    print("Yes")
elif b[0]+b[1]+b[2] ==3:
    print("Yes")
elif b[3]+b[4]+b[5] ==3:
    print("Yes")
elif b[6]+b[7]+b[8] ==3:
    print("Yes")
elif b[0]+b[4]+b[8] ==3:
    print("Yes")
elif b[2]+b[5]+b[8] ==3:
    print("Yes")
elif b[1]+b[4]+b[7] ==3:
    print("Yes")
elif b[0]+b[3]+b[6] ==3:
    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()))
mx = [a1, a2, a3]
#print(mx)
N = int(input())
b = {}
for i in range(N):
  b[int(input())] = True
  #b.append(int(input()))
#print(b)

def checkList(arr):
  for i in arr:
    if i not in b:
      return False
  return True
def check():
  if checkList(a1):
    return True
  if checkList(a2):
    return True
  if checkList(a3):
    return True
  if checkList([a1[0], a2[0], a3[0]]):
    return True
  if checkList([a1[1], a2[1], a3[1]]):
    return True
  if checkList([a1[2], a2[2], a3[2]]):
    return True
  if checkList([a1[0], a2[1], a3[2]]):
    return True
  if checkList([a1[2], a2[1], a3[0]]):
    return True
  return False

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

lines = sys.stdin.readlines()
bingo_card = np.zeros([3,3])
for i, l in enumerate(lines):
    if i <= 2:
        bingo_card[i] = [int(num) for num in l.split()]
    else:
        bingo_card[bingo_card == int(l)] = None
        
check_arr = np.isnan(bingo_card)
if check_arr[0].sum() == 3 or check_arr[1].sum() == 3 or check_arr[2].sum() == 3:
    print('Yes')
elif check_arr[:, 0].sum() == 3 or check_arr[:, 1].sum() == 3 or check_arr[:, 2].sum() == 3:
    print('Yes')
elif check_arr[0,0] and check_arr[1,1] and check_arr[2,2]:
    print('Yes')
elif check_arr[0,2] and check_arr[1,1] and check_arr[2,0]:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys

x = [0] * 3
y = [0] * 3
z = [0] * 3
for i in range(3):
    x[i], y[i], z[i] = map(int, input().split())
N = int(input())
S = []
for j in range(N):
    S.append(int(input())) 
for l in range(N):
    for k in range(3):
        if x[k] == S[l]:
            x[k] = 0
        else:
            a = 1
        if y[k] == S[l]:
            y[k] = 0
        else:
            a = 1
        if z[k] == S[l]:
            z[k] = 0
        else:
            a = 1
        
if x[0] == y[0] == z[0] == 0 or  x[1] == y[1] == z[1] == 0 or  x[2] == y[2] == z[2] == 0 or x[0] == x[1] == x[2] == 0 or y[0] == y[1] == y[2] == 0 or z[0] == z[1] == z[2] == 0 or x[0] == y[1] == z[2] == 0 or z[0] == y[1] == x[2] == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a,b,c = [int(x) for x in input().split()]
d,e,f = [int(x) for x in input().split()]
g,h,i = [int(x) for x in input().split()]

n = int(input())
S = {int(input()) for x in range(n)}

def q(x,y,z):
    return x in S and y in S and z in S

print('Yes' if q(a,b,c) or q(d,e,f) or q(g,h,i) or q(a,d,g) or q(b,e,h) or q(c,f,i) or q(a,e,i) or q(g,e,c) else 'No')

Submission status: Accepted

Solution code:
a = []
for i in range(3):
    a.append(input().split(" "))
b = [['101', '102', '103'], ['104', '105', '106'], ['107', '108', '109']]
N = input()
suji = []
for i in range(int(N)):
    suji.append(input())
for k in range(int(N)):
    for i in range(3):
        for s in range(3):
            if suji[k] == a[i][s]:
                b[i][s] = 0

judge = 0

for i in range(3):
    if b[i][0] == b[i][1] == b[i][2]:
        judge = 1
        
    if b[0][i] == b[1][i] == b[2][i]:
        judge = 1

if b[0][0] == b[1][1] == b[2][2]:
    judge = 1

if b[0][2] == b[1][1] == b[2][0]:
    judge = 1

if judge == 1:
    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())
b=[0]*N
for i in range(N):
  b[i]=int(input())
C1=any([i == A1[0] for i in b])
C2=any([i == A1[1] for i in b])
C3=any([i == A1[2] for i in b])
C4=any([i == A2[0] for i in b])
C5=any([i == A2[1] for i in b])
C6=any([i == A2[2] for i in b])
C7=any([i == A3[0] for i in b])
C8=any([i == A3[1] for i in b])
C9=any([i == A3[2] for i in b])

if(any([all([C1,C2,C3]),all([C4,C5,C6]),all([C7,C8,C9]),all([C1,C4,C7]),all([C2,C5,C8]),all([C3,C6,C9]),all([C1,C5,C9]),all([C3,C5,C7])])):
   print("Yes")
else:
   print("No")

Submission status: Accepted

Solution code:
import numpy as np

a1,a2,a3 = map(int,input().split())
a4,a5,a6 = map(int,input().split())
a7,a8,a9 = map(int,input().split())

a = np.array([[a1, a2, a3], [a4, a5, a6], [a7, a8, a9]])

n = int(input())
for i in range(n):
  b = int(input())
  a = np.where(a == b, 0, a)

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

Submission status: Accepted

Solution code:
def check(cor, cc):
    
    for i in range(cc):
        flg = True
        for j in range(cc):
            if cor[i][j] != 1:
                flg = False
                break
        if flg:
            return True

    
    for i in range(cc):
        flg = True
        for j in range(cc):
            if cor[j][i] != 1:
                flg = False
                break
        if flg:
            return True

    flg = True
    for i in range(cc):
        if cor[i][i] != 1:
            flg = False
            break
    if flg:
        return True

    flg = True
    for i in range(cc):
        if cor[i][cc-1-i] != 1:
            flg = False
            break
    if flg:
        return True
    
    return False
    
    

tmp = list(map(int, input().split(' ')))
cc = len(tmp)
box = [[]for _ in range(cc)]
cor = [[0 for _ in range(cc)] for _ in range(cc)]
box[0] = tmp

for i in range(cc-1):
    box[i+1] = list(map(int, input().split(' ')))


N = int(input())
for _ in range(N):
    num = int(input())
    for i in range(cc):
        for j in range(cc):
            if num == box[i][j]:
                cor[i][j] = 1

if check(cor, cc):
    print('Yes')
else:
    print('No')

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 = [int(input()) for _ in range(N)]

for i in range(N):
    if B[i] in A[0]:
        A[0][A[0].index(B[i])] = True
    elif B[i] in A[1]:
        A[1][A[1].index(B[i])] = True
    elif B[i] in A[2]:
        A[2][A[2].index(B[i])] = True

bingo_flag = False
for i in range(3):
    if A[i][0] == A[i][1] == A[i][2] == True:
        bingo_flag = True
    elif A[0][i] == A[1][i] == A[2][i] == True:
        bingo_flag = True

if A[0][0] == A[1][1] == A[2][2] == True:
    bingo_flag = True
if A[0][2] == A[1][1] == A[2][0] == True:
    bingo_flag = True

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

Submission status: Accepted

Solution code:
card = []
for i in range(3):
    num = [int(i) for i in input().split(" ")]
    for n in num:
        card.append(n)
# print(card)
N = int(input())
for i in range(N):
    m = int(input())
    try:
        idx = card.index(m)
    except ValueError:
        continue
    card[idx]=0
# print(card)
flag = 0
for i in [0,3,6]:
    if (card[i]+card[i+1]+card[i+2])==0:
        flag=1
        break
if flag!=1:
    for i in [0,1,2]:
        if (card[i]+card[i+3]+card[i+6])==0:
            flag=1
            break
if flag!=1:
    if (card[0]+card[4]+card[8])==0:
        flag=1
    elif (card[2]+card[4]+card[6])==0:
        flag=1
        
if flag==1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
l=[list(map(int,input().split())) for i in range(3)]
n=int(input())
s=set()
for i in range(n):
    s.add(int(input()))
ans="No"
for i in range(3):
    if l[i][0] in s and l[i][1] in s and l[i][2] in s:
        ans="Yes"
    if l[0][i] in s and l[1][i] in s and l[2][i] in s:
        ans="Yes"
if l[0][0] in s and l[1][1] in s and l[2][2] in s:
        ans="Yes"
if l[0][2] in s and l[1][1] in s and l[2][0] in s:
        ans="Yes"
print(ans)