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 = [0, 0, 0, 0, 0, 0, 0, 0, 0]
for i in range(3):
    A[3*i], A[3*i+1], A[3*i+2] = map(int, input().split())
A_bingo = [0, 0, 0, 0, 0, 0, 0, 0, 0]

N = int(input())
for _ in range(N):
    b = int(input())
    if b in A:
        A_bingo[A.index(b)] = 1

# check
for i in range(3):
    if (A_bingo[3*i] == 1 and A_bingo[3*i+1] == 1 and A_bingo[3*i+2] == 1):
        print("Yes")
        exit()
    elif (A_bingo[i] == 1 and A_bingo[i+3] == 1 and A_bingo[i+6] == 1):
        print("Yes")
        exit()
if (A_bingo[0] == 1 and A_bingo[4] == 1 and A_bingo[8] == 1) or (A_bingo[2] == 1 and A_bingo[4] == 1 and A_bingo[6] == 1):
    print("Yes")
    exit()

print("No")

Submission status: Accepted

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

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


#横にビンゴ
if (x[0][0] in b) and (x[0][1] in b)and (x[0][2] in b):
  print("Yes")
elif (x[1][0] in b) and (x[1][1] in b)and (x[1][2] in b):
  print("Yes")
elif (x[2][0] in b) and (x[2][1] in b)and (x[2][2] in b):
  print("Yes")
#縦にビンゴ
elif (x[0][0] in b) and (x[1][0] in b)and (x[2][0] in b):
  print("Yes")
elif (x[0][1] in b) and (x[1][1] in b)and (x[2][1] in b):
  print("Yes")
elif (x[0][2] in b) and (x[1][2] in b)and (x[2][2] in b):
  print("Yes")
#斜めにビンゴ
elif (x[0][0] in b) and (x[1][1] in b)and (x[2][2] in b):
  print("Yes")
elif (x[0][2] in b) and (x[1][1] in b)and (x[2][0] in b):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:

points = []
for _ in range(3):
    points.append(list(map(int, input().split())))

N = int(input())
nums = []
for _ in range(N):
    nums.append(int(input()))


for num in nums:
    for i in range(3):
        if num in points[i]:
            j = points[i].index(num)
            points[i][j] = 0

if (points[0][0] == 0) and (points[1][0] == 0) and (points[2][0] == 0):
    print("Yes")
elif (points[0][1] == 0) and (points[1][1] == 0) and (points[2][1] == 0):
    print("Yes")
elif (points[0][2] == 0) and (points[1][2] == 0) and (points[2][2] == 0):
    print("Yes")
elif (points[0][0] == 0) and (points[0][1] == 0) and (points[0][2] == 0):
    print("Yes")
elif (points[1][0] == 0) and (points[1][1] == 0) and (points[1][2] == 0):
    print("Yes")
elif (points[2][0] == 0) and (points[2][1] == 0) and (points[2][2] == 0):
    print("Yes")
elif (points[0][0] == 0) and (points[1][1] == 0) and (points[2][2] == 0):
    print("Yes")
elif (points[0][2] == 0) and (points[1][1] == 0) and (points[2][0] == 0):
    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)]

bingos = [
    [(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 = 'No'
for bingo in bingos:
    for bp in bingo:
        i, j = bp
        if a[i][j] not in b:
            break
    else:
        ans = 'Yes'
        break
print(ans)

Submission status: Accepted

Solution code:
A=[]
for i in range(3):
    A.append(list(map(int,input().split())))
b=int(input())
for i in range(b):
    l=int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k]==l:
                A[j][k]=0
a1=sum(A[0])
a2=sum(A[1])
a3=sum(A[2])
a4=A[0][0]+A[1][0]+A[2][0]
a5=A[0][1]+A[1][1]+A[2][1]
a6=A[0][2]+A[1][2]+A[2][2]
a7=A[0][0]+A[1][1]+A[2][2]
a8=A[2][0]+A[1][1]+A[0][2]
count=min(a1,a2,a3,a4,a5,a6,a7,a8)
if count==0:
     print("Yes")
else:
     print("No")

Submission status: Accepted

Solution code:
def check(A):
    for i in range(3):
        if A[i][0] == A[i][1] == A[i][2] == -1:
            return True
        if A[0][i] == A[1][i] == A[2][i] == -1:
            return True
    if A[0][0] == A[1][1] == A[2][2]:
        return True
    if A[2][0] == A[1][1] == A[0][2]:
        return True
    return False


def resolve():
    A = [list(map(int, input().split())) for i in range(3)]
    N = int(input())
    for _ in range(N):
        n = int(input())
        for i in range(3):
            for j in range(3):
                if A[i][j] == n:
                    A[i][j] = -1
    print("Yes" if check(A) else "No")


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
a = input().split() + input().split() + input().split()
n = int(input())
hit = [False] * 9
for _ in range(n):
    b = input()
    for i, ai in enumerate(a):
        if ai == b:
            hit[i] = True
            break
bingo = False
for i in range(3):
    if all(hit[i * 3:(i + 1)*3]):
        bingo = True
        break
    if all(hit[i::3]):
        bingo = True
        break
if all(hit[::4]) or all(hit[2:7:2]):
    bingo = True
print("Yes" if bingo else "No")

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    A = [list(map(int,input().split())) for _ in range(3)]
    N = int(input())
    B = [int(input()) for _ in range(N)]
    # print(A)
    # print(B)
    # N, M = map(int, input().split())
    # A = list(map(int, input().split()))
    for i in range(3):
        for j in range(3):
            for b in B:
                if A[i][j] == b:
                    A[i][j] = 0
    # print(A)
    bingo1 = (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)
    bingo2 = (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)
    bingo3 = (A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0) or (A[2][0] == 0 and A[1][1] == 0 and A[0][2] == 0)
    # print(bingo1)
    print("Yes" if (bingo1 or bingo2 or bingo3) else "No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

# n,m=map(int,input().split())
# a,b,c=map(int,input().split())
# s=input()
# s,t=map(str,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
L=[]
L.append(A)
L.append(B)
L.append(C)
n=int(input())

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

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

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

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

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


print("No")

Submission status: Accepted

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

bingo=[[0,0,0],[0,0,0],[0,0,0]]

for i in range(N):
    bi=int(input())
    for j in range(3):
        for k in range(3):
            a=A[j][k]
            if a==bi:
                bingo[j][k]=1

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
A = [input().split() for i in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]

Bingo = [[0,0,0],[0,0,0],[0,0,0]]

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

if Bingo[0][0] == 1 and Bingo[0][1] == 1 and Bingo[0][2] ==1 :
    ans = "Yes"
elif Bingo[1][0] == 1 and Bingo[1][1] == 1 and Bingo[1][2] ==1 :
    ans = "Yes"
elif Bingo[2][0] == 1 and Bingo[2][1] == 1 and Bingo[2][2] ==1 :
    ans = "Yes"
elif Bingo[0][0] == 1 and Bingo[1][0] == 1 and Bingo[2][0] ==1 :
    ans = "Yes"
elif Bingo[0][1] == 1 and Bingo[1][1] == 1 and Bingo[2][1] ==1 :
    ans = "Yes"
elif Bingo[0][2] == 1 and Bingo[1][2] == 1 and Bingo[2][2] ==1 :
    ans = "Yes"
elif Bingo[0][0] == 1 and Bingo[1][1] == 1 and Bingo[2][2] ==1 :
    ans = "Yes"
elif Bingo[0][2] == 1 and Bingo[1][1] == 1 and Bingo[2][0] ==1 :
    ans = "Yes"
else :
    ans = "No"

print(ans)

Submission status: Accepted

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

for n in range(N):
    d = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == d:
                A[i][j] = 0

for i in range(3):
    if sum(A[i]) == 0:
        print('Yes')
        exit()
    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')
    exit()

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 i in range(3):
  for j in range(3):
    if a[i][j] in b:
      a[i][j]=0
if a[0][0]==0 and a[0][1]==0 and a[0][2]==0:
  print("Yes")
  exit()
elif a[1][0]==0 and a[1][1]==0 and a[1][2]==0:
  print("Yes")
  exit()
elif a[2][0]==0 and a[2][1]==0 and a[2][2]==0:
  print("Yes")
  exit()
elif a[0][0]==0 and a[1][0]==0 and a[2][0]==0:
  print("Yes")
  exit()
elif a[0][1]==0 and a[1][1]==0 and a[2][1]==0:
  print("Yes")
  exit()
elif a[0][2]==0 and a[1][2]==0 and a[2][2]==0:
  print("Yes")
  exit()
elif a[0][0]==0 and a[1][1]==0 and a[2][2]==0:
  print("Yes")
  exit()
elif a[0][2]==0 and a[1][1]==0 and a[2][0]==0:
  print("Yes")
  exit()
else:
  print("No")

Submission status: Accepted

Solution code:
import sys,collections,math,random,fractions,bisect;sys.setrecursionlimit(10**7)
sr = sys.stdin.readline; P = print; P2 = lambda x: print(*x, sep="\n")
def I(i=0): t = [int(x)-i for x in sr().split()];return t
def S(): t = sr().split(); return t if len(t) > 1 else t[0]
L1,L2,L3,L4, = [],[],[],[]

ans = "No"
for i in range(3):
    L1.append(I())
N, = I()
for _ in range(N):
    t, = I()
    for i in range(3):
        for j in range(3):
            if L1[i][j] == t:
                L1[i][j] = 0
                break
for i in range(3):
    if sum(L1[i]) == 0:
        ans = "Yes"
for j in range(3):
    s = 0
    for i in range(3):
        s += L1[i][j]
    if s == 0:
        ans = "Yes"
if L1[0][0] + L1[1][1] + L1[2][2] == 0 or L1[2][0] + L1[1][1] + L1[0][2] == 0:
    ans = "Yes"
print(ans)

Submission status: Accepted

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

for num in b:
    for x in range(3):
        for y in range(3):
            if A[x][y] == num:
                A[x][y] = -1

amount = 0
for x in range(3):
    if max(A[x]) == -1:
        amount += 1
for y in range(3):
    if max([A[0][y], A[1][y], A[2][y]]) == -1:
        amount += 1
if max([A[0][0], A[1][1], A[2][2]]) == -1:
    amount += 1
if max([A[2][0], A[1][1], A[0][2]]) == -1:
    amount += 1

if amount > 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A = []
for i in range(3):
  temp = list(map(int, input().split()))
  A.append(temp)
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
flag = 0
for i in range(3):
  if(A[i][0]==0 and A[i][1]==0 and A[i][2]==0):
    print("Yes")
    flag=1
    break
  elif(A[0][i]==0 and A[1][i]==0 and A[2][i]==0):
    print("Yes")
    flag=1
    break
  elif(A[0][0]==0 and A[1][1]==0 and A[2][2]==0):
    print("Yes")
    flag=1
    break
  elif(A[0][2]==0 and A[1][1]==0 and A[2][0]==0):
    print("Yes")
    flag=1
    break
if(flag==0):
  print("No")

Submission status: Accepted

Solution code:
import sys
import math
import copy
import queue
input = sys.stdin.readline
A = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
for i in b:
    for j in range(3):
        for k in range(3):
            if i == A[j][k]:
                A[j][k] = 0
                break
        else:
            continue
        break

ok = False
for h in range(3):
    if A[h][0] == 0 and A[h][1] == 0 and A[h][2] == 0:
        ok = True
        break

for v in range(3):
    if A[0][v] == 0 and A[1][v] == 0 and A[2][v] == 0:
        ok = True
        break

if A[0][0] == 0 and A[1][1] == 0 and A[2][2] ==0:
    ok = True

if A[0][2] == 0 and A[1][1] == 0 and A[2][0] ==0:
    ok = True

if ok:
    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())
C=[0]*9
#print(b)
for i in range(3):
    #print(A1[i] in b)
    if A1[i] in b:
        C[i]=1
    if A2[i] in b:
        C[i+3]=1
    if A3[i] in b:
        C[i+6]=1
#print(C)
if C[0]==C[1]==C[2]==1:
    print('Yes')
elif C[3]==C[4]==C[5]==1:
    print('Yes')
elif C[6]==C[7]==C[8]==1:
    print('Yes')
elif C[0]==C[3]==C[6]==1:
    print('Yes')
elif C[1]==C[4]==C[7]==1:
    print('Yes')
elif C[2]==C[5]==C[8]==1:
    print('Yes')
elif C[0]==C[4]==C[8]==1:
    print('Yes')
elif C[2]==C[4]==C[6]==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 = [int(input()) for _ in range(n)]

check = [[0,1,2],[3,4,5],[6,7,8],
        [0,3,6],[1,4,7],
        [2,5,8],
        [0,4,8],[2,4,6]]

for tmp in check:
    count = 0
    for num in tmp:
        i = num//3
        j = num%3
        if(a[i][j] in b) == False:
            break
        count+=1
        if(count == 3):
            print('Yes')
            exit()

print('No')

Submission status: Accepted

Solution code:
A = []
for i in range(3):
    A.append(list(map(int, input().split())))
N = int(input())
B = [int(input()) for i in range(N)]
BINGO = False
for j in range(3):
    for i in range(3):
        if A[i][j] in B:
            continue
        break
    else:
        BINGO = True
        
if not BINGO:
    for i in range(3):
        for j in range(3):
            if A[i][j] in B:
                continue
            break
        else:
            BINGO = True

if not BINGO:
    for i in range(3):
        if A[i][i] in B:
            continue
        break
    else:
        BINGO = True

if not BINGO:
    for i in range(3):
        if A[i][2-i] in B:
            continue
        break
    else:
        BINGO = True
        
print('Yes' if BINGO else 'No')

Submission status: Accepted

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

for i in range(N):
    for j in range(3):
        for p in range(3):
            if nums[i] == A[j][p]:
                A[j][p] = 'x'

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

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

if A[0][0] == 'x' and A[1][1] == 'x' and A[2][2] == 'x':
    ans = 'Yes'
    
if A[0][2] == 'x' and A[1][1] == 'x' and A[2][0] == 'x':
    ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
A1 = input().split()
A2 = input().split()
A3 = input().split()
A = [A1, A2, A3]
N = int(input())
B = []

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

K = [[0,0,0],
     [0,0,0],
     [0,0,0]]

for i in range(3):
    for j in range(3):
        if A[i][j] in B:
            K[i][j] = 1

flag = 0

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

if K[0][0] and K[1][1] and K[2][2]:
    flag = 1

if K[0][2] and K[1][1] and K[0][2]:
    flag = 1

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

Submission status: Accepted

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

    for num in b:
        for i in range(3):
            for j in range(3):
                if a[i][j] == num:
                    a[i][j] = 0
    if sum(a[0]) == 0 or sum(a[1]) == 0 or sum(a[2]) == 0:
        print('Yes')
    elif 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')
    elif 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')

main()

Submission status: Accepted

Solution code:
A = []
for i in range(3):
  A.append(list(map(int, input().split())))
import numpy as np
A = np.array(A)
N = int(input())
for i in range(N):
  A = np.where(A==int(input()), 0, A)
flag = 0
if 0 in np.sum(A, axis = 0) or 0 in np.sum(A, axis = 1):
  flag = 1
if A[0, 0] + A[1, 1] + A[2, 2] == 0 or A[2, 0] + A[1, 1] + A[0, 2] == 0:
  flag = 1

if flag == 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())
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] == 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)\
    or (a[0][0] == a[1][1] == a[2][2] == 0) or (a[0][2] == a[1][1] == a[2][0] == 0):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import math
arr=[]
for i in range(3):
	temp=list(map(int,input().split()))
	arr.append(temp)
d={}
n=int(input())
for i in range(n):
	x=int(input())
	if x in d:
		d[x]+=1
	else:
		d[x]=1
brr=[]
for i in range(3):
	brr.append([])
for i in range(3):
	for j in range(3):
		if arr[i][j] in d:
			brr[i].append(1)
		else:
			brr[i].append(0)
flag=False
if brr[0][0]==1 and brr[0][1]==1 and brr[0][2]==1:
	flag=True
if brr[0][0]==1 and brr[1][1]==1 and brr[2][2]==1:
	flag=True
if brr[2][0]==1 and brr[1][1]==1 and brr[0][2]==1:
	flag=True
if brr[0][0]==1 and brr[1][0]==1 and brr[2][0]==1:
	flag=True
if brr[1][0]==1 and brr[1][1]==1 and brr[1][2]==1:
	flag=True
if brr[2][0]==1 and brr[2][1]==1 and brr[2][2]==1:
	flag=True
if brr[0][1]==1 and brr[1][1]==1 and brr[2][1]==1:
	flag=True 
if brr[0][2]==1 and brr[1][2]==1 and brr[2][2]==1:
	flag=True
if flag:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
card = []
result = [["n"]*3 for _ in range(3)]

for _ in range(3):
    a_list = [int(a) for a in input().split()]
    card.append(a_list)

N = int(input())
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if card[i][j] == b:
                result[i][j] = "y"

def solve():
    if result[0][0] == result[1][1] == result[2][2] == "y":
        return True
    elif result[0][2] == result[1][1] == result[2][0] == "y":
        return True

    for row in result:
        if row == ["y", "y", "y"]:
            return True

    for i in range(3):
        if result[0][i] == result[1][i] == result[2][i] == "y":
            return True

    return False

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

Submission status: Accepted

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

m = []
M = [[False, False, False], [False, False, False], [False, False, False]]
for _ in range(N):
    b = int(input())
    for j in range(3):
        for i in range(3):
            if b == A[j][i]:
                M[j][i] = True


ans = False
for j in range(3):
    if M[j].count(True) == 3:
        ans = True


for i in range(3):
    for j in range(3):
        if not M[j][i]:
            break
    else:
        ans = True

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

if ans:
    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()))
bingo = [0,0,0,0,0,0,0,0,0]
N = int(input())

for i in range(N):
  hoge = int(input())
  for i in range(3):
    if A[i] == hoge:
      bingo[i] = 1
    if B[i] == hoge:
      bingo[i+3] = 1
    if C[i] == hoge:
      bingo[i+6] = 1
      
if bingo[0] == 1 and bingo[1] == 1 and bingo[2] == 1:
  print("Yes")
elif bingo[3] == 1 and bingo[4] == 1 and bingo[5] == 1:
  print("Yes")
elif bingo[6] == 1 and bingo[7] == 1 and bingo[8] == 1:
  print("Yes")
elif bingo[0] == 1 and bingo[3] == 1 and bingo[6] == 1:
  print("Yes")
elif bingo[1] == 1 and bingo[4] == 1 and bingo[7] == 1:
  print("Yes")
elif bingo[2] == 1 and bingo[5] == 1 and bingo[8] == 1:
  print("Yes")
elif bingo[0] == 1 and bingo[4] == 1 and bingo[8] == 1:
  print("Yes")
elif bingo[2] == 1 and bingo[4] == 1 and bingo[6] == 1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

C = [[0,0,0] for i in range(3)]
N = int(input())
for i in range(N):
    b = int(input())
    for k in range(3):
        for l in range(3):
            if A[k][l] == b:
                C[k][l] = 1
flag = False
for i in range(3):
    if C[0][i] == C[1][i] == C[2][i] == 1:
        flag = True
for i in range(3):
    if C[i][0] == C[i][1] == C[i][2] == 1:
        flag = True
if C[0][0] == C[1][1] == C[2][2] == 1:
    flag = True
if C[2][0] == C[1][1] == C[0][2] == 1:
    flag = True

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

Submission status: Accepted

Solution code:
up_row = [int(a) for a in input().split(' ')]
middle_row = [int(a) for a in input().split(' ')]
down_row = [int(a) for a in input().split(' ')]
numbers_count = int(input())

bingo_mat = [up_row, middle_row, down_row]
selected_mat = [[False, False, False], [False, False, False], [False, False, False]]


for i in range(numbers_count):
    selected = int(input())
    for row in range(3):
        for col in range(3):
            if bingo_mat[row][col] == selected:
                selected_mat[row][col] = True

for col in range(3):
    if selected_mat[0][col] and selected_mat[1][col] and selected_mat[2][col]:
        print("Yes")
        exit()

for row in range(3):
    if selected_mat[row][0] and selected_mat[row][1] and selected_mat[row][2]:
        print("Yes")
        exit()

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

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

print("No")

Submission status: Accepted

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

check_card = [[False, False, False] for i in range(3)]


def check(num):
    for y in range(3):
        for x in range(3):
            if card[y][x] == num:
                check_card[y][x] = True


n = int(input())
for _ in range(n):
    num = int(input())
    check(num)


def ver(check_card):
    for x in range(3):
        res = [check_card[0][x], check_card[1][x], check_card[2][x]]
        if sum(res) == 3:
            return True
    return False


def hor(check_card):
    for y in range(3):
        res = check_card[y]
        if sum(res) == 3:
            return True
    return False


def naname(check_card):
    pat1 = check_card[0][0] + check_card[1][1] + check_card[2][2]
    pat2 = check_card[0][2] + check_card[1][1] + check_card[2][0]
    if pat1 == 3 or pat2 == 3:
        return True
    else:
        return False


if ver(check_card) or hor(check_card) or naname(check_card):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
A = [[int(str) for str in input().strip().split()] for _ in range(3)]
N = int(input().strip())
b = [int(input().strip()) for _ in range(N)]


ans = False
for i in range(3):
    ans |= all([A[i][j] in b for j in range(3)])

for j in range(3):
    ans |= all([A[i][j] in b for i in range(3)])

ans |= all([A[i][i] in b for i in range(3)])
ans |= all([A[i][2 - i] in b for i in range(3)])

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

Submission status: Accepted

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

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

for i in b:
    for j in range(3):
        for k in range(3):
            if a[j][k] == i:
                a[j][k] = True
ans = "No"
for i in a:
    if i.count(True) == 3:
        ans = "Yes"

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

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

print(ans)

Submission status: Accepted

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

for _ in range(N):
  p=int(input())
  for i in range(3):
    for j in range(3):
      if A[i][j]==p:
        check[i][j]=True
        
for i in range(3):
  ok=True
  for j in range(3):
    if check[i][j]==False:
      ok=False
  if ok:
    print("Yes")
    exit(0)
    
for j in range(3):
  ok=True
  for i in range(3):
    if check[i][j]==False:
      ok=False
  if ok:
    print("Yes")
    exit(0)
    
if check[0][0] and check[1][1] and check[2][2]:
  print("Yes")
  exit(0)
  
if check[2][0] and check[1][1] and check[0][2]:
  print("Yes")
  exit(0)
    
print("No")

Submission status: Accepted

Solution code:
input = raw_input

a_dict = {}
for i in range(3):
    a_line = map(int, input().split(" "))
    for j in range(3):
        a = a_line[j]
        a_dict[a] = (i, j)

n = int(input())
taishos = a_dict.keys()

attas = [[False, False, False] for _ in range(3)]
for _ in range(n):
    b = int(input())
    if b in taishos:
        i, j = a_dict[b]
        attas[i][j] = True

found = False

for i in range(3):
    for j in range(3):
        atta = attas[i][j]
        if not atta:
            break
        
        if j == 2:
            found = True

if not found:
    for j in range(3):
        for i in range(3):
            atta = attas[i][j]
            if not atta:
                break
            
            if i == 2:
                found = True

if not found:
    flag = attas[0][0] * attas[1][1] * attas[2][2] + attas[2][0] * attas[1][1] * attas[0][2]
    if flag >= 1:
        found = True

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

Submission status: Accepted

Solution code:
A=[[0 for i in range(3)]for i in range(3)]
for i in range(3):
  A[i]=list(map(int,input().split()))
N=int(input())
b=[]
for i in range(N):
  b+=[int(input())]
tf=[[0 for i in range(3)] for i in range(3)]
for i in range(3):
  for j in range(3):
    if A[i][j] in b:
      tf[i][j]=1
an=0
for i in range(3):
  if sum(tf[i])==3 or tf[0][i]+tf[1][i]+tf[2][i]==3:
    an=1
if tf[0][0]+tf[1][1]+tf[2][2]==3 or tf[0][2]+tf[1][1]+tf[2][0]==3:
  an=1
if an==1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


a = list()
for _ in range(3):
    a = a + na()
n = ni()
t = [0 for _ in range(9)]
for _ in range(n):
    b = ni()
    for i, ai in enumerate(a):
        if ai == b:
            t[i] = 1

ans = "No"
for i in range(3):
    if t[3 * i] + t[3 * i + 1] + t[3 * i + 2] == 3:
        ans = "Yes"
    if t[0 + i] + t[3 + i] + t[6 + i] == 3:
        ans = "Yes"
if t[0] + t[4] + t[8] == 3:
    ans = "Yes"
if t[2] + t[4] + t[6] == 3:
    ans = "Yes"
print(ans)

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())
k="No"
c=[0,0,0,0,0,0,0,0,0]
for i in range(n):
    b=int(input())
    if b in a:
        c[a.index(b)]=1
c=[0]+c
if c[1]==1 and c[2]==1 and c[3]==1:
    k="Yes"
elif c[1]==1 and c[4]==1 and c[7]==1:
    k="Yes"
elif c[1]==1 and c[5]==1 and c[9]==1:
    k="Yes"
elif c[2]==1 and c[5]==1 and c[8]==1:
    k="Yes"
elif c[3]==1 and c[6]==1 and c[9]==1:
    k="Yes"
elif c[4]==1 and c[5]==1 and c[6]==1:
    k="Yes"
elif c[7]==1 and c[8]==1 and c[9]==1:
    k="Yes"
elif c[3]==1 and c[5]==1 and c[7]==1:
    k="Yes"
print(k)

Submission status: Accepted

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

# print(S)
yoko = []
for s in S:
    yoko.append(set(s))

tate = []
for i in range(3):
    tate.append({S[0][i], S[1][i], S[2][i]})
# print(tate)

naname = [{S[0][0], S[1][1], S[2][2]}, {S[0][2], S[1][1], S[2][0]}]

N = int(input())
B_set = {int(input()) for i in range(N)}

for y in yoko:
    if y < B_set:
        print("Yes")
        exit()

for y in tate:
    if y < B_set:
        print("Yes")
        exit()

for y in naname:
    if y < B_set:
        print("Yes")
        exit()

print("No")