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 = []
check = []
for i in range(3):
    a.append([int(j) for j in input().split()])

d1 = [a[0][0],a[1][1], a[2][2]]
d2 = [a[0][2],a[1][1], a[2][0]]
col1 = [a[0][0],a[1][0], a[2][0]]
col2 = [a[0][1],a[1][1], a[2][1]]
col3 = [a[0][2],a[1][2], a[2][2]]

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

if all(elem in check for elem in d1):
    print("Yes")
elif all(elem in check for elem in d2):
    print("Yes")
elif all(elem in check for elem in col1):
    print("Yes")
elif all(elem in check for elem in col2):
    print("Yes")
elif all(elem in check for elem in col3):
    print("Yes")
elif all(elem in check for elem in a[0]):
    print("Yes")
elif all(elem in check for elem in a[1]):
    print("Yes")
elif all(elem in check for elem in a[2]):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A1_1,A1_2,A1_3 = map(int, input().split())
A2_1,A2_2,A2_3 = map(int, input().split())
A3_1,A3_2,A3_3 = map(int, input().split())
N =int(input())
B = []
for _ in range(N):
    B.append(int(input()))

a=str('Yes')
b=str('No')
if A1_1 in B and A1_2 in B and A1_3 in B:
     print(a)
elif A2_1 in B and A2_2 in B and A2_3 in B:
    print(a)
elif A3_1 in B and A3_2 in B and A3_3 in B:
     print(a)
elif A1_1 in B and A2_1 in B and A3_1 in B:
    print(a)
elif A1_2 in B and A2_2 in B and A3_2 in B:
    print(a)
elif A1_3 in B and A2_3 in B and A3_3 in B:
    print(a)
elif A1_1 in B and A2_2 in B and A3_3 in B:
     print(a)
elif A1_3 in B and A2_2 in B and A3_1 in B:
    print(a)
else:
    print(b)

Submission status: Accepted

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

for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                A[i][j]="HIT"
                
if A[0][0]==A[0][1]==A[0][2]=="HIT":
        ans=1
if A[1][0]==A[1][1]==A[1][2]=="HIT":
        ans=1
if A[2][0]==A[2][1]==A[2][2]=="HIT":
        ans=1
if A[0][0]==A[1][0]==A[2][0]=="HIT":
        ans=1
if A[0][1]==A[1][1]==A[2][1]=="HIT":
        ans=1
if A[0][2]==A[1][2]==A[2][2]=="HIT":
        ans=1
if A[0][0]==A[1][1]==A[2][2]=="HIT":
        ans=1
if A[0][2]==A[1][1]==A[2][0]=="HIT":
        ans=1
        
print("Yes" if ans else "No")

Submission status: Accepted

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

    for j in range(3):
        for k in range(3):
            if l[j][k] == m:
                l[j][k] = -1
o=0
p=0
for j in range(3):
    for k in range(3):
        o+=l[j][k]
        p+=l[k][j]
    if o==-3 or p==-3:
        print('Yes')
        exit()
    o=0
    p=0
if l[0][0]+l[1][1]+l[2][2]==-3 or l[0][2]+l[1][1]+l[2][0]==-3:
    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())
for i in range(N):
  tmp=int(input())
  for j in range(3):
    if tmp ==A[j]:
      A[j]=-1
    if tmp ==B[j]:
      B[j]=-1
    if tmp ==C[j]:
      C[j]=-1
if A[0]==A[1]==A[2]==-1:
  print('Yes')
  exit()
if B[0]==B[1]==B[2]==-1:
  print('Yes')
  exit()
if C[0]==C[1]==C[2]==-1:
  print('Yes')
  exit()
if A[0]==B[0]==C[0]==-1:
  print('Yes')
  exit()
if A[1]==B[1]==C[1]==-1:
  print('Yes')
  exit()
if A[2]==B[2]==C[2]==-1:
  print('Yes')
  exit()
if A[0]==B[1]==C[2]==-1:
  print('Yes')
  exit()
if C[0]==B[1]==A[2]==-1:
  print('Yes')
  exit() 
print('No')

Submission status: Accepted

Solution code:
bingo = [ input().split() for j in range(3)]
N = int(input())
b = []
for n in range(N):
	b.append(input())
for x in range(N):
	for i in range(3):
		for j in range(3):
			if bingo[i][j] == b[x]:
				bingo[i][j] = 'OK'
if bingo[0][0] == 'OK' and bingo[0][1] == 'OK' and bingo[0][2] == 'OK':
	print('Yes')
elif bingo[1][0] == 'OK' and bingo[1][1] == 'OK' and bingo[1][2] == 'OK':
	print('Yes')
elif bingo[2][0] == 'OK' and bingo[2][1] == 'OK' and bingo[2][2] == 'OK':
	print('Yes')
elif bingo[0][1] == 'OK' and bingo[1][1] == 'OK' and bingo[2][1] == 'OK':
	print('Yes')
elif bingo[0][0] == 'OK' and bingo[1][0] == 'OK' and bingo[2][0] == 'OK':
	print('Yes')
elif bingo[0][2] == 'OK' and bingo[1][2] == 'OK' and bingo[2][2] == 'OK':
	print('Yes')
elif bingo[0][0] == 'OK' and bingo[1][1] == 'OK' and bingo[2][2] == 'OK':
	print('Yes')
elif bingo[0][2] == 'OK' and bingo[1][1] == 'OK' and bingo[2][0] == 'OK':
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
def q2(data, num_list):
    data = [int(num) for d in data for num in d.split()]
    num_list = [int(n) for n in num_list]

    for num in num_list:
        data = [d if d != num else 0 for d in data]
        if check_bingo(data):
            return 'Yes'

    else:
        return 'No'


def check_bingo(data):
    # case1
    if sum(data[:3]) == 0: return True
    if sum(data[3:6]) == 0: return True
    if sum(data[6:]) == 0: return True
    if sum([data[0], data[3], data[6]]) == 0: return True
    if sum([data[3*i+1] for i in range(3)]) == 0: return True
    if sum([data[3*i + 2] for i in range(3)]) == 0: return True
    if sum([data[0], data[4], data[8]]) == 0: return True
    if sum([data[2], data[4], data[6]]) == 0: return True

    return False
  

data = [input() for _ in range(3)]

num = int(input())

num_list = [int(input()) for _ in range(num)]

print(q2(data, num_list))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys

DEBUG = False

def solve():
    return


def read_int_list(sep = " "):
    return [int(s) for s in sys.stdin.readline().rstrip().split(sep)]

def read_int():
    return int(sys.stdin.readline())

def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return

def printbingo(bingo):
    if not DEBUG:
        return
    for y in range(0, 3):
        for x in range(0, 3):
            print(bingo[y][x], end=" ")
        print()


def main():
    bingo = [[]] * 3
    bingo[0] = read_int_list()
    bingo[1] = read_int_list()
    bingo[2] = read_int_list()
    locs = {}
    for y in range(0, 3):
        for x in range(0, 3):
            locs[bingo[y][x]] = (y, x)
    printbingo(bingo)
            
    n = read_int()
    for _ in range(0, n):
        b = read_int()
        if b in locs:
            bingo[locs[b][0]][locs[b][1]] = -1
    printbingo(bingo)
    
    # column check
    for y in range(0, 3):
        is_bingo = True
        for x in range(0, 3):
            if bingo[y][x] != -1:
                is_bingo = False
                break
        if is_bingo:
            print("Yes")
            return
    # row check
    for x in range(0, 3):
        is_bingo = True
        for y in range(0, 3):
            if bingo[y][x] != -1:
                is_bingo = False
                break
        if is_bingo:
            print("Yes")
            return
    # cross check
    for (y, x), (dy, dx) in [((0, 0), (1, 1)), ((0, 2), (1, -1))]:
        is_bingo = True
        while is_bingo and 0 <= y < 3 and 0 <= x < 3:
            #dprint(f"(x,y):{(x, y)}, (dx,dy):{(dx,dy)}, bing[y][x]: {bingo[y][x]}")
            if bingo[y][x] != -1:
                is_bingo = False
                break
            y += dy
            x += dx
        if is_bingo:
            print("Yes")
            return
    print("No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A11,A12,A13 = map(int, input().split())

A21,A22,A23 = map(int, input().split())

A31,A32,A33 = map(int, input().split())

A1 = [A11, A12, A13]
A2 = [A21, A22, A23]
A3 = [A31, A32, A33]

B1 = [0, 0, 0]
B2 = [0, 0, 0]
B3 = [0, 0, 0]

N = input()
N = int(N)

b = list(range(N))

for l in b:
    b[l] = input()
    b[l] = int(b[l])

for i in range(N):
    if b[i] == A1[0]:
        B1[0] = 1
    elif b[i] == A1[1]:
        B1[1] = 1
    elif b[i] == A1[2]:
        B1[2] = 1
    elif b[i] == A2[0]:
        B2[0] = 1
    elif b[i] == A2[1]:
        B2[1] = 1
    elif b[i] == A2[2]:
        B2[2] = 1
    elif b[i] == A3[0]:
        B3[0] = 1
    elif b[i] == A3[1]:
        B3[1] = 1
    elif b[i] == A3[2]:
        B3[2] = 1

Bingo = 0

if B1[0] == 1 and B1[1] == 1 and B1[2] == 1:
    Bingo = 1
elif B2[0] == 1 and B2[1] == 1 and B2[2] == 1:
    Bingo = 1
elif B3[0] == 1 and B3[1] == 1 and B3[2] == 1:
    Bingo = 1
elif B1[0] == 1 and B2[0] == 1 and B3[0] == 1:
    Bingo = 1
elif B1[1] == 1 and B2[1] == 1 and B3[1] == 1:
    Bingo = 1
elif B1[2] == 1 and B2[2] == 1 and B3[2] == 1:
    Bingo = 1
elif B1[0] == 1 and B2[1] == 1 and B3[2] == 1:
    Bingo = 1
elif B1[2] == 1 and B2[1] == 1 and B3[0] == 1:
    Bingo = 1

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

Submission status: Accepted

Solution code:
import numpy as np
ary=[]
ary_=[]
num=[]
for i in range(3):
    lst=input().split()
    ary.append(lst)
n=int(input())
for i in range(n):
    num.append(input())

for i in range(3):
    for j in range(3):
        for k in num:
            if ary[i][j]==k:
                ary[i][j]=0

for i in range(3):
    if set(ary[i])=={0}:
        print('Yes')
        exit()
    elif ary[0][i]==0 and ary[0][i]==ary[1][i] and ary[2][i]==ary[0][i]:
        print('Yes')
        exit()
if ary[0][0]==0 and ary[1][1]==ary[0][0] and ary[2][2]==ary[0][0]:
    print('Yes')
    
elif ary[2][0]==0 and ary[2][0]==ary[1][1] and ary[1][1]==ary[0][2]:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np
A = np.zeros((3,3), dtype = "int")
A[0,0], A[0,1], A[0,2] = map(int,input().split())
A[1,0], A[1,1], A[1,2] = map(int,input().split())
A[2,0], A[2,1], A[2,2] = map(int,input().split())
N= int(input())
b = [int(input()) for i in range(N)]
for i in range(3):
	for j in range(3):
		for k in range(N):
			if A[i,j] == b[k]:
				A[i,j] = 0
if (A[0,0] == 0 and A[0,1] == 0 and A[0,2] ==0) or (A[1,0] == 0 and A[1,1] == 0 and A[1,2] == 0) or (A[2,0] ==0 and A[2,1] ==0 and A[2,2] == 0) or (A[0,0] == 0 and A[1,1] == 0 and A[2,2] == 0) or (A[2,0] == 0 and A[1,1] == 0 and A[0,2] == 0) or (A[0,0] == 0 and A[1,0] == 0 and A[2,0] == 0) or (A[0,1] == 0 and A[1,1] == 0 and A[2,1] == 0) or (A[0,2] == 0 and A[1,2] == 0 and A[2,2] == 0):
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
import sys

l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
n = int(input())
if n < 3:
  print("No")
  sys.exit()

l = [int(input()) for i in range(n)]
if (l1[0] in l and l1[1] in l and l1[2] in l) or (l2[0] in l and l2[1] in l and l2[2] in l) or (l3[0] in l and l3[1] in l and l3[2] in l) or (l1[0] in l and l2[0] in l and l3[0] in l) or (l1[1] in l and l2[1] in l and l3[1] in l) or (l1[2] in l and l2[2] in l and l3[2] in l) or (l1[0] in l and l2[1] in l and l3[2] in l) or (l1[2] in l and l2[1] in l and l3[0] in l):
  print("Yes")
  sys.exit()
else:
  print("No")

Submission status: Accepted

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

for b in Bs:
    for x in range(3):
        for y in range(3):
            if AAs[x][y] == b:
                CCs[x][y] = True

def check():
    for cs in CCs:
        if all(cs): 
            return True
    for cs in list(map(list, zip(*CCs))):
        if all(cs): 
            return True
    if CCs[0][0] and CCs[1][1] and CCs[2][2]:
        return True
    if CCs[0][2] and CCs[1][1] and CCs[2][0]:
        return True

    return False

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

Submission status: Accepted

Solution code:
H1 = [int(i) for i in input().split()]
H2 = [int(i) for i in input().split()]
H3 = [int(i) for i in input().split()]
N = int(input())
num = [int(input()) for i in range(N)]

L1 = [H1[0], H2[0], H3[0]]
L2 = [H1[1], H2[1], H3[1]]
L3 = [H1[2], H2[2], H3[2]]

S1 =[H1[0], H2[1], H3[2]]
S2 = [H1[2], H2[1], H3[0]]

ans = []
for i in [H1,H2,H3,L1,L2,L3,S1,S2]:
    i.extend(num)

ans = []
for i in [H1,H2,H3,L1,L2,L3,S1,S2]:
    ans.append(len(set(i)))

if min(ans) == N:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A_list = []
for i in range(3):
    A = list(map(int, input().split()))
    A_list.append(A)
N = int(input())
for i in range(N):
    B = int(input())
    for j in range(3):
        for k in range(3):
            if A_list[j][k]==B:
                A_list[j][k] = -1
flag = False
for i in range(3):
    if A_list[0][i] == -1 and A_list[1][i] == -1 and A_list[2][i] == -1:
        flag = True
if flag!=True:
    for i in range(3):
        if A_list[i][0] == -1 and A_list[i][1] == -1 and A_list[i][2] == -1:
            flag = True
    if flag!=True:
        if (A_list[0][0] == -1 and A_list[1][1] == -1 and A_list[1][1] == -1) or (A_list[0][2] == -1 and A_list[1][1] == -1 and A_list[2][0] == -1):
            flag = True
print("Yes") if flag else print("No")

Submission status: Accepted

Solution code:
l = []
flag = 0
for i in range(3):
  for j in input().split():
    l.append(j)
n = int(input())
for i in range(n):
  a = input()
  if a in l:
    l[l.index(a)] = 0
if not any(l[0:3])  or not any(l[3:6]) or not any(l[6:9]):
  flag = 1
if not any(l[0::3]) or not any(l[1::3]) or not any(l[2::3]):
  flag = 1
if not any(l[0::4]) or not any(l[2:7:2]):
  flag = 1
if flag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import itertools
A=[list(map(int,input().split())) for i in range(3)]
A=list(itertools.chain.from_iterable(A))
N=int(input())
for _ in range(N):
    b=int(input())
    try:
        A[A.index(b)]="X"
    except:
        continue
answer="No"
for bingo in [[0,1,2],[3,4,5],[6,7,8],[0,4,8],[2,4,6],[0,3,6],[1,4,7],[2,5,8]]:
    if A[bingo[0]]=="X" and A[bingo[1]]=="X" and A[bingo[2]]=="X":
        answer="Yes"
print(answer)

Submission status: Accepted

Solution code:
import sys
a = []
b = []
c = [[False for i in range(3)] for i in range(3)]
for i in range(3):
    a.append(list(map(int, input().split())))

n = int(input())
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 a[j][k] == b[i]:
                c[j][k] = True
# 縦
for i in range(3):
    if c[i] == [True, True, True]:
        print("Yes")
        sys.exit(0)

for i in range(3):
    if [c[0][i], c[1][i], c[2][i]] == [True, True, True]:
        print("Yes")
        sys.exit(0)

if [c[0][0], c[1][1], c[2][2]] == [True, True, True] or [c[0][2], c[1][1], c[2][0]] == [True, True, True]:
    print("Yes")
    sys.exit(0)
print("No")

Submission status: Accepted

Solution code:
A = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
B = [int(input()) for i in range(n)]
C = []
for a in A:
    a = ['o' if x in B else x for x in a]
    C.append(a)
for c in C:
    if c==['o','o','o']:
        print('Yes')
        exit()
for c in zip(*C):
    if list(c)==['o','o','o']:
        print('Yes')
        exit()
if C[0][0]==C[1][1]==C[2][2]=='o' or C[0][2]==C[1][1]==C[2][0]=='o':
    print('Yes')
    exit()
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()))
temp_list = []
temp_list.append(A1)
temp_list.append(A2)
temp_list.append(A3)

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

N = int(input())
for _ in range(N):
    temp = int(input())
    if (temp in A1):
      bingo_list[0][A1.index(temp)] = 1
    if (temp in A2):
      bingo_list[1][A2.index(temp)] = 1
    if (temp in A3):
      bingo_list[2][A3.index(temp)] = 1

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

Submission status: Accepted

Solution code:
rows = []
for i in range(3):
    row = [int(x) for x in input().split()]
    rows.append(row)


columns = []
for k in range(3):
    column = [rows[l][k] for l in range(3)]
    columns.append(column)

left = []
for m in range(3):
    left.append(rows[m][m])

right = []
o = 2
for n in range(3):
    right.append(rows[n][o])
    o -= 1


N = int(input())
choice = []
for j in range(N):
    choice.append(int(input()))


matches = []
for row in rows:
    matches.append([c for c in row if c in choice])

for column in columns:
    matches.append([c for c in column if c in choice])

matches.append([c for c in left if c in choice])
matches.append([c for c in right if c in choice])


isPrinted = False
for match in matches:
    if (len(match) == 3):
        print("Yes")
        isPrinted = True
        break

if (not isPrinted):
    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())
b = np.array([])
for _ in range(N):
    b = np.append(b, int(input()))
    
A = np.array([A1, A2, A3])
index = np.zeros((3,3))
for i in b:
  index += np.array(A==i, dtype=np.int)
retu = np.sum(index, axis=0)
gyou = np.sum(index, axis=1)
if np.any(retu >= 3):
  ans1 = 1
else:
  ans1 = 0

if np.any(gyou >= 3):
  ans2 = 1
else:
  ans2 = 0
  

if np.trace(index) >= 3:
  ans3 = 1
else:
  ans3 = 0
index = index[:, ::-1]
if np.trace(index) >= 3:
  ans4 = 1
else:
  ans4 = 0

y = ans1 + ans2 + ans3 + ans4
if y == 0:
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, i = map(int, input().split())
N = int(input())

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

for j in num_list:
    if a == j:
        a = 101
    if b == j:
        b = 101
    if c == j:
        c = 101
    if d == j:
        d = 101
    if e == j:
        e = 101
    if f == j:
        f = 101
    if g == j:
        g = 101
    if h == j:
        h = 101
    if i == j:
        i = 101

answer = 'No'
if a + b + c == 303:
    answer = 'Yes'
if d + e + f == 303:
    answer = 'Yes'
if g + h + i == 303:
    answer = 'Yes'
if a + d + g == 303:
    answer = 'Yes'
if b + e + h == 303:
    answer = 'Yes'
if c + f + i == 303:
    answer = 'Yes'
if a + e + i == 303:
    answer = 'Yes'
if c + e + g == 303:
    answer = 'Yes'

print(answer)

Submission status: Accepted

Solution code:
import sys

a = [list(map(int, sys.stdin.readline().split())) for _ in range(3)]
n, *b = map(int, sys.stdin.read().split())
b = set(b)

def main():
    res = [[False] * 3 for _ in range(3)]
    for i in range(3):
        for j in range(3):
            if a[i][j] in b:
                res[i][j] = True
    
    for i in range(3):
        for j in range(3):
            if not res[i][j]:
                break
        else:
            return 'Yes'
    
    for j in range(3):
        for i in range(3):
            if not res[i][j]:
                break
        else:
            return 'Yes'
    
    for i, j in zip(range(3), range(3)):
        if not res[i][j]:
            break
    else:
        return 'Yes'
    
    for i, j in zip(range(3), range(2, -1, -1)):
        if not res[i][j]:
            break
    else:
        return 'Yes'
    
    return 'No'

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
lines = [input().split() for i in range(3)]
 
num = int(input())
bs = []
for i in range(num):
  bs.append(input())
 
hits = []
for i in bs:
  for row_index in range(len(lines)):
    for col_index in range(len(lines[row_index])):
      if lines[row_index][col_index] == i:
        hits.append((row_index,col_index))
row_hits = [0,0,0]
col_hits = [0,0,0]
stride_hits = [0,0]
 
for hit in hits:
  r = hit[0]
  c = hit[1]
  row_hits[r]+=1
  col_hits[c]+=1
  if r == c:
    stride_hits[0]+=1
  if (r,c) == (0,2) or (r,c) == (1,1) or (r,c) == (2,0) :
    stride_hits[1]+=1
 
if max(row_hits)>= 3 or max(col_hits)>=3 or max(stride_hits)>= 3:
  print ('Yes')
else:
  print ('No')

Submission status: Accepted

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

n = int(input())
b = [int(input()) for i in range(n)]
c = []
for ii in range(n):
    for iii in range(9):
        if b[ii] == l[iii]:
            c.append(iii)
            break
flag = 'No'
for i in range(3):
    if 3*i in c and 3*i+1 in c and 3*i+2 in c:
        flag = 'Yes'
        break
    if i in c and 3+i in c and 6+i in c:
        flag = 'Yes'
        break
if 0 in c and 4 in c and 8 in c:
    flag = 'Yes'
elif 2 in c and 4 in c and 6 in c:
    flag = 'Yes'

print(flag)

Submission status: Accepted

Solution code:
import numpy as np

def in1d(ar1, ar2, assume_unique=False, invert=False):
    # Ravel both arrays, behavior for the first array could be different
    ar1 = np.asarray(ar1).ravel()
    ar2 = np.asarray(ar2).ravel()

    # Check if one of the arrays may contain arbitrary objects
    contains_object = ar1.dtype.hasobject or ar2.dtype.hasobject

    # This code is run when
    # a) the first condition is true, making the code significantly faster
    # b) the second condition is true (i.e. `ar1` or `ar2` may contain
    #    arbitrary objects), since then sorting is not guaranteed to work
    if len(ar2) < 10 * len(ar1) ** 0.145 or contains_object:
        if invert:
            mask = np.ones(len(ar1), dtype=bool)
            for a in ar2:
                mask &= (ar1 != a)
        else:
            mask = np.zeros(len(ar1), dtype=bool)
            for a in ar2:
                mask |= (ar1 == a)
        return mask

    # Otherwise use sorting
    if not assume_unique:
        ar1, rev_idx = np.unique(ar1, return_inverse=True)
        ar2 = np.unique(ar2)

    ar = np.concatenate((ar1, ar2))
    # We need this to be a stable sort, so always use 'mergesort'
    # here. The values from the first array should always come before
    # the values from the second array.
    order = ar.argsort(kind='mergesort')
    sar = ar[order]
    if invert:
        bool_ar = (sar[1:] != sar[:-1])
    else:
        bool_ar = (sar[1:] == sar[:-1])
    flag = np.concatenate((bool_ar, [invert]))
    ret = np.empty(ar.shape, dtype=bool)
    ret[order] = flag

    if assume_unique:
        return ret[:len(ar1)]
    else:
        return ret[rev_idx]

def isin(element, test_elements, assume_unique=False, invert=False):
    element = np.asarray(element)
    return in1d(element, test_elements, assume_unique=assume_unique,
                invert=invert).reshape(element.shape)
A = []
for i in range(3):
    A.append(list(map(int, input().split())))
A = np.array(A)

N = int(input())
b = np.zeros(N, dtype=np.int)
for i in range(N):
    b[i] = int(input())
T = isin(A,b)
ans=[0,0,0,0]
ans[0]=T.all(axis=0).any()
ans[1]=T.all(axis=1).any()
ans[2]=np.diag(T).all()
ans[3]=np.diag(T[:,[2,1,0]]).all()
if any(ans):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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


def create_bingo_card():
  result = [[0, 0, 0] for x in range(3)]
  i = 0
  while True:
    i2 = 0
    while True:
      if bs[i2] in As[i]:
        result[i][As[i].index(bs[i2])] += 1
      i2 += 1
      if i2 == len(bs):
        break
    i += 1
    if i == len(As):
      break
  return result


def solvd(bingo):
  tmp = [bingo[0][0], bingo[1][1], bingo[2][2]]
  if check1(tmp):
    print("Yes")
    return

  tmp = [bingo[0][2], bingo[1][1], bingo[2][0]]
  if check1(tmp):
    print("Yes")
    return

  r = 0
  for x in range(3):
    tmp = [bingo[0][x], bingo[1][x], bingo[2][x]]
    if check1(tmp):
      print("Yes")
      return

    bingoSet = set(bingo[x])
    if check2(bingoSet):
      r += 1

  if r >= 1:
    print("Yes")
    return
  print("No")


def check1(s):
  return s.count(1) == 3


def check2(s):
  return not (0 in list(s))


def main():
  Cs = create_bingo_card()
  solvd(Cs)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    re_dict_nums = dict()
    done_list = [0 for _ in range(9)]
    cnt = 0
    for _ in range(3):
        for s in map(int, input().split(' ')):
            re_dict_nums[s] = cnt
            cnt += 1
    for n in range(int(input())):
        try:
            done_list[re_dict_nums[int(input())]] = 1
        except KeyError:
            pass
    flag = False
    if done_list[4] == 1:
        if (done_list[0] == 1 and done_list[8] == 1) or (done_list[1] == 1 and done_list[7] == 1) or (
                done_list[2] == 1 and done_list[6] == 1) or 0 not in done_list[3:6]:
            flag = True
    if flag is False:
        if (0 not in done_list[:3]) or (0 not in done_list[6:]) or (
                done_list[0] == 1 and done_list[3] == 1 and done_list[6] == 1) or (
                done_list[2] == 1 and done_list[5] == 1 and done_list[8] == 1):
            flag = True
    if flag:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

    ans='No'
    for i in range(3):
        if c[i]==[1,1,1]:
            ans='Yes'
    for i in range(3):
        if [c[0][i],c[1][i],c[2][i]]==[1,1,1]:
            ans='Yes'
    if [c[0][0],c[1][1],c[2][2]]==[1,1,1]:
        ans='Yes'
    if [c[0][2],c[1][1],c[2][0]]==[1,1,1]:
        ans='Yes'
    print(ans)
resolve()

Submission status: Accepted

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

n=int(input())

for _ in range(n):
    x=int(input())
    for i in range(3):
        for j in range(3):
            if x==A[i][j]:
                A[i][j]=0
ans='No'
if A[1][1]==0:
    if A[0][0]==0 and A[2][2]==0:
        ans='Yes'
    if A[0][2]==0 and A[2][0]==0:
        ans='Yes'

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

Submission status: Accepted

Solution code:
x=[[]*3]*3
o=[[0] * 3 for i in range(3)]

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

n=int(input())

for i in range(0,n):
  b=int(input())
  for j in range(0,3):
    for k in range(0,3):
      if x[j][k]==b:
        o[j][k]=1

for i in range(0,3):
  if o[i][0]==1 and o[i][1]==1 and o[i][2]==1:
    print("Yes")
    exit()

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

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

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

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

n = 0
o = 0
p = 0
q = 0
r = 0
s = 0
t = 0
u = 0


for i in num:
    if i in [A[0],A[1],A[2]]:
        n += 1
for j in num:
    if j in [B[0],B[1],B[2]]:
        t += 1
for k in num:
    if k in [C[0],C[1],C[2]]:
        u += 1
for l in num:
    if l in [A[0],B[0],C[0]]:
        o += 1
for m in num:
    if m in [A[1],B[1],C[1]]:
        p += 1
for v in num:
    if v in [A[2],B[2],C[2]]:
        q += 1
for w in num:
    if w in [A[0],B[1],C[2]]:
        r += 1
for x in num:
    if x in [A[2],B[1],C[0]]:
        s += 1

if n >= 3 or o >= 3 or p >= 3 or q >= 3 or r >= 3 or s >= 3 or t >= 3  or u >= 3:
    print("Yes")
else:
    print('No')

Submission status: Accepted

Solution code:
a,b,c = [input().split() for i in range(3)]

a.extend(b)
a.extend(c)
N = int(input())
b = [input() for i in range(N)]
for b1 in b:
    a = ['a' if b1 == s in s else s for s in a]

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