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 = [0 for i in range(9)]
for i in range(3):
  A[3*i], A[3*i+1], A[3*i+2] = map(int, input().split())
N = int(input())
b = [0 for i in range(N)]
for i in range(N):
  b[i] = int(input())

#Check matching numbers
for i in range(9):
  for j in range(N):
    if A[i] == b[j]:
      A[i] = 0

# Check bingo or not
flag = 0
# Check rows
for i in [0, 3, 6]:
  if A[i]==A[i+1] and A[i+1]==A[i+2]:
    flag += 1
# Check colums
for j in range(3):
  if A[j]==A[j+3] and A[j+3]==A[j+6]:
    flag += 1
# Check naname?
if (A[0]==A[4] and A[4]==A[8]) or (A[2]==A[4] and A[4]==A[6]):
  flag += 1

if flag >= 1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
A = [0 for i in range(9)]
for i in range(3):
  A[3*i], A[3*i+1], A[3*i+2] = map(int, input().split())
N = int(input())
b = [0 for i in range(N)]
for i in range(N):
  b[i] = int(input())

#Check matching numbers
for i in range(9):
  for j in range(N):
    if A[i] == b[j]:
      A[i] = 1

# Check bingo or not
flag = 0
# Check rows
for i in [0, 3, 6]:
  if A[i]==A[i+1] and A[i+1]==A[i+2]:
    flag += 1
# Check colums
for j in range(3):
  if A[j]==A[j+3] and A[j+3]==A[j+6]:
    flag += 1
# Check naname?
if (A[0]==A[4] and A[4]==A[8]) or (A[2]==A[4] and A[4]==A[6]):
  flag += 1

if flag >= 1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

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

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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def check(arr):
    # 横チェック
    for i in range(len(arr)):
        if arr[i] == ["x", "x", "x"]:
            return True

    # 縦チェック
    for i in range(3):
        if arr[0][i] == "x" and arr[1][i] == "x" and arr[2][i] == "x":
            return True

    # 斜めチェック
    if arr[0][0] == "x" and arr[1][1] == "x" and arr[2][2] == "x":
        return True
    elif arr[0][2] == "x" and arr[1][1] == "x" and arr[2][0] == "x":
        return True

    return False

arr = []
for _ in range(3):
    arr.append(list(map(int, input().split(' '))))

n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(len(arr)):
        tmp_arr = []
        for ele in arr[i]:
            if b == ele:
                tmp_arr.append("x")
            else:
                tmp_arr.append(ele)
        arr[i] = tmp_arr

if check(arr) == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A = []
P = ['o']*9
for i in range(3):
    a = [int(i) for i in input().split()]
    for j in range(3):
        A.append(a[j])

N = int(input())
for i in range(N):
    b = int(input())
    for j in range(9):
        if A[j] == b:
            P[j] = 'x'

t = 0
for i in range(3):
    if (P[i] == P[i+3] == P[i+6] == 'x') or (P[3*i] == P[3*i+1] == P[3*i+2] == 'x'):
        t += 1
        break
if (P[0] == P[4] == P[8] == 'x') or (P[2] == P[4] == P[6] == 'x'):
    t += 1

if t == 0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

cnt=[]
pattern=[[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 i in range(n):
    b.append(int(input()))
    for j , x in enumerate(a):
        if x == b[i]:
            cnt.append(j)

for q,w,e in pattern:
    if q in cnt and w in cnt and e in cnt:
        print('Yes')
        break
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()))
n = int(input())
flag = 0
for _ in range(n):
    b = int(input())
    for i in range(3):
        if b == a1[i]:
            a1[i] = 0
        elif b == a2[i]:
            a2[i] = 0
        elif b == a3[i]:
            a3[i] = 0
    for i in range(3):
        if a1[i] == a2[i] == a3[i]:
            flag = 1
        if sum(a1) == 0:
            flag = 1
        if sum(a2) == 0:
            flag = 1
        if sum(a3) == 0:
            flag = 1
        if a1[0] == a2[1] == a3[2]:
            flag = 1
        if a1[2] == a2[1] == a3[0]:
            flag = 1
    if flag == 1:
        print("Yes")
        break
if flag == 0:
    print("No")

Submission status: Accepted

Solution code:
# coding: utf-8

def main():
    A = []
    num = [1 for _ in range(101)]
    C = [
        [0, 1, 2],
        [3, 4, 5],
        [6, 7, 8],
        [0, 3, 6],
        [1, 4, 7],
        [2, 5, 8],
        [0, 4, 8],
        [2, 4, 6],
    ]
    ans = 'No'
    
    for _ in range(3):
        for i in list(map(int, input().split())):
            A.append(i)
        

    N = int(input())

    for _ in range(N):
        num[int(input())] -= 1

    for c in C:
        if num[A[c[0]]] == 0 and num[A[c[1]]] == 0 and num[A[c[2]]] == 0:
            ans = 'Yes'
            break

    print(ans)


if __name__ == "__main__":
    main()

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)]
visited = [[False for i in range(3)] for j in range(3)]
for i in b:
    for j in range(3):
        for k in range(3):
            if i==a[j][k]:
                visited[j][k] = True

ans = "No"
for i in visited:
    if i==[True,True,True]:
        ans = "Yes"

for i in range(3):
    flag = True
    for j in range(3):
        if visited[j][i]==False:
            flag = False
            break
    if flag:
        ans = "Yes"

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

Submission status: Accepted

Solution code:
a = [0]*9
a[0],a[1],a[2] = map(int,input().split())
a[3],a[4],a[5] = map(int,input().split())
a[6],a[7],a[8] = map(int,input().split())
n = int(input())
ans = [0]*9
for i in range(n):
    b = int(input())
    for j in range(9):
        if b == a[j]:
            ans[j] = 1
if sum(ans[:3]) == 3 or sum(ans[3:6]) == 3 or sum(ans[6:9]) == 3:
    print('Yes')
elif sum(ans[0::3]) == 3 or sum(ans[1::3]) == 3 or sum(ans[2::3]) == 3:
    print('Yes')
elif sum(ans[0::4]) == 3 or sum(ans[2:7:2]) == 3:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a,b,c = map(int,input().split())
d,e,f = map(int,input().split())
g,h,i = map(int,input().split())

x = []
y = [a,b,c,d,e,f,g,h,i]

n = int(input())
for s in range(n):
  x.append(int(input()))

for m in range(9):
  if y[m] in x:
      y[m] = 0

if y[0] == y[1] == y[2] == 0:
    print("Yes")
elif y[3] == y[4] == y[5] == 0:
    print("Yes")

elif y[6] == y[7] == y[8] == 0:
    print("Yes")

elif y[0] == y[3] == y[6] == 0:
    print("Yes")

elif y[1] == y[4] == y[7] == 0:
    print("Yes")

elif y[2] == y[5] == y[8] == 0:
    print("Yes")

elif y[0] == y[4] == y[8] == 0:
    print("Yes")

elif y[2] == y[4] == y[6] == 0:
    print("Yes")

else:

    print("No")

Submission status: Accepted

Solution code:
import sys
a = 3
A = [list(map(int,input().split())) for c in range(a)]
N = int(input())
b = [int(input()) for c in range(N)]
#print(A)
#print(b)
C = [[0,0,0],[0,0,0],[0,0,0]]
for i in range(3):
    for j in range(3):
        for k in range(N):
            if b[k] == A[i][j]:
                C[i][j] = 1

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

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

if C[0][0]+C[1][1]+C[2][2] == 3 or C[0][2]+C[1][1]+C[2][0] == 3:
    print("Yes")
    sys.exit(0)

print("No")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().rstrip().split())
inl = lambda: list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))

a = inl()
b = inl()
c = inl()
n = ini()
bingo = []
for _ in range(n):
    bingo.append(ini())
ct = [0] * 9
for i in bingo:
    if i in a:
        ct[a.index(i)] = 1
    if i in b:
        ct[b.index(i) + 3] = 1
    if i in c:
        ct[c.index(i) + 6] = 1
if sum(ct[:3]) == 3 or sum(ct[3:6]) == 3 or sum(ct[6:9]) == 3:
    print("Yes")
elif (ct[0] + ct[4] + ct[8]) == 3 or (ct[2] + ct[4] + ct[6]) == 3:
    print("Yes")
elif (ct[0] + ct[3] + ct[6]) == 3 or (ct[1] + ct[4] + ct[7]) == 3 or (ct[2] + ct[5] + ct[8]) == 3:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.readline
import time
from heapq import heappush, heappop, heapify
import math
from math import gcd
import itertools as it
from collections import deque 


def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

# bingo = [[0] * 3 for i in range(3)]
# bingo[0][0] = 1
# print(bingo)

bingo = []
for i in range(3):
    ls = inpl()
    bingo.append(ls)
N = inp()
for i in range(N):
    a = inp()
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == a:
                bingo[i][j] = -1

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

if bingo[0][2] == -1 and bingo[1][1] == -1 and bingo[2][0] == -1:
        bl = True
 
print('Yes' if bl else 'No')


# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)

Submission status: Accepted

Solution code:
A1 = list(map(str,input().split()))
A2 = list(map(str,input().split()))
A3 = list(map(str,input().split()))
N = int(input())
for k in range(N):
  i = str(input())  
  if i == A1[0]:
    A1[0] = 'OK'
  if i == A1[1]:
    A1[1] = 'OK'
  if i == A1[2]:
    A1[2] = 'OK'
  if i == A2[0]:
    A2[0] = 'OK' 
  if i == A2[1]:
    A2[1] = 'OK'
  if i == A2[2]:
    A2[2] = 'OK'
  if i == A3[0]:
    A3[0] = 'OK'
  if i == A3[1]:
    A3[1] = 'OK'
  if i == A3[2]:
    A3[2] = 'OK'
if A1 == ['OK','OK','OK'] or A2 == ['OK','OK','OK'] or A3 == ['OK','OK','OK']:
  print('Yes')
  exit()
for i in range(3):
  if A1[i] == 'OK' and A2[i] == 'OK' and A3[i]== 'OK':
    print('Yes')
    exit()
if A1[0] == 'OK' and A2[1] == 'OK' and A3[2]== 'OK':
    print('Yes')
    exit()
if A1[2] == 'OK' and A2[1] == 'OK' and A3[0]== 'OK':
    print('Yes')
    exit()
print('No')

Submission status: Accepted

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

for k in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                a[i][j] = 0
    row0 = a[0] == [0, 0, 0]
    row1 = a[1] == [0, 0, 0]
    row2 = a[2] == [0, 0, 0]
    colum0 = [a[0][0], a[1][0], a[2][0]] == [0, 0, 0]
    colum1 = [a[0][1], a[1][1], a[2][1]] == [0, 0, 0]
    colum2 = [a[0][2], a[1][2], a[2][2]] == [0, 0, 0]
    diag0 = [a[0][0], a[1][1], a[2][2]] == [0, 0, 0]
    diag1 = [a[2][0], a[1][1], a[0][2]] == [0, 0, 0]
    if row0 or row1 or row2 or colum0 or colum1 or colum2 or diag0 or diag1:
        print('Yes')
        break
else:
    print('No')

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def bingo_check(card):
    #横チェック
    for low in card:
        if sum(low)==0:
            print("Yes")
            exit()
    #縦チェック
    column1=0
    column2=0
    column3=0
    for low in card:
        column1+=low[0]
        column2+=low[1]
        column3+=low[2]
    if column1 == 0 or column2 == 0 or column3==0:
        print("Yes")
        exit()
    #斜めチェック
    diagonal1=card[0][0]+card[1][1]+card[2][2]
    diagonal2=card[0][2]+card[1][1]+card[2][0]
    if diagonal1 == 0 or diagonal2 == 0:
        print("Yes")
        exit()
    print("No")

def main():
    bingo=[]
    use_card=[]
    bingo=[list(map(int,input().split())) for _ in range(3)]
    use_card=bingo
    n = int(input())

    for idx in range(n):
        number=int(input())
        for i in range(3):
            for j in range(3):
                if number==use_card[i][j]:
                    use_card[i][j]=0
                else:
                    continue
    bingo_check(use_card)

if __name__=="__main__":
    main()

Submission status: Accepted

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

called = [False] * 9

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

N = int(input())
for i in range(N):
  target = int(input())
  if target in A:
    called[A.index(target)] = True
  
for a,b,c in bingo:
  if called[a] and called[b] and called[c]:
    print("Yes")
    break
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()))
n = int(input())
B = [int(input()) for i in range(n)]
A = [A1,A2,A3]
ans = [[0,0,0],[0,0,0],[0,0,0]]
for b in B:
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        ans[i][j] = 1
for i in range(3):
  if ans[i][0] and ans[i][1] and ans[i][2]:
    print("Yes")
    quit()
  if ans[0][i] and ans[1][i] and ans[2][i]:
    print("Yes")
    quit()
if ans[0][0] and ans[1][1] and ans[2][2]:
  print("Yes")
  quit()
if ans[0][2] and ans[1][1] and ans[2][0]:
  print("Yes")
  quit()
print("No")

Submission status: Accepted

Solution code:
map_list = [list(map(int,input().split())) for x in range(3)]
 
n = int(input())
for i in range(n):
  a = int(input())
  for i in range(3):
    for j in range(3):
      if map_list[i][j] == a:
        map_list[i][j] = 0

ans = "No"
for k in range(3):
  if map_list[0][k] == map_list[1][k] == map_list[2][k] or \
     map_list[k][0] == map_list[k][1] == map_list[k][2]:
      ans = "Yes"
      break
  if map_list[0][0] == map_list[1][1] == map_list[2][2] or \
	 map_list[0][2] == map_list[1][1] == map_list[2][0]:
      ans = "Yes"
print(ans)

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



flag = 0
cnt = 0
# yoko
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            cnt += 1
    else:
        if cnt == 3:
            print("Yes")
            flag += 1
            exit()
        else:
            cnt = 0

# tate
if flag == 0:
    for i in range(3):
        for j in range(3):
            if a[j][i] in b:
                cnt += 1

        else:
            if cnt == 3:
                print("Yes")
                flag += 1
                exit()
            else:
                cnt = 0


# ななめ1
if flag == 0:
    for i in range(3):
        if a[i][i] in b:
             cnt += 1
    else:
        if cnt == 3:
            print("Yes")
            flag += 1
            exit()
        else:
            cnt = 0

# ななめ2
if flag == 0:
    if a[2][0] in b:
        if a[1][1] in b:
            if a[0][2] in b:
                print("Yes")
                flag += 1


if flag == 0:
    print("No")

Submission status: Accepted

Solution code:
a = [[0] * 3 for x in range(3)]
s = [[0] * 3 for x in range(3)]
for i in range(3):
  a[i] = [int(x) for x in input().split()]
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))
for i in range(n):
  for j in range(3):
    for k in range(3):
      if b[i] == a[j][k]:
        s[j][k] = 1
res = "No"
if s[0][0] == 1 and s[0][1] == 1 and s[0][2] == 1:
  res = "Yes"
if s[1][0] == 1 and s[1][1] == 1 and s[1][2] == 1:
  res = "Yes"
if s[2][0] == 1 and s[2][1] == 1 and s[2][2] == 1:
  res = "Yes"
if s[0][0] == 1 and s[1][0] == 1 and s[2][0] == 1:
  res = "Yes"
if s[0][1] == 1 and s[1][1] == 1 and s[2][1] == 1:
  res = "Yes"
if s[0][2] == 1 and s[1][2] == 1 and s[2][2] == 1:
  res = "Yes"
if s[0][0] == 1 and s[1][1] == 1 and s[2][2] == 1:
  res = "Yes"
if s[2][0] == 1 and s[1][1] == 1 and s[0][2] == 1:
  res = "Yes"
print(res)

Submission status: Accepted

Solution code:
A=[[int(n) for n in input().split()] for m 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]=0
                
ans="No"

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

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

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


print(ans)

Submission status: Accepted

Solution code:

def main():
    a = [list(map(int, input().split())) for _ in range(3)]
    n = int(input())
    x = [[0]*3 for _ in range(3)]
    b =[]
    for _ in range(n):
        b.append(int(input()))
    for i in range(3):
        for j in range(3):
            if a[i][j] in b:
                x[i][j] = 1
    
    for i in range(3):
        c = 1
        for j in range(3):
            c *= x[i][j]
        if c == 1:
            print("Yes")
            return
    for i in range(3):
        c = 1
        for j in range(3):
            c *= x[j][i]
        if c == 1:
            print("Yes")
            return
    c = 1
    for i in range(3):
        c *= x[i][i] 
    if(c):
        print("Yes")
        return
    if(x[0][2]*x[1][1]*x[2][0]):
        print("Yes")
        return
    print("No")
    

    
    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    A = [[]for _ in range(3)]
    for i in range(3):
        A[i] = LI()
    A_ = [[]for _ in range(3)]
    for i in range(3):
        for j in range(3):
            A_[j].append(A[i][j])
    A__ = [[]for  _ in range(2)]
    for i in range(3):
        A__[0].append(A[i][i])
        A__[1].append(A[i][2 - i])

    N = I()
    B = []
    for i in range(N):
        b = I()
        B.append(b)
        for i in range(3):
            if b in A[i]:
                ind = A[i].index(b)
                A[i][ind] = 0
            if b in A_[i]:
                ind = A_[i].index(b)
                A_[i][ind] = 0
        for j in range(2):
            if b in A__[j]:
                ind = A__[j].index(b)
                A__[j][ind] = 0
    ans_list = []
    for i in range(3):
        ans_list.append(sum(A[i]))
        ans_list.append(sum(A_[i]))
    for j in range(2):
        ans_list.append(sum(A__[j]))

    if 0 in ans_list:
        print('Yes')
    else:
        print('No')






if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
al=[list(map(int, input().split())) for _ in range(3)]
bl=[[False]*3 for _ in range(3)]
n=int(input())
for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if al[i][j] == b: bl[i][j] = True

for i in range(3):
    if all(bl[i]):
        print('Yes')
        exit()

for j in range(3):
    if all([bl[0][j],bl[1][j],bl[2][j]]):
        print('Yes')
        exit()

if all([bl[0][0],bl[1][1],bl[2][2]]) or all([bl[2][0],bl[1][1],bl[0][2]]):
    print('Yes')
    exit()

print('No')

Submission status: Accepted

Solution code:
A1 = [int(_) for _ in input().split()]
A2 = [int(_) for _ in input().split()]
A3 = [int(_) for _ in input().split()]
A_list = A1 + A2 + A3
N = int(input())
b_list = []
for _ in range(N):
    b_list.append(int(input()))

bingo_card = [False for _ in range(9)]

for b in b_list:
    for i in range(9):
        if A_list[i] == b:
            bingo_card[i] = True

flg = False

patterns = [
    [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 pattern in patterns:
    if (
        bingo_card[pattern[0]]
        == bingo_card[pattern[1]]
        == bingo_card[pattern[2]]
        == True
    ):
        flg = True

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

Submission status: Accepted

Solution code:
bingo = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
for _ in range(N):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if bingo[i][j] == b:
        bingo[i][j] = 0

ans = "No"
for k in range(3):
  if bingo[k][0] == bingo[k][1] == bingo[k][2] or \
     bingo[0][k] == bingo[1][k] == bingo[2][k]:
    ans = "Yes"
    break
if bingo[0][0] == bingo[1][1] == bingo[2][2] or \
   bingo[0][2] == bingo[1][1] == bingo[2][0]:
  ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
a = []
for _ in range(3):
  a = a + [int(i) for i in input().split()]
n = int(input())
a_bingo = [0] * 3 * 3
pos = [[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 _ in range(n):
  b = int(input())
  if b in a:
    a_bingo[a.index(b)] = 1
for po in pos:
  if a_bingo[po[0]] == a_bingo[po[1]] == a_bingo[po[2]] == 1:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

Solution code:
# B - Bingo
A = [0]*101
for i in range(3):
    tmp = list(map(int,input().split()))
    for j in range(3):
        A[tmp[j]] = 3*i+j+1
N = int(input())
S = set()
for _ in range(N):
    b = int(input())
    S.add(A[b])

def bingo(l):
    ans = False
    for x,y,z in l:
        if x in S and y in S and z in S:
            ans = True
            break
    return ans

if bingo([(1,2,3),(4,5,6),(7,8,9),(1,4,7),(2,5,8),(3,6,9),(1,5,9),(3,5,7)]):
    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)]

bingo = 'No'

for t in zip(*a):
    a.append(list(t))

a.append([a[i][i] for i in range(3)])
a.append([a[i][2-i]for i in range(3)])

for line in a:
    if all(item in b for item in line):
        bingo = 'Yes'
        break

print(bingo)

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

bingo = 'No'

for t in zip(*a):
    a.append(list(t))

a.append([a[i][i] for i in range(3)])
a.append([a[i][2-i]for i in range(3)])

for line in a:
    if all(item in b for item in line):
        bingo = 'Yes'

print(bingo)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
    nums = np.array(read().split(), np.int64)
    a = nums[:9]

    for x in nums[10:]:
        a[a == x] = 0
    pos = ((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 pose in pos:
        if a[pose[0]] == a[pose[1]] == a[pose[2]] == 0:
            print('Yes')
            sys.exit()
    print('No')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
list_a = [[int(n) for n in input().split()] for m in range(0, 3)]
n = int(input())
list_b = [int(input()) for k in range(0, n)]

if (list_a[0][0] in list_b and list_a[0][1] in list_b and list_a[0][2] in list_b) or\
    (list_a[1][0] in list_b and list_a[1][1] in list_b and list_a[1][2] in list_b) or\
    (list_a[2][0] in list_b and list_a[2][1] in list_b and list_a[2][2] in list_b) :
    print('Yes')

elif (list_a[0][0] in list_b and list_a[1][0] in list_b and list_a[2][0] in list_b) or\
    (list_a[0][1] in list_b and list_a[1][1] in list_b and list_a[2][1] in list_b) or\
    (list_a[0][2] in list_b and list_a[1][2] in list_b and list_a[2][2] in list_b) :
    print('Yes')

elif (list_a[0][0] in list_b and list_a[1][1] in list_b and list_a[2][2] in list_b) or\
    (list_a[2][0] in list_b and list_a[1][1] in list_b and list_a[0][2] in list_b):
    print('Yes')

else:
    print('No')

Submission status: Accepted

Solution code:
bin = []
for i in range(3):
  bin.append(list(map(int, input().split())))
bin = sum(bin, [])
N = int(input())
bingo = [False for _ in range(9)]
for _ in range(N):
  b = int(input())
  if b in bin:
    bingo[bin.index(b)] = True
if (bingo[0] and bingo[1] and bingo[2]) or (bingo[3] and bingo[4] and bingo[5]) or \
   (bingo[6] and bingo[7] and bingo[8]) or (bingo[0] and bingo[3] and bingo[6]) or \
   (bingo[1] and bingo[4] and bingo[7]) or (bingo[2] and bingo[5] and bingo[8]) or \
   (bingo[0] and bingo[4] and bingo[8]) or (bingo[2] and bingo[4] and bingo[6]):
  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
ans = 'No'
for i in range(3):
    if a[i][0] + a[i][1] + a[i][2] == 0:
        ans = 'Yes'
    if a[0][i] + a[1][i] + a[2][i] == 0:
        ans = 'Yes'
if a[0][0] + a[1][1] + a[2][2] == 0:
    ans = 'Yes'
if a[0][2] + a[1][1] + a[2][0] == 0:
    ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
A_Bingo = []
for i in range(3):
    A_Bingo.append(list(map(int,input().split())))

card =[]
n = int(input())
for k in range(n):
    card.append(int(input()))

r_cnt =[0,0,0]
c_cnt =[0,0,0]
rc_result = [[0,0,0],[0,0,0],[0,0,0]]

for row in range(3):
    for column in range(3):
        if A_Bingo[row][column] in card:
            r_cnt[row] += 1
            c_cnt[column] += 1
            rc_result[row][column] = 1

if 3 in r_cnt:
    print("Yes")
elif 3 in c_cnt:
    print("Yes")
elif rc_result[0][0]*rc_result[1][1]*rc_result[2][2] == 1:
    print("Yes")
elif rc_result[0][2]*rc_result[1][1]*rc_result[2][0] == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np

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

for b in B:
	for i in range(3):
		for j in range(3):
			if A[i][j]==b:A[i][j]=0
			
ans_axis0=np.sum(np.array(A),axis=0)
ans_axis1=np.sum(np.array(A),axis=1)
ans_naname=[A[0][0]+A[1][1]+A[2][2],A[0][2]+A[1][1]+A[2][0]]

#print(A,ans_axis0,ans_axis1,ans_naname)

if 0 in ans_axis0 or 0 in ans_axis1 or 0 in ans_naname:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
A = []

for i in range(3):
  p, q, r = map(int, input().split())
  A.append(p)
  A.append(q)
  A.append(r)
N = int(input())
c = [0] * 9
for i in range(N):
  B = int(input())
  if B in A:
    position = A.index(B)
    c[position] = 1
if c[0]==c[4]==c[8]==1 or c[2]==c[4]==c[6]==1 or c[0]==c[1]==c[2]==1 or c[3]==c[4]==c[5]==1 or c[6]==c[7]==c[8]==1 or c[0]==c[3]==c[6]==1 or c[1]==c[4]==c[7]==1 or c[2]==c[5]==c[8]==1:
  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 b in B:
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        A[i][j] = 0

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

  if A[0][i] == A[1][i] == A[2][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 itertools
a=[list(map(int,input().split())) for i in range(3)]
a=list(itertools.chain.from_iterable(a))
n=int(input())
b=[]

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

ans=['-']*9

for i in a:
  if i in b:
    ans[a.index(i)]='+'

if ans[0]==ans[1]==ans[2]=='+' or ans[3]==ans[4]==ans[5]=='+' or ans[6]==ans[7]==ans[8]=='+'\
   or ans[0]==ans[3]==ans[6]=='+' or ans[1]==ans[4]==ans[7]=='+' or ans[2]==ans[5]==ans[8]=='+'\
   or ans[0]==ans[4]==ans[8]=='+' or ans[2]==ans[4]==ans[6]=='+':
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

for q in Q:
    for i in range(3):
        for j in range(3):
            if A[i][j] == q:
                A[i][j] = 0

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

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

    if A[0][i] == A[1][i] == A[2][i] == 0:
        print('Yes')
        exit()

print('No')

Submission status: Accepted

Solution code:
s = " 012 345 678 036 147 258 048 246 "
a = [input().split() for i in range(3)]
b = a[0] + a[1] + a[2]

for i in [input()for i in range(int(input()))]:
  if i in b:
    s = s.replace(str(b.index(i)), "")
print("Yes" if "  " in s else "No")

Submission status: Accepted

Solution code:
bingo=[]
for i in range(3):
  a=list(map(int,input().split()))
  bingo.append(a)
  
n=int(input())
for i in range(n):
  b=int(input())
  for j in range(3):
    if b in bingo[j]:
      bingo[j][bingo[j].index(b)]=0
      
def hantei(l):
  for i in range(3):
    if all([l[i][j]==0 for j in range(3)]):
      return 'Yes'
    
    elif all([l[j][i]==0 for j in range(3)]):
      return 'Yes'
    
    elif l[0][0]==0 and l[1][1]==0 and l[2][2]==0:
      return 'Yes'
    
    elif l[0][2]==0 and l[1][1]==0 and l[2][0]==0:
      return 'Yes'
    
    else:
      continue
      
  return 'No'
    
#print(bingo)
print(hantei(bingo))