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

for i in range(n): 
    hoge = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == hoge:
                a[j][k] = 0
for i in range(3):
    if a[0][i] == a[1][i] == a[2][i]:
        ans = 'Yes'
    if a[i][0] == a[i][1] == a[i][2]:
        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:
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 i in range(n)]
for i in range(n):
  for j in range(3):
    for k in range(3):
      if B[i] == A[j][k]:
        A[j][k] = "*"
ans = ["*","*","*"]
for i in range(3):
  if A[i] == ans or [A[0][i],A[1][i],A[2][i]] == ans:
    print("Yes")
    exit()
    
if [A[0][0],A[1][1],A[2][2]] == ans or [A[0][2],A[1][1],A[2][0]] == ans:
  print("Yes")
  exit()

print("No")

Submission status: Accepted

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

n=int(input())
for i in range(n):
  b=int(input())
  if b in A:
    A[Ad[b]]=-1

for i in range(3):
  if A[i*3]==-1 and A[i*3+1]==-1 and A[i*3+2]==-1:
    print('Yes')
    exit()

for i in range(3):
  if A[i]==-1 and A[i+3]==-1 and A[i+6]==-1:
    print('Yes')
    exit()
    
if A[0]==-1 and A[4]==-1 and A[8]==-1:
  print('Yes')
  exit()
  
if A[2]==-1 and A[4]==-1 and A[6]==-1:
  print('Yes')
  exit()
  
print('No')

Submission status: Accepted

Solution code:
def solve():
    A = [list(map(int, input().split())) for _ in range(3)]
    N = int(input())
    B = [int(input()) for _ in range(N)]
    for b in B:
        for a in A:
            if b in a:
                a[a.index(b)] = 0

    print(judge(A))


def judge(A):
    if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
        return 'Yes'
    elif A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0:
        return 'Yes'
    elif A[0][0] == 0 and A[1][0] == 0 and A[2][0] == 0:
        return 'Yes'
    elif A[0][1] == 0 and A[1][1] == 0 and A[2][1] == 0:
        return 'Yes'
    elif A[0][2] == 0 and A[1][2] == 0 and A[2][2] == 0:
        return 'Yes'
    for i in range(3):
        if A[i].count(0) == 3:
            return 'Yes'
    return 'No'




if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
a=[[int(x) for x in input().split()] for i in range(3)]
n=int(input())
for i in range(n):
  bi = int(input())
  for j in range(3):
    if bi in a[j]:
      a[j][a[j].index(bi)] = 0
  # 判定
  for j in range(3):
    x = [a[k][j] for k in range(3)]
    if (not any(x)) or (not any(a[j])):
      print('Yes')
      sys.exit()
  if not any([a[0][0],a[1][1],a[2][2]]):
    print('Yes')
    sys.exit()
  if not any([a[2][0],a[1][1],a[0][2]]):
    print('Yes')
    sys.exit()
print('No')

Submission status: Accepted

Solution code:
A = []
res = [[False]*3]*3
cnt = False
for n in range(3):
    a = list(map(int, input().split()))
    A.append(a)
N = int(input())
B = []
for n in range(N):
    b = int(input())
    B.append(b)
for i in A:
    for j in range(len(i)):
        for n in range(N):
            if i[j] == B[n]:
                i[j] = 0
# for i in range(len(A)):
#     for j in range(3):
#         for n in range(N):
#             if A[i][j] == B[n]:
#                 res[i][j] = True
for i in range(3):
    if A[i][0] == 0 and A[i][1] == 0 and A[i][2] == 0:
        cnt = True
for i in range(3):
    if A[0][i] == 0 and A[1][i] == 0 and A[2][i] == 0:
        cnt = True
if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
    cnt = True
if A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0:
    cnt = True
if cnt:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
q,l,r = 0,0,0
for _ in range(n):
  b = int(input())
  for i in range(3):
    if b in a[i]:
      a[i][a[i].index(b)]=0
                
for i in range(3):
  l += a[i][i]
  t,y = 0,0
  for j in range(3):
    y += a[j][i]
    t += a[i][j]
    if i+j == 2:
      r += a[i][j]
  if not t or not y:
    q=1

print('Yes' if q or not l or not r else 'No')

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
m = [[0]*3 for i in range(3)]
ans,l,r = 0,1,1
for _ in range(N):
  b = int(input())
  for i in range(3):
    if b in A[i]:
      m[i][A[i].index(b)]=1
                
for i in range(3):
  l *= m[i][i]
  t,y = 1,1
  for j in range(3):
    y *= m[j][i]
    t *= m[i][j]
    if i+j == 2:
      r *= m[i][j]
  if t or y:
    ans=1

print('Yes' if ans or l or r else 'No')

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
m = [[0]*3 for i in range(3)]
ans,l,r = 0,0,0
for _ in range(N):
  b = int(input())
  for i in range(3):
    if b in A[i]:
      m[i][A[i].index(b)]=1
                
for i in range(3):
  t = sum(m[i])
  l += m[i][i]
  y = 0
  for j in range(3):
    y += m[j][i]
    if i+j == 2:
      r += m[i][j]
  if t==3 or y==3 or r==3 or l==3:
    ans=1

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

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
m = [[0]*3 for i in range(3)]
ans,l,r = 0,0,0
for _ in range(N):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if A[i][j]==b:
        m[i][j]=1
                
for i in range(3):
  t = sum(m[i])
  l += m[i][i]
  y = 0
  for j in range(3):
    y += m[j][i]
    if i+j == 2:
      r += m[i][j]
  if t==3 or y==3 or r==3 or l==3:
    ans=1

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

Submission status: Accepted

Solution code:
import numpy as np
A = []
for _ in range(3):
    A += list(map(int,input().split()))
# print('List of A: {}'.format(A))
N = int(input())
b = []
for _ in range(N):
    b.append(int(input()))
for v in b:
    if v in A:
        index = A.index(v)
        A[index] = 0
# print('List of A: {}'.format(A))
bingo_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]]
for bingo in bingo_list:
    # print((np.array(A)[bingo]))
    # print(sum((np.array(A)[bingo])))
    if sum((np.array(A)[bingo])) == 0:
        print('Yes')
        exit()
print("No")

Submission status: Accepted

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

def bingo_index(a,b):
  for i in range(3):
    if b in a[i]:
      return [i,a[i].index(b)]
  return 0
  
N=int(input())
for i in range(N):
  B=int(input())
  temp=bingo_index(A,B)
  if temp!=0:
    X[temp[0]][temp[1]]=1

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

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

print(ans)

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
ans = 0
skw1 = [0]*3
skw2 = [0]*3
for _ in range(N):
  b = int(input())
  for i in range(3):
    if b in A[i]:
      A[i][A[i].index(b)]=0
for i in range(3):
  if all([a==0 for a in A[i]]):
    ans = 1
  if all([a[i]==0 for a in A]):
    ans = 1
  if A[i][i]==0:
    skw1[i] = 1
  for j in range(3):
    if i+j == 2:
      if A[i][j]==0:
        skw2[i] = 1

print('Yes' if ans or all(skw1) or all(skw2) else 'No')

Submission status: Accepted

Solution code:
def abc157_b():
    grid = [list(map(int, input().split())) for _ in range(3)]
    bingo = [[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 b == grid[i][j]:
                    bingo[i][j] = True

    for i in range(3):
        if bingo[i][0] and bingo[i][1] and bingo[i][2]:
            return 'Yes'
        if bingo[0][i] and bingo[1][i] and bingo[2][i]:
            return 'Yes'
    if bingo[0][0] and bingo[1][1] and bingo[2][2]:
        return 'Yes'
    if bingo[0][2] and bingo[1][1] and bingo[2][0]:
        return 'Yes'
    return 'No'

print(abc157_b())

Submission status: Accepted

Solution code:
import itertools
import collections
A = [list(map(int, input().split())) for i in range(3)]
A2 = list(itertools.chain.from_iterable(A))
N = int(input())
B = [list(map(int, input().split())) for i in range(N)]
B2 = list(itertools.chain.from_iterable(B))
cnt = collections.Counter(B2)

bingo = [0] * 9

for i in range(len(A2)):
    if cnt[A2[i]] == 0:
        continue
    else:
        bingo[i] = 1

if sum(bingo) < 3:
    print('No')
    exit()
elif (bingo[0] == 1 and bingo[1] == 1 and bingo[2] == 1):
    print('Yes')
elif (bingo[0] == 1 and bingo[4] == 1 and bingo[8] == 1):
    print('Yes')
elif (bingo[0] == 1 and bingo[3] == 1 and bingo[6] == 1):
    print('Yes')
elif (bingo[1] == 1 and bingo[4] == 1 and bingo[7] == 1):
    print('Yes')
elif (bingo[2] == 1 and bingo[5] == 1 and bingo[8] == 1):
    print('Yes')
elif (bingo[2] == 1 and bingo[4] == 1 and bingo[6] == 1):
    print('Yes')
elif (bingo[3] == 1 and bingo[4] == 1 and bingo[5] == 1):
    print('Yes')
elif (bingo[6] == 1 and bingo[7] == 1 and bingo[8] == 1):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np
A = np.array([list(map(int, input().split())) for i in range(3)])
N = int(input())
for i in range(N):
    bingo_num = int(input())
    A = np.where(A == bingo_num, 0, A)

if (0 in np.sum(A, axis=1)
    or 0 in np.sum(A, axis=0)
    or np.sum(np.diag(A)) == 0
        or A[0, 2]+A[1, 1]+A[2, 0] == 0):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
matrix = [input().split() for i in range(3)]
matrix.append([matrix[0][0], matrix[1][1], matrix[2][2]])
matrix.append([matrix[0][2], matrix[1][1], matrix[2][0]])
matrix.append([matrix[0][2], matrix[1][1], matrix[2][0]])
matrix.append([matrix[0][0], matrix[1][0], matrix[2][0]])
matrix.append([matrix[0][1], matrix[1][1], matrix[2][1]])
matrix.append([matrix[0][2], matrix[1][2], matrix[2][2]])

N = int(input())
bingo = [input() for i in range(N)]

for i in matrix:
    if i[0] in bingo and i[1] in bingo and i[2] in bingo:
        print('Yes')
        sys.exit()
print('No')

Submission status: Accepted

Solution code:
import numpy as np
 

A = np.array([list(map(int, input().split())) for _ in range(3)])
n = int(input())
for _ in range(n):
  b = int(input())
  A = np.where(A == b, 0, A)
  
x = np.all(A[[0, 1, 2], [0, 1, 2]] == 0)
y = np.all(A[[0, 1, 2], [2, 1, 0]] == 0)
z = np.any(np.sum(A, axis=0) == 0)
w = np.any(np.sum(A, axis=1) == 0)
 
print(['Yes', 'No'][not x and not y and not z and not w])

Submission status: Accepted

Solution code:
x1=list(map(int,input().split()))
x2=list(map(int,input().split()))
x3=list(map(int,input().split()))
n=int(input())
for _ in range(n):
  m=int(input())
  x1 =[0 if m==x else x for x in x1]
  x2 =[0 if m==x else x for x in x2]
  x3 =[0 if m==x else x for x in x3]

if sum(x1)*sum(x2)*sum(x3) ==0 or x1[0]+x2[0]+x3[0]==0 or x1[1]+x2[1]+x3[1]==0 or x1[2]+x2[2]+x3[2]==0 or x1[0]+x2[1]+x3[2]==0 or x1[2]+x2[1]+x3[0]==0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import numpy as np

A  = list(map(int,input().split()))
A  +=list( map(int,input().split()))
A  += list(map(int,input().split()))

A = np.array(A)

bingo =np.array( [0] *9 )

N = int(input())
for i in range(N):
    b =int(input())
    for i in range(9):
        if A[i] == b:
            bingo[i] =1


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

Submission status: Accepted

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

for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k] == b:
                A[j][k] = -1

for j in range(3):
    f = True
    for k in range(3):
        if A[j][k] != -1:
            f = False
    if f:
        print('Yes')
        exit()

for x in range(3):
    f = True
    for y in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()

f = True
for x in range(3):
    if A[x][x] != -1:
        f = False
if f:
    print('Yes')
    exit()

f = True
for x in range(3):
    if A[2 - x][x] != -1:
        f = False
if f:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

Solution code:

B = []
for i in range(3):
    B.append(list(map(str, input().split())))

N = int(input())

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

for n in num_list:
    for i in range(3):
        for j in range(3):
            if B[i][j] == n:
                B[i][j] = "N"

ans = "No"
for i in range(3):
    if B[i][0] is B[i][1] is B[i][2]: ans = "Yes"
    if B[0][i] is B[1][i] is B[2][i]: ans = "Yes"

if B[0][0] is B[1][1] is B[2][2]: ans = "Yes"
if B[0][2] is B[1][1] is B[0][2]: ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
import sys
L=list()
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
g,h,i=map(int,input().split())
N=int(input())
R=[a,b,c,d,e,f,g,h,i]
for k in range(N):
  A=int(input())
  if A in R:
    L.append(A)
  if a in L and b in L and c in L:
    print("Yes")
    sys.exit()
  if d in L and e in L and f in L:
    print("Yes")
    sys.exit()
  if g in L and h in L and i in L:
    print("Yes")
    sys.exit()
  if a in L and d in L and g in L:
    print("Yes")
    sys.exit()
  if e in L and b in L and h in L:
    print("Yes")
    sys.exit()
  if f in L and i in L and c in L:
    print("Yes")
    sys.exit()
  if a in L and e in L and i in L:
    print("Yes")
    sys.exit()
  if e in L and g in L and c in L:
    print("Yes")
    sys.exit()
print("No")

Submission status: Accepted

Solution code:
A= [list(map(int, input().split())) for i in range(3)]
N = int(input())
B = [int(input()) for i in range(N)]
#print(A)
for b in B:
    for i in range(len(A)):
        for u in range(len(A[i])):
            if b==A[i][u]:
                A[i][u]=0
                
s=False
if A[0][0]==A[0][1]==A[0][2]==0:
    s=True
if A[1][0]==A[1][1]==A[1][2]==0:
    s=True
if A[2][0]==A[2][1]==A[2][2]==0:
    s=True
if A[0][0]==A[1][0]==A[2][0]==0:
    s=True
if A[0][1]==A[1][1]==A[2][1]==0:
    s=True
if A[0][2]==A[1][2]==A[2][2]==0:
    s=True
if A[0][0]==A[1][1]==A[2][2]==0:
    s=True
if A[0][2]==A[1][1]==A[2][0]==0:
    s=True
#print(A)
if s:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import numpy as np

A = []
for _ in range(3):
    A.append([int(x) for x in input().split()])
A = np.array(A)
R = np.zeros((3,3))
N = int(input())
B = []

for _ in range(N):
    b = int(input())
    x, y = np.where(A == b)
    if len(x) > 0:
        for i in range(len(x)):
            R[x[i], y[i]] = 1

#列
row1 = (np.sum(R, axis=1) >= 3).sum()
row2 = (np.sum(R, axis=0) >= 3).sum()

c1 = R[0][0] + R[1][1] + R[2][2]
c2 = R[0][2] + R[1][1] + R[2][0]
if row1 > 0 or row2 > 0 or c1 >= 3 or c2 >= 3:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np
A=[list(map(int,input().split())) for _ in range(3)]
N=int(input())
b=[int(input()) for _ in range(N)]
B=np.zeros((3,3))
for i in range(3):
  for j in range(3):
    for k in range(N):
      if A[i][j]==b[k]:
        B[i][j]=1
flag=False

for i in range(3):
  if B[i][0]==1 and B[i][1]==1 and B[i][2]==1:
    flag=True
  elif B[0][i]==1 and B[1][i]==1 and B[2][i]==1:
    flag=True
  elif B[0][0]==1 and B[1][1]==1 and B[2][2]==1:
    flag=True
  elif B[2][0]==1 and B[1][1]==1 and B[0][2]==1:
    flag=True
if flag==True:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
a = [[int(x) for x in 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 b == a[i][j]: a[i][j] = 0

ans = "No"
for i in range(3):
    if sum(a[i]) == 0: ans = "Yes"

for j in range(3):
    if a[0][j] + a[1][j] + a[2][j] == 0: ans = "Yes"

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import sys

A = []
for i in range(3):
    A.append([j for j in map(int,input().split())])
A = np.array(A)
N = int(input())
numbers = []
for n in range(N):
    numbers.append(int(input()))

for number in numbers:
    A = np.where(A==number,0,A)

for a in A:
    if np.array_equal(a,np.array([0,0,0])):
        print('Yes')
        sys.exit()
for a in A.T:
    if np.array_equal(a,np.array([0,0,0])):
        print('Yes')
        sys.exit()
if 0 == A[0][0] and 0 == A[1][1] and 0 == A[2][2]:
    print('Yes')
    sys.exit()
elif 0 == A[0][2] and 0 == A[1][1] and 0 == A[2][0]:
    print('Yes')
    sys.exit()

print('No')

Submission status: Accepted

Solution code:
#S = [[0 for j in range(3)] for i in range(2)]　2行3列の場合
S = [[0 for j in range(3)] for i in range(3)]

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

for i in range(3):
    Z=list(map(int,input().split()))
    for j in range(3):
        S[i][j]=Z[j]
        
N=int(input())

for k in range(N):
    tama=int(input())
    for i in range(3):
        for j in range(3):
            if tama==S[i][j]:
                bingo[i][j]=1

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

Submission status: Accepted

Solution code:
# ビンゴを用意x3行
A = [list(map(int, input().split())) for _ in range(3)]
# N個呼ぶ
N = int(input())

for _ in range(N):
    b = int(input())
    for y in range(3):
        for x in range(3):
            # リストAのy行x列目がbと一緒なら-1印をつける
            if A[y][x] == b:
                A[y][x] = -1
# たてビンゴの処理　もし1回もfalseにならなかったらyes
for y in range(3):
    f = True
    for x in range(3):
        # 上の処理で-1がビンゴとして
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()
# 横ビンゴの処理
for x in range(3):
    f = True
    for y in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()
# 1,1 2,2 3,3 右斜めビンゴの処理
f = True
for x in range(3):
    if A[x][x] != -1:
        f = False
if f:
    print('Yes')
    exit()
# xが2のとき0、１の時1、0の時2と左斜めビンゴの処理
f = True
for x in range(3):
    if A[2 - x][x] != -1:
        f = False
if f:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

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

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

for i in range(3):
    if bingo[i] == [True, True, True]:
        print("Yes")
        flag = True
        break
    elif bingo[0][i] and bingo[1][i] and bingo[2][i]:
        print("Yes")
        flag = True
        break
    elif (bingo[0][0] and bingo[1][1] and bingo[2][2]) or (bingo[0][2] and bingo[1][1] and bingo[2][0]):
        print("Yes")
        flag = True
        break

if not flag:
    print("No")

Submission status: Accepted

Solution code:
sheet = []
b = []

for i in range(3):
    sheet.append(list(map(int, input().split())))

N = int(input())

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

for number in b:
    if number in sheet[0]:
        sheet[0][sheet[0].index(number)] = 0
    if number in sheet[1]:
        sheet[1][sheet[1].index(number)] = 0
    if number in sheet[2]:
        sheet[2][sheet[2].index(number)] = 0

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

Submission status: Accepted

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

n = int(input())
b = set()
for _ in range(n):
  bi = int(input())
  b.add(bi)

for hi in range(3):
  ok = True
  for _ in range(3):
    if a[hi][_] not in b:
      ok = False
      
  if ok:
    print("Yes")
    sys.exit()

for wi in range(3):
  ok = True
  for _ in range(3):
    if a[_][wi] not in b:
      ok = False
      
  if ok:
    print("Yes")
    sys.exit()

if all([a[0][0] in b, a[1][1] in b, a[2][2] in b]) or all([a[0][2] in b, a[1][1] in b, a[2][0] in b]):
           print("Yes")
           sys.exit()
           
print("No")

Submission status: Accepted

Solution code:
def resolve():
    A = []
    ans = "No"
    for i in range(3):
        A.append(list(map(int, input().split())))
    n = int(input())
    b = 0
    for j in range(n):
        b = int(input())
        for p in range(3):
            for q in range(3):
                if A[p][q] == b:
                    A[p][q] = 0
    for g in range(3):
        if A[g][0]+A[g][1]+A[g][2] == 0 or A[0][g]+A[1][g]+A[2][g] == 0 or A[0][0]+A[1][1]+A[2][2] == 0 or A[0][2]+A[1][1]+A[2][0] == 0:
             ans ="Yes"
    print(ans)
resolve()

Submission status: Accepted

Solution code:
class Cell:
    def __init__(self, x, y, num):
        self.x = x
        self.y = y
        self.num = num
        self.opened = False

    def open(self) -> None:
        self.opened = True

    def punch(self, called_number: int) -> None:
        if called_number == self.num:
            self.open()


class Line:
    """タテ・ヨコ・ナナメいずれかのライン"""

    def __init__(self, values):
        self.values = values

    def __post_init__(self):
        # 気分で書いたけど、今回はなくても良いと思う
        if len(self.values) != 3:
            raise ValueError('今回は3つ以外ありえないよ〜')

    def is_bingo(self) -> bool:
        return all([c.opened for c in self.values])


class Cells:
    """Boardって概念もあると思うけど、単純にCellのコレクションでいく"""

    def __init__(self, values):
        self.values = values

    def punch(self, called_numbers) -> None:
        for called_number in called_numbers:
            for cell in self.values:
                cell.punch(called_number)

    def has_one_more_bingo(self) -> bool:
        # タテ
        tate1 = Line([c for c in self.values if c.y == 1])
        tate2 = Line([c for c in self.values if c.y == 2])
        tate3 = Line([c for c in self.values if c.y == 3])

        # ヨコ
        yoko1 = Line([c for c in self.values if c.x == 1])
        yoko2 = Line([c for c in self.values if c.x == 2])
        yoko3 = Line([c for c in self.values if c.x == 3])

        # ナナメ
        # 左上から右下に向かってのナナメ(＼)
        diag1 = Line([c for c in self.values if c.x == c.y])

        # 右上から左下に向かってのナナメ(／)
        diag2 = Line([c for c in self.values if (((c.x, c.y) == (1, 3)) or
                                                 ((c.x, c.y) == (2, 2)) or
                                                 ((c.x, c.y) == (3, 1)))])

        return any([tate1.is_bingo(), tate2.is_bingo(), tate3.is_bingo(),
                    yoko1.is_bingo(), yoko2.is_bingo(), yoko3.is_bingo(),
                    diag1.is_bingo(), diag2.is_bingo()])

    @classmethod
    def create(cls, A):
        cells = []

        for row, line in enumerate(A, start=1):
            for col, num in enumerate(line, start=1):
                cell = Cell(x=row, y=col, num=num)
                cells.append(cell)

        return Cells(cells)


def actual(n, A, B):
    cells = Cells.create(A)

    cells.punch(B)

    if cells.has_one_more_bingo():
        return 'Yes'

    return 'No'

line1 = list(map(int, input().split()))
line2 = list(map(int, input().split()))
line3 = list(map(int, input().split()))

A = [line1,
     line2,
     line3]

n = int(input())
B = []

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

print(actual(n, A, B))

Submission status: Accepted

Solution code:
###abc157
###<a>ac
##n=int(input())
##print(n//2+n%2)

#<b> wa
import numpy as np
s=np.array([list(map(int,input().split())) for i in range(3)])
n=int(input())
for j in range(n):
    s=np.where(s==int(input()),0,s)
bingo1=min(np.sum(s,axis=0))==0
bingo2=min(np.sum(s,axis=1))==0
bingo3=s[2][0]==0 and s[1][1]==0 and s[0][2]==0
bingo4=s[0][0]==0 and s[1][1]==0 and s[2][2]==0
if bingo1 or bingo2 or bingo3 or bingo4:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
def IsBingo(arr_9):
    BINGO=['x','x','x']
    C1=arr_9[0::3]
    C2=arr_9[1::3]
    C3=arr_9[2::3]
    X1=[arr_9[0],arr_9[4],arr_9[8]]
    X2=[arr_9[2],arr_9[4],arr_9[6]]
    if (arr_9[:3]==BINGO or arr_9[3:6]==BINGO or arr_9[6:]==BINGO
     or C1==BINGO or C2==BINGO or C3==BINGO or X1==BINGO or X2==BINGO):
        return 'BINGO'


A1=list(input().split())
A2=list(input().split())
A3=list(input().split())
A=A1+A2+A3
N=int(input())
for _ in range(N):
    n=input()
    if A.count(n)==1:
        A[A.index(n)]="x"
# A1=A[:3]
# A2=A[3:6]
# A3=A[6:]
# print(A1,A2,A3)

if IsBingo(A)=='BINGO':
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def IsBingo(arr_9):
    BINGO=['x','x','x']
    C1=arr_9[0::3]
    C2=arr_9[1::3]
    C3=arr_9[2::3]
    X1=[arr_9[0],arr_9[4],arr_9[8]]
    X2=[arr_9[2],arr_9[4],arr_9[6]]
    if arr_9[:3]==BINGO or arr_9[3:6]==BINGO or arr_9[6:]==BINGO or C1==BINGO or C2==BINGO or C3==BINGO or X1==BINGO or X2==BINGO:
        return 'BINGO'


A1=list(input().split())
A2=list(input().split())
A3=list(input().split())
A=A1+A2+A3
N=int(input())
for _ in range(N):
    n=input()
    if A.count(n)==1:
        A[A.index(n)]="x"
# A1=A[:3]
# A2=A[3:6]
# A3=A[6:]
# print(A1,A2,A3)

if IsBingo(A)=='BINGO':
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
A=[list(map(int,input().split())) for i in range(3)]
AB=[[0 for i in range(3)] for j in range(3)]
N=int(input())
for i in range(N):
    x=int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k]==x:
                AB[j][k]=1
c=1
for i in range(3):
    if AB[i][0]*AB[i][1]*AB[i][2]==1:
        c=0
        break
    if AB[0][i]*AB[1][i]*AB[2][i]==1:
        c=0
        break
    if AB[0][0]*AB[1][1]*AB[2][2]==1:
        c=0
        break
    if AB[0][2]*AB[1][1]*AB[2][0]==1:
        c=0
        break
        

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

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

b = []

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


for c in b:
    if c in a_1:
        a_1[a_1.index(c)] = 'O'
    elif c in a_2:
        a_2[a_2.index(c)] = 'O'
    elif c in a_3:
        a_3[a_3.index(c)] = 'O'

for d in range(3):
    if a_1[d] == 'O' and a_2[d] == 'O' and a_3[d] == 'O':
        print('Yes')
        exit()
    if a_1.count('O') == 3 :
        print('Yes')
        exit()
    if a_2.count('O') == 3 :
        print('Yes')
        exit()
    if a_3.count('O') == 3 :
        print('Yes')
        exit()

if a_1[0] == 'O' and a_2[1] == 'O' and a_3[2] == 'O':
    print('Yes')
    exit()
if a_1[2] == 'O' and a_2[1] == 'O' and a_3[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()))
n = int(input())
for i  in range(n):
  b = int(input())
  if b in a1:
    a1[a1.index(b)] = 0
  elif b in a2:
    a2[a2.index(b)] = 0
  elif b in a3:
    a3[a3.index(b)] = 0

ans = ''
if sum(a1) == 0 or sum(a2) == 0 or sum(a3) == 0:
  ans = 'Yes'
elif a1[0] + a2[0] + a3[0] == 0 or a1[1] + a2[1] + a3[1] == 0 or a1[2] + a2[2] + a3[2] == 0:
  ans = 'Yes'
elif a1[0] + a2[1] + a3[2] == 0 or a1[2] + a2[1] + a3[0] == 0:
  ans = 'Yes'
else:
  ans = 'No'
print(ans)