Problem:


Score : 200 points

Problem Statement

We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}.

The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet.

Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.

Constraints

All values in input are integers.

1 \leq A_{i, j} \leq 100

A_{i_1, j_1} \neq A_{i_2, j_2} ((i_1, j_1) \neq (i_2, j_2))

1 \leq N \leq 10

1 \leq b_i \leq 100

b_i \neq b_j (i \neq j)

Input

Input is given from Standard Input in the following format:

A_{1, 1} A_{1, 2} A_{1, 3}
A_{2, 1} A_{2, 2} A_{2, 3}
A_{3, 1} A_{3, 2} A_{3, 3}
N
b_1
\vdots
b_N

Output

If we will have a bingo, print Yes; otherwise, print No.

Sample Input 1

84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30

Sample Output 1

Yes

We will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3}, and complete the diagonal from the top-left to the bottom-right.

Sample Input 2

41 7 46
26 89 2
78 92 8
5
6
45
16
57
17

Sample Output 2

No

We will mark nothing.

Sample Input 3

60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34

Sample Output 3

Yes

We will mark all the squares.



Sample input:
84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30


Sample output:
Yes

Submission status: Accepted

Solution code:

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

mark = [[0]*3, [0]*3, [0]*3]

for i in range(N):
    b = int(input())
    for j, a in enumerate(A):
        for k, aa in enumerate(a):
            if aa == b:
                mark[j][k] = 1


if mark[0][0] == mark[1][1] == mark[2][2] == 1 or  mark[0][2] == mark[1][1] == mark[2][0] == 1:
    print("Yes")
    exit()
else:
    for i in range(3):
        if mark[i][0] == mark[i][1] == mark[i][2] == 1:
            print('Yes')
            exit()
        if mark[0][i] == mark[1][i] == mark[2][i] == 1:
            print("Yes")
            exit()

print("No")

Submission status: Accepted

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

alinelist = []
for i in range(1, 4):
  for j in range(1, 4):
    alinelist.append(alist[i - 1][j - 1])

n = int(input())

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

bhitlist = []
for k in blist:
  if str(k) in alinelist:
    hitindex = alinelist.index(str(k))
    bhitlist.append(hitindex)

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

bingoflag = False
for m in correctlist:
  bingocount = 0
  for n in m:
    if (n in bhitlist):
      bingocount += 1
    else:
      bingocount = 0
  if bingocount == 3:
    bingoflag = True
    break
  else:
        continue
  break

if bingoflag == True:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
# coding: utf-8
def main():
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    A = [a,b,c]
    n = int(input())
    B = []
    C = []
    for i in range(n):
        B.append(int(input()))
    for i in range(3):
        for j in range(3):
            if A[i][j] in B:
                C.append(i*10 + j)
    D = []
    if 0 in C:
        D += [1,4,7]
    if 1 in C:
        D += [1,5]
    if 2 in C:
        D += [1,6,8]
    if 10 in C:
        D += [2,4]
    if 11 in C:
        D += [2,5,7,8]
    if 12 in C:
        D += [2,6]
    if 20 in C:
        D += [3,4,8]
    if 21 in C:
        D += [3,5]
    if 22 in C:
        D += [3,6,7]
    for i in range(1,9):
        if D.count(i) == 3:
            print("Yes")
            quit()
    print("No")
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    L = []
    res = [[False] * 3 for _ in range(3)]
    for _ in range(3):
        L.append(lmi())
    n = ii()
    for _ in range(n):
        num = ii()
        for i in range(3):
            for j in range(3):
                if L[i][j] == num:
                    res[i][j] = True
    # print(res)
    trans = [[None] * 3 for _ in range(3)]
    for i in range(3):
        for j in range(3):
            trans[j][i] = res[i][j]
    print('Yes') if any(map(all, (res[0], res[1], res[2], trans[0], trans[1], trans[2], [res[0][0], res[1][1], res[2][2]], [res[0][2], res[1][1], res[2][0]]))) else print('No')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
bingo1 = list(map(int,input().split()))
bingo2 = list(map(int,input().split()))
bingo3 = list(map(int,input().split()))

bingo_list = []
bingo_list.append(bingo1)
bingo_list.append(bingo2)
bingo_list.append(bingo3)
N = int(input())

bingo_flag = False

for i in range(N):
    b = int(input())
    for j in range(3):
        if b in bingo_list[j]:
            index = bingo_list[j].index(b)
            bingo_list[j][index] = -1


for i in range(3):
    cnt1 = 0
    cnt2 = 0
    for j in range(3):
        if bingo_list[i][j] == -1:
            cnt1 += 1
        if bingo_list[j][i] == -1:
            cnt2 += 1
    if cnt1 == 3 or cnt2 == 3:
        bingo_flag = True
        break

if bingo_list[0][0] == -1 and bingo_list[1][1] == -1 and bingo_list[2][2]:
    bingo_flag = True


if bingo_list[0][2] == -1 and bingo_list[1][1] == -1 and bingo_list[2][0]:
    bingo_flag = True

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

Submission status: Accepted

Solution code:
import numpy as np

a = [[0] * 3 for i in range(3)]
for i in range(3):
    a[i] = list(map(int, input().split(' ')))

n = int(input())

for i in range(n):
    b = int(input())
    
    for r in range(3):
        for c in range(3):
            if a[r][c] == b:
                a[r][c] = 0

a = np.array(a)
sum1 = a.sum(axis=0)
sum2 = a.sum(axis=1)
naname1 = a[0][0] + a[1][1] + a[2][2]
naname2 = a[0][2] + a[1][1] + a[2][0]

if 0 in sum1 or 0 in sum2 or naname1 == 0 or naname2 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
a=[]
for i in range(3):
  a1,a2,a3=map(int,input().split())
  a.append([a1,a2,a3])
  
check=[[0]*3 for i in range(3)]
n=int(input())
b=[]
for i in range(n):
  b.append(int(input()))
for i in b:
  for j in range(3):
    if i in a[j]:
      check[j][a[j].index(i)]=1

naname=[0]*3

for i in range(3):
  if sum(check[i])==3:
    print('Yes')
    sys.exit()

for j in range(3):
  num=0
  for i in range(3):
    if check[i][j]==1:
      num+=1
      if num==3:
        print('Yes')
        sys.exit()
        
if check[0][0]==check[1][1]==check[2][2]==1:
  print('Yes')
  sys.exit()
if check[0][2]==check[1][1]==check[2][0]==1:
  print('Yes')
  sys.exit()
  
print('No')

Submission status: Accepted

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

flag = False
for i in range(n):
  b = int(input())
  for i in range(3):
    if a1[i] == b:
      a1[i] = 0
      flag = True
    if a2[i] == b:
      a2[i] = 0
      flag = True
    if a3[i] == b:
      a3[i] = 0
      flag = True

if flag == False:
  print('No')
else:
  if a1[0] == a2[0] == a3[0] == 0 or a1[1] == a2[1] == a3[1] == 0 or a1[2] == a2[2] == a3[2] == 0 or a1[0] == a1[1] == a1[2] == 0 or a2[0] == a2[1] == a2[2] == 0 or a3[0] == a3[1] == a3[2] == 0 or a1[0] == a2[1] == a3[2] == 0 or a3[0] == a2[1] == a1[2] == 0:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
A1 = [int(x) for x in input().split()]
A2 = [int(x) for x in input().split()]
A3 = [int(x) for x in input().split()]
A = [A1, A2, A3]
B = [[False] * 3 for i in range(3)]
N = int(input())
b = [0]*N
for i in range(N):
  j = int(input())
  for m in range(3):
    for n in range(3):
        if A[m][n] == j:
          B[m][n] = True
def check():
    for i in range(3):
      if sum(B[i]) == 3:
        return "Yes"
    for j in range(3):
      if sum([B[k][j] for k in range(3)]) == 3:
        return "Yes"
    if B[0][0] + B[1][1] + B[2][2] == 3 or B[0][2] + B[1][1] + B[2][0] == 3:
      return "Yes"
    return "No"
 
print(check())

Submission status: Accepted

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

def check(A, b):
    # 横
    for i in range(3):
        col, row = [], []
        for j in range(3):
            col.append(A[i][j])  # 横
            row.append(A[j][i])  # 縦
        if set(col) <= b or set(row) <= b:
            return True

    # 斜め
    if set([A[0][0], A[1][1], A[2][2]]) <= b or set([A[0][2], A[1][1], A[2][0]]) <= b:
        return True

if check(A, b):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

def check(A, b):
    # 縦
    for j in range(3):
        cand = []
        for i in range(3):
            cand.append(A[i][j])
        if set(cand) <= b:
            return True
        
    # 横
    for i in range(3):
        cand = []
        for j in range(3):
            cand.append(A[i][j])
        if set(cand) <= b:
            return True

    # 斜め
    if set([A[0][0], A[1][1], A[2][2]]) <= b or set([A[0][2], A[1][1], A[2][0]]) <= b:
        return True

if check(A, b):
    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()))
a1.extend(a2)
a1.extend(a3)
N = int(input())
b = [0]*N
for i in range(N):
  b[i] = int(input())
  if b[i] in a1:
    b1 = b[i]
    a1 = [0 if a1[j]==b1 else a1[j] for j in range(len(a1))]
n = sum(k==0 for k in a1)
if n >= 3:
  if n >= 7:
    print('Yes')
  elif a1[0]==a1[1]==a1[2] or a1[3]==a1[4]==a1[5] or a1[6]==a1[7]==a1[8] \
    or a1[0]==a1[3]==a1[6] or a1[1]==a1[4]==a1[7] or a1[2]==a1[5]==a1[8] \
    or a1[0]==a1[4]==a1[8] or a1[2]==a1[4]==a1[6]:
      print('Yes')
  else:
    print('No')
else:
  print('No')

Submission status: Accepted

Solution code:
d=[list(map(int,input().split()))for i in range(3)]
row=int(input())
num=[int(input()) for j in range(row)]
bingo=0
for a in range(3):
  if d[0][a] in num and d[1][a] in num and d[2][a] in num:
    bingo=bingo+1
  if d[a][0] in num and d[a][1] in num and d[a][2] in num:
    bingo=bingo+1
if d[1][1] in num and d[2][2] in num and d[0][0] in num:
  bingo=bingo+1
if d[1][1] in num and d[0][2] in num and d[2][0] in num:
  bingo=bingo+1
if bingo>0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
a=[[0]*3 for i in range(3)]
b=[]
for i in range(3):
  x=input().split()
  a[i][0]=x[0]
  a[i][1]=x[1]
  a[i][2]=x[2]
n=int(input())
for i in range(n):
  b.append(input())
for i in range(n):
  for j in range(9):
    if b[i]==a[j//3][j%3]:
      a[j//3][j%3]='X'
jud=[0,0,0,0]
z=0
res=0
for i in range(3):
  for j in range(2):
    if a[i][j]==a[i][j+1]:
      jud[0]+=1
    if a[j][i]==a[j+1][i]:
      jud[1]+=1
  if max(jud)>1:
    res-=1
  else:
    jud[0]=0
    jud[1]=0
for j in range(2):
  if a[j][j]==a[j+1][j+1]:
    jud[2]+=1
  if a[j][2-j]==a[j+1][2-j-1]:
    jud[3]+=1
if max(jud)>1:
  res-=1
if res<0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
def mark(number):
    """ビンゴシートにマークする

    Parameters
    ----------
    number : int
        出た数字
    """
    if number in yoko1:
        yoko1[number] = True

    if number in yoko2:
        yoko2[number] = True

    if number in yoko3:
        yoko3[number] = True

    if number in tate1:
        tate1[number] = True

    if number in tate2:
        tate2[number] = True

    if number in tate3:
        tate3[number] = True

    if number in naname1:
        naname1[number] = True

    if number in naname2:
        naname2[number] = True


def is_bingo():
    """ビンゴ達成したか否かを返す。
    """
    ans_list = []
    ans_list.append(False not in yoko1.values())
    ans_list.append(False not in yoko2.values())
    ans_list.append(False not in yoko3.values())
    ans_list.append(False not in tate1.values())
    ans_list.append(False not in tate2.values())
    ans_list.append(False not in tate3.values())
    ans_list.append(False not in naname1.values())
    ans_list.append(False not in naname2.values())

    return True in ans_list


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

yoko1 = {row1[0]: False, row1[1]: False, row1[2]: False}
yoko2 = {row2[0]: False, row2[1]: False, row2[2]: False}
yoko3 = {row3[0]: False, row3[1]: False, row3[2]: False}

tate1 = {row1[0]: False, row2[0]: False, row3[0]: False}
tate2 = {row1[1]: False, row2[1]: False, row3[1]: False}
tate3 = {row1[2]: False, row2[2]: False, row3[2]: False}

naname1 = {row1[0]: False, row2[1]: False, row3[2]: False}
naname2 = {row1[2]: False, row2[1]: False, row3[0]: False}

N = int(input())

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

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

Submission status: Accepted

Solution code:
import math

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

numbers = []
for i in range(num):
    numbers.append(int(input()))

position = []
for i in numbers:
    for j, column in enumerate(bingo_card):
        for k, num in enumerate(column):
            if i == num:
                position.append([j, k])

def main():
    for i in range(3):
        column_cnt = len(list(filter(lambda x : x[0] == i , position)))
        if (column_cnt == 3):
            return True
    
    for i in range(3):
        column_cnt = len(list(filter(lambda x : x[1] == i , position)))
        if (column_cnt == 3):
            return True
    
    x_1 = 0    
    for i in position:
        if (i == [0,0] or i == [1,1] or i == [2,2]):
            x_1 += 1
    
    if(x_1 == 3):
        return True
        
    x_2 = 0    
    for i in position:
        if (i == [0,2] or i == [1,1] or i == [2,0]):
            x_2 += 1
    
    if(x_2 == 3):
        return True
    
    return False

result = main()
if (result):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():

    def is_in(a, b):
        return (a, b) in nums_points

    flag = 0
    mat = [
        list(map(int, input().split())),
        list(map(int, input().split())),
        list(map(int, input().split()))
    ]

    n = int(input())
    nums = [int(input()) for i in range(n)]

    combs = defaultdict(int)
    for i in range(3):
        for j in range(3):
            combs[mat[i][j]] = (i, j)

    nums_points = []
    for n in nums:
        nums_points.append(combs[n])

    if is_in(0, 0) and is_in(0, 1) and is_in(0, 2):
        flag += 1
    if is_in(1, 0) and is_in(1, 1) and is_in(1, 2):
        flag += 1
    if is_in(2, 0) and is_in(2, 1) and is_in(2, 2):
        flag += 1
    if is_in(0, 0) and is_in(1, 0) and is_in(2, 0):
        flag += 1
    if is_in(0, 1) and is_in(1, 1) and is_in(2, 1):
        flag += 1
    if is_in(0, 2) and is_in(1, 2) and is_in(2, 2):
        flag += 1
    if is_in(0, 0) and is_in(1, 1) and is_in(2, 2):
        flag += 1
    if is_in(0, 2) and is_in(1, 1) and is_in(2, 0):
        flag += 1

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

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

N = int(input());

#Bの配列を作成
B = [];
for i in range(N):
  b = int(input())
  B.append(b);

#ビンゴの行列を作成
A = np.hstack([A1,A2,A3]);

for i in range(N):
  for j in range(len(A)):
    if B[i] == A[j]:
      A[j] = 0;
      break;
    else:
      pass;


if A[0] == 0 and A[1] == 0 and A[2] == 0:
  print("Yes");
elif A[3] == 0 and A[4] == 0 and A[5] == 0:
  print("Yes");
elif A[6] == 0 and A[7] == 0 and A[8] == 0:
  print("Yes");
elif A[0] == 0 and A[3] == 0 and A[6] == 0:
  print("Yes");
elif A[1] == 0 and A[4] == 0 and A[7] == 0:
  print("Yes");
elif A[2] == 0 and A[5] == 0 and A[8] == 0:
  print("Yes");
elif A[0] == 0 and A[4] == 0 and A[8] == 0:
  print("Yes");
elif A[2] == 0 and A[4] == 0 and A[6] == 0:
  print("Yes");
else:
  print("No");

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():

    def is_in(a, b):
        return (a, b) in nums_points

    flag = 0
    row1 = list(map(int, input().split()))
    row2 = list(map(int, input().split()))
    row3 = list(map(int, input().split()))

    n = int(input())
    nums = [int(input()) for i in range(n)]

    mat = [row1, row2, row3]
    combs = defaultdict(int)
    for i in range(3):
        for j in range(3):
            combs[mat[i][j]] = (i, j)

    nums_points = []
    for n in nums:
        nums_points.append(combs[n])

    if is_in(0, 0) and is_in(0, 1) and is_in(0, 2):
        flag += 1
    if is_in(1, 0) and is_in(1, 1) and is_in(1, 2):
        flag += 1
    if is_in(2, 0) and is_in(2, 1) and is_in(2, 2):
        flag += 1
    if is_in(0, 0) and is_in(1, 0) and is_in(2, 0):
        flag += 1
    if is_in(0, 1) and is_in(1, 1) and is_in(2, 1):
        flag += 1
    if is_in(0, 2) and is_in(1, 2) and is_in(2, 2):
        flag += 1
    if is_in(0, 0) and is_in(1, 1) and is_in(2, 2):
        flag += 1
    if is_in(0, 2) and is_in(1, 1) and is_in(2, 0):
        flag += 1

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main():
    *N, = map(int, open(0).read().split())
    A = N[0:9]
    N_number = N[9]
    b = N[10:]

    Ab_comm = set(A) & set(b)
    A_rep = [0 if i in Ab_comm else i for i in A]

    Ax=[]
    Ay=[]
    for i in range(0,3):
        Ax.append(A_rep[3*i] + A_rep[3*i + 1] + A_rep[3*i + 2])
        Ay.append(A_rep[i] + A_rep[i + 3] + A_rep[i + 6])
    An=[]
    An.append(A_rep[0] + A_rep[4] + A_rep[8])
    An.append(A_rep[2] + A_rep[4] + A_rep[6])
    if min(Ax + Ay + An) == 0:
        print("Yes")
    else:
        print("No")
        

main()

Submission status: Accepted

Solution code:
bingoMatrix=[list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()))]
n=int(input())
bingo=[]
fidnbingo=False
for i in range(n):
  bingo.append(int(input()))

result=[]
for i in range(3):
    tmpList=[]
    for j in range(3):
        tmpList.append(bingoMatrix[i][j])
    result.append(tmpList)
for i in range(3):
    tmpList=[]
    for j in range(3):
        tmpList.append(bingoMatrix[j][i])
    result.append(tmpList)
tmpList=[]
for i in range(3):
    tmpList.append(bingoMatrix[i][i])
result.append(tmpList)
result.append([bingoMatrix[0][2],bingoMatrix[1][1],bingoMatrix[2][0]])
for item in result:
    counter=0
    for i in item:
        if bingo.count(i):
            counter+=1
    if counter==3:
        fidnbingo=True
        break
if fidnbingo:
  	print ("Yes")
else:
	print ("No")

Submission status: Accepted

Solution code:
bingo_map = [[int(j) for j in input().split()] for i in range(3)]
n = int(input())
b_inputs = [int(input()) for i in range(n)]

for i in range(3):
    for j in range(3):
        if bingo_map[i][j] in b_inputs:
            bingo_map[i][j]=1
        else:
            bingo_map[i][j]=0

def check():
    for i in range(3):
        if sum(bingo_map[i])==3:
            return 'Yes'
                
    for j in range(3):
        if sum([bingo_map[k][j] for k in range(3)])==3:
            return 'Yes'

    if bingo_map[0][0] + bingo_map[1][1] + bingo_map[2][2]==3:
        return 'Yes'
    if bingo_map[0][2] + bingo_map[1][1] + bingo_map[2][0]==3:
        return 'Yes'
    return 'No'

print(check())

Submission status: Accepted

Solution code:
a = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _1 in range(n)]
for bingo in b:
    for i in range(3):
        for j in range(3):
            if a[i][j] == bingo:
                a[i][j] = 0
triple_pair =[a[0][t1]+a[1][t1]+a[2][t1] for t1 in range(3)] + [a[t2][0]+a[t2][1]+a[t2][2] for t2 in range(3)] + [a[0][0]+a[1][1]+a[2][2]] + [a[0][2]+a[1][1]+a[2][0]]
if 0 in triple_pair:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
*A, = map(int, open(0).read().split())
N = A[9]
B = A[10:]
A = A[:9]

T = [False]*9

for b in B:
    if b in A:
        T[A.index(b)] = True

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

for a, b, c in bingo:
    if T[a] and T[b] and T[c]:
        print('Yes')
        break
else:
    print('No')

Submission status: Accepted

Solution code:
a = []
for _ in range(3):
    a.append(list(map(int,input().split()))) 
n = int(input())
num_list = []
for _ in range(n):
    num_list.append(int(input()))
    
flg = False
for i in range(3):
    if a[i][0] in num_list and a[i][1] in num_list and a[i][2] in num_list:
        flg = True
        break
        
for i in range(3):
    if a[0][i] in num_list and a[1][i] in num_list and a[2][i] in num_list:
        flg = True
        break
        
if flg != True:
    diago = list([a[0][0],a[1][1],a[2][2]])
    if diago[0] in num_list and diago[1] in num_list and diago[2] in num_list:
        flg = True
        
if flg != True:
    diago2 = list([a[2][0],a[1][1],a[2][0]])
    if diago2[0] in num_list and diago2[1] in num_list and diago2[2] in num_list:
        flg = True
        
if flg:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  A = [[int(x) for x in readline().split()] for _ in range(3)]
  N = int(readline())
  bingo = [[False]*3 for _ in range(3)]
  for _ in range(N):
    b = int(input())
    for i in range(3):
      for j in range(3):
        if A[i][j] == b:
          bingo[i][j] = True
  ans = 'No'
  for i in range(3):
    if bingo[i][0] == bingo[i][1] == bingo[i][2] == True:
      ans = 'Yes'
    if bingo[0][i] == bingo[1][i] == bingo[2][i] == True:
      ans = 'Yes'
  if bingo[0][0] == bingo[1][1] == bingo[2][2] == True:
    ans = 'Yes'
  if bingo[0][2] == bingo[1][1] == bingo[2][0] == True:
    ans = 'Yes'
  print(ans)
  
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
a = []
while True:
    inp = input().split()
    if len(inp) == 3:
        a.append([int(x) for x in inp])
    else:
        break
n = int(inp[0])
bingo = [[False for _ in range(3)] for __ in range(3)]
for _ in range(n):
    b = int(input())
    for i in range(3):
        if b in a[i]:
            bingo[i][a[i].index(b)] = True
ans = "No"
for i in range(3):
    if bingo[i][0] == bingo[i][1] == bingo[i][2] == True:
        ans = "Yes"
    if bingo[0][i] == bingo[1][i] == bingo[2][i] == True:
        ans = "Yes"
if bingo[0][0] == bingo[1][1] == bingo[2][2] == True or bingo[0][2] == bingo[1][1] == bingo[2][0] == True:
    ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''
grid = []
for _ in range(3):
	temp = []
	temp = list(map(int,input().split()))
	grid.append(temp)
N = int(input())
b = []
for _ in range(N):
	b.append(int(input()))
for x in b:
	for i in range(3):
		for j in range(3):
			if grid[i][j]==x:
				grid[i][j]= -(grid[i][j])
ans = -1
# if not (grid[0][0]<0 and grid[1][1]<0 and grid[2][2]<0):	
for i in range(3):
	if grid[i][0]<0 and grid[i][1]<0 and grid[i][2]<0:
		ans  = 1
		break
	elif(grid[0][i]<0 and grid[1][i]<0 and grid[2][i]<0):
		ans = 1
		break
if ans!=1:
	if (grid[0][0]<0 and grid[1][1]<0 and grid[2][2]<0):
		ans = 1
	if( grid[0][2]<0 and grid[1][1]<0 and grid[2][0]<0):
		ans =1  
if(ans ==1):
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
A = []
ans = "No"

for _ in range(3):
    row = list(map(int, input().split()))
    A.append(row)

N = int(input())
for _ in range(N):
    bi = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == bi:
                A[i][j] = 0
                break

for i in range(3):
    if A[i][0] == A[i][1] == A[i][2]:
        ans = "Yes"
        break
    if A[0][i] == A[1][i] == A[2][i]:
        ans = "Yes"
        break

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

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

Submission status: Accepted

Solution code:
import sys
a=[[0 for i in range(3)] for j in range(3)]
for i in range(3):
    a[i]=list(map(int,input().split()))
n=int(input())
for _ in range(n):
    m=int(input())
    for i in range(3):
        for j in range(3):
            if m==a[i][j]:
                a[i][j]=0
    for k in range(3):
        if a[k][0]==0 and a[k][1]==0 and a[k][2]==0:
            print('Yes')
            sys.exit()
        if a[0][k]==0 and a[1][k]==0 and a[2][k]==0:
            print('Yes')
            sys.exit()
    if a[0][0]==0 and a[1][1]==0 and a[2][2]==0:
        print('Yes')
        sys.exit()
    if a[0][2]==0 and a[1][1]==0 and a[2][0]==0:
        print('Yes')
        sys.exit()
print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/python3

a = []

for i in range(3):
    a.append(tuple(map(int, input().split())))

n = int(input())

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

for i in range(n):
    b = int(input())
    for y in range(3):
        for x in range(3):
            if a[y][x] == b:
                tbl[y][x] = 1

if tbl[0][0] * tbl[0][1] * tbl[0][2] == 1:
    print('Yes')
elif tbl[1][0] * tbl[1][1] * tbl[1][2] == 1:
    print('Yes')
elif tbl[2][0] * tbl[2][1] * tbl[2][2] == 1:
    print('Yes')
elif tbl[0][0] * tbl[1][0] * tbl[2][0] == 1:
    print('Yes')
elif tbl[0][1] * tbl[1][1] * tbl[2][1] == 1:
    print('Yes')
elif tbl[0][2] * tbl[1][2] * tbl[2][2] == 1:
    print('Yes')
elif tbl[0][0] * tbl[1][1] * tbl[2][2] == 1:
    print('Yes')
elif tbl[0][2] * tbl[1][1] * tbl[2][0] == 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())
b = []
for i in range(N):
    b.append(int(input()))

bingo = []
for t in range(N):
    for i in range(3):
        if b[t] in A[i]:
            j = A[i].index(b[t])
            #bingo.append((i, j))
            A[i][j] = True

answer = "No"
for i in range(3):
    if A[i][0] == A[i][1] == A[i][2]:
        answer = "Yes"

for j in range(3):
    if A[0][j] == A[1][j] == A[2][j]:
        answer = "Yes"
if A[0][0] == A[1][1] == A[2][2]:
    answer = "Yes"

if A[2][0] == A[1][1] == A[0][2]:
    answer = "Yes"
    

print(answer)

Submission status: Accepted

Solution code:
# AtCoder
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
ans = 'No'
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            A[i][j] = True
        else:
            A[i][j] = False

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    card = []
    for _ in range(3):
        card.append(list(map(int, input().split())))
    bingo = [[0 for _ in range(3)] for _ in range(3)]
    N = int(input())
    for _ in range(N):
        b = int(input())
        for i in range(3):
            for j in range(3):
                if card[i][j] == b:bingo[i][j] = 1
    is_bingo = False
    for i in range(3):
        if bingo[i][0] == 1 and bingo[i][1] == 1 and bingo[i][2] == 1:
            is_bingo = True
            break
        if bingo[0][i] == 1 and bingo[1][i] == 1 and bingo[2][i] == 1:
            is_bingo = True
            break
    if bingo[0][0] == 1 and bingo[1][1] == 1 and bingo[2][2] == 1:
        is_bingo = True
    if bingo[0][2] == 1 and bingo[1][1] == 1 and bingo[2][0] == 1:
        is_bingo = True
    if is_bingo:
        print("Yes")
    else:
        print("No")
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = a + b + c
n = int(input())
n_list = [int(input()) for i in range(n)]
o = [False, False, False, False, False, False, False, False, False]
flag = False
for i in n_list:
    if i in d:
        o[d.index(i)] = True

for i in range(0, 7, 3):

    if o[i] and o[i + 1] and o[i + 2]:
        flag = True
        break

for i in range(0, 3):
    if o[i] and o[i + 3] and o[i + 6]:
        flag = True
        break

if o[0] and o[4] and o[8]:
    flag = True
if o[2] and o[4] and o[6]:
    flag = True

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