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:
from collections import defaultdict
dic = defaultdict(list)
for i in range(3):
    a = list(map(int,input().split()))
    for j in range(3):
        dic[a[j]].append([i,j])
n = int(input())
B = []
for _ in range(n):
    b = int(input())
    B.append(b)
h = [0]*3
w = [0]*3
d = 0
di = 0
for b in B:
    if b not in dic:
        continue
    x,y = dic[b][0]
    if x== y:
        d += 1
    if x + y ==2:
        di += 1
    h[x] += 1
    w[y] += 1
for i in range(3):
    if h[i]==3 or w[i]==3:
        print('Yes');exit()
if d ==3 or di ==3:
    print('Yes');exit()
print('No')

Submission status: Accepted

Solution code:
import numpy as np

bingo = []
for _ in range(3):
    array = list(map(int,input().split()))
    bingo.append(array)
bingo = np.array(bingo)
n = int(input())
bs = []
for _ in range(n):
    bs.append(int(input()))

for i in bs:
    bingo = np.where(bingo == i, 101, bingo)

h = False
if bingo[0][0] == bingo[1][1] == bingo[2][2] or bingo[0][2] == bingo[1][1] == bingo[2][0]:
    h = True
if h == False:
    for i in range(3):
        if bingo[i][0] == bingo[i][1] == bingo[i][2]:
            h = True
            break
    for j in range(3):
        if bingo[0][j] == bingo[1][j] == bingo[2][j]:
            h = True
            break

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

Submission status: Accepted

Solution code:
list = [list(map(int,input().split())) for i in range(3)]
N = int(input())
A = [[0] * 3 for i in range(3)]
for i in range(N):
  B = int(input())
  for j in range(3):
    for k in range(3):
      if list[j][k] == B:
        A[j][k] += 1
        
result = A[0][0] * A[0][1] * A[0][2]
result += A[1][0] * A[1][1] * A[1][2]
result += A[2][0] * A[2][1] * A[2][2]
result += A[0][0] * A[1][0] * A[2][0]
result += A[0][1] * A[1][1] * A[2][1]
result += A[0][2] * A[1][2] * A[2][2]
result += A[0][0] * A[1][1] * A[2][2]
result += A[0][2] * A[1][1] * A[2][0]
if result >= 1:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

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

for i in range(3):
    for j in range(3):
        for k in b:
            if bingo[i][j]==k:
                bingo[i][j]=-1

flg=False
for i in range(3):
    if bingo[i][0]==-1 and bingo[i][1]==-1 and bingo[i][2]==-1:
        flg=True
        break
    if bingo[0][i]==-1 and bingo[1][i]==-1 and bingo[2][i]==-1:
        flg=True
        break

if bingo[0][0]==-1 and bingo[1][1]==-1 and bingo[2][2]==-1:
    flg=True
elif bingo[0][2]==-1 and bingo[1][1]==-1 and bingo[2][0]==-1:
    flg=True

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

Submission status: Accepted

Solution code:
List = []
for i in range (3):
  List.append(list(map(int, input().split())))
Row = int(input())
Ball = []
for i in range (Row):
  Ball.append(int(input()))
for x in range(Row):
  for i in range(3):
    for j in range(3):
      if Ball[x] == List[i][j]:
        List[i][j] = 0
if List[0][0] == 0 and List[0][1] == 0 and List[0][2] == 0:
  print("Yes")
elif List[1][0] == 0 and List[1][1] == 0 and List[1][2] == 0:
  print("Yes")
elif List[2][0] == 0 and List[2][1] == 0 and List[2][2] == 0:
  print("Yes")
elif List[0][0] == 0 and List[1][0] == 0 and List[2][0] == 0:
  print("Yes")
elif List[0][1] == 0 and List[1][1] == 0 and List[2][1] == 0:
  print("Yes")
elif List[0][2] == 0 and List[1][2] == 0 and List[2][2] == 0:
  print("Yes")
elif List[0][0] == 0 and List[1][1] == 0 and List[2][2] == 0:
  print("Yes")
elif List[0][2] == 0 and List[1][1] == 0 and List[2][0] == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
def bingo_judge(li,a,b,c,d,e,f,flag):
    if li[a-1][b-1] + li[c-1][d-1] + li[e-1][f-1] == 3:
        return True
    if flag:
        return True
    else:
        return False

card = []
card_judge = []
for i in range(3):
    li = list(map(int, input().split()))
    card.append(li)
    card_judge.append([0,0,0])
N = int(input())
for i in range(N):
    number = int(input())
    for t in range(3):
        for u in range(3):
            if number == card[t][u]:
                card_judge[t][u] = 1
flag = False
flag = bingo_judge(card_judge,1,1,2,1,3,1,flag)
flag = bingo_judge(card_judge,1,2,2,2,3,2,flag)
flag = bingo_judge(card_judge,1,3,2,3,3,3,flag)
flag = bingo_judge(card_judge,1,1,1,2,1,3,flag)
flag = bingo_judge(card_judge,2,1,2,2,2,3,flag)
flag = bingo_judge(card_judge,3,1,3,2,3,3,flag)
flag = bingo_judge(card_judge,1,1,2,2,3,3,flag)
flag = bingo_judge(card_judge,1,3,2,2,3,1,flag)
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
a = list(map(int,input().split()))
a += list(map(int,input().split()))
a += list(map(int,input().split()))

c = []
d = [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]

n = int(input())

for i in range(n):
    b = int(input())
    if b in a:
        c += [a.index(b)]


for i in range(8):
    flag = 0
    for j in range(3):
        if d[i][j] in c:
            flag +=1
            if flag ==3:
                print("Yes")
                sys.exit()

else:
    print("No")

Submission status: Accepted

Solution code:
A = []
a1 = []
a2 = []
a3 = []
for i in range(3):
    a = list(map(int,input().split()))
    for K in range(3):
        A.append(a[K])


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




for i in range(9):
    if 0 <= i <= 2:
        a1.append(A[i])
    elif 3 <= i <= 5:
        a2.append(A[i])
    else:
        a3.append(A[i])

x = 0
y = 0
z = 0
for i in range(3):
    if a1[i] == 0:
        x += 1
    if a2[i] == 0:
        y += 1
    if a3[i] == 0:
        z += 1

if x == 3 or y == 3 or z == 3:
    print('Yes')
    exit()

for i in range(3):
    if a1[i] == 0 and a2[i] == 0 and a3[i] == 0:
        print('Yes')
        exit()

if a2[1] == 0:
    if a1[0] == 0 and a3[2] == 0 or a1[2] == 0 and a3[0] == 0:
        print('Yes')
        exit()

print('No')

Submission status: Accepted

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

n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if b == card[j][k]:
                check[j][k] = 1

flag = 0

for i in range(3):
    if check[i][0] == check[i][1] == check[i][2] == 1:
        flag = 1
        break
    elif check[0][i] == check[1][i] == check[2][i] == 1:
        flag = 1
        break
    elif check[0][0] == check[1][1] == check[2][2] == 1:
        flag = 1
        break
    elif check[0][2] == check[1][1] == check[2][0] == 1:
        flag = 1
        break

if flag:
    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 bingo in b:
    for gyou in range(3):
        for retu in range(3):
            if a[gyou][retu]==bingo:
                a[gyou][retu]=True

if a[0][0]==True and a[0][1]==True and a[0][2]==True:
    print("Yes")
    exit()
elif a[1][0]==True and a[1][1]==True and a[1][2]==True:
    print("Yes")
    exit()
elif a[2][0]==True and a[2][1]==True and a[2][2]==True:
    print("Yes")
    exit()
elif a[0][0]==True and a[1][0]==True and a[2][0]==True:
    print("Yes")
    exit()
elif a[0][1]==True and a[1][1]==True and a[2][1]==True:
    print("Yes")
    exit()
elif a[0][2]==True and a[1][2]==True and a[2][2]==True:
    print("Yes")
    exit()
elif a[0][0]==True and a[1][1]==True and a[2][2]==True:
    print("Yes")
    exit()
elif a[0][2]==True and a[1][1]==True and a[2][0]==True:
    print("Yes")
    exit()

print("No")

Submission status: Accepted

Solution code:
A=[list(map(int,input().split())) for _ in range(3)]
b=[i for i in [int(input()) for _ in range(int(input()))] for j in A if i in j]
A=[[1 if A[i][j] in b else 0 for j in range(len(A[i]))] for i in range(len(A))]
print('NYoe s'[any([all(i) for i in A]) or any([all(i) for i in list(zip(*A))]) or all([A[0][0],A[1][1],A[2][2]]) or all([A[0][2],A[1][1],A[2][0]])::2])

Submission status: Accepted

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

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

for i in range(3):
    for j in range(3):
        if A[i][j] in B:
            A[i][j] = -1

Q = [-1,-1,-1]
for i in range(3):
    if A[i] == Q:
        print("Yes")
        exit()
A = list(zip(*A))
Q = (-1,-1,-1)
for i in range(3):
    if A[i] == Q:
        print("Yes")
        exit()

if A[0][0] == A[1][1] == A[2][2] or A[0][2] == A[1][1] == A[2][0]:
    print("Yes")
    exit()

print("No")

Submission status: Accepted

Solution code:
A=[list(map(int,input().split())) for _ in range(3)]
b=[i for i in [int(input()) for _ in range(int(input()))] for j in A if i in j]
A=[[0 if A[i][j] in b else A[i][j] for j in range(len(A[i]))] for i in range(len(A))]
print('NYoe s'[any([1 if sum(i)==0 else 0 for i in A]) or any([1 if sum(i)==0 else 0 for i in list(zip(*A))]) or not A[0][0]+A[1][1]+A[2][2] or not A[0][2]+A[1][1]+A[2][0]::2])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections as cl
import sys


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


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    bingo_num = []

    for i in range(3):
        N = LI()
        bingo_num.append(N)

    N = II()

    for i in range(N):
        b = II()
        for row_i in range(3):
            for col_j in range(3):
                if bingo_num[row_i][col_j] == b:
                    bingo_num[row_i][col_j] = 0

    for i in range(3):
        if sum(bingo_num[i]) == 0:
            print("Yes")
            exit()

    for j in range(3):
        if bingo_num[0][j] + bingo_num[1][j] + bingo_num[2][j] == 0:
            print("Yes")
            exit()

    sum_naname = 0
    sum_naname_2 = 0
    for i in range(3):
        sum_naname += bingo_num[i][i]
        sum_naname_2 += bingo_num[i][2 - i]

    if sum_naname == 0 or sum_naname_2 == 0:
        print("Yes")
        exit()
    print("No")


main()

Submission status: Accepted

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

B = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
N =int(input())
for _ in range(N):
  b = int(input())
  for k in range(3):
    for j in range(3):
      if A[k][j] == b:
        B[k][j] = 1

if sum(B[0]) == 3 or sum(B[1]) == 3 or sum(B[2]) == 3:
  print('Yes')
elif B[0][0] + B[1][0] + B[2][0] ==3:
  print('Yes')
elif B[0][1] + B[1][1] + B[2][1] ==3:
  print('Yes')
elif B[0][2] + B[1][2] + B[2][2] ==3:
  print('Yes')
elif B[0][0] + B[1][1] + B[2][2] ==3:
  print('Yes')
elif B[0][2] + B[1][1] + B[2][0] ==3:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
X=[list(map(int,input().split()))for i in range(3)]
b=[int(input())for i in range(int(input()))]
for i in range(3):
 X[i]=[1 if i in b else 0 for i in X[i]]
print("Yes" if 3<=max(*[sum(i)for i in X],*[sum([x[i] for x in X])for i in range(3)],X[0][0]+X[1][1]+X[2][2],X[0][2]+X[1][1]+X[2][0]) else "No")

Submission status: Accepted

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

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

if a0[0] in b and a0[1] in b and a0[2] in b or a1[0] in b and a1[1] in b and a1[2] in b or a2[0] in b and a2[1] in b and a2[2] in b or  a0[0] in b and a1[0] in b and a2[0] in b or a0[1] in b and a1[1] in b and a2[1] in b or a0[2] in b and a1[2] in b and a2[2] in b or a0[0] in b and a1[1] in b and a2[2] in b or a0[2] in b and a1[1] in b and a2[0] in b:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
 
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
 
def main():
    A = [LI() for _ in range(3)]
    N = I()
    B = [I() for _ in range(N)]
    # print(B) 
    
    Hit = [[False] * 3, [False] * 3, [False] * 3]
    for i in range(3):
        for j in range(3):
            for k in range(N):
                if A[i][j]== B[k]:
                    Hit[i][j] = True
                    break
    
    ans = False
    for i in range(3):
            if (Hit[i][0] and Hit[i][1] and Hit[i][2]) or (Hit[0][i] and Hit[1][i] and Hit[2][i]):
              ans = True
              break  
    if (A[0][2] and Hit[1][1] and Hit[2][0]) or (Hit[0][0] and Hit[1][1] and Hit[2][2]):
        ans = True

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
 
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
 
def main():
    A = [LI() for _ in range(3)]
    N = I()
    B = [I() for _ in range(N)]
    # print(B) 
    
    for i in range(3):
        for j in range(3):
            for k in range(N):
                if A[i][j]== B[k]:
                    A[i][j] = 0
                    break
    
    ans = 'No'
    for i in range(3):
            if (A[i][0]==0 and A[i][1]==0 and A[i][2]==0) or (A[0][i]==0 and A[1][i]==0 and A[2][i]==0):
              ans = 'Yes'
              break  
    if (A[0][2]==0 and A[1][1]==0 and A[2][0]==0) or (A[0][0]==0 and A[1][1]==0 and A[2][2]==0):
        ans = 'Yes'
    print(ans)
main()

Submission status: Accepted

Solution code:
def judge(l):
    #yoko
    if sum(l[0]) == 3 or sum(l[1])==3 or sum(l[2])==3:
        return 1
    else:
        if l[0][0]+l[1][0]+l[2][0] == 3:
            return 1
        elif l[0][1]+l[1][1]+l[2][1] == 3:
            return 1
        elif l[0][2]+l[1][2]+l[2][2] == 3:
            return 1
        else:
            if l[0][0]+l[1][1]+l[2][2] == 3:
                return 1
            elif l[0][2]+l[1][1]+l[2][0] == 3:
                return 1
            else:
                return 0

A1 = [int(i) for i in input().split(' ')]
A2 = [int(i) for i in input().split(' ')]
A3 = [int(i) for i in input().split(' ')]
N = int(input())
bs = []
for n in range(N):
    bs.append(int(input()))

dic = {}
for i,a in enumerate(A1):
    dic[a] = (0,i)
for i,a in enumerate(A2):
    dic[a] = (1,i)
for i,a in enumerate(A3):
    dic[a] = (2,i)

l = [[0,0,0],[0,0,0],[0,0,0]]
for b in bs:
    if b in dic:
        index = dic[b]
        l[index[0]][index[1]] = 1

if judge(l) == 0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

a_list = []
a = []
c = [False for i in range(9)]
for i in range(3):
    a_list = lr()
    for num in a_list:
        a.append(num)
n = int(input())
for i in range(n):
    num = ir()
    if num in a:
        index = a.index(num)
        c[index] = True

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

M=[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)]

b = set(b)
for i in range(3):
    for j in range(3):
        if M[i][j] in b:
            ans[i][j]=1
score = 0 
for i in range(3):
    if sum(ans[i])==3:
        score = 1

if ans[0][0]==1 and ans[1][1]==1 and ans[2][2]==1:
    score = 1
if ans[0][2]==1 and ans[1][1]==1 and ans[2][0]==1:
    score = 1

for i in range(3):
    x = 0
    for j in range(3):
        x+=ans[j][i]
    if x==3:
        score=1

print('Yes') if score==1 else print('No')

Submission status: Accepted

Solution code:
import sys

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

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


def bingo_judge(A, B):
    # 縦列のビンゴを判定
    for i in range(3):
        flag = True
        for a in [A[0][i], A[1][i], A[2][i]]:
            if not (a in B):
                flag = False
        if flag:
            print("Yes")
            sys.exit()
    # 横列のビンゴを判定
    for i in range(3):
        flag = True
        for a in A[i]:
            if not (a in B):
                flag = False
        if(flag):
            print("Yes")
            sys.exit()
    # 斜めのビンゴを判定
    flag = True
    for a in [A[0][0], A[1][1], A[2][2]]:
        if not (a in B):
            flag = False
    if flag:
        print("Yes")
        sys.exit()
    flag = True
    for a in [A[0][2], A[1][1], A[2][0]]:
        if not (a in B):
            flag = False
    if flag:
        print("Yes")
        sys.exit()
    print("No")


bingo_judge(A, B)

Submission status: Accepted

Solution code:
import numpy as np

l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l = l1 + l2 + l3
n = int(input())

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

for i in range(len(l)):
    for j in bl:
        if l[i] == j:
            l[i] = 0
            
bingo = np.array(l).reshape(3,3)
print("Yes" if (min(bingo.sum(axis=1)) == 0) | (min(bingo.sum(axis=0)) == 0) | (min([np.diag(bingo).sum(), np.diag(np.fliplr(bingo)).sum()]) == 0) else "No")

Submission status: Accepted

Solution code:
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l = l1 + l2 + l3
n = int(input())

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

for i in range(len(l)):
    for j in bl:
        if l[i] == j:
            l[i] = 0
rowwise = 1 if (sum(l[0:3]) == 0) | (sum(l[3:6]) == 0)  | (sum(l[6:]) == 0) else 0
colwise = 1 if (sum([l[0], l[3], l[6]]) == 0) | (sum([l[1], l[4], l[7]]) == 0)  | (sum([l[2], l[5], l[8]]) == 0) else 0
crosswise = 1 if (sum([l[0], l[4], l[8]]) == 0) | (sum([l[2], l[4], l[6]]) == 0) else 0

print("Yes" if sum([rowwise, colwise, crosswise]) else "No")

Submission status: Accepted

Solution code:
ARR = [
    [84, 97, 66],
    [79, 89, 11],
    [61, 59, 7],
]


N = 7
BRR = [
    89,
    7,
    87,
    79,
    24,
    84,
    30,
]


ARR = []

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

N = int(input())

BRR = []

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


def calculagte(arr, n, brr):
    status = [
        [False, False, False],
        [False, False, False],
        [False, False, False]
    ]

    for h in range(3):
        for w in range(3):
            for i in range(n):
                if arr[h][w] == brr[i]:
                    status[h][w] = True

    isOk = False

    if status[0][0] and status[0][1] and status[0][2]:
        isOk = True

    if status[1][0] and status[1][1] and status[1][2]:
        isOk = True

    if status[2][0] and status[2][1] and status[2][2]:
        isOk = True


    if status[0][0] and status[1][0] and status[2][0]:
        isOk = True

    if status[0][1] and status[1][1] and status[2][1]:
        isOk = True

    if status[0][2] and status[1][2] and status[2][2]:
        isOk = True

    if status[0][0] and status[1][1] and status[2][2]:
        isOk = True

    if status[2][0] and status[1][1] and status[0][2]:
        isOk  = True

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

calculagte(ARR, N, BRR)

Submission status: Accepted

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

# print(A)
# print(A[0][0])
# print(A[0].index(66))
for b in B:
    for i in range(3):
        if b in A[i]:
            # print(b)
            A[i][A[i].index(b)] = 0
        


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

Submission status: Accepted

Solution code:
import numpy as np

line_1 = np.array(list(map(int, input().split())))
line_2 = np.array(list(map(int, input().split())))
line_3 = np.array(list(map(int, input().split())))
n = int(input())
lists = [int(input()) for i in range(n)]

line = np.concatenate([line_1, line_2, line_3])
for i in lists:
  index = np.where(line == i)
  line[index] = 0

line = np.reshape(line, (3,3))
condition_1 = line[0].sum() == 0
condition_2 = line[1].sum() == 0
condition_3 = line[2].sum() == 0
condition_4 = line[:,0].sum() == 0
condition_5 = line[:,1].sum() == 0
condition_6 = line[:,2].sum() == 0
condition_7 = line[0,0] + line[1,1] + line[2,2] == 0
condition_8 = line[2,0] + line[1,1] + line[0,2] == 0

if condition_1 or condition_2 or condition_3 or condition_4 or condition_5 or condition_6 or condition_7 or condition_8:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
# ビンゴの番号の入力
bingo = {}
for _ in range(3):
    l = list(map(int, input().split()))
    for i in range(3):
        bingo[l[i]] = 0

# 番号があれば該当の値を1にする
n = int(input())
for _ in range(n):
    x = int(input())
    if x in bingo:
        bingo[x] = 1

# 辞書の値をリストに変換
b = list(bingo.values())

# ビンゴ達成の判定(未達成ならflg==0になる)
flg = b[0] * b[1] * b[2]
flg += b[3] * b[4] * b[5]
flg += b[6] * b[7] * b[8]
flg += b[0] * b[3] * b[6]
flg += b[1] * b[4] * b[7]
flg += b[2] * b[5] * b[8]
flg += b[0] * b[4] * b[8]
flg += b[2] * b[4] * b[6]

# 出力
print(["Yes", "No"][flg == 0])

Submission status: Accepted

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

def bingo(x):
  a=False
  for s in range(3):
    if sum(x[s])==3:a=True
  
  for h in range(3):
    if x[0][h]+x[1][h]+x[2][h]==3:a=True
      
  if x[0][0]+x[1][1]+x[2][2]==3:a=True
  
  if x[0][2]+x[1][1]+x[2][0]==3:a=True
  
  return a

seen=[[0,0,0] for _ in range(3)]

for _ in range(int(input())):
  a=int(input())
  
  for i in range(3):
    for j in range(3):
      if A[i][j]==a:seen[i][j]=1

ff=bingo(seen)

if ff==True:
  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 b==a[j][k]:
                a[j][k]=-1
if (a[0][1]==-1 and a[0][2]==-1 and a[0][0]==-1):
    print("Yes")
elif a[1][0]==-1 and a[1][1]==-1 and a[1][2]==-1:
    print("Yes")
elif a[2][0]==-1 and a[2][1]==-1 and a[2][2]==-1:
    print("Yes")
elif a[0][0]==-1 and a[1][0]==-1 and a[2][0]==-1:
    print("Yes")
elif a[0][1]==-1 and a[1][1]==-1 and a[2][1]==-1:
    print("Yes")
elif a[0][2]==-1 and a[1][2]==-1 and a[2][2]==-1:
    print("Yes")
elif a[0][0]==-1 and a[1][1]==-1 and a[2][2]==-1:
    print("Yes")
elif a[2][0]==-1 and a[1][1]==-1 and a[0][2]==-1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

for i in range(3):
  for j in range(3):
    for k in range(N):

      if l[i][j] == q[k]:
        l[i][j] = 0
        
      if l[0][0] == 0 and l[0][1] == 0 and l[0][2] == 0:
        print('Yes')
        exit()
      elif l[1][0] == 0 and l[1][1] == 0 and l[1][2] == 0:
        print("Yes")
        exit()
      elif l[2][0] == 0 and l[2][1] == 0 and l[2][2] == 0:
        print("Yes")
        exit()
      elif l[0][0] == 0 and l[1][1] == 0 and l[2][2] == 0:
        print("Yes")
        exit()
      elif l[0][2] == 0 and l[1][1] == 0 and l[2][0] == 0:
        print("Yes")
        exit()
      elif l[0][0] == 0 and l[1][0] == 0 and l[2][0] == 0:
        print("Yes")
        exit()
      elif l[0][1] == 0 and l[1][1] == 0 and l[2][1] == 0:
        print("Yes")
        exit()
      elif l[0][2] == 0 and l[1][2] == 0 and l[2][2] == 0:
        print("Yes")
        exit()

print('No')

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
for k in b:
    for i in a:
        for j in range(3):
            if i[j] == k:
                i[j] = 0
tf1 = sum(a[0])==0 or sum(a[1])==0 or sum(a[2])==0
tf2 = a[0][0] == a[1][0] == a[2][0] or a[0][1] == a[1][1] == a[2][1] or a[0][2] == a[1][2] == a[2][2]
tf3 = a[0][0] == a[1][1] == a[2][2] or a[0][2] == a[1][1] == a[2][0]
tf = tf1 or tf2 or tf3

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

Submission status: Accepted

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
import itertools
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

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

for i in range(3):
    A[i][0],A[i][1],A[i][2] = MI()

N = I()
B = []
for i in range(N):
    B.append(I())

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


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

    if A[i][0] is True and A[i][1] is True and A[i][2] is True:
        ans = "Yes"
    
if A[0][0] is True and A[1][1] is True and A[2][2] is True:
    ans = "Yes"

if A[2][0] is True and A[1][1] is True and A[0][2] is True:
    ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
A=[]
i=0
for l in range(3):
    A.append(list(map(int,input().split())))
N=int(input())
B = [int(input()) for i in range(N)]
for C in B:
    for a in range(3):
        for b in range(3):
            if C==A[a][b]:
                A[a][b]=-1

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

Submission status: Accepted

Solution code:
bingo_list = [list(map(int,input().split())) for i in range(3)]
bingo_list = sum(bingo_list,[])
n = int(input())
bingo_number = [int(input())for i in range(n)]
check_list = [0 for i in range(9)]

for j in bingo_number:
    if j in bingo_list:
        check_list[bingo_list.index(j)] = 1

if  [1,1,1]  in [check_list[:3], check_list[3:6], check_list[6:], check_list[0:7:3], check_list[1:8:3],check_list[2:9:3],check_list[0:9:4],check_list[2:7:2]]:
    print('Yes')
else:
    print('No')