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:
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)]
tate1=[A1[0],A2[0],A3[0]]
tate2=[A1[1],A2[1],A3[1]]
tate3=[A1[2],A2[2],A3[2]]
naname1=[A1[0],A2[1],A3[2]]
naname2=[A1[2],A2[1],A3[0]]

if A1[0] in b and A1[1] in b and A1[2] in b:
    print('Yes')
    sys.exit()
if A2[0] in b and A2[1] in b and A2[2] in b:
    print('Yes')
    sys.exit()
if A3[0] in b and A3[1] in b and A3[2] in b:
    print('Yes')
    sys.exit()
if tate1[0] in b and tate1[1] in b and tate1[2] in b:
    print('Yes')
    sys.exit()
if tate2[0] in b and tate2[1] in b and tate2[2] in b:
    print('Yes')
    sys.exit()
if tate3[0] in b and tate3[1] in b and tate3[2] in b:
    print('Yes')
    sys.exit()
if naname1[0] in b and naname1[1] in b and naname1[2] in b:
    print('Yes')
    sys.exit()
if naname2[0] in b and naname2[1] in b and naname2[2] in b:
    print('Yes')
    sys.exit()
print('No')

Submission status: Accepted

Solution code:
def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

a = l_in()
b = l_in()
c = l_in()
N = n_in()

s = set()

for _ in range(N):
  s.add(n_in())

def check(L):
  return all(l in s for l in L)

if any(check(L) for L in [
  a,b,c,
  [a[0],b[0],c[0]],
  [a[1],b[1],c[1]],
  [a[2],b[2],c[2]],
  [a[0],b[1],c[2]],
  [a[2],b[1],c[0]],
  ]):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
row1 = list(map(int,input().split()))
row2 = list(map(int,input().split()))
row3 = list(map(int,input().split()))
n = int(input())
arr = []
for i in range(n):
    temp = int(input())
    arr.append(temp)
if row1[0] in arr and row1[1] in arr and row1[2] in arr or row2[0] in arr and row2[1] in arr and row2[2] in arr or row3[0] in arr and row3[1] in arr and row3[2] in arr:
    print("Yes")
    exit()
elif row1[0] in arr and row2[0] in arr and row3[0] in arr or row1[1] in arr and row2[1] in arr and row3[1] in arr or row1[2] in arr and row2[2] in arr and row3[2] in arr:
    print("Yes")
    exit()
elif row1[0] in arr and row2[1] in arr and row3[2] in arr or row1[2] in arr and row2[1] in arr and row3[0] in arr:
    print("Yes")
    exit()
else:
    print("No")

Submission status: Accepted

Solution code:
list_1 = list(map(int,input().split()))
list_2 = list(map(int,input().split()))
list_3 = list(map(int,input().split()))

#n,m = map(int,raw_input().split())
#list_a = []
#for i in range(M) 
list_a=list_1


for x in list_2:
    list_a.append(x)


for x in list_3:
    list_a.append(x)


N = int(input())
#list_b = [int(x) for x in input().split()]
#list_b = list(map(int,input().split()))


list_b=[]
for k in range(N):
    b=int(input())
    list_b.append(b)


list_c = [0,0,0,0,0,0,0,0,0]
for i in range(N):
    for j in range(9):
        if list_a[j] == list_b[i]:
            list_c[j] = 1

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

Submission status: Accepted

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


L_tate = list(zip(*L_yoko))

L_naname = []
L_naname.append([L_yoko[0][0],L_yoko[1][1],L_yoko[2][2]])
L_naname.append([L_yoko[0][2],L_yoko[1][1],L_yoko[2][0]])

n = int(input())
ans = [int(input()) for _ in range(n)]

a = int(0)
for z in L_tate:
    if z[0] in ans and z[1] in ans and z[2] in ans:
         a = 1
         break

for z in L_yoko:
    if z[0] in ans and z[1] in ans and z[2] in ans:
         a = 1
         break

for z in L_naname:
    if z[0] in ans and z[1] in ans and z[2] in ans:
         a = 1
         break


if a == 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline


def main():
	#N,M=map(int,input().split())
	#S=input().rstrip()
	#vA=list(map(int,input().split()))
	vAB=[tuple(map(int,input().split()))
		 for _ in [0,]*3]
	N=int(input())
	vD= [int(input()) for _ in [0,]*N]
	
	vQ = [False,] * 9
	for i in range(3):
		a,b,c = vAB[i]
		vQ[3*i+0] = a in vD
		vQ[3*i+1] = b in vD
		vQ[3*i+2] = c in vD
	
	bi = False
	if any((all(vQ[0:3]), all(vQ[3:6]),
		all(vQ[6:9]), all(vQ[0::3]),
		all(vQ[1::3]), all(vQ[2::3]),
		all((vQ[0],vQ[4],vQ[8])),
		all((vQ[2],vQ[4],vQ[6])),
		)):
		bi = True
	
	res = "Yes" if bi else "No"
	print(res)
	
	
main()

Submission status: Accepted

Solution code:
array = []
for i in range(3):
  alist = list(map(int, input().split()))
  array.append([])
  array[i].append(alist[0])
  array[i].append(alist[1])
  array[i].append(alist[2])
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))
for i in range(n):
  for j in range(3):
    for k in range(3):
      if b[i] == array[j][k]:
        array[j][k] = 0

flg = False
for i in range(3):
  if sum(array[i]) == 0:
    flg = True
for i in range(3):
  if (array[0][i] + array[1][i] + array[2][i]) == 0:
    flg = True
if (array[0][0] + array[1][1] + array[2][2]) == 0:
  flg = True
if (array[2][0] + array[1][1] + array[0][2]) == 0:
  flg = True
  
if flg:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
AL = [list(map(int, input().split())) for i in range(3)]
# print(AL)
N = int(input())
BL = list(int(input()) for i in range(N))
# print(BL)

def func1(lst, value):
    return [i for i, x in enumerate(lst) if x == value]

for k, i in enumerate(AL):
    for n,j in enumerate(i):
        if j in BL:
            AL[k][n]="True"

# print(AL)
ans=False
if AL[0][0]=="True" and AL[1][1]=="True" and AL[2][2]=="True":
    ans=True
if AL[0][2]=="True" and AL[1][1]=="True" and AL[2][0]=="True":
    ans=True
if AL[0][0]=="True" and AL[0][1]=="True" and AL[0][2]=="True":
    ans=True
if AL[1][0]=="True" and AL[1][1]=="True" and AL[1][2]=="True":
    ans=True
if AL[2][0]=="True" and AL[2][1]=="True" and AL[2][2]=="True":
    ans=True
if AL[0][0]=="True" and AL[1][0]=="True" and AL[2][0]=="True":
    ans=True
if AL[0][1]=="True" and AL[1][1]=="True" and AL[2][1]=="True":
    ans=True
if AL[0][2]=="True" and AL[1][2]=="True" and AL[2][2]=="True":
    ans=True

if ans:
    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)]

for b in B:
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        A[i][j] = -100

f = False
for i in range(3):
  s = 0
  for j in range(3):
    s += A[i][j]
  if s == -300:
    f = True
for i in range(3):
  s = 0
  for j in range(3):
    s += A[j][i]
  if s == -300:
    f = True
s = 0
for i in range(3):
  s += A[i][i]
  if s == -300:
    f = True
s = 0
for i in range(3):
  s += A[i][2-i]
  if s == -300:
    f = True
print('Yes' if f else 'No')

Submission status: Accepted

Solution code:
A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]
    
import numpy as np
A = np.array(A)
l = []
for i in range(N):
  if b[i] in A:
    l.append(tuple(nd[0] for nd in np.where(A == b[i])))
if (0, 0) in l and (1, 0) in l and (2, 0) in l:
  print("Yes")
elif (0, 0) in l and (1, 1) in l and (2, 2) in l:
  print("Yes")
elif (0, 1) in l and (1, 1) in l and (2, 1) in l:
  print("Yes")
elif (0, 2) in l and (1, 1) in l and (2, 0) in l:
  print("Yes")
elif (0, 2) in l and (1, 2) in l and (2, 2) in l:
  print("Yes")
elif (0, 0) in l and (0, 1) in l and (0, 2) in l:
  print("Yes")
elif (1, 0) in l and (1, 1) in l and (1, 2) in l:
  print("Yes")
elif (2, 0) in l and (2, 1) in l and (2, 2) in l:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import numpy as np
a = []
for _ in range(3):
    a.append(list(map(int, input().split())))
a = list(np.array(a).flatten())
N = int(input())
index = []
for _ in range(N):
    b_i = int(input())
    if b_i in a:
        index.append(a.index(b_i))
for i in sorted(index):
    if 0 in index and 1 in index and 2 in index:
        print("Yes")
        exit()
    elif 0 in index and 3 in index and 6 in index:
        print("Yes")
        exit()
    elif 0 in index and 4 in index and 8 in index:
        print("Yes")
        exit()
    elif 1 in index and 4 in index and 7 in index:
        print("Yes")
        exit()
    elif 2 in index and 5 in index and 8 in index:
        print("Yes")
        exit()
    elif 2 in index and 4 in index and 6 in index:
        print("Yes")
        exit()
    elif 3 in index and 4 in index and 5 in index:
        print("Yes")
        exit()
    elif 6 in index and 7 in index and 8 in index:
        print("Yes")
        exit()
print("No")

Submission status: Accepted

Solution code:
a1, a2, a3 = input(), input(), input()
a1 = [int(i) for i in a1.split()]
a2 = [int(i) for i in a2.split()]
a3 = [int(i) for i in a3.split()]
A = [a1, a2, a3]
N = int(input())
b = []
for i in range(N):
    b.append(int(input()))
for i in range(len(b)):
    for j in range(len(A)):
        for k in range(len(A[0])):
            if b[i] == A[j][k]:
                A[j][k] = 0
ans = 0
for i in range(3):
    if A[0][i] == 0 and A[1][i] == 0 and A[2][i] == 0:
        ans = 1
    if A[i][0] == 0 and A[i][1] == 0 and A[i][2] == 0:
        ans = 1
if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
    ans = 1
if A[2][0] == 0 and A[1][1] == 0 and A[0][2] == 0:
    ans = 1
if ans == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
input1 = list(map(int, (input().split())))
input2 = list(map(int, (input().split())))
input3 = list(map(int, (input().split())))

a = input1 + input2 + input3

n = int(input())

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

# print(b)
for s in b:
    for i in range(9):
        if a[i] == s:
            a[i] = 0

for i in range(3):
    if(a[i] + a[i+3] + a[i+6] == 0):
        print("Yes")
        exit(0)

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

if(a[0] + a[4] + a[8] == 0):
    print("Yes")
    exit(0)

if(a[2] + a[4] + a[6] == 0):
    print("Yes")
    exit(0)

print("No")

Submission status: Accepted

Solution code:
import sys

f = sys.stdin

l1 = f.readline().rstrip().split(" ")
l2 = f.readline().rstrip().split(" ")
l3 = f.readline().rstrip().split(" ")

mat = l1 + l2 + l3

f.readline()  #skip N
nums = []
for line in f.readlines():
    nums.append(line.rstrip())


#check
def check(kohos, n1, n2, n3):
    kohos = set(kohos)
    if n1 in kohos:
        if n2 in kohos:
            if n3 in kohos:
                #return True
                print("Yes", end="")
                quit()
    return False


#all patterns..
check(nums, mat[0], mat[1], mat[2])
check(nums, mat[3], mat[4], mat[5])
check(nums, mat[6], mat[7], mat[8])

check(nums, mat[0], mat[3], mat[6])
check(nums, mat[1], mat[4], mat[7])
check(nums, mat[2], mat[5], mat[8])

check(nums, mat[0], mat[4], mat[8])
check(nums, mat[2], mat[4], mat[6])
print("No", end="")

Submission status: Accepted

Solution code:
bingo = []
for i in range(3):
  row = [int(j) for j in input().split()]
  bingo.append(row)
ans = "No"
n = int(input())
for i in range(n):
  lot = int(input())
  for j in range(len(bingo)):
    for k in range(len(bingo[j])):
      if bingo[j][k] == lot:
      	bingo[j][k] = -1
    if sum(bingo[j]) == -3:
  	  ans = "Yes"
if (bingo[0][0] + bingo[1][1] + bingo[2][2]) == -3:
  ans = "Yes"
if (bingo[0][2] + bingo[1][1] + bingo[2][0]) == -3:
  ans = "Yes"
if (bingo[0][0] + bingo[1][0] + bingo[2][0]) == -3:
  ans = "Yes"
if (bingo[0][1] + bingo[1][1] + bingo[2][1]) == -3:
  ans = "Yes"
if (bingo[0][2] + bingo[1][2] + bingo[2][2]) == -3:
  ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
import sys
a = [ list(map(int,input().split(" "))) for i in range(3)]
N=int(input())
c=0
for i in range(N):
  b=int(input())
  for j in range(3):
    
    for z in range(3):
      if a[j][z]-b==0:
        
        a[j][z]=0

if a[0][0]+a[1][1]+a[2][2]==0 or a[2][0]+a[1][1]+a[0][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][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:
A=[[0,0,0] for i in range(0,3)]
for i in range(0,3):
  A[i]=list(map(int,input().split()))
N=int(input())
b=[0 for i in range(0,N)]
for i in range(0,N):
  b[i]=int(input())
 
bingo=[[0,0,0] for i in range(0,3)]
for i in range(0,3):
  for j in range(0,3):
    if A[i][j] in b:
      bingo[i][j]=1

flag=0
for i in range(0,3):
  if bingo[i][0]*bingo[i][1]*bingo[i][2]==1:
    flag=1
for i in range(0,3):
  if bingo[0][i]*bingo[1][i]*bingo[2][i]==1:
    flag=1
if bingo[0][0]*bingo[1][1]*bingo[2][2]==1:
  flag=1
if bingo[0][2]*bingo[1][1]*bingo[2][0]==1:
  flag=1

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

Submission status: Accepted

Solution code:
a=[list(map(int,input().split())) for _ in range(3)]
n=int(input())
b=list(set([int(input()) for _ in range(n)]))
l=[]
for i in range(len(b)):
  for j in range(3):
    for k in range(3):
      if b[i]==a[j][k]:
        l.append([j+1,k+1])
if len(l)>=7:
  print('Yes')
elif len(l)<=2:
  print('No')
else:
  if l.count([1,1])==l.count([2,2])==l.count([3,3])==1 or l.count([1,3])==l.count([2,2])==l.count([3,1])==1:
    print('Yes')
  else:
    count1,count2=1,1
    l=sorted(l, key=lambda x: (x[0]))
    ll=sorted(l, key=lambda x: (x[1]))
    for i in range(len(l)-1):
      if l[i][0]==l[i+1][0]:
        count1+=1
      elif count1!=3:
        count1=1
      if ll[i][1]==ll[i+1][1]:
        count2+=1
      elif count2!=3:
        count2=1
    if count1==3 or count2==3:
      print('Yes')
    else:
      print('No')

Submission status: Accepted

Solution code:
a0=list(map(int, input().split()))
a1=list(map(int, input().split()))
a2=list(map(int, input().split()))
n=int(input())
b=[]
for i in range(n):
    b.append(int(input()))
ans=[]
for i in b:
    if (i in a0) == True:
        ans.append(a0.index(i))
    if (i in a1) == True:
        ans.append((a1.index(i))+3)
    if (i in a2) == True:
        ans.append((a2.index(i))+6)
if (0 in ans) and (1 in ans) and (2 in ans) == True:
    print("Yes")
elif (0 in ans) and (3 in ans) and (6 in ans) == True:
    print("Yes")
elif (0 in ans) and (4 in ans) and (8 in ans) == True:
    print("Yes")
elif (1 in ans) and (4 in ans) and (7 in ans) == True:
    print("Yes")
elif (2 in ans) and (5 in ans) and (8 in ans) == True:
    print("Yes")
elif (2 in ans) and (4 in ans) and (6 in ans) == True:
    print("Yes")
elif (3 in ans) and (4 in ans) and (5 in ans) == True:
    print("Yes")
elif (6 in ans) and (7 in ans) and (8 in ans) == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np
bingo = []
for _ in range(3):
    l=list(map(int, input().split()))
    bingo.extend(l)

N = int(input())
indices=[]

for _ in range(N):
    num = int(input())
    if num in bingo:
        indices.append(bingo.index(num))

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]]
ans='No'
for candidate in candidates:
    if len(list(set(indices)&set(candidate))) == 3:
        ans='Yes'
        break
print(ans)

Submission status: Accepted

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

for h in range(3):
    for w in range(3):
        for i in range(N):
            if b[i] == A[h][w]:
                A[h][w] = 0
if [0,0,0] in A:
    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:
    ans = 'No'
    for i in zip(*A):
        if i == (0,0,0):
            ans = 'Yes'
            break
    print(ans)

Submission status: Accepted

Solution code:
l = [list(map(int,input().split())) for _ in range(3)]
lb = [[0 for j in range(3)] for i in range(3)]
bl = []
cnt = 0
f = 0

# print(l)
# print(lb)

n = int(input())

for i in range(n):
    bl.append(int(input()))

bll = list(dict.fromkeys(bl))
# print(bll)

for i in bll:
    for j in range(3):
        for k in range(3):
            if l[j][k] == int(i):
                # print('hit')
                lb[j][k] = 1
                break

# print(lb)

for i in range(3):
    for j in range(3):
        if lb[i][j] == 1:
            cnt += 1
        else:
            cnt = 0
            break
    else:
        if cnt == 3:
            f = 1
            break
        else:
            cnt = 0

cnt = 0

for i in range(3):
    for j in range(3):
        if lb[j][i] == 1:
            cnt += 1
        else:
            cnt = 0
            break
    else:
        if cnt == 3:
            f = 1
            break
        else:
            cnt = 0

if lb[0][0] == 1 and lb[1][1] == 1 and lb[2][2] == 1:
    f = 1
elif lb[0][2] == 1 and lb[1][1] == 1 and lb[2][0] == 1:
    f = 1

if f:
    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()]
# print(A1)
# print(A2)
# print(A3)

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

for b in B:
    if b in A1:
        A1[A1.index(b)] = 0
    if b in A2:
        A2[A2.index(b)] = 0
    if b in A3:
        A3[A3.index(b)] = 0

if sum(A1) * sum (A2) * sum(A3) * (A1[0]+A2[0]+A3[0]) * (A1[1]+A2[1]+A3[1]) * (A1[2]+A2[2]+A3[2]) * (A1[0]+A2[1]+A3[2]) * (A1[2]+A2[1]+A3[0]) == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import itertools
import sys

[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())
num_list = []
for j in range(N):
  n = int(input())
  num_list.append(n)

set_list = [{a,b,c},{d,e,f},{g,h,i},{a,d,g},{b,e,h},{c,f,i},{a,e,i},{c,e,g}]
the_set = set(num_list) & set([a,b,c,d,e,f,g,h,i])

v = itertools.permutations(the_set,3)
for k in v:
  if set(k) in set_list:
    print('Yes')
    sys.exit()
print('No')

Submission status: Accepted

Solution code:
s=[list(map(int,input().split())) for i in range(3)]
t=int(input())
u=[int(input()) for i in range(t)]
for i in range(t):
  for j in range(3):
    for k in range(3):
      if s[j][k]==u[i]:
        s[j][k]=0
b=0
if s[0][0]==0 and s[1][0]==0 and s[2][0]==0:
  b=1
elif s[0][1]==0 and s[1][1]==0 and s[2][1]==0:
  b=1
elif s[0][2]==0 and s[1][2]==0 and s[2][2]==0:
  b=1
elif s[0][0]==0 and s[0][1]==0 and s[0][2]==0:
  b=1
elif s[1][0]==0 and s[1][1]==0 and s[1][2]==0:
  b=1
elif s[2][0]==0 and s[2][1]==0 and s[2][2]==0:
  b=1
elif s[0][0]==0 and s[1][1]==0 and s[2][2]==0:
  b=1
elif s[0][2]==0 and s[1][1]==0 and s[2][0]==0:
  b=1
if b==1:
  print('Yes')
else:
  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 _ in range(N):
    B.append(int(input()))

# まず横の列を検索する
bingo=False
for i in range(3):
    for j in range(3):
        if not A[i][j] in B:
            break
        if j == 2:
            bingo=True

# 次に縦の列を検索する
for i in range(3):
    for j in range(3):
        if not A[j][i] in B:
            break
        if j == 2:
            bingo=True

# 最後に斜め
for i in range(3):
    if not A[i][i] in B:
        break
    if i == 2:
        bingo = True

for i in range(3):
    if not A[2-i][i] in B:
        break
    if i == 2:
        bingo = True

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

Submission status: Accepted

Solution code:
A = []

for i in range(3):
  A00 = input().rstrip().split(' ')
  A0 = int(A00[0])
  A1 = int(A00[1])
  A2 = int(A00[2])
  A.append([A0, A1, A2])

N = int(input())
b = []

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

#flag_a = [[0, 0, 0],["","",""],["","",""]]
flag_A = [[0,0,0],[0,0,0],[0,0,0]]

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

if flag_A[0][0] == 1 and flag_A[0][1] == 1 and flag_A[0][2] == 1:
  print("Yes")
elif flag_A[1][0] == 1 and flag_A[1][1] == 1 and flag_A[1][2] == 1:
  print("Yes")
elif flag_A[2][0] == 1 and flag_A[2][1] == 1 and flag_A[2][2] == 1:
  print("Yes")
elif flag_A[0][0] == 1 and flag_A[1][0] == 1 and flag_A[2][0] == 1:
  print("Yes")
elif flag_A[0][1] == 1 and flag_A[1][1] == 1 and flag_A[2][1] == 1:
  print("Yes")
elif flag_A[0][2] == 1 and flag_A[1][2] == 1 and flag_A[2][2] == 1:
  print("Yes")
elif flag_A[0][0] == 1 and flag_A[1][1] == 1 and flag_A[2][2] == 1:
  print("Yes")
elif flag_A[0][2] == 1 and flag_A[1][1] == 1 and flag_A[2][0] == 1:
  print("Yes")
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()))
x=[[0 for i in range(3)] for j in range(3)]
N=int(input())
if N>=3:
  for i in range(N):
    b=int(input())
    for j in range(3):
      if A[j]==b:
        x[0][j]=1
      elif B[j]==b:
        x[1][j]=1
      elif C[j]==b:
        x[2][j]=1
  flag=0
  if x[0][0]==1:
    if x[0][1]==1 and x[0][2]==1:
      flag=1
    if x[1][0]==1 and x[2][0]==1:
      flag=1
    if x[1][1]==1 and x[2][2]==1:
      flag=1
  if x[1][1]==1:
    if x[0][1]==1 and x[2][1]==1:
      flag=1
    if x[1][0]==1 and x[1][2]==1:
      flag=1
    if x[0][2]==1 and x[2][0]==1:
      flag=1
  if x[2][2]==1:
    if x[2][0]==1 and x[2][1]==1:
      flag=1
    if x[0][2]==1 and x[1][2]==1:
      flag=1
  if flag==1:
    print("Yes")
  else:
    print("No")
  #print(x)
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 = {int(input()) for _ in range(N)}
A = a1+a2+a3
ijk = [ [0,1,2], [3,4,5], [6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]


end = False
for i,j,k in ijk:
    if {A[i], A[j], A[k]} <= B:
        print('Yes')
        end = True
        break
    else:
        continue
if not end:        
    print('No')

Submission status: Accepted

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

N=int(input())
for i in range(N):
    b=int(input()) 
    for i in range(3):
        for j in range(3):
            if  A[i][j]==b:
                B[i][j]=1    

for i in range(3):
    count=0
    for j in range(3):
        if  B[i][j]==1:
            count+=1
    if count==3:
        print('Yes')
        exit()
            
            
for j in range(3):
    count=0
    for i in range(3):
        if B[i][j]==1:
            count+=1
        if count==3:
            print('Yes')
            exit()

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

Submission status: Accepted

Solution code:
import sys
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for i in range(N)]
for i in range(3):
    # for j in range(3):
    if A[i][0] in B and A[i][1] in B and A[i][2] in B:
        print("Yes")
        sys.exit()
    elif A[0][i] in B and A[1][i] in B and A[2][i] in B:
        print("Yes")
        sys.exit()
    elif A[0][0] in B and A[1][1] in B and A[2][2] in B:
        print("Yes")
        sys.exit()
    elif A[0][2] in B and A[1][1] in B and A[2][0] in B:
        print("Yes")
        sys.exit()
print("No")

Submission status: Accepted

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    res = 'No'

    C = [[0 for i in range(3)] for j in range(3)]

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

    for i in range(3):
        if C[i] == [1,1,1]:
            res = 'Yes'

    for i in range(3):
        temp = []
        for j in range(3):
            if C[j][i] == 1:
                temp.append(1)
            else:
                temp.append(0)
        # temp = [C[0][i],C[1][i],C[2][i]]
        if temp == [1,1,1]:
            res = 'Yes'
            break

    temp1 = [C[0][0],C[1][1],C[2][2]]
    temp2 = [C[0][2],C[1][1],C[2][0]]

    if temp1 == [1,1,1]:
        res = 'Yes'
    if temp2 == [1,1,1]:
        res = 'Yes'

    print(res)



main()

Submission status: Accepted

Solution code:
import sys
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()))
#print(b)
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            a[i][j] = 0
#print(a)

for i in range(3):
    if sum(a[i])==0:
        print('Yes')
        exit()
for i in range(3):
    if a[0][i]+a[1][i]+a[2][i]==0:
        print('Yes')
        exit()
if (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:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    a = LIR(3)
    n = II()
    c = [0] * 9
    for i in range(n):
        b = II()
        for i in range(3):
            for j in range(3):
                c[i * 3 + j] |= a[i][j] == b
    ans = (c[0] & c[1] & c[2]) | (c[3] & c[4] & c[5]) | (c[6] & c[7] & c[8])
    for i in range(3):
        ans |= c[i] & c[3 + i] & c[6 + i]
    ans |= c[0] & c[4] & c[8]
    ans |= c[2] & c[4] & c[6]
    print("Yes" if ans else "No")
    return



#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
a11,a12,a13 = input().split()
a21,a22,a23 = input().split()
a31,a32,a33 = input().split()
lst = [a11,a12,a13,a21,a22,a23,a31,a32,a33]
bingo = []
n = int(input())
for i in range(n):
    ai = input()
    if ai in lst:
        bingo.append(lst.index(ai))
if 4 in bingo:
    if 0 in bingo:
        if 8 in bingo:
            print('Yes')
            exit()
    if 1 in bingo:
        if 7 in bingo:
            print('Yes')
            exit()
    if 2 in bingo:
        if 6 in bingo:
            print('Yes')
            exit()
    if 3 in bingo:
        if 5 in bingo:
            print('Yes')
            exit()
if 0 in bingo:
    if 1 in bingo:
        if 2 in bingo:
            print('Yes')
            exit()
    if 3 in bingo:
        if 6 in bingo: 
            print('Yes')
            exit()
if 8 in bingo:
    if 2 in bingo:
        if 5 in bingo:
            print('Yes')
            exit()
    if 6 in bingo:
        if 7 in bingo:           
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
import itertools

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

a = list(itertools.chain.from_iterable(a))

def return_index(l, x, default=-1):
    if x in l:
        return l.index(x)
    else:
        return default

def check_bingo(a):
    if a[0] + a[1] + a[2] == 0:
        return True
    if a[3] + a[4] + a[5] == 0:
        return True
    if a[6] + a[7] + a[8] == 0:
        return True
    if a[0] + a[3] + a[6] == 0:
        return True
    if a[1] + a[4] + a[7] == 0:
        return True
    if a[2] + a[5] + a[8] == 0:
        return True
    if a[0] + a[4] + a[8] == 0:
        return True
    if a[2] + a[4] + a[6] == 0:
        return True
    return False

for i in b:
    if return_index(a, i) >= 0:
        a[return_index(a, i)] = 0

print("Yes") if check_bingo(a) else print("No")

Submission status: Accepted

Solution code:
l=[list(map(int,input().split())) for i in range(3)]
N=int(input())
b=[int(input()) for i in range(N)]
if b.count(l[0][0])>0 and b.count(l[0][1])>0 and b.count(l[0][2])>0:
    print("Yes")
    exit()
if b.count(l[1][0])>0 and b.count(l[1][1])>0 and b.count(l[1][2])>0:
    print("Yes")
    exit()
if b.count(l[2][0])>0 and b.count(l[2][1])>0 and b.count(l[2][2])>0:
    print("Yes")
    exit()
if b.count(l[0][0])>0 and b.count(l[1][0])>0 and b.count(l[2][0])>0:
    print("Yes")
    exit()
if b.count(l[0][1])>0 and b.count(l[1][1])>0 and b.count(l[2][1])>0:
    print("Yes")
    exit()
if b.count(l[0][2])>0 and b.count(l[1][2])>0 and b.count(l[2][2])>0:
    print("Yes")
    exit()
if b.count(l[0][0])>0 and b.count(l[1][1])>0 and b.count(l[2][2])>0:
    print("Yes")
    exit()
if b.count(l[0][2])>0 and b.count(l[1][1])>0 and b.count(l[2][0])>0:
    print("Yes")
    exit()
else:
    print("No")