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())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

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

check = False
r0 = [r[0] for r in a]
r1 = [r[1] for r in a]
r2 = [r[2] for r in a]
if a[0].count(0) == 3 or a[1].count(0) == 3 or a[2].count(0) == 3:
    check = True
elif r0.count(0) == 3 or r1.count(0) == 3 or r2.count(0) == 3:
    check = True
elif (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):
    check = True

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

Submission status: Accepted

Solution code:
card = [[],[],[]]

isBingo = False

for n in range(3):
    rawInput = input().split()
    for m in rawInput:
        card[n].append(int(m))

N = int(input())

shirushi = []

for n in range(N):
    shirushi.append(int(input()))

markedhairetu = [[False,False,False],[False,False,False],[False,False,False]]

for p in range(3):
    for q in range(3):
        for r in range(N):
            if shirushi[r] == card[p][q]:
                markedhairetu[p][q] = True

for n in range(3):
    if markedhairetu[n].count(True) == 3:
        isBingo = True

for n in range(3):
        if markedhairetu[0][n] == True and markedhairetu[1][n] == True and markedhairetu[2][n] == True:
            isBingo = True

if markedhairetu[0][0] == True and markedhairetu[1][1] == True and markedhairetu[2][2] == True:
    isBingo = True

if markedhairetu[2][0] == True and markedhairetu[1][1] == True and markedhairetu[0][2] == True:
    isBingo = True

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

Submission status: Accepted

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

def judge(a):
    if a[0][0] == 0 and a[0][1] == 0 and a[0][2] == 0:
        return True
    elif a[1][0] == 0 and a[1][1] == 0 and a[1][2] == 0:
        return True
    elif a[2][0] == 0 and a[2][1] == 0 and a[2][2] == 0:
        return True
    elif a[0][0] == 0 and a[1][0] == 0 and a[2][0] == 0:
        return True
    elif a[0][1] == 0 and a[1][1] == 0 and a[2][1] == 0:
        return True
    elif a[0][2] == 0 and a[1][2] == 0 and a[2][2] == 0:
        return True
    elif a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
        return True
    elif a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0:
        return True
    return False
    

for i in range(n):
    num = int(input())
    for x in range(3):
        for y in range(3):
            if a[x][y] == num:
                a[x][y] = 0

if judge(a):
    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()))
n=int(input())
l = [list(map(int, input().split())) for _ in range(n)]
import numpy as np
y=np.zeros(9).reshape(3,3)
for i in range(n):
    for x in range(3):
        if a[x]==l[i][0]:
            y[0][x]=1
for i in range(n):
    for x in range(3):
        if b[x]==l[i][0]:
            y[1][x]=1
for i in range(n):
    for x in range(3):
        if c[x]==l[i][0]:
            y[2][x]=1
if sum(y[0])==3:
    print('Yes')
elif sum(y[1])==3:
    print('Yes')
elif sum(y[2])==3:
    print('Yes')
elif sum(y[1])==3:
    print('Yes')
elif y[0][0]+y[1][0]+y[2][0]==3:
    print('Yes')
elif y[0][1]+y[1][1]+y[2][1]==3:
    print('Yes')
elif y[0][2]+y[1][2]+y[2][2]==3:
    print('Yes')
elif y[0][0]+y[1][1]+y[2][2]==3:
    print('Yes')
elif y[0][2]+y[1][1]+y[2][0]==3:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
ok=True
a1=[int(x) for x in input().split()]
a2=[int(x) for x in input().split()]
a3=[int(x) for x in input().split()]
b1=[a1[0]]+[a2[0]]+[a3[0]]
b2=[a1[1]]+[a2[1]]+[a3[1]]
b3=[a1[2]]+[a2[2]]+[a3[2]]
c1=[a1[0]]+[a2[1]]+[a3[2]]
c2=[a1[2]]+[a2[1]]+[a3[0]]
alle=[a1,a2,a3,b1,b2,b3,c1,c2]
val=int(input())
d=[]
for i in range(val):
    d=int(input())
    for i1 in alle:
        if d in i1:
            i1.remove(d)
for i in alle:
    if i==[]:
        print("Yes")
        ok=False
        break
if ok:
    print("No")

Submission status: Accepted

Solution code:
import sys

def main():
    a=[]
    b=[]
    c=[]
    for i in range(3):
        tmp = input().replace('\n','').split(' ')
        tmp = list(map(int, tmp))
        a.append([tmp[0],False])
        a.append([tmp[1],False])
        a.append([tmp[2],False])
        c.append(tmp[0])
        c.append(tmp[1])
        c.append(tmp[2])
    n = int(input().replace('\n',''))
    for i in range(n):
        try:
            tmp = c.index(int(input().replace('\n','')))
            a[tmp][1] = True
        except ValueError:
            pass
    for i in range(3):
        if a[i][1] and a[i+3][1] and a[i+6][1]:
            res = 'Yes'
            break
        elif a[i*3][1] and a[i*3+1][1] and a[i*3+2][1]:
            res = 'Yes'
            break
        elif a[0][1] and a[4][1] and a[8][1] or a[2][1] and a[4][1] and a[6][1]:
            res = 'Yes'
            break
        else:
            res = 'No'
    print(res)
if __name__ == '__main__':
    input = sys.stdin.readline
    main()

Submission status: Accepted

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

N = int(input())
for _ in range(N):
    is_matched = False
    b = int(input())
    for row in range(3):
        for col in range(3):
            if A[row][col] == b:
                is_matched = True
                A[row][col] = True
                if A[row][0] == True and A[row][1] == True and A[row][2] == True:
                    print('Yes')
                    exit()
                elif A[0][col] == True and A[1][col] == True and A[2][col] == True:
                    print('Yes')
                    exit()
                elif A[0][0] == True and A[1][1] == True and A[2][2] == True:
                    print('Yes')
                    exit()
                elif A[0][2] == True and A[1][1] == True and A[2][0] == True:
                    print('Yes')
                    exit()
                break
        if is_matched:
            break
print('No')

Submission status: Accepted

Solution code:
import sys
ans = [
    {0, 1, 2},
    {3, 4, 5},
    {6, 7, 8},
    {0, 4, 8},
    {2, 4, 6},
    {0, 3, 6},
    {1, 4, 7},
    {2, 5, 8}
]

input_list = []
for i in range(3):
    input_list += input().split(" ")

n = int(input())
call = set()
for i in range(n):
    call_num = input()
    if call_num in input_list:
        call.add(input_list.index(call_num))
        for j in ans:
            if len(call & j) == 3:
                print("Yes")
                sys.exit()
print("No")

Submission status: Accepted

Solution code:
bingo_card = [list(map(int,input().split())) for _ in range(3)] 
bingo_card_series = bingo_card[0] + bingo_card[1] + bingo_card[2]
n = int(input())
nums = [int(input()) for _ in range(n)]

for i,x in enumerate(bingo_card_series):
    if x in nums:
        bingo_card_series[i] = -1

if bingo_card_series[0] == bingo_card_series[1] == bingo_card_series[2]:
    print("Yes")
elif bingo_card_series[3] == bingo_card_series[4] == bingo_card_series[5]:
    print("Yes")
elif bingo_card_series[6] == bingo_card_series[7] == bingo_card_series[8]:
    print("Yes")
elif bingo_card_series[0] == bingo_card_series[3] == bingo_card_series[6]:
    print("Yes")
elif bingo_card_series[1] == bingo_card_series[4] == bingo_card_series[7]:
    print("Yes")
elif bingo_card_series[2] == bingo_card_series[5] == bingo_card_series[8]:
    print("Yes")
elif bingo_card_series[0] == bingo_card_series[4] == bingo_card_series[8]:
    print("Yes")
elif bingo_card_series[2] == bingo_card_series[4] == bingo_card_series[6]:
    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 i in range(N):
    b.append(int(input()))
x = False
for i in range(3):
    count = 0
    for j in range(3):
        for k in range(N):
            if A[i][j] == b[k]:
                count += 1
    if count == 3:
        x = True
        break
if not x:
    for i in range(3):
        count = 0
        for j in range(3):
            for k in range(N):
                if A[j][i] == b[k]:
                    count += 1
        if count == 3:
            x = True
            break
if not x:
    count = 0
    for i in range(3):
        for k in range(N):

            if A[i][i] == b[k]:
                count += 1
    if count == 3:
        x = True
if not x:
    count = 0
    for i in range(3):
        for k in range(N):
            if A[2-i][i] == b[k]:
                count += 1
    if count == 3:
        x = True

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

Submission status: Accepted

Solution code:
A11,A12,A13=list(map(lambda i:int(i),input().split()))
A21,A22,A23=list(map(lambda i:int(i),input().split()))
A31,A32,A33=list(map(lambda i:int(i),input().split()))

N=int(input())

bingo=False
b=[]
for i in range(N):
    b.append(int(input()))

if A11 in b and A12 in b and A13 in b:
    bingo =True
elif A21 in b and A22 in b and A23 in b:
    bingo =True
elif A31 in b and A32 in b and A33 in b:
    bingo =True
elif A11 in b and A21 in b and A31 in b:
    bingo =True
elif A12 in b and A22 in b and A32 in b:
    bingo =True
elif A13 in b and A23 in b and A33 in b:
    bingo =True
elif A11 in b and A22 in b and A33 in b:
    bingo =True
elif A13 in b and A22 in b and A31 in b:
    bingo =True

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

Submission status: Accepted

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

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

for i in range(3):
  if x[i][0]+x[i][1]+x[i][2]==3:
    ans='Yes'


if x[0][0]+x[1][1]+x[2][2]==3:
  ans='Yes'
elif x[2][0]+x[1][1]+x[0][2]==3:
  ans='Yes'

print(ans)

Submission status: Accepted

Solution code:
aa=list(map(int, input().split()))
ab=list(map(int, input().split()))
ac=list(map(int, input().split()))
n=int(input())
b=[int(input()) for i in range (n)]
aaa=0
aab=0
aac=0
aba=0
abb=0
abc=0
aca=0
acb=0
acc=0
for i in range (n):
    if aa[0]==b[i]:
        aaa=aaa+1
    elif aa[1]==b[i]:
        aab=aab+1
    elif aa[2]==b[i]:
        aac=aac+1
    elif ab[0]==b[i]:
        aba=aba+1
    elif ab[1]==b[i]:
        abb=abb+1
    elif ab[2]==b[i]:
        abc=abc+1
    elif ac[0]==b[i]:
        aca=aca+1
    elif ac[1]==b[i]:
        acb=acb+1
    elif ac[2]==b[i]:
        acc=acc+1
ha=aaa*aab*aac
hb=aba*abb*abc
hc=aca*acb*acc
va=aaa*aba*aca
vb=aab*abb*acb
vc=aac*abc*acc
ca=aaa*abb*acc
cb=aac*abb*aca
if ha+hb+hc+va+vb+vc+ca+cb==0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
num = []
for i in range(3):
  num.append(list(map(int,input().split())))
  
ans = []
  
for i in range(3):
  temp = []
  for j in range(3):
    temp.append(num[j][i])
  ans.append(temp)
  ans.append(num[i])

for i in range(1):
  temp = []
  for j in range(3):
    temp.append(num[j][j])
  ans.append(temp)
  
for i in range(1):
  temp = []
  temp.append(num[0][2])
  temp.append(num[1][1])
  temp.append(num[2][0])
  ans.append(temp)
N = int(input())
for i in range(N):
  X = int(input())
  for j in range(8):
    if X in ans[j]:
      ans[j].remove(X)

f = True
for i in range(8):
  if len(ans[i]) == 0:
    print('Yes')
    f = False
    break
if f:
  print('No')

Submission status: Accepted

Solution code:
def Main(A, N, B):
    BINGO = (
        (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_ind = []
    for e in B:
        if e in A:
            ans_ind.append(A.index(e))
    if len(ans_ind) <= 2:
        return "No"
    else:
        for b in BINGO:
            counter = 0
            for c in b:
                if c in ans_ind:
                    counter += 1
                if counter == 3:
                    return "Yes"
    return "No"
                    
                

def main():
    A = []
    for i in range(3):
        A += list(map(int, input().split()))
    N = int(input())
    B = []
    for i in range(N):
        B.append(int(input()))
    print(Main(A, N, B))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A = []
hole = []
for i in range(3):
    A.append(list(input().split()))
    hole.append(["","",""])
# print(A)
# print(hole)
N = int(input())
B = []
for j in range(N):
    B.append(input())

for m in range(3):
    for n in range(3):
#         print(A[m][n])
        if str(A[m][n]) in B:
#             print("match")
            hole[m][n] = "#"
# print(hole)
ans = "No"

if hole[0][0] == "#" and hole[1][1] == "#" and hole[2][2]== "#":
    ans = "Yes"
elif hole[0][0] == "#" and hole[0][1] == "#" and hole[0][2]== "#":
    ans = "Yes"
elif hole[1][0] == "#" and hole[1][1] == "#" and hole[1][2]== "#":
    ans = "Yes"
elif hole[2][0] == "#" and hole[2][1] == "#" and hole[2][2]== "#":
    ans = "Yes"
elif hole[0][0] == "#" and hole[1][0] == "#" and hole[2][0]== "#":
    ans = "Yes"
elif hole[0][1] == "#" and hole[1][1] == "#" and hole[2][1]== "#":
    ans = "Yes"
elif hole[0][2] == "#" and hole[1][2] == "#" and hole[2][2]== "#":
    ans = "Yes"
elif hole[0][2] == "#" and hole[1][1] == "#" and hole[2][0]== "#":
    ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
 
def main():
 
    A = np.zeros([3,3])
    for i in range(3):
        A[i] = list(map(int, input().split()))
 
    B = np.zeros([3,3])
 
    N = int(input())
    for i in range(N):
        b = int(input())
        B[A == b] = 1
 
 
    for i in range(3):
        if B[i,:].sum() == 3:
            print('Yes')
            return
        if B[:, i].sum() == 3:
            print('Yes')
            return
    
    if B[0,0] == B[1,1] == B[2,2] == 1:
        print('Yes')
        return
 
    if B[2,0] == B[1,1] == B[0,2] == 1:
        print('Yes')
        return
 
    print('No')
    return
 
main()

Submission status: Accepted

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

#print(bingo)
#print(number)
check=[0,0,0,0,0,0,0,0,0]
ans=0
for i in range(N):
    for j in range(3):
        for k in range(3):
            if number[i][0]==bingo[j][k]:
                check[3*j+k]=1
                
                
                
for i in range(3):
    if check[0+3*i]==check[1+3*i]==check[2+3*i]==1:
        ans=1
    if check[i]==check[i+3]==check[i+6]==1:
        ans=1
        
if check[0]==check[4]==check[8]==1:
    ans=1
if check[2]==check[4]==check[6]==1: 
    ans=1
    
if ans==1:
    print("Yes")
else:
    print("No")
    
#print(check)

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
bingo = [[False, False, False] for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                bingo[i][j] = True

# print('A', A, N, b, bingo)

for i in range(3):
    if sum(bingo[i]) == 3:
        print('Yes')
        exit()
for i in range(3):
    tmp = [bingo[0][i], bingo[1][i], bingo[2][i]]
    # print('tmp', tmp, sum(tmp))
    if sum(tmp) == 3:
        print('Yes')
        exit()

tmp = [bingo[0][0], bingo[1][1], bingo[2][2]]
# print('tmp', tmp, sum(tmp))
if sum(tmp) == 3:
    print('Yes')
    exit()

tmp = [bingo[0][2], bingo[1][1], bingo[2][0]]
if sum(tmp) == 3:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

Solution code:
import numpy as np

a1 = list(map(int, input().split(' ')))
a2 = list(map(int, input().split(' ')))
a3 = list(map(int, input().split(' ')))
n = int(input())

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

arr = np.array([a1, a2, a3])
mask = np.zeros_like(arr)

for num in nums:
    idx = np.where(arr == num)

    if len(idx[0]) == 0:
        pass
    else:
        mask[idx] = 1

s_v = np.sum(mask, axis=0)
s_h = np.sum(mask, axis=1)
s_diag_1 = mask[0, 0] + mask[1, 1] + mask[2, 2]
s_diag_2 = mask[0, 2] + mask[1, 1] + mask[2, 0] 
s = np.maximum(np.concatenate([s_v, s_h, [s_diag_1], [s_diag_2]]) - 2, 0)

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

Submission status: Accepted

Solution code:
import numpy as np

A = [[0] * 3 for i in range(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())

if ((A[0][0] in b) & (A[0][1] in b) & (A[0][2] in b)):
    print('Yes')
elif ((A[1][0] in b) & (A[1][1] in b) & (A[1][2] in b)):
    print('Yes')
elif ((A[2][0] in b) & (A[2][1] in b) & (A[2][2] in b)):
    print('Yes')
elif ((A[0][0] in b) & (A[1][0] in b) & (A[2][0] in b)):
    print('Yes')
elif ((A[0][1] in b) & (A[1][1] in b) & (A[2][1] in b)):
    print('Yes')
elif ((A[0][2] in b) & (A[1][2] in b) & (A[2][2] in b)):
    print('Yes')
elif ((A[0][0] in b) & (A[1][1] in b) & (A[2][2] in b)):
    print('Yes')
elif ((A[0][2] in b) & (A[1][1] in b) & (A[2][0] in b)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# ABC157 B

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())
    for j in range(len(A)):
        if b in A[j]:
            A[j][A[j].index(b)] = "-"

v0Count = 0
v1Count = 0
v2Count = 0
res = "No"

# 横ビンゴ確認
for k in range(len(A)):
    if A[k].count("-") == 3:
        res = "Yes"
        break
    if A[k][0] == "-":
        v0Count += 1
    if A[k][1] == "-":
        v1Count += 1
    if A[k][2] == "-":
        v2Count +=1

# 縦ビンゴ確認
if res == "No":
    if 3 in [v0Count, v1Count, v2Count]:
        res = "Yes"
    
    # 斜めビンゴ確認
    if (A[0][0] == "-" and A[1][1] == "-" and A[2][2] == "-") or (A[0][2] == "-" and A[1][1] == "-" and A[2][0] == "-"):
        res = "Yes"

print(res)

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 i in range(n)]

a = a1+a2+a3
for i in b:
    if i in a:
        a[a.index(i)] = True

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

Submission status: Accepted

Solution code:
import numpy as np	
import sys
stdin = open(0)
K1 = (stdin.readline()).split()
K2 = (stdin.readline()).split()
K3 = (stdin.readline()).split()
KKK = np.array([K1,K2,K3], dtype='int')
N = np.array((stdin.readline()).split(),dtype='int')
K = np.array(stdin.readlines())
for i in range(len(K)):
  K[i] = K[i].replace('\n','')
K = np.array(K, dtype='int')

AAA = np.zeros((3,3),dtype='int')
for i in range(3):
  for j in range(3):
    for k in K:
      if KKK[i,j] == k:
        AAA[i,j] = 1
for i in range(3):
  if np.sum(AAA[i,:]) == 3:
    print('Yes')
    sys.exit()
  if np.sum(AAA[:,i]) == 3:
    print('Yes')
    sys.exit()
if (AAA[0,0]+AAA[1,1]+AAA[2,2])==3:
    print('Yes')
    sys.exit()
if (AAA[0,2]+AAA[1,1]+AAA[2,0])==3:
    print('Yes')
    sys.exit()
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())
for i in range(n):
    b=int(input())
    for j in range(3):
        if a1[j]==b: a1[j]=-1
        if a2[j]==b: a2[j]=-1
        if a3[j]==b: a3[j]=-1
if a1[0]+a2[0]+a3[0]==-3 or a1[1]+a2[1]+a3[1]==-3 or a1[2]+a2[2]+a3[2]==-3:
    print("Yes")
    exit()
print("Yes" if sum(a1)==-3 or sum(a2)==-3 or sum(a3)==-3 or a1[0]+a2[1]+a3[2]==-3 or a1[2]+a2[1]+a3[0]==-3 else "No" )

Submission status: Accepted

Solution code:
init = list(input().split() for _ in range(3))

flag = 0

n = int(input())


for i in range(n):
    num = int(input())
    for j in range(3):
        for l in range(3):
            if(int(init[j][l]) == num):
                init[j][l] = 0

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

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


if(init[0][0] == init[1][1] == init[2][2] == 0):
    flag = 1
    
if(init[0][2] == init[1][1] == init[2][0] == 0):
    flag = 1


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

#print(init)

Submission status: Accepted

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

if N < 3:
    print("No")
    exit()

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

yes = False

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


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

Submission status: Accepted

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

Chosen = []
for _ in range(3):
    Chosen.append([False] * 3)

Bingo = [
    [[0, 0], [0, 1], [0, 2]],
    [[1, 0], [1, 1], [1, 2]],
    [[2, 0], [2, 1], [2, 2]],
    [[0, 0], [1, 0], [2, 0]],
    [[0, 1], [1, 1], [2, 1]],
    [[0, 2], [1, 2], [2, 2]],
    [[0, 0], [1, 1], [2, 2]],
    [[2, 0], [1, 1], [0, 2]]
    ]

ans = False

for sample in b:
    for i in range(3):
        for j in range(3):
            if A[i][j] == sample:
                Chosen[i][j] = True

for i in range(len(Bingo)):
    if Chosen[Bingo[i][0][0]][Bingo[i][0][1]] and Chosen[Bingo[i][1][0]][Bingo[i][1][1]] and Chosen[Bingo[i][2][0]][Bingo[i][2][1]]:
        ans = True
        break

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

Submission status: Accepted

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

count = [[0,0,0],[0,0,0],[0,0,0]]

for i in range(0,n):
   for j in range(0,3):
      for k in range(0,3):
         if alist[i] == blist[j][k]:
            count[j][k] += 1

ans = 0
temp = 0

for i in range(0,3):
   for k in range(0,3):
      if count[i][k] == 1:
         temp += 1
      if temp == 3:
         ans += 1
   temp = 0

for i in range(0,3):
   for k in range(0,3):
      if count[k][i] >= 1:
         temp += 1
      if temp == 3:
         ans += 1
   temp = 0

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

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

Submission status: Accepted

Solution code:
grid = [[0 for i in xrange(3)] for j in xrange(3)]
for i in xrange(3):
    grid[i] = map(int, raw_input().strip().split())

ans = [[0 for i in xrange(3)] for j in xrange(3)]

q = input()
for _ in xrange(q):
    num = input()
    for i in xrange(3):
        for j in xrange(3):
            if grid[i][j] == num:
                ans[i][j] = 1

yes = "No"
for i in xrange(3):
    if ans[i] == [1, 1, 1]:
        yes = "Yes"

for i in xrange(3):
    if [ans[j][i] for j in xrange(3)] == [1, 1, 1]:
        yes = "Yes"

if [ans[i][i] for i in xrange(3)] == [1, 1, 1]:
    yes = "Yes"

if [ans[2][0], ans[1][1], ans[0][2]] == [1, 1, 1]:
    yes = "Yes"

print yes

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

for i in range(n):
    if b[i]==a1[0]:
        an[0]=1
    if b[i]==a1[1]:
        an[1]=1
    if b[i]==a1[2]:
        an[2]=1
    if b[i]==a2[0]:
        an[3]=1
    if b[i]==a2[1]:
        an[4]=1
    if b[i]==a2[2]:
        an[5]=1
    if b[i]==a3[0]:
        an[6]=1
    if b[i]==a3[1]:
        an[7]=1
    if b[i]==a3[2]:
        an[8]=1



if an[0]==1 and an[1]==1 and an[2]==1:
    print("Yes")
elif an[3]==1 and an[4]==1 and an[5]==1:
    print("Yes")
elif an[6]==1 and an[7]==1 and an[8]==1:
    print("Yes")
elif an[0]==1 and an[3]==1 and an[6]==1:
    print("Yes")
elif an[1]==1 and an[4]==1 and an[7]==1:
    print("Yes")
elif an[2]==1 and an[5]==1 and an[8]==1:
    print("Yes")
elif an[0]==1 and an[4]==1 and an[8]==1:
    print("Yes")
elif an[2]==1 and an[4]==1 and an[6]==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()))
board = [a, b, c]

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

result = [[False] * 3, [False] * 3, [False] * 3]


for x in l:
  for i in range(3):
    for j in range(3):
      if x == board[i][j]:
        result[i][j] = True
        
ans = False

for i in result:
  if all(i):
    ans = True

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

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

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

Submission status: Accepted

Solution code:
import numpy as np
a_1 = list(map(int,input().split()))
a_2 = list(map(int,input().split()))
a_3 = list(map(int,input().split()))
a = []
a.append(a_1)
a.append(a_2)
a.append(a_3)
bingo = [[False] * 3 for _ in range(3)]
n = int(input())
for _ in range(n):
    tmp = int(input())
    for x,row in enumerate(a):
        try:
            pos = [x,row.index(tmp)]
            bingo[pos[0]][pos[1]] = True
            break
        except ValueError:
            pass
bingo = np.array(bingo)
if (sum(bingo[0]) == 3) | (sum(bingo[1])==3) | (sum(bingo[2])==3) | (3 in np.sum(bingo,axis=0)):
    print('Yes')
elif ((bingo[0][0]==True) & (bingo[1][1]==True) & (bingo[2][2]==True)) | ((bingo[0][2]==True) & (bingo[1][1]==True) & (bingo[2][0]==True)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
import numpy as np
A = []
for n in range(3):
    tmp_lis = list(map(int, input().split()))
    A.append(tmp_lis)
N = int(input())

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

if N <= 2:
    print("No")
    sys.exit()

bool_lis = [[False, False, False],
            [False, False, False],
            [False, False, False]]

for i in range(3):
    for j in range(3):
        if A[i][j] in B:
            bool_lis[i][j] = True

arr = np.array(bool_lis)

if (np.trace(arr) == 3) or all([arr[0][2], arr[1][1], arr[2][0]]) or (3 in sum(arr)) or (3 in sum(arr.T)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import defaultdict
D  = [list(map(int, s.split())) for s in open(0)]
bingo = D[0:3]
num = [d[0] for d in D[4:]]
n = []
cases = [
    [(0,0), (0, 1), (0, 2)], 
    [(1,0), (1, 1), (1, 2)], 
    [(2,0), (2, 1), (2, 2)], 
    [(0,0), (1, 0), (2, 0)],
    [(0,1), (1, 1), (2, 1)],  
    [(0,2), (1, 2), (2, 2)],  
    [(0,0), (1, 1), (2, 2)],  
    [(0,2), (1, 1), (2, 0)]]
for i in range(len(bingo)):
    for j in range(len(bingo[i])):
        if bingo[i][j] in num:
            n.append((i, j))
flag = 0
for c in cases:
    f = 0
    for l in c:
        if l in n:
            f += 1
    if f == 3:
        flag += 1
        
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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


judge = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

for b_i in b:
    for i in range(3):
        for j in range(3):
            if b_i == A[i][j]:
                judge[i][j] = 1

bool = False

for i in range(3):
    if judge[i][0] == 1 and judge[i][1] == 1 and judge[i][2] == 1:
        print('Yes')
        bool = True
        break
    elif judge[0][i] == 1 and judge[1][i] == 1 and judge[2][i] == 1:
        print('Yes')
        bool = True
        break
    elif judge[0][0] == 1 and judge[1][1] == 1 and judge[2][2] == 1:
        print('Yes')
        bool = True
        break
    elif judge[0][2] == 1 and judge[1][1] == 1 and judge[2][0] == 1:
        print('Yes')
        bool = True
        break

if bool == False:
    print('No')

Submission status: Accepted

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

for i in range(3):
    cnt = 0
    for j in range(3):
        if a[i][j] == True:
            cnt += 1
        if cnt == 3:
            print("Yes")
            exit()

for i in range(3):
    cnt = 0
    for j in range(3):
        if a[j][i] == True:
            cnt += 1
        if cnt == 3:
            print("Yes")
            exit()

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

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

print("No")

Submission status: Accepted

Solution code:
r1 = list(map(int,input().split()))
r2 = list(map(int,input().split()))
r3 = list(map(int,input().split()))
r1.extend(r2)
r1.extend(r3)
N = int(input())
for i in range(N):
    num = int(input())
    if num in r1:
        r1[r1.index(num)] = 0
ans = False
if sum(r1[::3]) == 0 or sum(r1[1::3]) == 0 or sum(r1[2::3]) == 0:
    ans = True
elif sum(r1[:3]) == 0 or sum(r1[3:6]) == 0 or sum(r1[6:]) == 0:
    ans = True
elif (r1[0]+r1[4]+r1[8]) == 0 or (r1[2]+r1[4]+r1[6]) == 0:
    ans = True
if ans:
    print("Yes")
else:
    print("No")