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 numpy as np
import sys

A = np.zeros((3, 3), dtype=np.int64)
for i in range(3):
    l, m, n = map(int, input().split())
    A[i][0] = l
    A[i][1] = m
    A[i][2] = n
N = int(input())
b = []
for i in range(N):
    k = int(input())
    b.append(k)
for k in range(N):
    for i in range(3):
        for j in range(3):
            if b[k] == A[i][j]:
                A[i][j] = 0


row = np.sum(A, axis=1)
for i in range(3):
    if row[i] == 0:
        print('Yes')
        sys.exit()


col = np.sum(A, axis=0)
for i in range(3):
    if col[i] == 0:
        print('Yes')
        sys.exit()

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

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

print('No')

Submission status: Accepted

Solution code:
import numpy as np
A=list(list(map(int, input().split())) for _ in range(3))
N=int(input())
B=list(int(input()) for _ in range(N))
a=np.array(A)
c=a.flatten()
C=c.tolist()

for c in range(len(C)):
    for b in range(len(B)):
        if C[c]==B[b]:
            C[c]=0

if (sum(C[:3])==0) | (sum(C[3:6])==0) | (sum(C[6:9])==0):
    print("Yes")
elif (C[0]+C[3]+C[6]==0) | (C[1]+C[4]+C[7]==0) | (C[2]+C[5]+C[8]==0):
    print("Yes")
elif (C[0]+C[4]+C[8]==0) | (C[2]+C[4]+C[6]==0): 
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def solve():
    s1 = list(map(int,input().split()))
    s2 = list(map(int,input().split()))
    s3 = list(map(int,input().split()))
    s4 = [s[0] for s in [s1,s2,s3]]
    s5 = [s[1] for s in [s1,s2,s3]]
    s6 = [s[2] for s in [s1,s2,s3]]
    s7 = [s[i] for i,s in zip([0,1,2], [s1,s2,s3])]
    s8 = [s[i] for i,s in zip([2,1,0], [s1,s2,s3])]
    S = set(int(input()) for _ in range(int(input())))
    if any(set(s).issubset(S) for s in [s1,s2,s3,s4,s5,s6,s7,s8]):
        return 'Yes'
    else:
        return 'No'

if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
b = [0] * 9


def hantei():
    for i in range(3):
        if b[i * 3] == 1 and b[i * 3 + 1] == 1 and b[i * 3 + 2] == 1:
            return True
    for i in range(3):
        if b[i] == 1 and b[i + 3] == 1 and b[i + 6] == 1:
            return True
    if b[0] == 1 and b[4] == 1 and b[8] == 1:
        return True
    if b[2] == 1 and b[4] == 1 and b[6] == 1:
        return True
    return False


a = [0] * 9
[a[0], a[1], a[2]] = input().split()
[a[3], a[4], a[5]] = input().split()
[a[6], a[7], a[8]] = input().split()
a = [int(i) for i in a]

n = int(input())

for i in range(n):
    c = int(input())
    for j in range(len(a)):
        if a[j] == c:
            b[j] = 1

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

Submission status: Accepted

Solution code:
'''
Created on Mar 1, 2020

@author: dell
'''
arr=[]
for i in range(3):
    a=list(map(int,input().split()))
    arr.append(a)
n=int(input())
f=0
lst=[]
for i in range(n):
    a=int(input())
    lst.append(a)
if(arr[0][0] in lst and arr[1][1] in lst and arr[2][2] in lst):
    print("Yes")
elif(arr[0][2] in lst and arr[1][1] in lst and arr[2][0] in lst):
    print("Yes")
else:
    for i in range(3):
        f=0
        for j in range(3):
            if(arr[i][j] not in lst):
                f=1
        if(f==0):
            print("Yes")
            break
if(f==1):
    for i in range(3):
        f=0
        for j in range(3):
            if(arr[j][i] not in lst):
                f=1
        if(f==0):
            print("Yes")
            break
if(f==1):
    print("No")

Submission status: Accepted

Solution code:
A = []

for _ in range(3):
  tmp = map(int, input().split())
  A += tmp

N = int(input())

b = []

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

Bingo=[]
  
for bb in b:
  if bb not in A:
    continue;
  Bingo.append(A.index(bb)+1)

if ((1 in Bingo) and (2 in Bingo) and (3 in Bingo)) or\
((4 in Bingo) and (5 in Bingo) and (6 in Bingo)) or\
((7 in Bingo) and (8 in Bingo) and (9 in Bingo)) or\
((1 in Bingo) and (4 in Bingo) and (7 in Bingo)) or\
((2 in Bingo) and (5 in Bingo) and (8 in Bingo)) or\
((3 in Bingo) and (6 in Bingo) and (9 in Bingo)) or\
((1 in Bingo) and (5 in Bingo) and (9 in Bingo)) or\
((3 in Bingo) and (5 in Bingo) and (7 in Bingo)):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy

def main():
  card = []
  bingo = numpy.zeros((3, 3))
  for i in range(3):
    card.append(list(map(int, input().split())))
  card = numpy.array(card)
  n = int(input())
  for _ in range(n):
    b = int(input())
    for i in range(3):
      for j in range(3):
        if card[i, j] == b:
          bingo[i, j]=1

  l, r = 0, 0
  for i in range(3):
    if sum(bingo[i, :]) == 3 or sum(bingo[:, i]) == 3:
      print('Yes')
      return 
    l += bingo[i, i]
    r += bingo[i, 2-i]
  if l == 3 or r == 3:
    print('Yes')
    return 
  print('No')
  


if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
num_card = [[int(i) for i in input().split()] for _ in range(3)]
n = int(input())
b_array = [int(input()) for _ in range(n)]

card = [[False for _ in range(3)] for _ in range(3)]

for b in b_array:
    for i in range(3):
        for j in range(3):
            if num_card[i][j] == b:
                card[i][j] = True

bingo = False

for i in range(3):
    if all(card[i]):
        bingo = True
        break
    if all((card[0][i], card[1][i], card[2][i])):
        bingo = True
        break

if all([card[i][i] for i in range(3)]):
    bingo = True

if all([card[i][2-i] for i in range(3)]):
    bingo = True

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

Submission status: Accepted

Solution code:
def solve():
    A = [list(map(int, input().split())) for _ in range(3)]
    n = int(input())
    for b in [int(input()) for _ in range(n)]:
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    A[i][j] = 0
    for i in range(3):
        if sum(A[i]) == 0:
            return "Yes"
    A = list(zip(*A[::-1]))
    for i in range(3):
        if sum(A[i]) == 0:
            return "Yes"
    if A[0][0] + A[1][1] + A[2][2] == 0 or A[2][0] + A[1][1] + A[0][2] == 0:
        return "Yes"
    return "No"
print(solve())

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

A = [read_int() for _ in range(3)]
N = read_int()[0]
B = [read_int()[0] for _ in range(N)]

# card = [[0 for j in range(3)] for i in range(3)]
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]]
def solve():
    for b in B:
        for row in A:
            pos = ind_or_f(row, b)
            if pos != -1:
                row[pos] = -1
                break
    for bb in bingo:
        flag = True
        for b in bb:
            if A[b // 3][b % 3] != -1:
                flag = False
            if not flag:
                break
        if flag == True:
            return "Yes"
    return "No"

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

if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
A1 = list(map(int,input().rstrip().split()))
A2 = list(map(int,input().rstrip().split()))
A3 = list(map(int,input().rstrip().split()))

a = []
a.append(A1)
a.append(A2)
a.append(A3)

N = int(input().rstrip())
b = []
for i in range(N):
  b.append(int(input().rstrip()))

out = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for t in b:
  for m in range(3):
    for n in range(3):
      if a[m][n] == t :
        out[m][n] = 1

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

Submission status: Accepted

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

N = int(input())

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

atari_l = []
for b in b_l:
  if b in card:
    atari_l.append( card.index(b)) 
  else:
    continue

#準備
def warusan(n):
  return n%3
atari = list(map(warusan,atari_l))

#斜め
if 0 in atari_l and 4 in atari_l and 8 in atari_l:
  print("Yes")
elif 2 in atari_l and 4 in atari_l and 6 in atari_l:
  print("Yes")

#横
elif 0 in atari_l and 1 in atari_l and 2 in atari_l:
  print("Yes")
elif 3 in atari_l and 4 in atari_l and 5 in atari_l:
  print("Yes")
elif 6 in atari_l and 7 in atari_l and 8 in atari_l:
  print("Yes")  


#縦
elif atari.count(0) == 3:
  print("Yes")
elif atari.count(1) == 3:
  print("Yes")
elif atari.count(2) == 3:
  print("Yes")

else:
  print("No")

Submission status: Accepted

Solution code:
import numpy as np
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()))
a = np.array(a)
for i in range(n):
    a[np.where(a == b[i])] = bool(b[i] in a)
def check(i,j):
    if i >= 0 and i < 3 and j >= 0 and j < 3:
        if a[i][j] == 1:
            return True
    return False
for i in range(3):
    if ((a[i][0] == 1 and a[i][1] == 1 and a[i][2] == 1) or (a[0][i] == 1 and a[1][i] == 1 and a[2][i] == 1)):
        print('Yes')
        break
else:
    if ((a[0][0] == 1 and a[1][1] == 1 and a[2][2] == 1) or (a[0][2] == 1 and a[1][1] == 1 and a[2][0] == 1)):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
import math
import numpy as np
from collections import deque
def main():
    a_1 = [int(t)for t in input().split()]
    a_2 = [int(t)for t in input().split()]
    a_3 = [int(t)for t in input().split()]

    a = [a_1,a_2,a_3]

    card = np.array(a)

    n = int(input())

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

    result = np.zeros((3,3),np.int)!=0

    for i in b:
        t = card==i
        result |= t

    rest = result.T
    c = result[0].all() or result[1].all() or result[2].all()
    r = rest[0].all() or rest[1].all() or rest[2].all()

    sl = result[0][0] and result[1][1] and result[2][2]
    bs = result[2][0] and result[1][1] and result[0][2]

    print("Yes" if c or r or sl or bs else "No")
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a = []
a.append([int(i) for i in input().split()])
a.append([int(i) for i in input().split()])
a.append([int(i) for i in input().split()])
    
tf = [[False for i in range(3)] for j in range(3)]
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                tf[j][k] = True

bingo = 0
for i in range(3):
    if tf[i] == [True, True, True]:
        bingo += 1

for i in range(3):
    if tf[0][i] == True and tf[1][i] == True and tf[2][i] == True:
        bingo += 1

if tf[0][0] == True and tf[1][1] == True and tf[2][2] == True:
    bingo += 1
    
if tf[0][2] == True and tf[1][1] == True and tf[2][0] == True:
    bingo += 1

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

Submission status: Accepted

Solution code:
import collections as c
import sys
input = sys.stdin.readline
ip = lambda : map(int, input().split())
mod = 10**9+7
# ##############
A = []
for i in range(3):
    A.append(list(ip()))
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] = 0
# print(A)
if sum(A[0]) == 0 or sum(A[1]) == 0 or sum(A[2]) == 0 or (A[0][0] + A[1][0] + A[2][0] == 0) or (A[0][1] + A[1][1] + A[2][1] == 0) or (A[0][2] + A[1][2] + A[2][2] == 0) or (A[0][0] + A[1][1] + A[2][2] == 0) or (A[0][2] + A[1][1] + A[2][0] == 0):
    print('Yes')
else:print('No')

Submission status: Accepted

Solution code:
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l3=list(map(int,input().split()))
n=int(input())
a=[int(input()) for i in range (n)]
if l1[0] in a:
  l1[0]=0
if l1[1] in a:
  l1[1]=0   
if l1[2] in a:
  l1[2]=0 
if l2[0] in a:
  l2[0]=0 				
if l2[1] in a:
  l2[1]=0 
if l2[2] in a:
  l2[2]=0 
if l3[0] in a:
  l3[0]=0 
if l3[1] in a:
  l3[1]=0
if l3[2] in a:
  l3[2]=0 
ans="No"
if l1==[0,0,0]:
  ans="Yes"
if l2==[0,0,0]:
  ans="Yes"
if l3==[0,0,0]:
  ans="Yes"
if l1[0]==l2[0]==l3[0]==0:
  ans="Yes"
if l1[1]==l2[1]==l3[1]==0:
  ans="Yes"
if l1[2]==l2[2]==l3[2]==0:
  ans="Yes"
if l1[0]==l2[1]==l3[2]==0:
  ans="Yes"
if l1[2]==l2[1]==l3[0]==0:
   ans="Yes"
print(ans)

Submission status: Accepted

Solution code:
card_1 = [i for i in input().split()]
card_2 = [i for i in input().split()]
card_3 = [i for i in input().split()]
call_cnt = int(input())
call_num = [input() for i in range(call_cnt)]

cent_num = card_2[1]

tate_1 = [card_1[0], card_2[0], card_3[0]]
tate_2 = [card_1[1], card_2[1], card_3[1]]
tate_3 = [card_1[2], card_2[2], card_3[2]]

cross_l = [card_1[0], card_2[1], card_3[2]]
cross_r = [card_1[2], card_2[1], card_3[0]]

if cent_num in call_num:
    if len(set(call_num)&set(card_1)) == 3:
        print('Yes')
    elif len(set(call_num)&set(card_2)) == 3:
        print('Yes')
    elif len(set(call_num)&set(card_3)) == 3:
        print('Yes')
    elif len(set(call_num)&set(tate_1)) == 3:
        print('Yes')
    elif len(set(call_num)&set(tate_2)) == 3:
        print('Yes')
    elif len(set(call_num)&set(tate_3)) == 3:
        print('Yes')
    elif len(set(call_num)&set(cross_l)) == 3:
        print('Yes')
    elif len(set(call_num)&set(cross_r)) == 3:
        print('Yes')
    else:
        print('No')
else:
    if len(set(call_num)&set(card_1)) == 3:
        print('Yes')
    elif len(set(call_num)&set(card_3)) == 3:
        print('Yes')
    elif len(set(call_num)&set(tate_1)) == 3:
        print('Yes')
    elif len(set(call_num)&set(tate_3)) == 3:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

sc = 1
DEB = False

def check_vertical(card):
    V = [sum(card[sc][i]) for i in range(3)]
    if DEB: print(V)
    return (3 in V)

def check_horizen(card):
    H = [sum([card[sc][j][i] for j in range(3)]) for i in range(3)]
    if DEB: print(H)
    return (3 in H)
def check_diag(card):
    D = [card[sc][0][0]+card[sc][1][1]+card[sc][2][2],
         card[sc][0][2]+card[sc][1][1]+card[sc][2][0]]
    if DEB: print(D)
    return(3 in D)

def check_card(card):
    return (check_diag(card) or check_horizen(card) or check_vertical(card))

for b in B:
    for i in range(3):
        for j in range(3):
            if card[0][i][j] == b: card[1][i][j] = 1
            tf = check_card(card)
            if tf:
                print('Yes')
                break
        else:
            continue
        break
    else:
        continue
    break
else:
    if tf is False:
        print('No')

Submission status: Accepted

Solution code:
import sys
a = []
for i in range(3):
    a.append(list(input().split()))    

n = int(input())
b = []
for i in range(n):
    b.append(input())
# if n > 6:
#     print("Yes")
# elif n < 3:
#     print("No")
# else:
ans = [["0","0","0"],["0","0","0"],["0","0","0"]]
for i in range(n):
    for j in range(3):
        if b[i] in a[j]:
            index = a[j].index(b[i])
            ans[j][index]  = "1"
# print(ans)
for i in range(3):
    if "0" in ans[i]:
        pass
    else:
        print("Yes")
        sys.exit()

count = 0
for i in range(3):
    if "0" in ans[i][0]:
        pass
    else:
        count += 1
if count == 3:
    print("Yes")
    sys.exit()
count = 0
for i in range(3):
    if "0" in ans[i][1]:
        pass
    else:
        count += 1
if count == 3:
    print("Yes")
    sys.exit()
count = 0
for i in range(3):
    if "0" in ans[i][2]:
        pass
    else:
        count += 1
if count == 3:
    print("Yes")
    sys.exit()

count = 0
for i in range(3):
    # print(a[i][i])
    if ans[i][i] == "1":
        # print(count)
        count += 1
    if count == 3:
        print("Yes")
        sys.exit()

count = 0
for i in range(3):
    if ans[i][-(i+1)] == "1":
        count += 1
    if count == 3:
        print("Yes")
        sys.exit()
print("No")



# print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def abc157b(bingo, b):
    ans = False

    # check row
    for i in range(0, 3):
        bCnt = 0
        for j in range(0, 3):
            if bingo[i][j] in b:
                bCnt += 1
#                print("bingo!" + str(i) + str(j))
        if bCnt == 3:
            ans = True

    # check column
    for j in range(0, 3):
        bCnt = 0
        for i in range(0, 3):
            if bingo[i][j] in b:
                bCnt += 1
#                print("bingo!" + str(i) + str(j))
        if bCnt == 3:
            ans = True

    # check slope
    bCnt = 0
    for i in range(0, 3):
        if bingo[i][i] in b:
            bCnt += 1
#            print("bingo!" + str(i) + str(i))
    if bCnt == 3:
        ans = True

    bCnt = 0
    for i in range(0, 3):
        if bingo[i][2-i] in b:
            bCnt += 1
#            print("bingo!" + str(i) + str(2-i))
    if bCnt == 3:
        ans = True
    
    if ans:
        return("Yes")
    else:
        return("No")

###
# main
if(__name__ == '__main__'):
    # input
    bingoArray = [[] for _ in range(3)]
    for i in range(0, 3):
        bingoArray[i] = list(map(int, input().split(" ")))
    n = int(input())
    b = [[] for _ in range(n)]
    for j in range(0, n):
        b[j] = int(input())
    
    accomplishment = abc157b(bingoArray, b)
    
    # output
    print(accomplishment)
# else:
    # do nothing

Submission status: Accepted

Solution code:
a1 = input().split()
a2 = input().split()
a3 = input().split()

n = int(input())

bingo_sheet = a1 + a2 + a3

atari = []


for _ in range(n):
    num = input()
    try:
        atari_index = bingo_sheet.index(num)
        atari.append(str(atari_index + 1))
    except:
        continue


atari_true = False

if '1' in atari:
    if '2' in atari:
        if '3' in atari:
            atari_true = True
    if '4' in atari:
        if '7' in atari:
            atari_true = True
    if '5' in atari:
        if '9' in atari:
            atari_true = True

if '2' in atari:
    if '5' in atari:
        if '8' in atari:
            atari_true = True

if '3' in atari:
    if '6' in atari:
        if '9' in atari:
            atari_true = True
    if '5' in atari:
        if '7' in atari:
            atari_true = True

if '4' in atari:
    if '5' in atari:
        if '6' in atari:
            atari_true = True

if '7' in atari:
    if '8' in atari:
        if '9' in atari:
            atari_true = True
            
if atari_true:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np

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

a = np.array(a)
b = np.array(b)

after = np.zeros((3,3))
for i in range(N):
    after += a == b[i]
    
bool1 = (np.sum(after, axis=0)==3).sum()
bool2 = (np.sum(after, axis=1)==3).sum()
bool3 = (after[0,0]+after[1,1]+after[2,2])==3
bool4 = (after[0,2]+after[1,1]+after[2,0])==3

if bool1+bool2+bool3+bool4>0:
    ans = 'Yes'
else:
    ans = 'No'
    
print(ans)

Submission status: Accepted

Solution code:
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
a3 = list(map(int,input().split()))
n = int(input())
b = []
ans = "No"
for i in range(n):
    b.append(int(input()))

count = 0
for i in a1:
    if i in b:
        count += 1
if count == 3:
    ans = "Yes"

count2 = 0
for i in a2:
    if i in b:
        count2 += 1
if count2 == 3:
    ans = "Yes"

count3 = 0
for i in a3:
    if i in b:
        count3 += 1
if count3 == 3:
    ans = "Yes"

for i in range(3):
    if (a1[i] in b) and (a2[i] in b) and (a3[i] in b):
        ans = "Yes"


if (a1[0] in b) and (a2[1] in b) and (a3[2] in b):
    ans = "Yes"

if (a1[2] in b) and (a2[1] in b) and (a3[0] in b):
    ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
def bingocheck(ANS):
    if'A00' in ANS and 'A10' in ANS and 'A20' in ANS:
        return 1
    if'A01' in ANS and 'A11' in ANS and 'A21' in ANS:
        return 1
    if'A02' in ANS and 'A12' in ANS and 'A22' in ANS:
        return 1
    if'A00' in ANS and 'A01' in ANS and 'A02' in ANS:
        return 1
    if'A10' in ANS and 'A11' in ANS and 'A12' in ANS:
        return 1
    if'A20' in ANS and 'A21' in ANS and 'A22' in ANS:
        return 1
    if'A00' in ANS and 'A11' in ANS and 'A22' in ANS:
        return 1
    if'A02' in ANS and 'A11' in ANS and 'A20' in ANS:
        return 1
    return 0




A0 = list(map(int,input().split()))
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
n = int(input())
ANS = []
for i in range(n):
    b = int(input())
    for i in range(3):
        if b == A1[i]:
            ANS.append('A1'+str(i))
    for i in range(3):
        if b == A2[i]:
            ANS.append('A2'+str(i))
    for i in range(3):
        if b == A0[i]:
            ANS.append('A0'+str(i))
    if bingocheck(ANS)==1:
        print('Yes')
        break
else:
    print('No')

Submission status: Accepted

Solution code:
*a1, = map(int, input().split())
*a2, = map(int, input().split())
*a3, = map(int, input().split())
a = [a1, a2, a3]


n = int(input())
for _ in range(n):
    b = int(input())
    for i, row in enumerate(a):
        for j, x in enumerate(row):
            if x == b:
                a[i][j] = 0

is_bingo = False
for row in a:
    if sum(row) == 0:
        is_bingo = True

for col in zip(*a):
    if sum(col) == 0:
        is_bingo = True

if all(a[i][i] == 0 for i in range(3)):
    is_bingo = True

if a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0:
    is_bingo = True

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

def main():
    import numpy as np
    A = [list(map(int,readline().split())) for _ in range(3)]
    N, *b = map(int, read().split())
    A = np.array(A)
    B = np.zeros(A.shape)
    for i in A.reshape(-1):
        if i in b:
            B[np.where(A == i)] = 1
    for i in range(3):
        if np.all(B[i, :] == 1):
            print('Yes')
            break
        if np.all(B[:, i] == 1):
            print('Yes')
            break
    else:
        if B[0,0]==B[1,1]==B[2,2]==1:
            print('Yes')
        elif B[0,2]==B[1,1]==B[2,0]==1:
            print('Yes')
        else:
            print('No')
    return
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
        
A = []
A = np.zeros((3, 3))
for i in range(3):
    A[i] =[int(e) for e in input().split()]
N = int(input())    
B = []
for i in range(N):
    B.append(int(input()))
ans = []
for i in range(3):
    ans.append(A[i])
ans.append([A[0][0], A[1][1], A[2][2]])
ans.append([A[0][2], A[1][1], A[2][0]])
ans.append([A[0][0], A[1][0], A[2][0]])
ans.append([A[0][1], A[1][1], A[2][1]])
ans.append([A[0][2], A[1][2], A[2][2]])
ans = np.array(ans)
flg = 0
for i in ans:
    if i[0] in B and i [1] in B and i[2] in B:
        print('Yes')
        flg = 1
        break
if flg == 0:
    print('No')

Submission status: Accepted

Solution code:
BingoRow = 3
BingoList = [list(map(int,input().split())) for i in range(BingoRow)]
 
TargetRow = int(input())
TargetList = [int(input()) for i in range(TargetRow)]
 
ansList = []
x = 0
flg = False
for row in BingoList:
  for num in row:
    flg = False
    for target in TargetList:
      if num == target:
        ansList.append(1)
        flg = True
    if not flg:
      ansList.append(0)
 
if (ansList[0] + ansList[1] + ansList[2]) == 3:
  print('Yes')
elif (ansList[3] + ansList[4] + ansList[5]) == 3:
  print('Yes')
elif (ansList[6] + ansList[7] + ansList[8]) == 3:
  print('Yes')
elif (ansList[0] + ansList[3] + ansList[6]) == 3:
  print('Yes')
elif (ansList[1] + ansList[4] + ansList[7]) == 3:
  print('Yes')
elif (ansList[2] + ansList[5] + ansList[8]) == 3:
  print('Yes')
elif (ansList[0] + ansList[4] + ansList[8]) == 3:
  print('Yes')
elif (ansList[2] + ansList[4] + ansList[6]) == 3:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
A = list(input().split() for l in range(3))
N = int(input())
B = list(int(input()) for i in range(N))

for s in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == str(s):
                A[i][j] = "0"

def bingo(A):
    for i in range(3):
        if A[i][0] + A[i][1] + A[i][2] == "000" or A[0][i] + A[1][i] + A[2][i] == "000" or A[0][0] + A[1][1] + A[2][2] == "000" or A[0][2] + A[1][1] + A[2][0] == "000":
            return "Yes"
    return "No"

print(bingo(A))

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 = [0]*N
for i in range(N):
    b = int(input())
    B[i]=b

marubatu = [[0,0,0],
[0,0,0],
[0,0,0]]

for b in B:
    for i,a1 in enumerate(A1):
        if b==a1:
            marubatu[0][i]=1
    for i,a2 in enumerate(A2):
        if b==a2:
            marubatu[1][i]=1
    for i,a3 in enumerate(A3):
        if b==a3:
            marubatu[2][i]=1

def tate():
    f = False
    for i in range(3):
        if (marubatu[i][0])and(marubatu[i][1])and(marubatu[i][2]==1):
            f=True
    return f

def yoko():
    f = False
    for i in range(3):
        if (marubatu[0][i])and(marubatu[1][i])and(marubatu[2][i]==1):
            f=True
    return f

def migisagari():
    f = False
    if (marubatu[0][0])and(marubatu[1][1])and(marubatu[2][2]==1):
        f=True
    return f

def hidarisagari():
    flag=False
    if (marubatu[0][2])and(marubatu[1][1])and(marubatu[2][0]==1):
        flag=True
    return flag

#print(marubatu)

f1 = tate()
f2 = yoko()
f3 = migisagari()
f4 = hidarisagari()

if f1 or f2 or f3 or f4:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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


n=int(input())
l2=[]
for i in range(n):
  l2.append(int(input()))

  
for i in range(len(l)):
  if l[i] in l2:
    l[i]=0
#print(l)

y1=l[0]+l[1]+l[2]
y2=l[3]+l[4]+l[5]
y3=l[6]+l[7]+l[8]
t1=l[0]+l[3]+l[6]
t2=l[1]+l[4]+l[7]
t3=l[2]+l[5]+l[8]
n1=l[0]+l[4]+l[8]
n2=l[2]+l[4]+l[6]

if y1*y2*y3*t1*t2*t3*n1*n2==0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
def output(A, b): 
    BW = [0,0,0]
    for i in range(len(A)):
        for j in range(len(b)):
            if(A[i] == b[j]):
                BW[i] = 1
                break
            else:
                continue
    return BW

A0 = list(map(int, input().split()))
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
N = int(input())
b = [0]*N
for i in range(N):
    b[i] = int(input())

x = output(A0, b)
y = output(A1, b)
z = output(A2, b)

ans = 0
if(sum(x)==3 or sum(y)==3 or sum(z)==3):
    ans = 1
for i in range(3):
    if(x[i]==1 and y[i]==1 and z[i]==1):
        ans = 1
        break
if(x[0]==1 and y[1]==1 and z[2]==1):
    ans = 1
elif(x[2]==1 and y[1]==1 and z[0]==1):
    ans = 1

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

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 = [int(input()) for _ in range(N)]
for i in range(N):
    for j in range(9):
        if b[i] == A[j]:
            A[j] = 0
if A[0]==A[1]==A[2]==0 or A[3]==A[4]==A[5]==0 or A[6]==A[7]==A[8]==0 or A[0]==A[3]==A[6]==0 or A[1]==A[4]==A[7]==0 or A[2]==A[5]==A[8]==0 or A[0]==A[4]==A[8]==0 or A[2]==A[4]==A[6]==0:          
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a = []
for i in range(3):
    ai = list(map(int, input().split()))
    a += [ai]
bingo = [[False, False, False], [False, False, False], [False, False, False]]
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        if b in a[j]:
            bingo[j][a[j].index(b)] = True
            break
e = []
d = []
c = []
r = []
l = []
count = 0
for i in range(3):
    if not (False in bingo[i]):
        print("Yes")
        exit()
    e.append(bingo[i][0])
    d.append(bingo[i][1])
    c.append(bingo[i][2])
    r.append(bingo[i][count])
    l.append(bingo[i][2 - count])
    count += 1
if not (False in e):
    print("Yes")
    exit()
elif not (False in d):
    print("Yes")
    exit()
elif not (False in c):
    print("Yes")
    exit()
elif not (False in r):
    print("Yes")
    exit()
elif not (False in l):
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
A = [[0]*3 for i in range(3)]
a = [[0]*3 for i in range(3)]

for i in range (3):
    X,Y,Z = map(int,input().split())
    a[i][0] = X
    a[i][1] = Y
    a[i][2] = Z

N = int(input())
b = [0]*N

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

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

if sum(A[0]) ==3 or sum(A[1]) ==3 or sum(A[2]) ==3 or A[0][0]+A[1][0]+A[2][0] ==3 or A[0][1]+A[1][1]+A[2][1] ==3 or A[0][2]+A[1][2]+A[2][2] ==3 or A[0][0]+A[1][1]+A[2][2] ==3 or A[0][2]+A[1][1]+A[2][0] ==3:
    print("Yes")
else:
    print("No")