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:
def mark(n):
    for i in range(n):
        num = int(input())
        if num in A:
            A[A.index(num)]=0

def tate():
    for i in range(3):
        if A[i]==A[i+3] and A[i]==A[i+6]:
            return 1
    return 0

def yoko():
    for i in range(0,7,3):
        if A[i]==A[i+1] and A[i]==A[i+2]:
            return 1
    return 0

def naname():
    if A[4]==A[0] and A[4]==A[8]:
        return 1
    elif A[4]==A[2] and A[4]==A[6]:
        return 1
    else:
        return 0

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())
mark(n)
if tate()+yoko()+naname()>0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
A = A1 + A2 + A3
N = int(input())
s = set() # index of A
for _ in range(N):
  b = int(input())
  if b in A:
    s |= {A.index(b)}
# bingo index
bingo = [{0, 1, 2}, {0, 3, 6}, {0, 4, 8}, {1, 4, 7}, {2, 4, 6}, {2, 5, 8}, {3, 4, 5}, {6, 7, 8}]
print(['No','Yes'][any(b <= s for b in bingo)])

Submission status: Accepted

Solution code:
def solve():
    card = []
    num_pos = {}
    for i in range(3):
        row = [int(num) for num in input().split()]
        card.append(row)
        for j,num in enumerate(row):
            num_pos[num] = (i,j)

    N = int(input())
    for i in range(N):
        target = int(input())
        # print(int(input()))
        if target in num_pos:
            pos_i, pos_j = num_pos[target]
            card[pos_i][pos_j] = 0

    ans = False
    for row in card:
        if not any(row):
            ans = True
    for column in range(3):
        column_flag = True
        for i in range(3):
            if card[i][column]:
                column_flag = False
        if column_flag:
            ans = True
    diagonal_flag = True
    for i in range(3):
        if card[i][i]:
            diagonal_flag = False
    if diagonal_flag:
        ans = True
    diagonal_flag = True
    for i in range(3):
        if card[2-i][i]:
            diagonal_flag = False
    if diagonal_flag:
        ans = True
    if ans:
        print("Yes")
    else:
        print("No")
    # for row in card:
    #     print(row)

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

#ヨコ
for i in range(3):
    if A[i] == [-1,-1,-1]:
        print("Yes")
        exit()
#タテ
for i in range(3):
    if [A[0][i],A[1][i],A[2][i]] == [-1,-1,-1]:
        print("Yes")
        exit()
#ナナメ
if [A[0][0],A[1][1],A[2][2]] == [-1,-1,-1]:
    print("Yes")
    exit()
if [A[0][2],A[1][1],A[2][0]] == [-1,-1,-1]:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

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

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

#ヨコ
for i in range(3):
    if A[i] == [-1,-1,-1]:
        print("Yes")
        exit()
#タテ
for i in range(3):
    if [A[0][i],A[1][i],A[2][i]] == [-1,-1,-1]:
        print("Yes")
        exit()
#ナナメ
if [A[0][0],A[1][1],A[2][2]] == [-1,-1,-1]:
    print("Yes")
    exit()
if [A[0][2],A[1][1],A[2][0]] == [-1,-1,-1]:
    print("Yes")
    exit()
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)]

a = np.array(A)

for i in b:
    a = np.where(a == i, 0, a)

for i in range(3):
    if sum(a[i]) == 0:
        print('Yes')
        exit()
    if sum(a[:,i]) == 0:
        print('Yes')
        exit()

if a[0,0] + a[1,1] + a[2,2] == 0:
    print('Yes')
    exit()

if a[0,2] + a[1,1] + a[2,0] == 0:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

Solution code:
import sys

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

card = [
    [0, 0, 0],
    [0, 0, 0],
    [0, 0, 0]
]

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

if card[0].count(1) == 3:
    print("Yes")
    sys.exit()

if card[1].count(1) == 3:
    print("Yes")
    sys.exit()

if card[2].count(1) == 3:
    print("Yes")
    sys.exit()

if card[0][0] == 1 and card[1][0] == 1 and card[2][0] == 1:
    print("Yes")
    sys.exit()

if card[0][1] == 1 and card[1][1] == 1 and card[2][1] == 1:
    print("Yes")
    sys.exit()

if card[0][2] == 1 and card[1][2] == 1 and card[2][2] == 1:
    print("Yes")
    sys.exit()

if card[0][0] == 1 and card[1][1] == 1 and card[2][2] == 1:
    print("Yes")
    sys.exit()

if card[0][2] == 1 and card[1][1] == 1 and card[2][0] == 1:
    print("Yes")
    sys.exit()

print("No")

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
for _ in range(n):
  d = int(input())
  for i in range(3):
    if d in a[i]:
      a[i][a[i].index(d)] = -1

for i in range(3):
  if sum(a[i])==-3:
    print('Yes')
    exit()
  s = 0
  for j in range(3):
    s += a[j][i]
  if s==-3:
    print('Yes')
    exit()
if a[0][0]+a[1][1]+a[2][2]==-3:
  print('Yes')
  exit()
if a[0][2]+a[1][1]+a[2][0]==-3:
  print('Yes')
  exit()

print('No')

Submission status: Accepted

Solution code:


def checkBingo(A,c):
    for i in range(3):
        for j in range(3):
            if A[i][j]==c:
                A[i][j]=0

    for i in range(3):
        if max(A[i])==0 :
            return 1
    for i in range(3):
        if A[0][i]==0 and A[1][i]==0 and A[2][i]==0:
            return 1
    if A[0][0]==0 and A[1][1]==0 and A[2][2]==0:
        return 1
    if A[0][2]==0 and A[1][1]==0 and A[2][0]==0:
        return 1
    return 0

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

# print(A, min(A[0]),min(A[1]),min(A[2]))
n = int(input())

res=0
for i in range(n):
    b = (int(input()))
    # print(A)
    res += checkBingo(A,b)

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

Submission status: Accepted

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

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

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

if card[0][0] + card[1][1] + card[2][2] == 0:
    ans = "Yes"
if card[0][2] + card[1][1] + card[2][0] == 0:
    ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
import math


def resolve():
    import sys
    input = sys.stdin.readline
    a = []
    a1 = [int(x) for x in input().rstrip().split(" ")]
    a2 = [int(x) for x in input().rstrip().split(" ")]
    a3 = [int(x) for x in input().rstrip().split(" ")]


    a += a1 + a2 + a3

    opened = set()

    n = int(input().rstrip())
    for _ in range(n):
        b = int(input().rstrip())
        if b in a:
            opened.add(a.index(b))

    # 判定
    if all([x in opened for x in {0,3,6}]) or all([x in opened for x in {1,4,7}]) or all([x in opened for x in {2,5,8}]):
        print("Yes")
    elif all([x in opened for x in {0,1,2}]) or all([x in opened for x in {3,4,5}]) or all([x in opened for x in {6,7,8}]):
        print("Yes")
    elif all([x in opened for x in {0,4,8}]) or all([x in opened for x in {2,4,6}]):
        print("Yes")
    else:
        print("No")




if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
A_lists = [map(int, input().split()) for _ in range(3)]
num_dict = {}
for n1, A_list in enumerate(A_lists):
    for n2, a in enumerate(A_list):
        num_dict[a] = (n1, n2)

N = int(input())
B_list = [int(input()) for _ in range(N)]
bing_ar = [[False, False, False] for _ in range(3)]

keys = num_dict.keys()
for b in B_list:
    if b in num_dict:
        n1, n2 = num_dict[b]
        bing_ar[n1][n2] = True

if ((sum(bing_ar[0]) == 3) or (sum(bing_ar[1]) == 3) or (sum(bing_ar[2]) == 3)) or \
    ((bing_ar[0][0] == True) and (bing_ar[1][0] == True) and (bing_ar[2][0] == True)) or \
    ((bing_ar[0][1] == True) and (bing_ar[1][1] == True) and (bing_ar[2][1] == True)) or \
    ((bing_ar[0][2] == True) and (bing_ar[1][2] == True) and (bing_ar[2][2] == True)) or \
    ((bing_ar[0][0] == True) and (bing_ar[1][1] == True) and (bing_ar[2][2] == True)) or \
    ((bing_ar[0][2] == True) and (bing_ar[1][1] == True) and (bing_ar[2][0] == True)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

a = inpll(3)
n = inp()
B = inplm(n)

tmp = np.zeros((3,3),dtype=np.int)

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

ans = 'No'
if np.any(np.all(tmp == 1,axis=0) == True) or np.any(np.all(tmp == 1,axis=1) == True) or (tmp[0][0] == 1 and tmp[1][1] == 1 and tmp[2][2] == 1) or (tmp[0][2] == 1 and tmp[1][1] == 1 and tmp[2][0] == 1):
    ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
import sys
numbers = []

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

hits = []
N = int(input())
for _ in range(N):
    hits.append(int(input()))

lines = [
    [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 line in lines:
    a, b, c = line
    if numbers[a] in hits and numbers[b] in hits and numbers[c] in hits:
        print('Yes')
        sys.exit()
        
print('No')

Submission status: Accepted

Solution code:
# B - Bingo
import itertools
A = list()
for o in range(3):
    a = list(map(int, input().split()))
    A.append(a)
N = int(input())
b = list(int(input()) for p in range(N))#mapオブジェクトにlistをつける

bingo = [A[0],A[1],A[2],[A[0][0],A[1][0],A[2][0]],[A[0][1],A[1][1],A[2][1]],[A[0][0],A[1][1],A[2][2]],[A[0][2],A[1][2],A[2][2]],[A[0][2],A[1][1],A[2][0]]]

B_perm = []    
B = itertools.permutations(b,3)
for i in B:
    B_perm.append(list(i))#タプルをリストに直す

result = 'No'
for j in range(len(B_perm)):
    if B_perm[j] in bingo: 
        result = 'Yes'

print(result)

Submission status: Accepted

Solution code:
A = []
A += map(int, input().split())
A += map(int, input().split())
A += map(int, input().split())
N = int(input())
for _ in range(N):
    b = int(input())
    try:
        A[A.index(b)] = 0
    except ValueError:
        pass
res = (
    (A[0]+A[1]+A[2])*(A[3]+A[4]+A[5])*(A[6]+A[7]+A[8])*
    (A[0]+A[3]+A[6])*(A[1]+A[4]+A[7])*(A[2]+A[5]+A[8])*
    (A[0]+A[4]+A[8])*(A[2]+A[4]+A[6])
)
print("Yes" if res == 0 else "No")

Submission status: Accepted

Solution code:
a = []
for _ in range(3):
    a += list(map(int, input().split()))
n = int(input())
for _ in range(n):
    b = int(input())
    if b in a:
        i = a.index(b)
        a[i] = 0
if sum(a[0:3]) == 0 or sum(a[3:6]) == 0 or sum(a[6:]) == 0 \
    or sum(a[0::3]) == 0 or sum(a[1::3]) == 0 or sum(a[2::3]) == 0 \
    or sum(a[0::4]) == 0 or sum(a[2:7:2]) == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A=[list(map(int,input().split())) for _ in range(3)]
N=int(input())
B=[int(input()) for _ in range(N)]
S=[[0,0,0] for _ in range(3)]
for b in B:
  for i in range(3):
    if b in A[i]:
      S[i][A[i].index(b)] = 1
      break
p = False
for a in S:
  if sum(a)==3:
    p = True
    break
if not p:
  for i in range(3):
    if S[0][i]+S[1][i]+S[2][i]==3:
      p = True
      break
if not p:
  if S[0][0]+S[1][1]+S[2][2]==3 or S[2][0]+S[1][1]+S[0][2]==3:
    p=True
print("Yes" if p else "No")

Submission status: Accepted

Solution code:
def isBingo(ary):
  ret = False
  if (
    (ary[0] == ary[1] == ary[2] == 0)
    or (ary[3] == ary[4] == ary[5] == 0)
    or (ary[6] == ary[7] == ary[8] == 0)
    or (ary[0] == ary[3] == ary[6] == 0)
    or (ary[1] == ary[4] == ary[7] == 0)
    or (ary[2] == ary[5] == ary[8] == 0)
    or (ary[0] == ary[4] == ary[8] == 0)
    or (ary[2] == ary[4] == ary[6] == 0)
  ):
    ret = True

  return ret

A = []
for i in range(3):
  row = input().split(" ")
  for n in row:
    A.append(int(n))

B = []
N = int(input())
for i in range(N):
  B.append(int(input()))
  
B = list(set(B))
C = list(map(lambda a: 0 if a in B else a, A))

print("Yes") if isBingo(C) else print("No")

Submission status: Accepted

Solution code:
AA1 = input().split()
AA2 = input().split()
AA3 = input().split()
AA4 = [AA1[0],AA2[0],AA3[0]]
AA5 = [AA1[1],AA2[1],AA3[1]]
AA6 = [AA1[2],AA2[2],AA3[2]]
AA7 = [AA1[0],AA2[1],AA3[2]]
AA8 = [AA1[2],AA2[1],AA3[0]]
N = int(input())
list1 = []
for i in range(N):
  b = input()
  list1.append(b)
count = 0
bingo =0
for i in list1:
  if i in AA1:
    count +=1
if count ==3 :
  bingo =1
else:
  count =0
  
for i in list1:
  if i in AA2:
    count +=1
if count ==3 :
  bingo =1
else:
  count =0

for i in list1:
  if i in AA3:
    count +=1
if count ==3 :
  bingo =1
else:
  count =0
  
for i in list1:
  if i in AA4:
    count +=1
if count ==3 :
  bingo =1
else:
  count =0

for i in list1:
  if i in AA5:
    count +=1
if count ==3 :
  bingo =1
else:
  count =0

for i in list1:
  if i in AA6:
    count +=1
if count ==3 :
  bingo =1
else:
  count =0
  
for i in list1:
  if i in AA7:
    count +=1
if count ==3 :
  bingo =1
else:
  count =0
for i in list1:
  if i in AA8:
    count +=1
if count ==3 :
  bingo =1
else:
  count =0
if bingo ==1:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:

A1=input()

A2=input()

A3=input()

#N=int(N)

list1 = A1.split()

list1 = [int(i) for i in list1]


list2 = A2.split()

list2 = [int(i) for i in list2]


list3 = A3.split()

list3 = [int(i) for i in list3]


N = input()

N=int(N)

num=[]

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


T1 = all([(i in num ) for i in list1])

T2 = all([(i in num ) for i in list2])

T3 = all([(i in num ) for i in list3])

T4 = all([(list1[0] in num),(list2[0] in num),(list3[0] in num)])

T5 = all([(list1[1] in num),(list2[1] in num),(list3[1] in num)])

T6 = all([(list1[2] in num),(list2[2] in num),(list3[2] in num)])

T7 = all([(list1[0] in num),(list2[1] in num),(list3[2] in num)])

T8 = all([(list1[2] in num),(list2[1] in num),(list3[0] in num)])

if (any([T1,T2,T3,T4,T5,T6,T7,T8])) == True:
    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())
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

for i in range(3):
    if sum(a[i]) == 0:
        print("Yes")
        exit()
for i in range(3):
    if sum([a[0][i], a[1][i], a[2][i]]) == 0:
        print("Yes")
        exit()
if sum([a[0][0], a[1][1], a[2][2]]) == 0 or sum([a[0][2], a[1][1], a[2][0]]) == 0:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    d = []
    for _ in range(3):
        d.append(list(map(int, input().split())))

    N = int(input())
    for _ in range(N):
        b = int(input())
        for i in range(3):
            for j in range(3):
                if d[i][j] == b:
                    d[i][j] = 0

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

    for j in range(3):
        t = 0
        for i in range(3):
            t += d[i][j]
        if t == 0:
            print("Yes")
            return

    if d[0][0] + d[1][1] + d[2][2] == 0:
        print("Yes")
        return

    if d[0][2] + d[1][1] + d[2][0] == 0:
        print("Yes")
        return

    print("No")


def main():
    solve()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ls = []
for i in range(3):
    ls.append(list(input().split(' ')))

N = int(input())
for i in range(N):
    X = input()
    for i in range(3):
        if X in ls[i]:
            ls[i][ls[i].index(X)] = 0

result = False
for i in range(3):
    if ls[i].count(0) == 3:
        result = True
        break

if not result:
    for i in range(3):
        cnt = 0
        for j in range(3):
            if ls[j][i] == 0:
                cnt += 1
        if cnt == 3:
            result = True
            break

if not result:
    cnt = 0
    for i in range(3):
        if ls[i][i] == 0:
            cnt += 1
    if cnt == 3:
        result = True

if not result:
    cnt = 0
    for i in range(3):
        if ls[i][3-i-1] == 0:
            cnt += 1
    if cnt == 3:
        result = True

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

Submission status: Accepted

Solution code:
a = []
for i in range(3):
    l,m,n = map(int,input().split())
    a.append([l,m,n])
n = int(input())
b = []
for i in range(n):
    b.append(int(input()))
#print(a)
#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
tmp = 0
for i in range(3):
    if a[i][0]+a[i][1]+a[i][2] == 0:
        tmp = 1
    elif a[0][i]+a[1][i]+a[2][i] == 0:
        tmp = 1
if a[0][0]+a[1][1]+a[2][2] ==0:
    tmp = 1
elif a[0][2]+a[1][1]+a[2][0] ==0:
    tmp = 1
if tmp == 1:
    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())
for i in range(N):
  x=int(input())
  for row in A:
    for num in range(len(row)):
      if x==row[num]:
        row[num]=0

for i in A:
  if i==[0,0,0]:
    print("Yes")
    exit(0)
for i in range(3):
  if A[0][i]==0 and A[1][i]==0 and A[2][i]==0:
    print("Yes")
    exit(0)
if A[0][0]==0 and A[1][1]==0 and A[2][2]==0:
    print("Yes")
    exit(0)
if A[2][0]==0 and A[1][1]==0 and A[0][2]==0:
    print("Yes")
    exit(0)
print("No")

Submission status: Accepted

Solution code:
l = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
ans = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

for bb in b:
    for i in range(3):
        for j in range(3):
            if l[i][j] == bb:
                ans[i][j] = 1

if ans[0][0] == ans[1][1] == ans[2][2] == 1:
    print('Yes')
elif ans[0][2] == ans[1][1] == ans[2][0] == 1:
    print('Yes')
elif ans[0][0] == ans[1][0] == ans[2][0] == 1:
    print('Yes')
elif ans[0][1] == ans[1][1] == ans[2][1] == 1:
    print('Yes')
elif ans[0][2] == ans[1][2] == ans[2][2] == 1:
    print('Yes')

elif ans[0][0] == ans[0][1] == ans[0][2] == 1:
    print('Yes')
elif ans[1][0] == ans[1][1] == ans[1][2] == 1:
    print('Yes')
elif ans[2][0] == ans[2][1] == ans[2][2] == 1:
    print('Yes')

else:
    print('No')

Submission status: Accepted

Solution code:
arr = []
b = []
cmp_arr = [[False] * 3 for _ in range(3)]

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

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

for i in range(3):
  for j in range(3):
    for k in range(N):
      if arr[i][j] == b[k]:
        cmp_arr[i][j] = True

for i in range(3):
  if cmp_arr[i][0] and cmp_arr[i][1] and cmp_arr[i][2]:
    print("Yes");exit()
  if cmp_arr[0][i] and cmp_arr[1][i] and cmp_arr[2][i]:
    print("Yes");exit()

if cmp_arr[0][0] and cmp_arr[1][1] and cmp_arr[2][2]:
  print("Yes");exit()
if cmp_arr[0][2] and cmp_arr[1][1] and cmp_arr[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)]
cnt = [0]*8
ans = "No"
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            cnt[i] += 1
            cnt[j+3] += 1
            if i == j:
                cnt[-1] += 1
            if i+j == 2:
                cnt[-2] += 1
for k in range(8):
    if cnt[k] >= 3:
        ans = "Yes"
        break
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

for bingo_num in b:
    for line in range(3):
        if bingo_num in a[line]:
            a[line][a[line].index(bingo_num)] =0

flag = False
for i in range(3):
    if a[i]==[0,0,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[2][0]==a[1][1]==a[0][2]==0:
    flag = True

print("Yes" if flag else "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())
R = []
for i in range(N):
  S = int(input())
  R.append(S)

if A1[0] in R and A2[1] in R and A3[2] in R:
  print("Yes")
elif A1[2] in R and A2[1] in R and A3[0] in R:
  print("Yes")
elif A1[0] in R and A1[1] in R and A1[2] in R:
  print("Yes")
elif A2[0] in R and A2[1] in R and A2[2] in R:
  print("Yes")
elif A3[0] in R and A3[1] in R and A3[2] in R:
  print("Yes")
elif A1[0] in R and A2[0] in R and A3[0] in R:
  print("Yes")
elif A2[1] in R and A2[1] in R and A3[1] in R:
  print("Yes")
elif A1[2] in R and A2[2] in R and A3[2] in R:
  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()))

bingo = False

#check rows and columns
for i in range(3):
    rowMatches = 0
    colMatches = 0
    for j in range(3):
        if A[i][j] in B:
            rowMatches += 1
        if A[j][i] in B:
            colMatches += 1

    if (rowMatches == 3 or colMatches == 3):
        bingo = True
        break

if (bingo):
    print("Yes")
else:
    #check diagonals
    diag1 = 0
    diag2 = 0
    for i in range(3):
        if A[i][i] in B:
            diag1 += 1
        if A[i][3-1-i] in B:
            diag2 += 1

    if (diag1 == 3 or diag2 == 3):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

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

a_2 = list(zip(*a))
flag_1 = sum(a[0]) == 0 or sum(a[1]) == 0 or sum(a[2]) == 0
flag_2 = sum(a_2[0]) == 0 or sum(a_2[1]) == 0 or sum(a_2[2]) == 0
flag_3 = a[0][0] + a[1][1] + a[2][2] == 0 or a[0][2] + a[1][1] + a[2][0] == 0

print(['No','Yes'][flag_1 or flag_2 or flag_3])

Submission status: Accepted

Solution code:
l = []

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

n = int(input())
for _ in range(n):
  b = int(input())
  if b in l:
    l[l.index(b)] = 0

for i in range(3):
  if sum(l[0+3*i:3+3*i]) == 0:
    print("Yes")
    exit()
  
  if sum(l[i:9:3]) == 0:
    print("Yes")
    exit()

if (l[0]+l[4]+l[8]) == 0:
  print("Yes")
  exit()
if (l[2]+l[4]+l[6]) == 0:
  print("Yes")
  exit()
  
print("No")

Submission status: Accepted

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

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

a = []

Atf = [[False] * 3 for _ in range(3)]

for i in range(3):
    for aa in A[i]:
        a.append(aa)

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

res = False

for i in range(3):
    if Atf[i][0] and Atf[i][1] and Atf[i][2]:
        res = True
        break
    elif Atf[0][i] and Atf[1][i] and Atf[2][i]:
        res = True
        break

if not res:
    if Atf[0][0] and Atf[1][1] and Atf[2][2]:
        res = True
    elif Atf[0][2] and Atf[1][1] and Atf[2][0]:
        res = True
 

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

Submission status: Accepted

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

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

# print(a)
for i in range(3):
    if sum(a[i*3:i*3+3]) == 0:
        print('Yes')
        exit()
    if sum(a[i:9:3]) == 0:
        print('Yes')
        exit()

if (a[0] + a[4] + a[8]) == 0:
    print('Yes')
    exit()
if (a[2] + a[4] + a[6]) == 0:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

Solution code:
def solve():
    Ass = [tuple(map(int, input().split())) for _ in range(3)]
    N = int(input())
    Bs = set([int(input()) for _ in range(N)])

    isOKss = [[0]*(3) for _ in range(3)]
    for i in range(3):
        for j in range(3):
            if Ass[i][j] in Bs:
                isOKss[i][j] = 1

    for i in range(3):
        for j in range(3):
            if not isOKss[i][j]:
                break
        else:
            return True

    for j in range(3):
        for i in range(3):
            if not isOKss[i][j]:
                break
        else:
            return True

    for i in range(3):
        if not isOKss[i][i]:
            break
    else:
        return True

    for i in range(3):
        if not isOKss[i][2-i]:
            break
    else:
        return True

    return False


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

Submission status: Accepted

Solution code:
bingo = [list(map(int,input().split())) for i in range(3)]
n =  int(input())
num = [int(input()) for l in range(n)]
arr = [[],[],[]]

for number in num:
    cnt = 0
    for b in bingo:
        if number in b:
             arr[cnt].append(b.index(number))
        cnt  = cnt + 1

if len(arr[0]) == 3 or len(arr[1]) == 3 or len(arr[2]) == 3:
    print("Yes")
elif 0 in arr[0] and 1 in arr[1] and 2 in arr[2]:
    print("Yes")
elif 2 in arr[0] and 1 in arr[1] and 2 in arr[0]:
    print("Yes")
elif 0 in arr[0] and 0 in arr[1] and 0 in arr[2]:
    print("Yes")
elif 1 in arr[0] and 1 in arr[1] and 1 in arr[2]:
    print("Yes")
elif 2 in arr[0] and 2 in arr[1] and 2 in arr[2]:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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


cnt=0

for i in range(N):
    for j in range(3):
        for k in range(3):
            if b[i] == a[j][k]:
                a[j][k] =1000
                if sum(a[j]) ==3000 or a[0][k]+a[1][k]+a[2][k]==3000 or a[0][0]+a[1][1]+a[2][2]==3000 or a[0][2]+a[1][1]+a[2][0]==3000:
                    cnt +=1
print('Yes' if cnt>0 else 'No')

Submission status: Accepted

Solution code:
bingo = [list(map(int, input().split())) for _ in range(3)]
def chec_line():
    ret = False
    for i in range(3):
        cnt = 0
        for j in range(3):
            if bingo[i][j] == -1:
                cnt += 1
        if cnt == 3:
            ret =True

    for i in range(3):
        cnt = 0
        for j in range(3):
            if bingo[j][i] == -1:
                cnt += 1
        if cnt == 3:
            ret =True
    cnt = 0
    for i in range(3):
        if bingo[i][i] == -1:
            cnt += 1
    if cnt == 3:
        ret =True
    
    cnt = 0
    for i in range(3):
        if bingo[2-i][i] == -1:
            cnt += 1
    if cnt == 3:
        ret =True

    return ret
def check_num( num):
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == num:
                bingo[i][j] = -1
                

n = int(input())
flag = False
for _ in range(n):
    check_num(int(input()))
    flag = chec_line() 
    if flag:
        break
if flag :
    print('Yes')
else:
    print('No')