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
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
C1 =  [0] * 3
C2 =  [0] * 3
C3 =  [0] * 3
for j in range(N):
    b = int(input())
    if b in A1:
        C1[A1.index(b)]=1
    if b in A2:
        C2[A2.index(b)] = 1
    if b in A3:
        C3[A3.index(b)] = 1

if sum(C1)==3 or sum(C2)==3 or sum(C3)==3:
    print('Yes')
    sys.exit()
elif C1[0]+C2[1]+C3[2]==3:
    print('Yes')
    sys.exit()
elif C3[0]+C2[1]+C1[2]==3:
    print('Yes')
    sys.exit()
else:
    for m in range(3):
        if C1[m]+C2[m]+C3[m]==3:
            print('Yes')
            sys.exit()

print('No')

Submission status: Accepted

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

c = [[0 for _ in range(3)] for _ in range(3)]
result = ""

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

for i in range(3):
    if c[i][0] == c[i][1] == c[i][2] == 1:
        result = "Yes"
        break
    elif c[0][i] == c[1][i] == c[2][i] == 1:
        result = "Yes"
        break

if c[0][0] == c[1][1] == c[2][2] == 1:
    result = "Yes"
elif c[0][2] == c[1][1] == c[2][0] == 1:
    result = "Yes"

if result == "":
    result ="No"

print(result)

Submission status: Accepted

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

for _ in range(N):
    B = int(input())
    if B in A:
        A[A.index(B)] = 0

if A[0] == A[3] == A[6] == 0:
    print('Yes')
elif A[1] == A[4] == A[7] == 0:
    print('Yes')
elif A[2] == A[5] == A[8] == 0:
    print('Yes')
elif sum(A[:3]) == 0:
    print('Yes')
elif sum(A[3:6]) == 0:
    print('Yes')
elif sum(A[6:9]) == 0:
    print('Yes')
elif A[0] == A[4] == A[8] == 0:
    print('Yes')
elif A[2] == A[4] == A[6] == 0:
    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 = set(int(input()) for _ in range(n))
ans = False

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

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

if all(A[i][i] in B for i in range(3)):
    ans = True


if all(A[i][2-i] in B for i in range(3)):
    ans = True

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

Submission status: Accepted

Solution code:
import sys

a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
d = [int(input()) for f in range(n)]

for k in range(3):
  if a[k][0] in d and a[k][1] in d and a[k][2] in d:
    print("Yes")
    sys.exit()
  elif a[0][k] in d and a[1][k] in d and a[2][k] in d:
    print("Yes")
    sys.exit()
if a[0][0] in d and a[1][1] in d and a[2][2] in d:
  print("Yes")
  sys.exit()
elif a[0][2] in d and a[1][1] in d and a[2][0] in d:
  print("Yes")
  sys.exit()
else:
  print("No")

Submission status: Accepted

Solution code:
card = [list(map(int, input().split())) for i in range(3)]
N = int(input())
bingo = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
ans = 'No'
for _ in range(N):
    x = int(input())
    for i in range(3):
        for j in range(3):
            if x == card[i][j]:
                bingo[i][j] = 1

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

print(ans)

Submission status: Accepted

Solution code:
A_1 = list(map(int, input().split()))
A_2 = list(map(int, input().split()))
A_3 = list(map(int, input().split()))
A = A_1 + A_2 + A_3
N = int(input())

for i in range(N):
  B = int(input())
  if B in A:
    A[A.index(B)] = 0

bingo = [A[0] + A[1] + A[2],
         A[3] + A[4] + A[5],
         A[6] + A[7] + A[8],
         A[0] + A[4] + A[8],
         A[2] + A[4] + A[6],
         A[0] + A[3] + A[6],
         A[1] + A[4] + A[7],
         A[2] + A[5] + A[8]]

if 0 in bingo:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7

a_matrix = []
for i in range(3):
    a_vec = list(map(int, input().split()))
    a_matrix.append(a_vec)

a_mat = np.array(a_matrix)

def bingo_check(m):
    ch1 = (0 in m.sum(axis = 0))
    ch2 = (0 in m.sum(axis = 1))
    ch3 = not (m.trace())
    ch4 = not (np.rot90(m).trace())
    return ch1 or ch2 or ch3 or ch4
    
def num_change(n):
    dim1 = a_mat.shape[0]
    dim2 = a_mat.shape[1]
    for i in range(dim1):
        for j in range(dim2):
            if a_mat[i][j] == n:
                a_mat[i][j] = 0

n = int(input())
for i in range(n):
    b = int(input())
    num_change(b)

if bingo_check(a_mat):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) for _ 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 a[j][k] == b:
                a[j][k] = "#"
                break

for i in range(3):
    if a[i][0] == a[i][1] == a[i][2] == "#":
        print("Yes")
        break
    elif a[0][i] == a[1][i] == a[2][i] == "#":
        print("Yes")
        break
    elif a[0][0] == a[1][1] == a[2][2] == "#":
        print("Yes")
        break
    elif a[0][2] == a[1][1] == a[2][0] == "#":
        print("Yes")
        break
else:
    print("No")

Submission status: Accepted

Solution code:
num = 0
table = {}
for _ in range(3):
    row = map(int, input().split())
    for r in row:
        table[r] = num
        num += 1

N = int(input())

bingo = set()
for _ in range(N):
    b = int(input())
    if b in table:
        bingo.add(table[b])

atari = [
    {0,1,2},
    {3,4,5},
    {6,7,8},
    {0,3,6},
    {1,4,7},
    {2,5,8},
    {0,4,8},
    {2,4,6}
]

for a in atari:
    if a <= bingo:
        print('Yes')
        break
else:
    print('No')

Submission status: Accepted

Solution code:
from sys import exit
def judge_line(card):
    for i in range(0,9,3):
        for j in range(3):
            if card[i+j] != 0:
                break
            else:
                if j == 2:
                    print("Yes")
                    exit(0)
                else:
                    None
        
        
def judge_row(card):
    for i in range(3):
        for j in range(i,9,3):
            if card[j] != 0:
                break
            else:
                if j == 6 or j == 7 or j == 8:
                    print("Yes")
                    exit(0)
                else:
                    None

def judge_rightslanting(card):
    if card[0] == 0 and card[4] == 0 and card[8] == 0:
        print("Yes")
        exit(0)

def judge_leftslanting(card):
    if card[2] == 0 and card[4] == 0 and card[6] == 0:
        print("Yes")
        exit(0)


card = []

for _ in range(3):
    card += [int(x) for x in input().split()]

N = int(input())
for i in range(N):
    b = int(input())
    try:
        ind = card.index(b)
        card[ind] = 0
    except ValueError:
        None
    
    judge_line(card)
    judge_row(card)
    judge_rightslanting(card)
    judge_leftslanting(card)

print("No")

Submission status: Accepted

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

if X[0][0]*X[0][1]*X[0][2] + X[1][0]*X[1][1]*X[1][2] + X[2][0]*X[2][1]*X[2][2] + X[0][0]*X[1][0]*X[2][0] + X[0][1]*X[1][1]*X[2][1] + X[0][2]*X[1][2]*X[2][2] + X[0][0]*X[1][1]*X[2][2] + X[0][2]*X[1][1]*X[0][2] > 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#inport
import sys
import numpy as np
import itertools as itlt
from collections import deque

#input 

s = [[0,0,0]
    ,[0,0,0]
    ,[0,0,0]]    
s[0] = [int(x) for x in sys.stdin.readline().split()]
s[1] = [int(x) for x in sys.stdin.readline().split()]
s[2] = [int(x) for x in sys.stdin.readline().split()]
g = [[0,0,0]
    ,[0,0,0]
    ,[0,0,0]]
N = int(sys.stdin.readline())
p = list([0]*N)
s = np.array(s)
for _ in range(N):
    a = int(sys.stdin.readline())
    b = np.where(s == a)
    for i in range(np.size(b[0])):
        g[b[0][i]][b[1][i]] = 1

#print("debug")


flg_win = 0

for i in range(3):
    if (g[i][0] + g[i][1] + g[i][2]) == 3:
        flg_win = 1
    if (g[0][i] + g[1][i] + g[2][i]) == 3:
        flg_win = 1

if (g[0][0]+g[1][1]+g[2][2]) == 3:
    flg_win = 1

if (g[0][2]+g[1][1]+g[2][0]) == 3:
    flg_win = 1

if flg_win == 1:
    print("Yes")
else:
    print("No")
#print(g)

Submission status: Accepted

Solution code:
board = []
for i in range(3):
  temp = list(map(int, input().split()))
  board.append(temp)
n = int(input())
TF = [[False] * 3 for i in range(3)]
for _ in range(n):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if board[i][j] == b:
        TF[i][j] = True
res = False
for i in range(3):
  res = res or (TF[i][0] and TF[i][1] and TF[i][2])
  res = res or (TF[0][i] and TF[1][i] and TF[2][i])
res = res or (TF[0][0] and TF[1][1] and TF[2][2])
res = res or (TF[0][2] and TF[1][1] and TF[2][0])
print('Yes' if res else 'No')

Submission status: Accepted

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

open=[]
for i in range(n):
    if b[i] in a:
        open.append(a.index(b[i]))

correct=[{0,1,2},{3,4,5},{6,7,8},{2,5,8},{1,4,7},{0,3,6},{0,4,8},{2,4,6}]

for i in correct:
    if i <= set(open):
        print('Yes')
        break
else:
    print('No')

Submission status: Accepted

Solution code:
#B
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
for i in range(n):
    m = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == m:
                a[j][k] = 0
f = False
for j in range(3):
    if a[j][0] == 0 and a[j][1] == 0 and a[j][2] == 0:
        f = True
    if a[0][j] == 0 and a[1][j] == 0 and a[2][j] == 0:
        f = True
if (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):
    f = True
if f:
    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)]

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

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

chk = False
if ans[0][0] == ans[0][1] == ans[0][2] == 1:
  print("Yes")
elif ans[1][0] == ans[1][1] == ans[1][2] == 1:
  print("Yes")
elif ans[2][0] == ans[2][1] == ans[2][2] == 1:
  print("Yes")
elif ans[0][0] == ans[1][0] == ans[2][0] == 1 :
  print("Yes")
elif ans[0][1] == ans[1][1] == ans[2][1] == 1 :
  print("Yes")
elif ans[0][2] == ans[1][2] == ans[2][2] == 1 :
  print("Yes")
elif ans[0][0] == ans[1][1] == ans[2][2] == 1 :
  print("Yes")
elif ans[0][2] == ans[1][1] == ans[2][0] == 1 :
  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 j in range (n)]
ans = "No"
for k in range (n):
  for l in range(3):
    for m in range(3):
      if a[l][m] == b[k]:
        a[l][m] = 0
for o in range(3):
  if a[o][0] == a[o][1] == a[o][2] or a[0][o] == a[1][o] == a[2][o]:
    ans = "Yes"
if a[0][0] == a[1][1] == a[2][2] or a[2][0] == a[1][1] == a[0][2]:
  ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations

A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
A3=list(map(int,input().split()))
N=int(input())
for i in range(N):
    chk = int(input())
    for m in range(3):
        if A1[m] == chk:
            A1[m] = 0
        if A2[m] == chk:
            A2[m] = 0
        if A3[m] == chk:
            A3[m] = 0



if (A1[0] == 0 and A1[1] == 0 and A1[2] == 0) \
or (A2[0] == 0 and A2[1] == 0 and A2[2] == 0) \
or (A3[0] == 0 and A3[1] == 0 and A3[2] == 0) \
or (A1[0] == 0 and A2[0] == 0 and A3[0] == 0) \
or (A1[1] == 0 and A2[1] == 0 and A3[1] == 0) \
or (A1[2] == 0 and A2[2] == 0 and A3[2] == 0) \
or (A1[0] == 0 and A2[1] == 0 and A3[2] == 0) \
or (A1[2] == 0 and A2[1] == 0 and A3[0] == 0) :
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

n = int(input())

for j in range(n):
    b = int(input())
    for l in range(3):
        if A[l][0] == b:
            A[l][0] = 0
        if A[l][1] == b:
            A[l][1] = 0
        if A[l][2] == b:
            A[l][2] = 0
if A[0][0]==A[1][1]==A[2][2]==0:
    print("Yes")
    sys.exit()
elif A[0][2]==A[1][1]==A[2][0]==0:
    print("Yes")
    sys.exit()
elif A[0][0]==A[0][1]==A[0][2]==0:
    print("Yes")
    sys.exit()
elif A[1][0]==A[1][1]==A[1][2]==0:
    print("Yes")
    sys.exit()
elif A[2][0]==A[2][1]==A[2][2]==0:
    print("Yes")
    sys.exit()
elif A[0][0]==A[1][0]==A[2][0]==0:
    print("Yes")
    sys.exit()
elif A[0][1]==A[1][1]==A[2][1]==0:
    print("Yes")
    sys.exit()    
elif A[0][2]==A[1][2]==A[2][2]==0:
    print("Yes")
    sys.exit()   
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())

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

if A1[0]==A1[1]==A1[2]==0:
    print("Yes")
    exit
elif A2[0]==A2[1]==A2[2]==0:
    print("Yes")
    exit
elif A3[0]==A3[1]==A3[2]==0:
    print("Yes")
    exit

elif A1[0]==A2[0]==A3[0]==0:
    print("Yes")
    exit
elif A1[1]==A2[1]==A3[1]==0:
    print("Yes")
    exit
elif A1[2]==A2[2]==A3[2]==0:
    print("Yes")
    exit
    
elif A1[0]==A2[1]==A3[2]==0:
    print("Yes")
    exit
elif A1[2]==A2[1]==A3[0]==0:
    print("Yes")
    exit
else:
    print("No")

Submission status: Accepted

Solution code:
#n , m , l = map(int , input().split())

# list_n = list(map(int , inpuut().split()))<Paste>

#n = input()
# list = [input() for i in range(N)

#list = [[i for i in range(N)] for _ in range(M)]

A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())

for i in range(N):
    B = int(input())
    for j in range(3):
        if A1[j] == B:
            A1[j] = 0
        if A2[j] == B:
            A2[j] = 0
        if A3[j] == B:
            A3[j] = 0

if sum(A1) == 0:
    print("Yes")
    exit()
if sum(A2) == 0:
    print("Yes")
    exit()
if sum(A3) == 0:
    print("Yes")
    exit()
for i in range(3):
    if A1[i]+A2[i]+A3[i] == 0:
        print("Yes")
        exit()
if A1[0] + A2[1] + A3[2] == 0:
    print("Yes")
    exit()
if A1[2] + A2[1] + A3[0] == 0:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
import sys

A=[list(map(int,input().split())) for _ in range(3)]
n=int(input())
for i in range(n):
    b=int(input())
    for l in range(3):
        if b in A[l]:
            A[l][A[l].index(b)]=0

for i in range(3):
    if A[i][0] == A[i][1] == A[i][2]:
        print('Yes')
        sys.exit()
    elif A[0][i] == A[1][i] == A[2][i]:
        print('Yes')
        sys.exit()
if A[0][0] == A[1][1] == A[2][2]:
    print('Yes')
    sys.exit()
elif A[0][2] == A[1][1] == A[2][0]:
    print('Yes')
    sys.exit()
else:
    print('No')

Submission status: Accepted

Solution code:
A11, A12, A13 = input().split(' ')
A21, A22, A23 = input().split(' ')
A31, A32, A33 = input().split(' ')
A11 = int(A11)
A12 = int(A12)
A13 = int(A13)
A21 = int(A21)
A22 = int(A22)
A23 = int(A23)
A31 = int(A31)
A32 = int(A32)
A33 = int(A33)
N = int(input())
b = []
for i in range(N):
  bi = int(input())
  b.append(bi)
if A11 in b and A12 in b and A13 in b:
  print('Yes')
elif A21 in b and A22 in b and A23 in b:
  print('Yes')
elif A31 in b and A32 in b and A33 in b:
  print('Yes')
elif A11 in b and A21 in b and A31 in b:
  print('Yes')
elif A12 in b and A22 in b and A32 in b:
  print('Yes')
elif A13 in b and A23 in b and A33 in b:
  print('Yes')
elif A11 in b and A22 in b and A33 in b:
  print('Yes')
elif A13 in b and A22 in b  and A31 in b:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
def check():
    for i in range(3):
        f1 = True
        f2 = True
        for j in range(3):
            f1 = f1 and card[i][j]
            f2 = f2 and card[j][i]
        if f1 or f2:
            return 'Yes'
    f1 = True
    f2 = True
    for i in range(3):
        f1 = f1 and card[i][i]
        f2 = f2 and card[i][2-i]
    if f1 or f2:
        return 'Yes'
    return 'No'

card = [[False] * 3 for _ in range(3)]
A = []
for _ in range(3):
    a = list(map(int, input().split()))
    A += a
N = int(input())
for _ in range(N):
    b = int(input())
    if b in A:
        idx = A.index(b)
        card[idx // 3][idx % 3] = True
print(check())

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

for i in range(N):
    b = int(input())
    for t in range(3):
        if A1[t] == b:
            A1[t] = -1
        elif A2[t] == b:
            A2[t] = -1
        elif A3[t] == b:
            A3[t] = -1

if A1 == [-1, -1, -1] \
        or A2 == [-1, -1, -1] \
        or A3 == [-1, -1, -1] \
        or A1[1] == A2[1] == A3[1] == -1 \
        or A1[2] == A2[2] == A3[2] == -1 \
        or A1[0] == A2[0] == A3[0] == -1 \
        or A1[0] == A2[1] == A3[2] == -1 \
        or A1[2] == A2[1] == A3[0] == -1 \
        or A1[0] == A2[0] == A3[0] == -1 \
        or A1[1] == A2[1] == A3[1] == -1 \
        or A1[2] == A2[2] == A3[2] == -1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ka = a + b + c
x = int()
n = int(input())
for i in range(n):
    k = int(input())
    if k in ka: ka[ka.index(k)] = x
ans = "No"
if ka[0] == x and ka[1] == x and ka[2] == x:ans = "Yes"
elif ka[3] == x and ka[4] == x and ka[5] == x:ans = "Yes"
elif ka[6] == x and ka[7] == x and ka[8] == x:ans = "Yes"
elif ka[0] == x and ka[3] == x and ka[6] == x:ans = "Yes"
elif ka[1] == x and ka[4] == x and ka[7] == x:ans = "Yes"
elif ka[2] == x and ka[5] == x and ka[8] == x:ans = "Yes"
elif ka[0] == x and ka[4] == x and ka[8] == x:ans = "Yes"
elif ka[2] == x and ka[4] == x and ka[6] == x:ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
import sys

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

for i in range(N):
    b = int(input())
    if b in A[0]:
        A[0][A[0].index(b)] = 0
    elif b in A[1]:
        A[1][A[1].index(b)] = 0
    elif b in A[2]:
        A[2][A[2].index(b)] = 0

for i in range(3):
    if A[i][0] == A[i][1] == A[i][2]:
        print('Yes')
        sys.exit()
    elif A[0][i] == A[1][i] == A[2][i]:
        print('Yes')
        sys.exit()

if A[0][0] == A[1][1] == A[2][2]:
    print('Yes')
    sys.exit()
elif A[0][2] == A[1][1] == A[2][0]:
    print('Yes')
    sys.exit()
else:
    print('No')

Submission status: Accepted

Solution code:

A = [[0] * 3, [0] * 3, [0] * 3]
Field = [[False] * 3, [False] * 3, [False] * 3]

for i in range(0, 3):
    A1, A2, A3 = list(map(int, input().split()))
    A[i][0] = A1
    A[i][1] = A2
    A[i][2] = A3

N = int(input())
B = [0] * N
for i in range(0, N):
    B[i] = int(input())

for b in range(0, N):
    for i in range(3):
        for j in range(3):
            if A[i][j] == B[b]:
                Field[i][j] = True

Ans = False
for i in range(3):
    field = True
    for j in range(3):
        if Field[i][j] == False:
            field = False
    
    if field==True:
        Ans = True
        break
else:
    Ans = False
    for i in range(3):
        field = True
        for j in range(3):
            if Field[j][i] == False:
                field = False
        
        if field==True:
            Ans = True
            break
    else:
        Ans = False
        if Field[0][0] and Field[1][1] and Field[2][2]:
            Ans = True
        if Field[0][2] and Field[1][1] and Field[2][0]:
            Ans = True

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

Submission status: Accepted

Solution code:
import sys

A = [0] * 3

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

N = int(input())
for i in range(N):
    b = int(input())
    if b in A[0]:
        A[0][A[0].index(b)] = 0
    elif b in A[1]: 
        A[1][A[1].index(b)] = 0
    elif b in A[2]:
        A[2][A[2].index(b)] = 0

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

if A[0][0] == A[1][1] == A[2][2]:
    print("Yes")
    sys.exit()
elif A[0][2] == A[1][1] == A[2][0]:
    print("Yes")
    sys.exit()
else:
    print("No")

Submission status: Accepted

Solution code:
la1=list(map(int,input().split()))
la2=list(map(int,input().split()))
la3=list(map(int,input().split()))
n=int(input())
ln=[int(input()) for i in range(n)]
la=[la1,la2,la3]
ls=[[0,0,0],[0,0,0],[0,0,0]]
for i in range(3):
  for j in range(3):
    if la[i][j] in ln:
      ls[i][j]=1
if ls[0]==[1,1,1] or ls[1]==[1,1,1] or ls[2]==[1,1,1]:
  print("Yes")
elif ls[0][0]==ls[1][0]==ls[2][0]==1 or ls[0][1]==ls[1][1]==ls[2][1]==1 or ls[0][2]==ls[1][2]==ls[2][2]==1:
  print("Yes")
elif ls[0][0]==ls[1][1]==ls[2][2]==1 or ls[0][2]==ls[1][1]==ls[2][0]==1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
bingo_card = [input().split() for _ in range(3)]

N = int(input())

for _ in range(N):
    b = input()
    for i in range(3):
        if b in bingo_card[i]:
            j = bingo_card[i].index(b)
            bingo_card[i][j] = "O"
            break

def check_h():
    for line in bingo_card:
        for s in line:
            if s != "O":
                break
        else:
            return True
    return False

def check_v():
    for i in range(3):
        for j in range(3):
            if bingo_card[j][i] != "O":
                break
        else:
            return True
    return False

def check_d():
    for x in [True, False]:
        for i in range(3):
            if x:
                if bingo_card[i][i] != "O":
                    break
            else:
                if bingo_card[i][2 - i] != "O":
                    break
        else:
            return True
    return False

checks = [check_h, check_v, check_d]
for check in checks:
    if check():
        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()))
x = a+b+c
ans = "No"
N = int(input())
for i in range(N) :
    b = int(input())
    x = ["x" if i == b else i for i in x]

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

Submission status: Accepted

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

B = set()
for _ in range(int(input())):
    B.add(int(input()))


checkList = list()
for i in range(3):
    checkList.append(set(A[i]))
for j in range(3):
    checkList.append(set([A[0][j], A[1][j], A[2][j]]))
checkList.append(set([A[0][0], A[1][1], A[2][2]]))
checkList.append(set([A[0][2], A[1][1], A[2][0]]))

flag = False
for s in checkList:
    if len(s - B) == 0:
        flag = True
        break

if flag:
    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()))
x = a1 + a2 + a3

n=int(input())
ans='No'

for i in range(n):
  ent=int(input())
  x=['x' if i==ent else i for i in x]

if x[0]==x[3]==x[6]=='x':ans='Yes'
elif x[1]==x[4]==x[7]=='x':ans='Yes'
elif x[2]==x[5]==x[8]=='x':ans='Yes'
elif x[0]==x[1]==x[2]=='x':ans='Yes'
elif x[3]==x[4]==x[5]=='x':ans='Yes'
elif x[6]==x[7]==x[8]=='x':ans='Yes'
elif x[0]==x[4]==x[8]=='x':ans='Yes'
elif x[2]==x[4]==x[6]=='x':ans='Yes'

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
zeroarr = np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])
l1= list(map(int, input().split()))
l2= list(map(int, input().split()))
l3=list(map(int, input().split()) )
bing = np.array([np.array(l1), np.array(l2), np.array(l3)])
n=int(input())
x=[]
for _ in range(n):
  l=int(input())
  x.append(l)
def check(ls, b, dd):
    for i in ls:
        if i in b:
            xxx=np.argwhere(b==i)
            for m in xxx:
                dd[m[0], m[1]]=1
check(x, bing, zeroarr)
def matrixsum(a):
    ans="No"
    if a[0,0]+a[0,1]+a[0,2]==3:
        ans="Yes"
    if a[1,0]+a[1,1]+a[1,2]==3:
        ans="Yes"
    if a[2,0]+a[2,1]+a[2,2]==3:
        ans="Yes"
    if a[0,0]+a[1,0]+a[2,0]==3:
        ans="Yes"
    if a[0,1]+a[1,1]+a[2,1]==3:
        ans="Yes"
    if a[0,2]+a[1,2]+a[2,2]==3:
        ans="Yes"
    if a[0,0]+a[1,1]+a[2,2]==3:
        ans="Yes"
    if a[0,2]+a[1,1]+a[2,0]==3:
        ans="Yes"
    return ans
print(matrixsum(zeroarr))

Submission status: Accepted

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

C=[[False]*3 for _ in range(3)]
D=[(0,0),(0,1),(0,2),(1,0),(1,1),(1,2),(2,0),(2,1),(2,2)]

N=int(input())
for _ in range(N):
    b=int(input())
    for (p,q) in D:
        if A[p][q]==b:
            C[p][q]=True

T=False
for i in range(3):
    U=True
    for j in range(3):
        U&=C[i][j]
    T|=U
    
for j in range(3):
    U=True
    for i in range(3):
        U&=C[i][j]
    T|=U 

U=True
for i in range(3):
    U&=C[i][i]
T|=U

U=True
for i in range(3):
    U&=C[i][2-i]
T|=U

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

Submission status: Accepted

Solution code:
import numpy as np 
A=[]
A.extend(list(map(int,input().split())))
A.extend(list(map(int,input().split())))
A.extend(list(map(int,input().split())))
N = int(input())
check = [False]*9
for i in range(N):
    b=int(input())
    if(b in A):
        check[A.index(b)]=True
posi_list=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
np_check=np.array(check)
for i in range(len(posi_list)):
    if (False not in np_check[posi_list[i]]):
        print('Yes')
        exit()
print('No')

Submission status: Accepted

Solution code:
row1 = list(map(int,input().split()))
row2 = list(map(int,input().split()))
row3 = list(map(int,input().split()))

n = int(input())
nums = []
ans = "No"


for i in range(0, n):
  nums.append(int(input()))

for i in range(0,3):
  if row1[i] in nums: row1[i] = "O"
  if row2[i] in nums: row2[i] = "O"
  if row3[i] in nums: row3[i] = "O"

#Columns
for i in range(0,3):
  if row1[i] == row2[i] == row3[i]: ans = "Yes"
    
#Rows
if row1 == ["O","O","O"] or row2 == ["O","O","O"] or row3 == ["O","O","O"]: ans = "Yes"
  
#Diagonals
if row1[0] == row2[1] == row3[2] or row1[2] == row2[1] == row3[0]: ans = "Yes"
  
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
import bisect as bs
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

a = np.array([iarr() for i in range(3)])
n = iinput()
for i in range(n):
    b = iinput()
    for i in range(3):
        for j in range(3):
            if a[i][j] == b: a[i][j] = 0

vertical = np.all(a == 0, axis=0)
horizontal = np.all(a == 0, axis=1)
diagonal = a[0][0]==a[1][1]==a[2][2]==0 or a[0][2]==a[1][1]==a[2][0]
flag = np.any(vertical==1) or np.any(horizontal==1) or diagonal
ans = "Yes" if flag else "No"
print(ans)

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 = []
for l in sys.stdin:
    b.append(int(l))

def bingo():
  if len(set(a1) &  set(b)) == 3 or len(set(a2) &  set(b)) == 3 or len(set(a3) &  set(b)) == 3:
    print('Yes')
    return
  
  if a1[0] in b and a2[1] in b and a3[2] in b: 
    print('Yes')
    return
  
  if a1[2] in b and a2[1] in b and a3[0] in b: 
    print('Yes')
    return
  
  for i in range(3):
    if a1[i] in b and a2[i] in b and a3[i] in b:
      print('Yes')
      return
  print('No')
  return

bingo()
    
   

# リストが全て満たされている場合
# リストと一致する数値が全て一致する場合
# リストの数値が±1のステップで一致する場合