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 = []
a = []
for i in range(3):
    A.append(list(map(int, input().split())))
    a.append([0, 0, 0])

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] == A[j][k]:
                a[j][k] += 1

judge = 'No'
for i in range(3):
    if a[0][i] == 1 and a[1][i] == 1 and a[2][i] == 1:
        judge = "Yes"
    elif a[i][0] == 1 and a[i][1] == 1 and a[i][2] == 1:
        judge = "Yes"
if a[0][0] == 1 and a[1][1] == 1 and a[2][2] == 1:
    judge = 'Yes'
elif a[0][2] == 1 and a[1][1] == 1 and a[2][0] == 1:
    judge = 'Yes'

print(judge)

Submission status: Accepted

Solution code:
a = [] 
for i in range(3):
    a.extend(input().split())
n = int(input())
for i in range(n):
    c = input()
    if c in a:
        a[a.index(c)] = '0'
if (a[0] == a[1] == a[2] or a[3] == a[4] == a[5] or a[6] == a[7] == a[8] or
    a[0] == a[3] == a[6] or a[1] == a[4] == a[7] or a[2] == a[5] == a[8] or
        a[0] == a[4] == a[8] or a[2] == a[4] == a[6]):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a = [[int(i) for i in input().split()] for j in range(3)]
n = int(input())
for i in range(n):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if b==a[j][k]:
        a[j][k] = 0
ans = 'No'
for i in range(3):
  if a[i][0]==0 and a[i][1]==0 and a[i][2]==0:
    ans = 'Yes'
for i in range(3):
  if a[0][i]==0 and a[1][i]==0 and a[2][i]==0:
    ans = 'Yes'
if a[0][0]==0 and a[1][1]==0 and a[2][2]==0:
  ans = 'Yes'
if a[0][2]==0 and a[1][1]==0 and a[2][0]==0:
  ans = 'Yes'
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)]

c = [[0]*3 for _ in range(3)]
for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                c[i][j] = 1


for i in range(3):
  if c[i][0] and c[i][1] and c[i][2]:
    print('Yes')
    exit()
  if c[0][i] and c[1][i] and c[2][i]:
    print('Yes')
    exit()
if c[0][0] and c[1][1] and c[2][2]:
  print('Yes')
  exit()
if c[0][2] and c[1][1] and c[2][0]:
  print('Yes')
  exit()

print('No')

Submission status: Accepted

Solution code:
def main():
    a1_lis = list(map(int, input().split()))
    a2_lis = list(map(int, input().split()))
    a3_lis = list(map(int, input().split()))

    n = int(input())
    b_lis = []
    for _ in range(n):
        b_lis.append(int(input()))
    
    if a1_lis[0] in b_lis and a1_lis[1] in b_lis and a1_lis[2] in b_lis:
        print('Yes')
        exit()
    if a2_lis[0] in b_lis and a2_lis[1] in b_lis and a2_lis[2] in b_lis:
        print('Yes')
        exit()
    if a3_lis[0] in b_lis and a3_lis[1] in b_lis and a3_lis[2] in b_lis:
        print('Yes')
        exit()
    if a1_lis[0] in b_lis and a2_lis[0] in b_lis and a3_lis[0] in b_lis:
        print('Yes')
        exit()
    if a1_lis[1] in b_lis and a2_lis[1] in b_lis and a3_lis[1] in b_lis:
        print('Yes')
        exit()
    if a1_lis[2] in b_lis and a2_lis[2] in b_lis and a3_lis[2] in b_lis:
        print('Yes')
        exit()



    if a1_lis[0] in b_lis and a2_lis[1] in b_lis and a3_lis[2] in b_lis:
        print('Yes')
        exit()
    
    if a3_lis[0] in b_lis and a2_lis[1] in b_lis and a1_lis[2] in b_lis:
        print('Yes')
        exit()
    else:
        print("No")
        


    


if __name__ == "__main__":
    main()

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

Submission status: Accepted

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

B = []
N = int(input())
for i in range(N):
  b = int(input())
  B.append(b)
  
if A[0][0] in B and A[1][1] in B and A[2][2] in B:
  print('Yes')
elif A[0][2] in B and A[1][1] in B and A[2][0] in B:
  print('Yes')
else:
  for i in range(3):
    if A[i][0] in B and A[i][1] in B and A[i][2] in B:
      print('Yes')
      exit()
    if A[0][i] in B and A[1][i] in B and A[2][i] in B:
      print('Yes')
      exit()
  print('No')

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools


l = [list(map(int, input().split())),list(map(int, input().split())),list(map(int, input().split()))]
n = int(input())
b = []
for i in range(n):
    b.append(int(input()))

ij = []
for i in range(n):
    for j in range(3):
        for k in range(3):
            if b[i] == l[j][k]:
                ij.append([j,k])

for i in range(3):
    count = 0
    for j in range(3):
        for k in range(len(ij)):
            if ij[k] == [i,j]:
                count += 1
        if count >= 3:
            print("Yes")
            quit()

for i in range(3):
    count = 0
    for j in range(3):
        for k in range(len(ij)):
            if ij[k] == [j,i]:
                count += 1
        if count >= 3:
            print("Yes")
            quit()

count = 0
for i in range(3):
    for j in range(len(ij)):
        if ij[j] == [i,i]:
            count += 1
    if count >= 3:
        print("Yes")
        quit()

count = 0
for i in range(len(ij)):
    if ij[i] == [0,2] or ij[i] == [1,1] or ij[i] == [2,0]:
        count += 1
if count >= 3:
    print("Yes")
    quit()

print("No")

Submission status: Accepted

Solution code:
A = []
for i in range(3):
    temp = list(map(int, input().split()))
    A += temp
N = int(input())
bingo = [0]*9
for i in range(N):
    b = int(input())
    if b in A:
        bingo[A.index(b)] = 1
flag = bingo[0]*bingo[1]*bingo[2] + bingo[3]*bingo[4]*bingo[5] + bingo[6]*bingo[7]*bingo[8]
flag += bingo[0]*bingo[3]*bingo[6] + bingo[1]*bingo[4]*bingo[7] + bingo[2]*bingo[5]*bingo[8]
flag += bingo[0]*bingo[4]*bingo[8] + bingo[2]*bingo[4]*bingo[6]
if flag > 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A = []
for _ in range(3):
  A += list(map(int,input().split()))
N = int(input())
B = [int(input()) for _ in range(N)]
C = [0]*9
for i in B:
  if i in A:
    x = A.index(i)
    C[x] = 1
if C[0]*C[1]*C[2] == 1 or C[3]*C[4]*C[5]==1 or C[6]*C[7]*C[8] ==1 or C[0]*C[3]*C[6] ==1 or C[1]*C[4]*C[7]==1 or C[2]*C[5]*C[8] ==1 or C[0]*C[4]*C[8] ==1 or C[2]*C[4]*C[6] ==1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))

def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1''などで指定、整数に戻すならintをかます
MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline

import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))

def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline

A = LI2(3)
N = I()
for _ in range(N):
    b = I()
    for i in range(3):
        for j in range(3):
            if b==A[i][j]:
                A[i][j]=0
for c in A:
    if sum(c)==0:
        print('Yes')
        break
else:
    for r in range(3):
        if A[0][r]+A[1][r]+A[2][r]==0:
            print('Yes')
            break
    else:
        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:
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 _ in range(n):
    b = int(input())
    if b in a1:
        a1[a1.index(b)] = 0
    elif b in a2:
        a2[a2.index(b)] = 0
    elif b in a3:
        a3[a3.index(b)] = 0
k = sum(a1) * sum(a2) * sum(a3)
for i in range(3):
    k *= a1[i] + a2[i] + a3[i]
k *= (a1[0] + a2[1] + a3[2]) * (a1[2] + a2[1] + a3[0])
if k == 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)]
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            a[i][j] = True
        else:
            a[i][j] = False
a += [[a[0][i], a[1][i], a[2][i]] for i in range(3)]
a += [[a[i][i] for i in range(3)]] + [[a[0][2], a[1][1], a[2][0]]]
bingo = False
for i in a:
    if all(i):
        bingo = True
        break
if bingo:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a = [[] for _ in range(3)]
for i in range(3):
    a[i] = list(map(int, input().split()))
n = int(input())
b_arr = [int(input()) for _ in range(n)] 
for b in b_arr:
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                a[i][j] = 0
isB = False
for c in range(3):
    if a[0][c] + a[1][c] + a[2][c] == 0:
        isB = True
for r in range(3):
    if a[r][0] + a[r][1] + a[r][2] == 0:
        isB = True
if a[0][0] + a[1][1] + a[2][2] == 0:
    isB = True
if a[0][2] + a[1][1] + a[2][0] == 0:
    isB = True
print("Yes" if isB else "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):
        for m in range(n):
            if b[m] == a[i][j] :
                a[i][j]=0

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

Submission status: Accepted

Solution code:
seat = [list(map(int, input().split())) for i in range(3)]
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if seat[j][k] == b:
                seat[j][k] = 0
for i in range(3):
    if seat[i].count(0) == 3:
        print('Yes')
        exit()
for i in range(3):
    for j in range(3):
        if seat[j][i] != 0:
            break
    else:
        print('Yes')
        exit()
if seat[0][0] == seat[1][1] == seat[2][2] == 0:
    print('Yes')
    exit()
if seat[0][2] == seat[1][1] == seat[2][0] == 0:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

Solution code:

import numpy as np

def check(board):
    for i in range(3):
        if min(board[i]) == 1:
            return True
        if min(board[:, i]) == 1:
            return True
        if min(np.diag(board)) == 1:
            return True
        if board[0][2] == board[1][1] == board[2][0] == 1:
            return True
    return False


A = np.array([list(map(int, input().split())) for _ in range(3)])
N = int(input())
board = np.zeros((3, 3))
for i in range(N):
    B = int(input())
    board[np.where(A == B)] = 1
if check(board):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
A = []

for i in range(3):
    A.extend(input().split())

n = int(input())

for i in range(n):
    com = input()
    if com in A:
        A[A.index(com)] = '0'

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

Submission status: Accepted

Solution code:
a1,a2,a3 = map(int, input().split())
a4,a5,a6 = map(int, input().split())
a7,a8,a9 = map(int, input().split())
A = [a1,a2,a3,a4,a5,a6,a7,a8,a9]

n = int(input())
for _ in range(n):
    b = int(input())
    if b in A:
        i = A.index(b)
        A[i] = 0

if A[0]+A[1]+A[2]==0 or A[3]+A[4]+A[5]==0 or A[6]+A[7]+A[8]==0:
    print("Yes")
elif A[0]+A[3]+A[6]==0 or A[1]+A[4]+A[7]==0 or A[2]+A[5]+A[8]==0:
    print("Yes")
elif A[0]+A[4]+A[8]==0 or A[2]+A[4]+A[6]==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
AList = list(map(int, input().split()))
BList = list(map(int, input().split()))
CList = list(map(int, input().split()))
N = int(input())
DList = [int(input()) for i in range(N)]

def Bcheck(AList,BList,CList):
    if AList[0]=="x" and AList[1]=="x" and AList[2]=="x":
        return "bingo"
    elif BList[0]=="x" and BList[1]=="x" and BList[2]=="x":
        return "bingo"
    elif CList[0]=="x" and CList[1]=="x" and CList[2]=="x":
        return "bingo"
    elif AList[0]=="x" and BList[0]=="x" and CList[0]=="x":
        return "bingo"
    elif AList[1]=="x" and BList[1]=="x" and CList[1]=="x":
        return "bingo"
    elif AList[2]=="x" and BList[2]=="x" and CList[2]=="x":
        return "bingo"
    elif AList[0]=="x" and BList[1]=="x" and CList[2]=="x":
        return "bingo"
    elif AList[2]=="x" and BList[1]=="x" and CList[0]=="x":
        return "bingo"
    else:
        return 0

i=0
while i<N:
    if AList.count(DList[i])!=0:
        AList[(AList.index(DList[i]))]="x"
    elif BList.count(DList[i])!=0:
        BList[(BList.index(DList[i]))]="x"
    elif CList.count(DList[i])!=0:
        CList[(CList.index(DList[i]))]="x"
        
    if Bcheck(AList,BList,CList)=="bingo":
        print("Yes")
        quit()

    i+=1

print("No")

Submission status: Accepted

Solution code:
numbers = []
numbers.extend(list(map(int, input().split(' '))))
numbers.extend(list(map(int, input().split(' '))))
numbers.extend(list(map(int, input().split(' '))))
N = int(input())
answers = set()
for _ in range(N):
    answers.add(int(input()))

results = [False] * 9

for i in range(len(numbers)):
    if numbers[i] in answers:
        results[i] = True

if all(results[0:3]) or all(results[3:6]) or all(results[6:9]):
    print('Yes')
elif all(results[0::3]) or all(results[1::3]) or all(results[2::3]):
    print('Yes')
elif all((results[0], results[4], results[8])) or all((results[2], results[4], results[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 = [int(input()) for i in range(N)]
#print(A)
#print(N)
#print(B)
for i in range(N):
    for j in range(3):
        for k in range(3):
            if A[j][k] == B[i]:
                A[j][k] = 0
#print(A)
for i in range(3):
    if (A[i][0] == A[i][1] == A[i][2] == 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):
    print("Yes")
    exit()
elif(A[0][2] == A[1][1] == A[2][0] == 0):
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
# your code goes here# your code goes hereimport sys
import sys
A=[list(map(int,input().split())) for i in range(3)]
N=int(input())
b=[]
for i in range(N):
    b.append(int(input()))


for i in range(3):
    for j in range(3):
        for x in range(N):
            if A[i][j]==b[x]:
                A[i][j]=0

for i in range(3):
    if A[i][0]==0 and A[i][1]==0 and A[i][2]==0:
        print("Yes")
        sys.exit(0)
for i in range(3):
    if A[0][i]==0 and A[1][i]==0 and A[2][i]==0:
        print("Yes")
        sys.exit(0)
if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
    print("Yes")
    sys.exit(0)
if A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0:
    print("Yes")
    sys.exit(0)
print("No")
# your code goes here

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
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)]

con1 = A1[0] in B and A1[1] in B and A1[2] in B
con2 = A2[0] in B and A2[1] in B and A2[2] in B
con3 = A3[0] in B and A3[1] in B and A3[2] in B
con4 = A1[0] in B and A2[0] in B and A3[0] in B
con5 = A1[1] in B and A2[1] in B and A3[1] in B
con6 = A1[2] in B and A2[2] in B and A3[2] in B
con7 = A1[0] in B and A2[1] in B and A3[2] in B
con8 = A1[2] in B and A2[1] in B and A3[0] in B

if (con1 or con2 or con3 or con4 or con5 or con6 or con7 or con8):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import math
def py():
    print("Yes")
def pn():
    print("No")
def iin():
    x = int(input())
    return x

neko = 0
nya = 0
nuko = 0
a = [] 
x = [[0] * 3 for i in range(3)]
for i in range(3):
    a.append([int(x) for x in input().split()])
n = iin()
b = [0] * n
for i in range(n):
    b[i] = iin()

for i in range(3):
    for j in range(3):
        for f in range(n):
            if a[i][j] == b[f]:
                x[i][j] = 1
for i in range(3):
    if sum(x[i]) == 3:
        neko = neko + 1
    nya = x[0][i] + x[1][i] + x[2][i]
    if nya == 3:
        neko = neko + 1
nya = x[0][0]+ x[1][1] + x[2][2]
if nya == 3:
    neko = neko + 1
nya = x[0][2]+ x[1][1] + x[2][0]
if nya == 3:
    neko = neko + 1
if neko > 0:
    py()
else:
    pn()

Submission status: Accepted

Solution code:
import sys

a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
n=int(input())
d=[int(input())for _ in range(n)]
lsa,lsb,lsc=[0]*3,[0]*3,[0]*3

for i in d:
  if i in a:
    lsa[a.index(i)]+=1
    
  elif i in b:
    lsb[b.index(i)]+=1
    
  elif i in c:
    lsc[c.index(i)]+=1
    
if all(i>=1 for i in lsa):
  print("Yes")
  sys.exit()
  
elif all(i>=1 for i in lsb):
  print("Yes")
  sys.exit()
  
elif all(i>=1 for i in lsc):
  print("Yes")
  sys.exit()
  
for i in range(3):
  if lsa[i]>=1 and lsb[i]>=1 and lsc[i]>=1:
    print("Yes")
    sys.exit()
    
if lsa[0]>=1 and lsb[1]>=1 and lsc[2]>=1 or lsa[2]>=1 and lsb[1]>=1 and lsc[0]>=1:
  print("Yes")
  sys.exit()
  
print("No")

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


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

    bg = []
    for i in range(3):
        bg.append(a[i])
        bg.append([a[0][i], a[1][i], a[2][i]])
    bg.append([a[i][i] for i in range(3)])
    bg.append([a[i][2 - i] for i in range(3)])

    for bgi in bg:
        if len(list(set(bgi) - set(b))) == 0:
            print('Yes')
            exit()

    print('No')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

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)]

flag = False
for i in range(3):
    if a[i][0] in b and a[i][1] in b and a[i][2] in b:
        flag = True
        break
    if a[0][i] in b and a[1][i] in b and a[2][i] in b:
        flag = True
        break
if a[0][0] in b and a[1][1] in b and a[2][2] in b:
    flag = True
if a[2][0] in b and a[1][1] in b and a[0][2] in b:
    flag = True
    
print("Yes" if flag else "No")

Submission status: Accepted

Solution code:
import numpy as np

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

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

at = a.transpose()
flag = False
for i in range(3):
    if sum(a[:][i]) == 0 or sum(at[:][i]) == 0:
        flag = True
        break
diag = a[0][0] + a[1][1] + a[2][2]
diag2 = a[2][0] + a[1][1] + a[0][2]
if diag == 0 or diag2 == 0:
    flag = True

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

Submission status: Accepted

Solution code:
B = {}
for i in range(3):
    for j, e in enumerate(input().split()):
        B[e] = (i, j)

L = []
for i in range(8):
    L.append(0)
        
N = int(input())
for i in range(N):
    b = input()
    if b in B:
        L[B[b][0] % 3] += 1
        L[(B[b][0] * 3 + B[b][1]) % 3 + 3] += 1
        if B[b][0] == B[b][1]:
            L[6] += 1
            if B[b][0] == 1:
                L[7] += 1
        elif abs(B[b][0] - B[b][1]) == 2:
            L[7] += 1
            
if 3 in L:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))
l3 = list(map(int,input().split()))
n = int(input())
A = [int(input()) for _ in range(n)]
l4 = []
l5 = []
l6 = []
l7 = []
l8 = []
l4 += [l1[0],l2[0],l3[0]]
l5 += [l1[1],l2[1],l3[1]]
l6 += [l1[2],l2[2],l3[2]]
l7 += [l1[0],l2[1],l3[2]]
l8 += [l1[2],l2[1],l3[0]]
l = []
l += [l1,l2,l3,l4,l5,l6,l7,l8]
for i in A:
    for k in l:
        if i in k:
            k.remove(i)

count=0
for j in l:
    if len(j)==0:
        count += 1
if count == 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys

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

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

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

cnt = 0
for i in range(3):
    if a[i][2-i] in b:
        cnt += 1
if cnt == 3:
    print("Yes")
    sys.exit()

print("No")

Submission status: Accepted

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


list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
list3 = list(map(int, input().split()))
N = int(input())
num_list = [int(input()) for _ in range(N)]

list1.extend(list2)
list1.extend(list3)
hit_list = [0] * 9

for num in num_list:
    res = my_index(list1, num)
    if res != -1:
        hit_list[res] += 1

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

Submission status: Accepted

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

for i in range(N):
    B = input()
    for k in range(3):
        for m in range(3):
            if A[k][m] == B:
                A[k][m] = '-1'


if A[0][0] == '-1' and A[0][1] == '-1' and A[0][2] == '-1':
    print('Yes')
    exit()

if A[1][0] == '-1' and A[1][1] == '-1' and A[1][2] == '-1':
    print('Yes')
    exit()

if A[2][0] == '-1' and A[2][1] == '-1' and A[2][2] == '-1':
    print('Yes')
    exit()

if A[0][0] == '-1' and A[1][0] == '-1' and A[2][0] == '-1':
    print('Yes')
    exit()

if A[0][1] == '-1' and A[1][1] == '-1' and A[2][1] == '-1':
    print('Yes')
    exit()

if A[0][2] == '-1' and A[1][2] == '-1' and A[2][2] == '-1':
    print('Yes')
    exit()

if A[0][0] == '-1' and A[1][1] == '-1' and A[2][2] == '-1':
    print('Yes')
    exit()

if A[0][2] == '-1' and A[1][1] == '-1' and A[2][0] == '-1':
    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())
for i in range(n):
    b = int(input())
    for j in a:
        if b in j:
            a[a.index(j)][j.index(b)] = 0

ans = 0
for i in range(3):
    if a[0][i] == a[1][i] == a[2][i] == 0:
        ans = 1
    elif a[i][0] == a[i][1] == a[i][2] == 0:
        ans = 1
if a[0][0] == a[1][1] == a[2][2] == 0:
    ans = 1
if a[0][2] == a[1][1] == a[2][0] == 0:
    ans = 1

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

Submission status: Accepted

Solution code:
import collections

mat = [map(int,raw_input().split(' ')) for _ in range(3)]
d = {mat[i][j] : (i,j) for i in range(3) for j in range(3)} 
n = int(raw_input())

cols = collections.Counter()
rows = collections.Counter()
ac = collections.Counter()
cc = collections.Counter()
flag = False
for __ in range(n):
	h = d.get(int(raw_input()), None)
	if h is not None:
		i,j = h
		cols[j]+=1
		rows[i]+=1
		if i == j: cc[0]+=1
		if j == 2- i: ac[0]+=1
		
		if (cols[j] == 3) or (rows[i] == 3) or (cc[0] == 3) or (ac[0] == 3):
			flag = True
			break
print 'Yes' if flag else 'No'

Submission status: Accepted

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


def main():
    A = [list(map(int, input().split()))for _ in range(3)]
    N = int(input())
    B = [int(input()) for _ in range(N)]
    for bn in B:
        for i in range(len(A)):
            for j in range(len(A[i])):
                if bn == A[i][j]:
                    A[i][j] = 0
    for m in range(len(A)):
        if all(A[m][n] == 0 for n in range(len(A))):
            print("Yes")
            exit()
        if all(A[n][m] == 0 for n in range(len(A))):
            print("Yes")
            exit()
        if all(A[n][n] == 0 for n in range(len(A))):
            print("Yes")
            exit()
        if all(A[n][len(A)-n-1] == 0 for n in range(len(A))):
            print("Yes")
            exit()
    print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

N = int(input())
b = [int(input()) for _ in range(N)]

candidates = []

for i in range(len(card)):
    candidates.append(card[i])

for i in range(len(card[0])):
    candidates.append([card[j][i] for j in range(len(card))])

candidates.append([card[0][0], card[1][1], card[2][2]])
candidates.append([card[0][2], card[1][1], card[2][0]])

if any([all([num in b for num in c]) for c in candidates]):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

def bingo_check(card):
    naname = (card[0] and card[4] and card[8]) \
                or (card[2] and card[4] and card[6])
    yoko = all(card[0:3]) or all(card[3:6]) or all(card[6:9])
    tate = all(card[0::3]) or all(card[1::3]) or all(card[2::3])
    return naname or yoko or tate

for i in range(N):
    if b[i] in A:
        index = A.index(b[i])
        card[index] = True

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