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:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    for i in range(3):
        for j in range(3):
            if A[i][j] in b:
                A[i][j] = 0
    for i in range(3):
        row_flag = True
        for j in range(3):
            if A[i][j]!=0:
                row_flag = False
        if row_flag == True:
            print(YES)
            return
    for j in range(3):
        line_flag = True
        for i in range(3):
            if A[i][j]!=0:
                line_flag = False
        if line_flag == True:
            print(YES)
            return
    if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
        print(YES)
        return
    if A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0:
        print(YES)
        return
    print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [[int(next(tokens)) for _ in range(3)] for _ in range(3)]  # type: "List[List[int]]"
    N = int(next(tokens))  # type: int
    b = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(A, N, b)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

memo = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

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

    for j, ai in enumerate(bingo_sheet):
        for k, a in enumerate(ai):
            if a == b:
                memo[j][k] = 1

ans = False

for i in range(3):
    if memo[i][0] and memo[i][1] and memo[i][2]:
        ans = True
        break

    elif memo[0][i] and memo[1][i] and memo[2][i]:
        ans = True
        break

if memo[0][0] and memo[1][1] and memo[2][2]:
    ans = True

if memo[0][2] and memo[1][1] and memo[2][0]:
    ans = True

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

Submission status: Accepted

Solution code:
def hantei(array):
  for i in range(3):
    if array[i][0] and array[i][1] and array[i][2]:
      return True
    
  for i in range(3):
    if array[0][i] and array[1][i] and array[2][i]:
      return True
    
  if array[0][0] and array[1][1] and array[2][2]:
    return True
  
  if array[2][0] and array[1][1] and array[0][2]:
    return True
  
  return False

bingo = []
array = [[False for i in range(3)] for j in range(3)]

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

n = int(input())

for i in range(n):
  b = int(input())
  
  for j in range(3):
    for k in range(3):
      if b == bingo[j][k]:
        array[j][k] = True
        
if hantei(array):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
from itertools import product

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

for h, w in product(range(3), repeat=2):
    if A[h][w] in B:
        A[h][w] = -1

for h in range(3):
    if all(A[h][i]==-1 for i in range(3)):
        print('Yes')
        exit()

for w in range(3):
    if all(A[i][w]==-1 for i in range(3)):
        print('Yes')
        exit()

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

print('No')

Submission status: Accepted

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

flag_hit = [[False,False,False],
            [False,False,False],
            [False,False,False]]

for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                flag_hit[j][k] = True

flag_bingo = False
for i in range(3):
    if (flag_hit[i][0] is True) and (flag_hit[i][1] is True) and (flag_hit[i][2] is True):
        flag_bingo = True
    if (flag_hit[0][i] is True) and (flag_hit[1][i] is True) and (flag_hit[2][i] is True):
        flag_bingo = True
    if (flag_hit[0][0] is True) and (flag_hit[1][1] is True) and (flag_hit[2][2] is True):
        flag_bingo = True
    if (flag_hit[0][2] is True) and (flag_hit[1][1] is True) and (flag_hit[2][0] is True):
        flag_bingo = True

if flag_bingo is True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) for _ in range(3)]
mark = [[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 a[i][j] == b:
        mark[i][j] = True
bingo = False
for i in range(3):
  if mark[i][0] and mark[i][1] and mark[i][2]:
    bingo = True
  if mark[0][i] and mark[1][i] and mark[2][i]:
    bingo = True
if mark[0][0] and mark[1][1] and mark[2][2]:
  bingo = True
if mark[0][2] and mark[1][1] and mark[2][0]:
  bingo = True
if bingo:
  print('Yes')
else:
  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)]
if A[0][0] in B:
    if A[0][1] in B:
        if A[0][2] in B:
            print("Yes")
            exit()
    if A[1][0] in B:
        if A[2][0] in B:
            print("Yes")
            exit()
    if A[1][1] in B:
        if A[2][2] in B:
            print("Yes")
            exit()
if A[0][1] in B:
    if A[1][1] in B:
        if A[2][1] in B:
            print("Yes")
            exit()
if A[0][2] in B:
    if A[1][2] in B:
        if A[2][2] in B:
            print("Yes")
            exit()
    if A[1][1] in B:
        if A[2][0] in B:
            print("Yes")
            exit()
if A[1][0] in B:
    if A[1][1] in B:
        if A[1][2] in B:
            print("Yes") 
            exit()
if A[2][0] in B:
    if A[2][1] in B:
        if A[2][2] in B:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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

N = int(input())
bingo_flag = [[False] * 3 for _ in range(3)]
for _ in range(N):
    num = int(input())
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == num:
                bingo_flag[i][j] = True

# print(bingo_flag)
is_bing = False
for i in range(3):
    if bingo_flag[i][0] and bingo_flag[i][1] and bingo_flag[i][2] or \
            bingo_flag[0][i] and bingo_flag[1][i] and bingo_flag[2][i]:
        is_bing = True
        break

if bingo_flag[0][0] and bingo_flag[1][1] and bingo_flag[2][2] or \
        bingo_flag[0][2] and bingo_flag[1][1] and bingo_flag[2][0]:
    is_bing = True

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

Submission status: Accepted

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

#整数値入力 1文字の入力
def input_one_number():
    return int(input())

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

#整数値龍力　複数の入力(配列)
def input_multiple_number_as_list():
    return list(map(int, input().split()))


a= input_multiple_number_as_list()
b= input_multiple_number_as_list()
c = input_multiple_number_as_list()

n= input_one_number()

for i in range(n):
    bq = input_one_number()
    for j in range(3):
        if a[j] == bq:
            a[j] = -1
        if b[j] == bq:
            b[j] = -1
        if c[j] == bq:
            c[j] = -1

if (a[0] == -1 and b[0] == -1 and c[0] == -1) or(a[1] == -1 and b[1] == -1 and c[1] == -1) or (a[2] == -1 and b[2] == -1 and c[2] == -1) or(a[0] == -1 and a[1] == -1 and a[2] == -1) or(b[0] == -1 and b[1] == -1 and b[2] == -1) or(c[0] == -1 and c[1] == -1 and c[2] == -1) or(a[0] == -1 and b[1] == -1 and c[2] == -1) or(a[2] == -1 and b[1] == -1 and c[0] == -1) :
    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()))
N = int(input())
b = set()
for i in range(N):
  b.add(int(input()))

flag = 0

if (A1[0] in b) and (A1[1] in b) and (A1[2] in b):
  flag = 1

if (A2[0] in b) and (A2[1] in b) and (A2[2] in b):
  flag = 1

if (A3[0] in b) and (A3[1] in b) and (A3[2] in b):
  flag = 1

for col in range(3):
  n = 0
  if (A1[col] in b) and (A2[col] in b) and (A3[col] in b):
    flag = 1

if (A1[0] in b) and (A2[1] in b) and (A3[2] in b):
    flag = 1
if (A1[2] in b) and (A2[1] in b) and (A3[0] in b):
    flag = 1    

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

Submission status: Accepted

Solution code:
A = [list(map(int,input().split())) for i in range(3)]
N = int(input())
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 b == A[i][j]:
                bingo[i][j] = True

ans = False
# for k in range(3):
#     print(bingo[k])
for i in range(3):
    if all(bingo[i]):
        print('Yes')
        exit()

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

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

if all([bingo[0][2],bingo[1][1],bingo[2][0]]):
    print('Yes')
    exit()
print('No')

Submission status: Accepted

Solution code:


A = []

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

N = int(input())

Flag = [[0] * 3 for i in range(3)]

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

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

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

	if(Flag[0][i] + Flag[1][i] + Flag[2][i] == 3):
		print('Yes')
		exit(0)

if(Flag[0][0] + Flag[1][1] + Flag[2][2] == 3):
	print('Yes')
	exit(0)

if(Flag[2][0] + Flag[1][1] + Flag[0][2] == 3):
	print('Yes')
	exit(0)

print('No')

Submission status: Accepted

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

for k in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                c[i][j] = True

for i in range(3):
    flag1 = 1
    flag2 = 1
    for j in range(3):
        flag1 *= c[i][j]
        flag2 *= c[j][i]
    if flag1 or flag2:
        ans = True
        break

if not ans:
    flag1 = 1
    flag2 = 1
    for i in range(3):
        flag1 *= c[i][i]
        flag2 *= c[i][2 - i]
    if flag1 or flag2:
        ans = True

if ans:
    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()))
n = int(input())
b = [int(input()) for i in range(n)]

a1_a = [0]*3
a2_a = [0]*3
a3_a = [0]*3

for i in range(n):
  for j in range(3):
    if a1[j] == b[i]:
      a1_a[j] = 1
    if a2[j] == b[i]:
      a2_a[j] = 1
    if a3[j] == b[i]:
      a3_a[j] = 1
if sum(a1_a) == 3 or sum(a2_a) == 3 or sum(a3_a) == 3:
  print("Yes")
elif a1_a[0] + a2_a[0] + a3_a[0] == 3:
  print("Yes")
elif a1_a[1] + a2_a[1] + a3_a[1] == 3:
  print("Yes")
elif a1_a[2] + a2_a[2] + a3_a[2] == 3:
  print("Yes")
elif a1_a[0] + a2_a[1] + a3_a[2] == 3:
  print("Yes")
elif a1_a[2] + a2_a[1] + a3_a[0] == 3:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    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, a in enumerate(A):
            for j, aa in enumerate(a):
                if b == aa:
                    A[i][j] = 0

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

    print(ans)

if __name__ == '__main__':
    resolve()

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

ans=[[0 for i in range(3)] for i in range(3)]

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

#print(ans)
c=0
for i in range(3):
    if ans[0][i]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0
for i in range(3):
    if ans[1][i]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0 
for i in range(3):
    if ans[2][i]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0  
for i in range(3):
    if ans[i][0]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0  
for i in range(3):
    if ans[i][1]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0   
for i in range(3):
    if ans[i][2]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0  
for i in range(3):
    if ans[1][i]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0

for i in range(3):
    if ans[i][i]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0

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

Submission status: Accepted

Solution code:
def main():
    A = []
    for _ in range(3):
        A.append([int(s) for s in input().strip().split()])
    n = int(input().strip())
    B = []
    for _ in range(n):
        B.append(int(input().strip()))
    
    for row in A:
        for i, x in enumerate(row):
            if x in B:
                row[i] = "*"
    for i in range(3):
        if A[i][0] == A[i][1] == A[i][2] == "*" or A[0][i] == A[1][i] == A[2][i] == "*":
            print("Yes")
            return
    if A[0][0] == A[1][1] == A[2][2] == "*" or A[0][2] == A[1][1] == A[2][0] == "*":
        print("Yes")
        return
    print("No")


main()

Submission status: Accepted

Solution code:
bingo = []
checker = 0
for i in range(3):
    bingo.append([int(j) for j in input().split()])
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if bingo[j][k] == b:
                bingo[j][k] = 0
for i in range(3):
    if checker == 1:
        break
    if bingo[i][0] ==0 and  bingo[i][1] == 0 and bingo[i][2] == 0:
        checker = 1
    if bingo[0][i] == 0 and bingo[1][i] == 0 and bingo[2][i] == 0:
        checker = 1
    if bingo[0][0] == 0 and  bingo[1][1] == 0 and bingo[2][2] == 0:
        checker = 1
    if bingo[0][2] == 0 and bingo[1][1] == 0 and bingo[2][0] == 0:
        checker = 1

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

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

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

tables = [[0,0,0] for i in range(3)]
for n in range(N):
    for i in range(3):
        for j in range(3):
            if A[i][j] == b[n]:
                tables[i][j] = 1

ans = 0
for i in range(3):
    if tables[i][0] == tables[i][1] == tables[i][2] == 1:
        ans = 1
    if tables[0][i] == tables[1][i] == tables[2][i] == 1:
        ans = 1
    if tables[0][0] == tables[1][1] == tables[2][2] == 1:
        ans = 1
    if tables[0][2] == tables[1][1] == tables[2][0] == 1:
        ans = 1

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

Submission status: Accepted

Solution code:
#B
#入力
A=[list(map(int,input().split())) for i in range(3)]
N=int(input())
B=[int(input()) for i in range(N)]
#処理
C=[[0 for i in range(3)] for j in range(3)]
for a in B:
    for b in range(3):
        for c in range(3):
            if a==A[b][c]:
                C[b][c]=1
t=0
for i in range(3):
    if C[i][0]*C[i][1]*C[i][2]==1:
        print("Yes")
        t=1
        break
    if C[0][i]*C[1][i]*C[2][i]==1:
        print("Yes")
        t=1
        break
if t==0:
    if C[0][0]*C[1][1]*C[2][2]==1:
        print("Yes")
    elif C[0][2]*C[1][1]*C[2][0]==1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

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

a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))

b1 = [a1[0], a2[0], a3[0]]
b2 = [a1[1], a2[1], a3[1]]
b3 = [a1[2], a2[2], a3[2]]

c1 = [a1[0], a2[1], a3[2]]
c2 = [a1[2], a2[1], a3[0]]

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

ca1 = 0
ca2 = 0
ca3 = 0
cb1 = 0
cb2 = 0
cb3 = 0
cc1 = 0
cc2 = 0
for x in s:
    if x in a1:
        ca1+=1
    if x in a2:
        ca2+=1
    if x in a3:
        ca3+=1
    if x in b1:
        cb1+=1
    if x in b2:
        cb2+=1
    if x in b3:
        cb3+=1
    if x in c1:
        cc1+=1
    if x in c2:
        cc2+=1

if ca1 == 3:
    print("Yes")
elif ca2 == 3:
    print("Yes")
elif ca3 == 3:
    print("Yes")
elif cb1 == 3:
    print("Yes")
elif cb2 == 3:
    print("Yes")
elif cb3 == 3:
    print("Yes")
elif cc1 == 3:
    print("Yes")
elif cc2 == 3:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

for k in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if b == a[i][j]:
                a[i][j] = '#'

flag = 0

if a[0][0] == a[0][1] and a[0][1] == a[0][2]:
    flag = 1
if a[1][0] == a[1][1] and a[1][1] == a[1][2]:
    flag = 1
if a[2][0] == a[2][1] and a[2][1] == a[2][2]:
    flag = 1
if a[0][0] == a[1][0] and a[1][0] == a[2][0]:
    flag = 1
if a[0][1] == a[1][1] and a[1][1] == a[2][1]:
    flag = 1
if a[0][2] == a[1][2] and a[1][2] == a[2][2]:
    flag = 1
if a[0][0] == a[1][1] and a[1][1] == a[2][2]:
    flag = 1
if a[0][2] == a[1][1] and a[1][1] == a[2][0]:
    flag = 1

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

Submission status: Accepted

Solution code:

A_list = []
A_list.append(list(map(int, input().split())))
A_list.append(list(map(int, input().split())))
A_list.append(list(map(int, input().split())))
N = int(input())

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

for _ in range(N):
	b = int(input())
	for i in range(3):
		for j in range(3):
			if b == A_list[i][j]:
				B_list[i][j] = True

def check():
	for i in range(3):
		if all(B_list[i]) or all(map(lambda j: B_list[j][i], range(3))):
			return True
	
	if all(map(lambda i : B_list[i][i], range(3))) or all(map(lambda i : B_list[i][2 - i], range(3))):
		return True
	
	return False

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

Submission status: Accepted

Solution code:
A = []
for i in range(3):
  A.append([int(i) for i in input().split()])

N = int(input())
ans = "No"

for i in range(N):
  B = int(input())
  for j in range(len(A)):
    for k in range(len(A[0])):
      if A[j][k] == B:
        A[j][k] = -1

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

# naname
if A[0][0] == -1 and A[1][1] == -1 and A[2][2] == -1:
  ans = "Yes"

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

print(ans)

Submission status: Accepted

Solution code:
a = []
for i in range(3):
    aa = list(map(int, input().split()))
    a.append(aa)
n = int(input())
flag = []
for i in range(3):
    flag.append([0, 0, 0])
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                flag[j][k] = 1
ans = False
for j in range(3):
    if flag[0][j] == 1 and flag [1][j] == 1 and flag[2][j] == 1:
        ans = True
for i in range(3):
    if flag[i][0] == 1 and flag [i][1] == 1 and flag[i][2] == 1:
        ans = True
if flag[0][0] == 1 and flag [1][1] == 1 and flag[2][2] == 1:
        ans = True
if flag[2][0] == 1 and flag [1][1] == 1 and flag[0][2] == 1:
        ans = True
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A = [list(map(int,input().split(" "))) for _ in range(3)]
N = int(input())
ans = 'No'
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] = -1
for i in range(3):
    if A[i] == [-1,-1,-1]:
        ans = 'Yes'
        break
    elif [A[0][i],A[1][i],A[2][i]] == [-1,-1,-1]:
        ans = 'Yes'
        break
    elif [A[j][j] for j in range(3)] == [-1,-1,-1]:
        ans = 'Yes'
        break
    elif [A[0][2],A[1][1],A[2][0]] == [-1,-1,-1]:
        ans = 'Yes'
        break
print(ans)

Submission status: Accepted

Solution code:
a=[list(map(int,input().split())) for _ in range(3)]
f=[[0]*3 for _ in range(3)]
for _ in range(int(input())):
  x=int(input())
  for i in range(3):
    for j in range(3):
      if x==a[i][j]:
        f[i][j]=1
ans=0
for i in range(3):
  if all(f[i][j] for j in range(3)) or all(f[j][i] for j in range(3)):
    ans=1
if f[0][0]==f[1][1]==f[2][2]==1 or f[0][2]==f[1][1]==f[2][0]==1:
  ans=1
print("Yes" if ans 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())
B = [int(input()) for _ in range(N)]
ans = False
if A1[0] in B and A2[0] in B and A3[0] in B:
    ans = True
if A1[1] in B and A2[1] in B and A3[1] in B:
    ans = True
if A1[2] in B and A2[2] in B and A3[2] in B:
    ans = True
if A1[1] in B and A1[0] in B and A1[2] in B:
    ans = True
if A2[1] in B and A2[0] in B and A2[2] in B:
    ans = True
if A3[1] in B and A3[0] in B and A3[2] in B:
     ans = True
if A1[0] in B and A2[1] in B and A3[2] in B:
     ans = True
if A3[0] in B and A2[1] in B and A1[2] in B:
     ans = True
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

ALL.append([ALL[0][0],ALL[1][1],ALL[2][2]])
ALL.append([ALL[0][2],ALL[1][1],ALL[2][0]])

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

j = 0
for i in ALL:
    if i[0] in c and i[1] in c and i[2] in c:
        j = 1
        break

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

Submission status: Accepted

Solution code:
def main():
    a = [ list(map(int, input().split())) for _ in range(3) ]
    f = [ [ False ]*3 for _ in range(3) ]
    n = int(input())
    for i in range(n):
        b = int(input())
        for y in range(3):
            for x in range(3):
                if a[y][x] == b:
                    f[y][x] = True

    is_bingo = False
    # 横に揃う
    for y in range(3):
        is_bingo = all(f[y])
        if is_bingo:
            print("Yes")
            return 0
    # 縦に揃う
    for x in range(3):
        t = []
        for y in range(3):
            t.append(f[y][x])
        is_bingo = all(t)
        if is_bingo:
            print("Yes")
            return 0

    # 斜めに揃う
    is_bingo = all( [f[0][0], f[1][1], f[2][2]] )
    if is_bingo:
        print("Yes")
        return 0
    is_bingo = all( [f[0][2], f[1][1], f[2][0]] )
    if is_bingo:
        print("Yes")
        return 0
    print("No")

main()

Submission status: Accepted

Solution code:
import numpy as np

a = np.zeros((3,3))
for i in range(3):
    a[i] = np.asarray(input().split(), dtype=np.int32)

n = int(input())

for i in range(n):
    a[a == int(input())] = 0

for i in range(3):
    if a[i][0] == 0 and a[i][1] == 0 and a[i][2] == 0:
        print("Yes")
        break
    if a[0][i] == 0 and a[1][i] == 0 and a[2][i] == 0:
        print("Yes")
        break
    if i == 2:
        if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
            print("Yes")
            break
        elif a[2][0] == 0 and a[1][1] == 0 and a[0][2] == 0:
            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())
for _ in range(n):
    b = int(input())
    if b in a1:
        a1[a1.index(b)] = 0
    elif b in a2:
        a2[a2.index(b)] = 0
    elif b in a3:
        a3[a3.index(b)] = 0

if a1.count(0) == 3 or a2.count(0) == 3 or a3.count(0) == 3:
    print('Yes')
elif a1[0] == 0 and a2[0] == 0 and a3[0] == 0:
    print('Yes')
elif a1[1] == 0 and a2[1] == 0 and a3[1] == 0:
    print('Yes')
elif a1[2] == 0 and a2[2] == 0 and a3[2] == 0:
    print('Yes')
elif a1[0] == 0 and a2[1] == 0 and a3[2] == 0:
    print('Yes')
elif a1[2] == 0 and a2[1] == 0 and a3[0] == 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)]
res = [[0]*3 for _ in range(3)]
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            res[i][j] = 1
            
for i in res:
    if all(i):
        print('Yes')
        exit()
for i in range(3):
    if res[0][i]==1 and res[1][i]==1 and res[2][i]==1:
        print('Yes')
        exit()
if res[0][0]==1 and res[1][1]==1 and res[2][2]==1:
    print('Yes')
    exit()
if res[0][2]==1 and res[1][1]==1 and res[2][0]==1:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

Solution code:
def main():
    A = [[int(i) for i in input().split()] for j in range(3)]
    seen = [[False]*3 for j in range(3)]
    N = int(input())
    for i in range(N):
        b = int(input())
        for j in range(3):
            for k in range(3):
                if A[j][k] == b:
                    seen[j][k] = True
    flag = False
    for i in range(3):
        if all(seen[i]):
            flag = True
    for i in range(3):
        if all([seen[0][i], seen[1][i], seen[2][i]]):
            flag = True
    if all([seen[0][0], seen[1][1], seen[2][2]]) or \
            all([seen[0][2], seen[1][1], seen[2][0]]):
        flag = True
    if flag:
        print("Yes")
    else:
        print("No")


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)]
x=[[0]*3 for i in range(3)]
for b in B:
    for i,l in enumerate(A):
        for j,a in enumerate(l):
            if a==b:
                x[i][j]=1
print('Yes' if sum([all(l) for l in x]+[all(l) for l in zip(*x)]+[all([x[i][i] for i in range(3)]),all([x[i][2-i] for i in range(3)])]) else 'No')

Submission status: Accepted

Solution code:
from collections import defaultdict

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

    for i in range(3):
        for j in range(3):
            d[A[i][j]].append(i)
            d[A[i][j]].append(j)

    bingo = [[False] * 3 for _ in range(3)]
    N = int(input())
    for _ in range(N):
        b = int(input())
        if d[b]:
            i, j = d[b]
            bingo[i][j] = True

    for i in range(3):
        flag = True
        for j in range(3):
            if bingo[i][j] == False:
                flag = False
                break
        if flag:
            print('Yes')
            exit()

    for j in range(3):
        flag = True
        for i in range(3):
            if bingo[i][j] == False:
                flag = False
                break
        if flag:
            print('Yes')
            exit()
    
    if bingo[0][0] == True and bingo[1][1] == True and bingo[2][2] == True:
        print('Yes')
        exit()

    if bingo[2][0] == True and bingo[1][1] == True and bingo[0][2] == True:
        print('Yes')
        exit()

    print('No')
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    A1 = [int(x) for x in stdin.readline().rstrip().split()]
    A2 = [int(x) for x in stdin.readline().rstrip().split()]
    A3 = [int(x) for x in stdin.readline().rstrip().split()]
    A4 = [A1[0], A2[0], A3[0]]
    A5 = [A1[1], A2[1], A3[1]]
    A6 = [A1[2], A2[2], A3[2]]
    A7 = [A1[0], A2[1], A3[2]]
    A8 = [A1[2], A2[1], A3[0]]
    As = [A1, A2, A3, A4, A5, A6, A7, A8]
    N = int(stdin.readline().rstrip())
    bs = [int(stdin.readline().rstrip()) for _ in range(N)]
    b = set(bs)
    for A in As:
        a = set(A)
        x = a & b
        if(len(x) == 3):
            print('Yes')
            return
    print('No')


if __name__ == "__main__":
    main()

Submission status: Accepted

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

n=int(input())
b=[]
for i in range(n):
    b.append(int(input()))
x=[[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]]
for i in range(8):
    if a[x[i][0]-1] in b and a[x[i][1]-1] in b and a[x[i][2]-1] in b:
        print("Yes")
        sys.exit()
print("No")