Problem:


Score : 200 points

Problem Statement

We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}.

The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet.

Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.

Constraints

All values in input are integers.

1 \leq A_{i, j} \leq 100

A_{i_1, j_1} \neq A_{i_2, j_2} ((i_1, j_1) \neq (i_2, j_2))

1 \leq N \leq 10

1 \leq b_i \leq 100

b_i \neq b_j (i \neq j)

Input

Input is given from Standard Input in the following format:

A_{1, 1} A_{1, 2} A_{1, 3}
A_{2, 1} A_{2, 2} A_{2, 3}
A_{3, 1} A_{3, 2} A_{3, 3}
N
b_1
\vdots
b_N

Output

If we will have a bingo, print Yes; otherwise, print No.

Sample Input 1

84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30

Sample Output 1

Yes

We will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3}, and complete the diagonal from the top-left to the bottom-right.

Sample Input 2

41 7 46
26 89 2
78 92 8
5
6
45
16
57
17

Sample Output 2

No

We will mark nothing.

Sample Input 3

60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34

Sample Output 3

Yes

We will mark all the squares.



Sample input:
84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30


Sample output:
Yes

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7


def bingo(c):
    for i in range(3):
        flag = [False for _ in range(3)]
        for j in range(3):
            if c[i][j]:
                flag[j] = True
        if flag[0] and flag[1] and flag[2]:
            return True
    for i in range(3):
        flag = [False for _ in range(3)]
        for j in range(3):
            if c[j][i]:
                flag[j] = True
        if flag[0] and flag[1] and flag[2]:
            return True
    flag = [False for _ in range(3)]
    for i in range(3):
        if c[i][i]:
            flag[i] = True
    if flag[0] and flag[1] and flag[2]:
        return True
    flag = [False for _ in range(3)]
    for i in range(3):
        if c[i][2-i]:
            flag[i] = True
    if flag[0] and flag[1] and flag[2]:
        return True
    return False


a = [LIST() for _ in range(3)]
c = [[0 for _ in range(3)] for _ in range(3)]
n = int(input())
for _ in range(n):
    b = int(input())
    d = -1
    e = -1
    for i in range(3):
        if b in a[i]:
            d = i
            e = a[i].index(b)
    if d != -1:
        c[d][e] = 1
    if bingo(c):
        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()))
a = a1 + a2 + a3

n = int(input())

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

l = []
for x in a:
    if x in b:
        l.append('o')
    else:
        l.append('x')

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

Submission status: Accepted

Solution code:
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a1.extend(a2)
a3 = list(map(int, input().split()))
a1.extend(a3)

n = int(input())

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

l = []
for x in a1:
    if x in b:
        l.append('o')
    else:
        l.append('x')

if l[0] == l[1] == l[2] == 'o' or l[3] == l[4] == l[5] == 'o' or l[6] == l[7] == l[8] == 'o' or l[0] == l[3] == l[6] == 'o' or l[1] == l[4] == l[7] == 'o' or l[2] == l[5] == l[8] == 'o' or l[0] == l[4] == l[8] == 'o' or l[2] == l[4] == l[6] == 'o' :
    print('Yes')
else:
    print('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()))

box = [[0] * 3 for _ in range(3)]

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

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

Submission status: Accepted

Solution code:
A=[]
b=[]
c=[[0,0,0],[0,0,0],[0,0,0]]
d=[[0,0,0],[0,0,0],[0,0,0]]
for i in range(3):
    x,y,z=map(int,input().split())
    A.append([x,y,z])

N = int(input())

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

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

if [1,1,1] in c:
    print('Yes')
elif [1,1,1] in d:
    print('Yes')
elif (c[0][0]+c[1][1]+c[2][2] == 3) or (c[0][2]+c[1][1]+c[2][0] == 3):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    a = [list(map(int, input().rstrip('\n').split())) for _ in range(3)]
    n = int(input().rstrip('\n'))
    for _ in range(n):
        b = int(input().rstrip('\n'))
        for i in range(3):
            for j in range(3):
                if a[i][j] == b:
                    a[i][j] = -1
    for i in range(3):
        if a[i][0] == a[i][1] == a[i][2] == -1:
            print("Yes")
            exit()
        elif a[0][i] == a[1][i] == a[2][i] == -1:
            print("Yes")
            exit()
    if a[0][0] == a[1][1] == a[2][2] == -1:
        print("Yes")
        exit()
    elif a[0][2] == a[1][1] == a[2][0] == -1:
        print("Yes")
        exit()
    print("No")


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def bingo_check():
    from collections import defaultdict
    import sys
    A = []
    pos = {}
    for i in range(3):
        a1, a2, a3 = list(map(int, input().split()))
        A += [[a1, a2, a3]]
        pos[a1] = (i+1, 1)
        pos[a2] = (i+1, 2)
        pos[a3] = (i+1, 3)

    checked = defaultdict(lambda: False)
    N = int(input())
    for _ in range(N):
        b = int(input())
        if pos.get(b):
            checked[pos[b]] = True
    
    ### checked を確認する
    for i in range(1, 4):
        ### 横
        if checked[(i, 1)] and checked[(i, 2)] and checked[(i, 3)]:
            return "Yes"
        ### 縦
        if checked[(1, i)] and checked[(2, i)] and checked[(3, i)]:
            return "Yes"
            

    ### 斜め
    if checked[(1, 1)] and checked[(2, 2)] and checked[(3, 3)]:
        return "Yes"
    if checked[(1, 3)] and checked[(2, 2)] and checked[(3, 1)]:
        return "Yes"
    
    return "No"

print(bingo_check())

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

flg = 0
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')
        flg = 1
        break
    elif (a[0][i] in b) and (a[1][i] in b) and (a[2][i] in b):
        print('Yes')
        flg = 1
        break
    
if flg == 1:
    pass
elif (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:
    print('No')

Submission status: Accepted

Solution code:
A=[]
for i in range(3):
  a=list(map(int,input().split()))
  A+=a
n=int(input())
C=[0]*9
for i in range(n):
  b=int(input())
  for j in range(9):
    if b==A[j]:
         C[j]+=1
if min(C[0:3])>0:
  print('Yes')
elif min(C[3:6])>0:
  print('Yes')
elif min(C[6:9])>0:
  print('Yes')
elif min(C[0::3])>0:
  print('Yes')
elif min(C[1::3])>0:
  print('Yes')
elif min(C[2::3])>0:
  print('Yes')
elif min(C[::4])>0:
  print('Yes')
elif min(C[2],C[4],C[6])>0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(9):
        if b == a[i // 3][i % 3]:
            a[i // 3][i % 3] = 0
flag = True
if a[0][0] == a[0][1] == a[0][2] == 0:
    flag = False
if a[1][0] == a[1][1] == a[1][2] == 0:
    flag = False
if a[2][0] == a[2][1] == a[2][2] == 0:
    flag = False
if a[0][0] == a[1][0] == a[2][0] == 0:
    flag = False
if a[0][1] == a[1][1] == a[2][1] == 0:
    flag = False
if a[0][2] == a[1][2] == a[2][2] == 0:
    flag = False
if a[0][0] == a[1][1] == a[2][2] == 0:
    flag = False
if a[0][2] == a[1][1] == a[2][0] == 0:
    flag = False
print('YNeos' [flag::2])

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(9):
        if b == a[i // 3][i % 3]:
            a[i // 3][i % 3] = 0
flag = False
if a[0][0] == a[0][1] == a[0][2] == 0:
    flag = True
if a[1][0] == a[1][1] == a[1][2] == 0:
    flag = True
if a[2][0] == a[2][1] == a[2][2] == 0:
    flag = True
if a[0][0] == a[1][0] == a[2][0] == 0:
    flag = True
if a[0][1] == a[1][1] == a[2][1] == 0:
    flag = True
if a[0][2] == a[1][2] == a[2][2] == 0:
    flag = True
if a[0][0] == a[1][1] == a[2][2] == 0:
    flag = True
if a[0][2] == a[1][1] == a[2][0] == 0:
    flag = True
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

    N = int(input())
    for _ in range(N):
        a = int(input())
        for i in range(9):
            if B[i] == a:
                B[i] = 0

    bingo = [
        [0,1,2],
        [3,4,5],
        [6,7,8],
        [0,3,6],
        [1,4,7],
        [2,5,8],
        [0,4,8],
        [2,4,6],
        ]
    
    ans = 'No'
    
    for a, b, c in bingo:
        if B[a] == 0 and B[b] == 0 and B[c] == 0:
            ans = 'Yes'

    return ans

print(solve())

Submission status: Accepted

Solution code:
def check_bng(t):
	c = 0
	for i in range(3):
		if t[i][0] + t[i][1] + t[i][2] == -3:
			c = 1
		if t[0][i] + t[1][i] + t[2][i] == -3:
			c = 1
	if t[0][0] + t[1][1] + t[2][2] == -3 or t[2][0] + t[1][1] + t[0][2] == -3:
		c = 1

	return c

def check(b,t):
	for i in range(3):
		if t[i].count(b) == 1:
			t[i][t[i].index(b)] = -1
	return t

if __name__ == '__main__':
	A1 = [int(a) for a in input().split()]
	A2 = [int(a) for a in input().split()]
	A3 = [int(a) for a in input().split()]
	N = int(input())

	t = [A1, A2, A3]

	nlst = []
	for i in range(N):
		check(int(input()),t)

	if check_bng(t) == 1:
		print('Yes')
	else:
		print('No')

Submission status: Accepted

Solution code:
def main():
    A = []
    for _ in range(3):
        a = map(int,input().split())
        A += a
    N = int(input())
    B = [int(input()) for _ in range(N)]
    for i in range(N):
        for j in range(9):
            if A[j] == B[i]:
                A[j] = -1
    ans = False
    #縦方向
    for i in range(3):
        if A[i] == -1 and A[i + 3] == -1 and A[i + 6] == -1 :
            ans = True
    #横
    for i in range(3):
        if A[3 * i] == - 1 and A[3 * i + 1] == -1 and A[3 * i + 2] == -1 :
            ans = True
    #斜め
    for i in [2, 4]:
        if A[4] == -1 and A[4 - i] == -1 and A[4 + i] == -1 :
            ans = True
    if ans :
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

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

AA = [[False, False, False],
[False, False, False],
[False, False, False]]

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

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

Submission status: Accepted

Solution code:
bingo = []
for i in range(3):
    bingo.append(input().split())
N = int(input())

for i in range(N):
    inp=input()
    for j in range(3):
        for h in range(3):
            if bingo[j][h]==inp:
                bingo[j][h]=0

Ans = "No"
for i in range(3):
    if sum([int(x) for x in bingo[i]])==0:
        Ans ="Yes"

for i in range(3):
    if sum([int(row[i]) for row in bingo])==0:
        Ans="Yes"

if int(bingo[0][0])+int(bingo[1][1])+int(bingo[2][2])==0:
    Ans="Yes"
    
if int(bingo[2][0])+int(bingo[1][1])+int(bingo[0][2])==0:
    Ans="Yes"
print(Ans)

Submission status: Accepted

Solution code:
import numpy as np
A = []
C = []
counts = [0]*8
for i in range(3):
  inp = input().split()
  A.append(inp)
  C.append(inp)
A = np.array(A)
for i in range(3):
  C.append(list(A[:,i]))
C.append([A[0,0],A[1,1],A[2,2]])
C.append([A[0,2],A[1,1],A[2,0]])
#print(C)
N = int(input())
for i in range(N):
  b = input()
  for i, c in enumerate(C):
    if b in c:
      counts[i] += 1
if max(counts)==3:
  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 = [int(input()) for i in range(N)]

for i in b:
    for j in range(3):
        if A1[j] == i:
            A1[j] = 0
        if A2[j] == i:
            A2[j] = 0
        if A3[j] == i:
            A3[j] = 0

flag = False
A = [A1,A2,A3]
for i in range(3):
    if sum(A[i]) == 0:
        flag = True
    sum_ = 0
    for j in range(3):
        sum_ += A[j][i]
    if sum_ == 0:
        flag = True

if A1[0] + A2[1] + A3[2] == 0:
    flag = True
if A1[2] + A2[1] + A3[0] == 0:
    flag = True
print('Yes' if flag else 'No')

Submission status: Accepted

Solution code:
a_list=[]
a_list.append(list(map(int, input().split())))
a_list.append(list(map(int, input().split())))
a_list.append(list(map(int, input().split())))
n = int(input())
b=[]
for i in range(n):
  b_i = int(input())
  b.append(b_i)
  for j in range(len(a_list)):
    for k in range(len(a_list[j])):
      if a_list[j][k] == b_i:
        a_list[j][k] = -1
    
if ((a_list[0][0]==-1 and a_list[0][1] == -1 and a_list[0][2] == -1) or
    (a_list[1][0]==-1 and a_list[1][1] == -1 and a_list[1][2] == -1) or
    (a_list[2][0]==-1 and a_list[2][1] == -1 and a_list[2][2] == -1) or
    (a_list[0][0]==-1 and a_list[1][0] == -1 and a_list[2][0] == -1) or
    (a_list[0][1]==-1 and a_list[1][1] == -1 and a_list[2][1] == -1) or
    (a_list[0][2]==-1 and a_list[1][2] == -1 and a_list[2][2] == -1) or
    (a_list[0][0]==-1 and a_list[1][1] == -1 and a_list[2][2] == -1) or
    (a_list[0][2]==-1 and a_list[1][1] == -1 and a_list[2][0] == -1)):

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

Submission status: Accepted

Solution code:
import numpy as np
a = []
a.append(input().split())
a.append(input().split())
a.append(input().split())
a = np.array(a).astype(int)

N = int(input())
for i in range(N):
    a[a == int(input())] = -1
    
def check(a):
    if a.max(axis=0).min() == -1:
        return "Yes"
    if a.max(axis=1).min() == -1:
        return "Yes"
    if a[0,0] + a[1,1] + a[2,2] == -3:
        return "Yes"
    if a[2,0] + a[1,1] + a[0,2] == -3:
        return "Yes"
    return "No"
print(check(a))

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())
a_list=[a1_1, a1_2, a1_3, a2_1, a2_2, a2_3, a3_1, a3_2, a3_3]
n = int(input())
b=[]
for i in range(n):
  b_i = int(input())
  b.append(b_i)
  for j, a_j in enumerate(a_list):
    if a_j == b_i:
      a_list[j] = -1
    
if ((a_list[0]==-1 and a_list[1] == -1 and a_list[2] == -1) or
    (a_list[3]==-1 and a_list[4] == -1 and a_list[5] == -1) or
    (a_list[6]==-1 and a_list[7] == -1 and a_list[8] == -1) or
    (a_list[0]==-1 and a_list[3] == -1 and a_list[6] == -1) or
    (a_list[1]==-1 and a_list[4] == -1 and a_list[7] == -1) or
    (a_list[2]==-1 and a_list[5] == -1 and a_list[8] == -1) or
    (a_list[0]==-1 and a_list[4] == -1 and a_list[8] == -1) or
	(a_list[2]==-1 and a_list[4] == -1 and a_list[6] == -1)):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
l = [tuple(map(int, input().split())) for _ in range(3)]
used = [[False]*3 for _ in range(3)]

N = int(input())
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if l[i][j]==b:
                used[i][j]=True

def check():
    if used[0][0] and used[1][1] and used[2][2]:
        return True
    if used[0][2] and used[1][1] and used[2][0]:
        return True
    for i in range(3):
        if used[i][0] and used[i][1] and used[i][2]:
            return True
        if used[0][i] and used[1][i] and used[2][i]:
            return True

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

Submission status: Accepted

Solution code:
A = [ list(map(int, input().split())) for _ in range(3) ]
n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A[i][j] = 0
flag = False
for i in range(3):
    if sum( [ A[i][j] for j in range(3)] ) == 0:
        flag = True
    if sum( [ A[j][i] for j in range(3)] ) == 0:
        flag = True
if sum( [A[i][i] for i in range(3)] ) == 0 or sum( [A[2-i][i] for i in range(3)] ) == 0:
    flag = True
print("Yes") if flag else print("No")

Submission status: Accepted

Solution code:
import numpy as np


def main():
    As = [list(map(int, input().split())) for j in range(3)]
    As = np.array(As)
    n = int(input())
    bs = [int(input()) for i in range(n)]
    for b in bs:
        As = np.where(As == b, 0, As)

    if np.any(np.all(As == 0, axis=0)):
        print("Yes")
    elif np.any(np.all(As == 0, axis=1)):
        print("Yes")
    elif As[0][0] == 0 and As[1][1] == 0 and As[2][2] == 0:
        print("Yes")
    elif As[0][2] == 0 and As[1][1] == 0 and As[2][0] == 0:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

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

for i in range(n):
  s=int(input())
  count=-1
  for T in [A,B,C]:
    count+=1
    if s in T:
      
      ans[count][T.index(s)]=1
for i in range(3):
  if ans[i]==[1,1,1]:
    print("Yes")
    exit()
for i in range(3):
  if [ans[j][i] for j in range(3)]==[1,1,1]:
    print("Yes")
    exit()
if [ans[0][0],ans[1][1],ans[2][2]]==[1,1,1]:
  print("Yes")
  exit()
if [ans[0][2],ans[1][1],ans[2][0]]==[1,1,1]:
  print("Yes")
  exit()
print("No")

Submission status: Accepted

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

X = []
X += [set(A[i]) for i in range(3)]
X += [set([A[j][i] for j in range(3)]) for i in range(3)]
X += [set([A[0][2], A[1][1], A[2][0]]), set([A[2][2], A[1][1], A[0][0]])]

for x in X:
    if x <= B: #setの場合は、順不同で比較する。　<=は部分重合
        print('Yes')
        break
else:
    print('No')

Submission status: Accepted

Solution code:

A = [list(map(int, input().split(' '))) for  _ in range(3)]
N = int(input())
B = set([int(input()) for _ in range(N)])

X = []
X += [set(A[i]) for i in range(3)]
X += [set([A[j][i] for j in range(3)]) for i in range(3)]
X += [set([A[0][2], A[1][1], A[2][0]]), set([A[2][2], A[1][1], A[0][0]])]

for x in X:
    if x <= B:
        print('Yes')
        break
else:
    print('No')

Submission status: Accepted

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

n=int(input())

b=list(int(input()) for i in range(n))

c=[[0]*3 for i in range(3)]

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

answer="No"

for i in range(3):
    if (c[i][0] and c[i][1] and c[i][2]):
        answer="Yes"
    if (c[0][i] and c[1][i] and c[2][i]):
        answer="Yes"
if (c[0][0] and c[1][1] and c[2][2]):
    answer="Yes"
if (c[0][2] and c[1][1] and c[2][0]):
    answer="Yes"

print(answer)

Submission status: Accepted

Solution code:
import sys

mat=[]
for i in range(3):
  array=list(map(int,input().split()))
  mat.append(array)
  
N=int(input())
bset=set()
for i in range(N):
  b=int(input())
  bset.add(b)
  
#print(mat)
#print(bset)

#yoko
for i in range(3):
  for j in range(3):
    if not mat[i][j] in bset:
      break
  else:
    print("Yes")
    sys.exit()
    
#tate
for i in range(3):
  for j in range(3):
    if not mat[j][i] in bset:
      break
  else:
    print("Yes")
    sys.exit()
    
#naname
for i in range(3):
  if not mat[i][i] in bset:
    break
else:
  print("Yes")
  sys.exit()
for i in range(3):
  if not mat[i][2-i] in bset:
    break
else:
  print("Yes")
  sys.exit()
  
print("No")

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

A = []
A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))

a = [[0,0,0],[0,0,0],[0,0,0]]

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

flag = False

for i in range(3):
    if 0 not in a[i]: flag = True
    if a[0][i]*a[1][i]*a[2][i] == 1: flag = True
    
if a[0][0]*a[1][1]*a[2][2] == 1: flag = True
if a[0][2]*a[1][1]*a[2][0] == 1: flag = True

print('Yes') if flag == True else print('No')

Submission status: Accepted

Solution code:
bingo = []
tmp = input()
bingo.append(tmp.split(' '))
tmp = input()
bingo.append(tmp.split(' '))
tmp = input()
bingo.append(tmp.split(' '))
for i in range(len(bingo)):
    bingo[i] = [int(bingo[i][0]), int(bingo[i][1]), int(bingo[i][2])]

n = input()
data = []
arr = range(int(n))
arr = list(arr)
for count in arr:
    tmp = input()
    data.append(int(tmp))

ans = []
for num in data:
    for i in range(len(bingo)):
        for j in [0, 1, 2]:
            if bingo[i][j] is num:
                ans.append([i, j])

# 1 2 3
# 4 5 6
# 7 8 9

# 6 15 12 15 15 24 18
# more 3

# 11 12 13
# 21 22 23
# 31 32 33

if [0, 0] in ans and [0, 1] in ans and [0, 2] in ans:
    print('Yes')
    exit(0)

if [1, 0] in ans and [1, 1] in ans and [1, 2] in ans:
    print('Yes')
    exit(0)

if [2, 0] in ans and [2, 1] in ans and [2, 2] in ans:
    print('Yes')
    exit(0)

if [0, 0] in ans and [1, 0] in ans and [2, 0] in ans:
    print('Yes')
    exit(0)

if [0, 1] in ans and [1, 1] in ans and [2, 1] in ans:
    print('Yes')
    exit(0)

if [0, 2] in ans and [1, 2] in ans and [2, 2] in ans:
    print('Yes')
    exit(0)

if [0, 0] in ans and [1, 1] in ans and [2, 2] in ans:
    print('Yes')
    exit(0)

if [0, 2] in ans and [1, 1] in ans and [2, 0] in ans:
    print('Yes')
    exit(0)

print('No')

Submission status: Accepted

Solution code:
import numpy as np
bingo = np.ndarray((3,3)).astype(np.int)
for i in range(3):
    line = list(map(int,input().split()))
    bingo[i] = line
N = int(input())

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

row = min(np.max(bingo,axis=1))
col = min(np.max(bingo,axis=0))
diag = min(bingo[0,0]+bingo[1,1]+bingo[2,2],bingo[0,-1]+bingo[1,-2]+bingo[2,-3])
if min(row,col,diag)==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(
            think(
                [
                    [84, 97, 66],
                    [79, 89, 11],
                    [61, 59, 7]
                ],
                [89, 7, 87, 79, 24, 84, 30]
            ),
            'Yes'
        )

    def test_2(self):
        self.assertEqual(
            think(
                [
                    [41, 7, 46],
                    [26, 89, 2],
                    [78, 92, 8]
                ],
                [6, 45, 16, 57, 17]
            ),
            'No'
        )

    def test_3(self):
        self.assertEqual(
            think(
                [
                    [60, 88, 34],
                    [92, 41, 43],
                    [65, 73, 48]
                ],
                [60, 43, 88, 11, 48, 73, 65, 41, 92, 34]
            ),
            'Yes'
        )


def solve():
    a, b = read()
    result = think(a, b)
    write(result)


def read():
    a = []
    for _ in range(3):
        a.append(read_int(3))
    b = []
    n = read_int(1)[0]
    for _ in range(n):
        b.append(read_int(1)[0])
    return a, b


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a, b):
    check_mark = 0
    for q in b:
        for row in a:
            for i, cell in enumerate(row):
                if cell == q:
                    row[i] = check_mark
    return 'Yes' if is_bingo(a, check_mark) else 'No'


def write(result):
    print(result)


def is_bingo(a, check_mark):
    rows = len(a)
    cols = len(a[0])

    for y in range(rows):
        if is_bingo_found_in_row(a, y, check_mark):
            return True

    for x in range(cols):
        if is_bingo_found_in_col(a, x, check_mark):
            return True

    if is_bingo_found_in_diagonal(a, check_mark):
        return True
    return False


def is_bingo_found_in_row(a, y, check_mark):
    row = a[y]
    return all(map(lambda x: x == check_mark, row))


def is_bingo_found_in_col(a, x, check_mark):
    col = []
    for row in a:
        col.append(row[x])
    return all(map(lambda x: x == check_mark, col))


def is_bingo_found_in_diagonal(a, check_mark):
    rows = len(a)
    cols = len(a[0])
    if rows != cols:
        return False

    diagonal = []
    for i in range(rows):
        diagonal.append(a[i][i])
    if all(map(lambda x: x == check_mark, diagonal)):
        return True

    diagonal = []
    for i in range(rows):
        diagonal.append(a[i][rows - i - 1])
    if all(map(lambda x: x == check_mark, diagonal)):
        return True

    return False


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

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) for i in range(3)]
output =[[0,0,0],[0,0,0],[0,0,0]]
n = int(input())
check=False
for k in range(n):
    b=int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j]==b:
                output[i][j]=1
for i in range(3):
    if output[i][0]*output[i][1]*output[i][2]==1:
        check=True
    elif output[0][i]*output[1][i]*output[2][i]==1:
        check=True
if output[0][0]*output[1][1]*output[2][2]==1:
    check=True
elif output[2][0]*output[1][1]*output[0][2]==1:
    check=True
if check==True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N = int(input())
b_list=[]
for i in range(N):
  b_list.append(int(input()))
 
for i in b_list:
  A1 = [x if x != i else -1 for x in A1]
  A2 = [y if y != i else -1 for y in A2]
  A3 = [z if z != i else -1 for z in A3]
 
if sum(A1)==-3 or sum(A2)==-3 or sum(A3)==-3:
  print('Yes')
  sys.exit()
for t in range(3):
  if A1[t]+A2[t]+A3[t] == -3:
    print('Yes')
    sys.exit()
if A1[0]+A2[1]+A3[2] == -3 or A1[2]+A2[1]+A3[0] == -3:
  print('Yes')
  sys.exit()
print('No')

Submission status: Accepted

Solution code:
import numpy as np

A=np.zeros((3,3),dtype=int)
B=np.zeros((3,3),dtype=int)

#Aのビンゴカード生成
for i in range(3):
    A[i][0],A[i][1],A[i][2]=map(int,input().split())

N=int(input())

#Bで穴の空いた場所を1とする
for i in range(N):
    b=int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                B[i][j]=1

#ビンゴ判定
ans=False

#横方向
for i in range(3):
    cnt=0
    for j in range(3):
        cnt+=B[i][j]
    if cnt==3:
        ans=True

#縦方向
for i in range(3):
    cnt=0
    for j in range(3):
        cnt+=B[j][i]
    if cnt==3:
        ans=True

#斜め右下がり
cnt=0
for i in range(3):
    cnt+=B[i][i]
if cnt==3:
    ans=True

#斜め右上がり
cnt=0
for i in range(3):
    cnt+=B[i][2-i]
if cnt==3:
    ans=True

if ans==True:
    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()))
d = [a[0],b[0],c[0]]
e = [a[1],b[1],c[1]]
f = [a[2],b[2],c[2]]
g = [a[0],b[1],c[2]]
h = [a[2],b[1],c[0]]

n = int(input())

bs = []
for _ in range(n):
    bs.append(int(input()))
       
for l in [a,b,c,d,e,f,g,h]:
    if (l[0] in bs) and (l[1] in bs) and (l[2] in bs):
        print("Yes")
        break
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()))
d = [a[0],b[0],c[0]]
e = [a[1],b[1],c[1]]
f = [a[2],b[2],c[2]]
g = [a[0],b[1],c[2]]
h = [a[2],b[1],c[0]]

n = int(input())

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

for l in [a,b,c,d,e,f,g,h]:
    if (l[0] in bs) and (l[1] in bs) and (l[2] in bs):
        print("Yes")
        break
else:
        print("No")