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: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	A = []
	A1 = inputList()
	A2 = inputList()
	A3 = inputList()
	A.append(A1)
	A.append(A2)
	A.append(A3)

	hantei1 = [[False for j in range(3)] for i in range(3)]
	#print(hantei1)

	ans = "No"
	N = inputInt()
	for i in range(N):
		tmp = inputInt()
		for ii,vol in enumerate(A):
			for jj,val in enumerate(vol):
				if tmp == val:
					hantei1[ii][jj] = True

		for iii in hantei1:
			if iii == [True,True,True]:
				ans = "Yes"
		for iii in range(3):
			flg = True
			for jjj in hantei1:
				if jjj[iii] == False:
					flg = False
					break
			if flg == True:
				ans = "Yes"
		if hantei1[0][0] == True and hantei1[1][1] == True and hantei1[2][2] == True:
				ans = "Yes"
		if hantei1[0][2] == True and hantei1[1][1] == True and hantei1[2][0] == True:
				ans = "Yes"
	#print(hantei1)
	print("No")

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# special thanks :
#  https://nagiss.hateblo.jp/entry/2019/07/01/185421
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

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

for n in B:
    for i in range(8):
        for j in range(3):
            if C[i][j] == n:
                C[i][j] = 0

for i in range(8):
    C[i] = sum(C[i])

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

Submission status: Wrong Answer

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

G = [[False] * 3 for i in range(3)]
N = int(input())
for i in range(N):
    b = int(input())
    for k in range(3):
        for i in range(3):
            if A[i][k] == b:
                G[i][k] = True

def check():
    for r in range(3):
        if all(G[r][c] for c in range(3)):
            return "Yes"
    for c in range(3):
        if all(G[r][c] for r in range(3)):
            return "Yes"
    if all(G[c][c] for r in range(3)):
        return "Yes"
    if G[0][2] and G[1][1] and G[2][0]:
        return "Yes"
    return "No"
#print(G)
print(check())

Submission status: Wrong Answer

Solution code:

# n,m=map(int,input().split())
# a,b,c=map(int,input().split())
# s=input()
# s,t=map(str,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
L=[]
L.append(A)
L.append(B)
L.append(C)
n=int(input())

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

if L[0][0]==0 and L[0][1]==0 and L[0][2]==0:
  print("Yes")
  exit()

if L[1][0]==0 and L[1][1]==0 and L[1][2]==0:
  print("Yes")
  exit()

if L[2][0]==0 and L[2][1]==0 and L[2][2]==0:
  print("Yes")
  exit()

if L[0][0]==0 and L[1][0]==0 and L[2][0]==0:
  print("Yes")
  exit()
if L[0][1]==0 and L[1][1]==0 and L[2][1]==0:
  print("Yes")
  exit()
if L[0][2]==0 and L[1][2]==0 and L[2][2]==0:
  print("Yes")
  exit() 
if L[0][0]==0 and L[1][1]==0 and L[2][2]==0:
  print("Yes")
  exit()


print("No")

Submission status: Wrong Answer

Solution code:
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/g.inp"
exit $?
'''
import sys


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return [int(x) for x in sys.stdin.readline().strip().split()]


def judge(a):
    for aij in ai:
        if aij not in b:
            flag = False
            break


def main():
    a = [_ia() for _ in range(3)]

    n = _i()
    b = [_i() for _ in range(n)]
    f1 = True
    for i in range(3):
        if a[i][i] not in b:
            f1 = False
        f2, f3 = [True] * 2
        for j in range(3):
            if a[i][j] not in b: f2 = False
            if a[j][i] not in b: f3 = False
        if f2 or f3: return "Yes"
    return "Yes" if f1 else "No"


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

Submission status: Wrong Answer

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

for i in range(N):
  b=int(input())
  for j in range(3):
    if A[j]==b:
      x[0][j]=1
    elif B[j]==b:
      x[1][j]=1
    elif C[j]==b:
      x[2][j]=1
flag=0
if x[0][0]==1:
  if x[0][1]==1 and x[0][2]==1:
    flag=1
  elif x[1][0]==1 and x[2][0]==1:
    flag=1
  elif x[1][1]==1 and x[2][2]==1:
    flag=1
elif x[1][1]==1:
  if x[0][1]==1 and x[2][1]==1:
    flag=1
  elif x[1][0]==1 and x[2][0]==1:
    flag=1
  elif x[0][2]==1 and x[2][0]==1:
    flag=1
elif x[2][2]==1:
  if x[2][0]==1 and x[2][1]==1:
    flag=1
  elif x[0][2]==1 and x[1][2]==1:
    flag==1
if flag==1:
  print("Yes")
else:
  print("No")
#print(x)

Submission status: Wrong Answer

Solution code:
a=[]
for _ in range(3):
  a.append(list(map(int,input().split())))
n=int(input())
b=[int(input()) for _ in range(n)]
bingo=[]
bingo+=a
for i in range(3):
  t=[]
  for j in range(3):
    t.append(a[i][j])
  bingo.append(t)

bingo.append([a[0][0],a[1][1],a[2][2]])
bingo.append([a[2][0],a[1][1],a[0][2]])

for i in range(n):
  for j in bingo:
    if b[i] in j:
      j.remove(b[i])

if [] in bingo:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

bingos = [
    [(0,0), (0,1), (0,2)],
    [(1,0), (1,1), (1,2)],
    [(2,0), (2,1), (2,2)],
    [(0,0), (1,0), (2,0)],
    [(0,1), (1,1), (2,1)],
    [(0,2), (1,2), (2,2)],
    [(0,0), (1,1), (2,2)],
    [(2,1), (1,1), (0,2)],
]

ans = 'No'
for bingo in bingos:
    for bp in bingo:
        i, j = bp
        if a[i][j] not in b:
            break
    else:
        ans = 'Yes'
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

A = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

*B, = map(int, input().split())
A[0][0] = B[0]
A[0][1] = B[1]
A[0][2] = B[2]

*B, = map(int, input().split())
A[1][0] = B[0]
A[1][1] = B[1]
A[1][2] = B[2]

*B, = map(int, input().split())
A[2][0] = B[0]
A[2][1] = B[1]
A[2][2] = B[2]

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] = -1

#斜めのチェック
if A[0][0]==A[1][1]==A[2][2]:
    print("Yes")
    sys.exit()
#縦のチェック
for i in range(3):
    if A[0][i]==A[1][i]==A[2][i]:
        print("Yes")
        sys.exit()

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

Submission status: Wrong Answer

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

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

f = 0
for i in range(3):
    if sum(A[i][:]) == 0:
        f = 1


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

if f == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

aa = [0] * 8
for i in range(3):
    for j in range(3):
        if bingo[i][j] in b:
            aa[i] += 1
            aa[j+2] += 1
            if i == j:
                aa[-2] += 1
            if i + j == 3:
                aa[-1] += 1
if 3 in aa:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

x = [[0] * 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:
                x[i][j] = 1

for i in range(3):
    if sum(x[i]) == 3:
        print('Yes')
        exit()
for i in range(3):
    s0 = 0
    s0 += x[i][0]
    s1 = 0
    s1 += x[i][1]
    s2 = 0
    s2 += x[i][2]
    if s0 == 3 or s1 == 3 or s2 == 3:
        print('Yes')
        exit()
if x[0][0] + x[1][1] + x[2][2] == 3:
    print('Yes')
    exit()
if x[0][2] + x[1][1] + x[2][0] == 3:
    print('Yes')
    exit()
print('No')

Submission status: Wrong Answer

Solution code:
import sys
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)]
tate1=[A1[0],A2[0],A3[0]]
tate2=[A1[1],A2[1],A3[1]]
tate3=[A1[2],A2[2],A3[2]]
naname1=[A1[0],A2[1],A3[2]]
naname2=[A1[2],A2[1],A3[0]]

if A1[0] and A1[1] and A1[2] in b:
    print('Yes')
    sys.exit()
if A2[0] and A2[1] and A2[2] in b:
    print('Yes')
    sys.exit()
if A3[0] and A3[1] and A3[2] in b:
    print('Yes')
    sys.exit()
if tate1[0] and tate1[1] and tate1[2] in b:
    print('Yes')
    sys.exit()
if tate2[0] and tate2[1] and tate2[2] in b:
    print('Yes')
    sys.exit()
if tate3[0] and tate3[1] and tate3[2] in b:
    print('Yes')
    sys.exit()
if naname1[0] and naname1[1] and naname1[2] in b:
    print('Yes')
    sys.exit()
if naname2[0] and naname2[1] and naname2[2] in b:
    print('Yes')
    sys.exit()
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from itertools import product

A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]
bingo = [[0] * 3 for _ in range(3)]
for b in B:
    for i, j in product(range(3), repeat=2):
        if A[i][j] == b:
            bingo[i][j] = 1
            break
flag = False
for i in range(3):
    if sum(A[i]) == 3:
        flag = True
        break
else:
    for j in range(3):
        if sum(A[i][j] for i in range(3)) == 3:
            flag = True
            break
    else:
        if sum(A[i][i] for i in range(3)) == 3 or sum(A[i][2-i] for i in range(3)):
            flag = True
print('Yes' if flag else 'No')

Submission status: Wrong Answer

Solution code:
import math
A=[list(map(int,input().split())) for _  in range(3)]
N=int(input())
b=[int(input()) for _ in range(N)]
l=[[0 for _ in range(3)] for _ in range(3)]
flag=0
#print(A,b,l)

for i in range(N):
    for j in range(3):
        for k in range(3):
            if b[i]==A[j][k]:
                l[j][k]=1
#print(l)
for i in range(3):
    if (l[i][0]+l[i][1]+l[i][2])==3:
        flag=1
        break
    if (l[0][i]+l[0][i]+l[0][i])==3:
        flag=1
        break
if (l[0][0]+l[1][1]+l[2][2]==3)or(l[2][0]+l[1][1]+l[0][2]==3):
    flag=1
if flag==0:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np
a = []
for _ in range(3):
    a.append(list(map(int, input().split())))
a = list(np.array(a).flatten() )
N = int(input())
index = []
for _ in range(N):
    b_i = int(input())
    if b_i in a:
        index.append(a.index(b_i))
index = sorted(list(set(index)))

for i in index:
    if i + 1 in index and i + 2 in index:
        print("Yes")
        exit()
    if i + 2 in index and i + 4 in index:
        print("Yes")
        exit()
    if i + 3 in index and i + 6 in index:
        print("Yes")
        exit()
    if i + 4 in index and i + 8 in index:
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

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

for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            A[i][j] = 'X'
print(A)

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

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

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

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

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

# t
if A[0][0] == A[1][0] == A[2][0] == 'X':
    print('Yes')
    exit()
if A[0][1] == A[1][1] == A[2][1] == 'X':
    print('Yes')
    exit()
if A[0][2] == A[1][2] == A[2][2] == 'X':
    print('Yes')
    exit()
print('No')

Submission status: Wrong Answer

Solution code:
from itertools import product
data = [list(map(int, input().split())) for i in range(3)]
n = int(input())
bl = [int(input()) for _ in range(n)]
ok = [[0]*3 for _ in range(3)]

for b in bl:
    for i in range(3):
        for j in range(3):
            if data[i][j] == b:
                ok[i][j] = 1

# print(data)
# print(ok)
if sum(ok[0][:]) == 3 or sum(ok[1][:]) == 3 or sum(ok[2][:]) == 3 or sum(ok[:][0]) == 3 or sum(ok[:][1]) == 3 or sum(ok[:][2]) == 3 or (ok[0][0]+ok[1][1]+ok[2][2]) or (ok[0][2]+ok[1][1]+ok[2][0]):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
SEL = 0
A = [[int(j) for j in input().split(' ')] for i in range(3)]
N = int(input())
for _ in range(N):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if b == A[i][j]:
        A[i][j] = SEL

if (A[0][0] == A[0][1] == A[0][2] == SEL or
    A[1][0] == A[1][1] == A[1][2] == SEL or
    A[2][0] == A[2][1] == A[2][2] == SEL or 
    A[0][0] == A[1][0] == A[2][0] == SEL or
    A[0][1] == A[1][1] == A[2][1] == SEL or
    A[0][2] == A[1][2] == A[2][2] == SEL or
    A[0][0] == A[1][1] == A[2][2] == SEL or
    A[0][2] == A[1][1] == A[2][0] == SEL):
  print('Yes')
else:
  print('No')
print(A)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	A = []
	A1 = inputList()
	A2 = inputList()
	A3 = inputList()
	A.append(A1)
	A.append(A2)
	A.append(A3)

	hantei1 = [[False for j in range(3)] for i in range(3)]
	#print(hantei1)

	N = inputInt()
	for i in range(N):
		tmp = inputInt()
		for ii,vol in enumerate(A):
			for jj,val in enumerate(vol):
				if tmp == val:
					hantei1[ii][jj] = True

		for iii in hantei1:
			if iii == [True,True,True]:
				print("Yes")
				sys.exit()
		for iii in range(3):
			flg = True
			for jjj in hantei1:
				if jjj[iii] == False:
					flg = False
					break
			if flg == True:
				print("Yes")
				sys.exit()
		if hantei1[0][0] == True and hantei1[1][1] == True and hantei1[2][2] == True:
				print("Yes")
				sys.exit()
		if hantei1[0][2] == True and hantei1[1][1] == True and hantei1[2][0] == True:
				print("Yes")
				sys.exit()
	print(hantei1)
	print("No")

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# special thanks :
#  https://nagiss.hateblo.jp/entry/2019/07/01/185421
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import math as m

def main(**kwargs):
    r = "No"

    if (A[0][0] in B) and (A[0][1] in B) and (A[0][2] in B):
        r = "Yes"
    
    if (A[1][0] in B) and (A[1][1] in B) and (A[1][2] in B):
        r = "Yes"
    
    if (A[2][0] in B) and (A[2][1] in B) and (A[2][2] in B):
        r = "Yes"
    
    if (A[0][0] in B) and (A[1][0] in B) and (A[2][0] in B):
        r = "Yes"
    
    if (A[0][1] in B) and (A[1][1] in B) and (A[2][1] in B):
        r = "Yes"
    
    if (A[0][2] in B) and (A[1][2] in B) and (A[2][2] in B):
        r = "Yes"
    
    if (A[0][0] in B) and (A[1][1] in B) and (A[2][2] in B):
        r = "Yes"
    
    if (A[2][2] in B) and (A[1][1] in B) and (A[0][0] in B):
        r = "Yes"
    
    return r

if __name__ == "__main__":
    A = np.zeros((3, 3), dtype="int")
    cin = np.array(input().split(" ")).astype("int")
    A[0][0], A[0][1], A[0][2] = cin
    cin = np.array(input().split(" ")).astype("int")
    A[1][0], A[1][1], A[1][2] = cin
    cin = np.array(input().split(" ")).astype("int")
    A[2][0], A[2][1], A[2][2] = cin

    cin = np.array(input().split(" ")).astype("int")
    n, *_ = cin

    B = np.zeros(n, dtype="int")

    for i in range(n):
        cin = np.array(input().split(" ")).astype("int")
        B[i], *_ = cin
    
    cout = main(A=A, n=n, B=B)
    print(cout)

Submission status: Wrong Answer

Solution code:
A=[]
for i in range(3):
    A.append(list(map(int,input().split())))
b=int(input())
for i in range(b):
    l=int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k]==l:
                A[j][k]=0
a1=sum(A[0])
a2=sum(A[1])
a3=sum(A[2])
a4=A[0][0]+A[1][0]+A[2][0]
a5=A[0][0]+A[1][0]+A[2][0]
a6=A[0][1]+A[1][1]+A[2][1]
a7=A[0][0]+A[1][1]+A[2][2]
a8=A[2][0]+A[1][1]+A[0][2]
count=min(a1,a2,a3,a4,a5,a6,a7,a8)
if count==0:
     print("Yes")
else:
     print("No")

Submission status: Wrong Answer

Solution code:
# n, m = map(int, input().split())
maze = []
for i in range(3):
    a_row = list(map(int,input().split()))
    maze.append(a_row)
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        row = maze[j]
        for k in range(3):
            if row[k] == b:
                row[k] = 0
for i in range(3):
    if sum(maze[i]) == 0:
        print("Yes")
        exit()
for i in range(3):
    if maze[i][0] + maze[i][1] + maze[i][2] == 0:
        print("Yes")
        exit()
if maze[0][0] + maze[1][1] + maze[2][2] == 0 or maze[0][2] + maze[1][1] + maze[2][0] == 0:
    print("Yes")
    exit()
print("No")

Submission status: Wrong Answer

Solution code:
a = []
for i in range(3):
  a.append(list(map(int,input().split())))
for i in range(int(input())):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k] == b:
        a[j][k] = 0
def bingo():
  for i in range(3):
    if sum(a[i]) == 0 or a[0][i] + a[0][j] + a[0][k] == 0:
      return 'Yes'
  if a[0][0] + a[1][1] + a[2][2] == 0 or a[0][2] + a[1][1] + a[2][0] == 0:
    return 'Yes'
  return 'No'
print(bingo())

Submission status: Wrong Answer

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

def main():
    A = [list(map(int,input().split())) for _ in range(3)]
    hit = [['n'] * 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:
                    hit[i][i] = 'y'

    for i in range(3):
        row = hit[i]
        if 'n' not in row:
            print('Yes')
            quit()

        vert = [hit[x][i] for x in range(3)]
        if 'n' not in vert:
            print('Yes')
            quit()

    ri = [hit[0][0], hit[1][1], hit[2][2]]
    if 'n' not in ri:
        print('Yes')
        quit()

    le = [hit[2][0], hit[1][1], hit[2][0]]
    if 'n' not in le:
        print('Yes')
        quit()

    print('No')


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

flag = True
for i in range(3):
    if (A1 in B) or (A2 in B) or (A3 in B):
        print('Yes')
        flag = False
        break
    elif (A1[i] in B) and (A2[i] in B) and (A3[i] in B):
        print('Yes')
        flag = False
        break 
    elif (A1[0] in B) and (A2[1] in B) and (A3[2] in B):
        print('Yes')
        flag = False
        break 
    elif (A1[2] in B) and (A2[1] in B) and (A3[0] in B):
        print('Yes')
        flag = False
        break 
if flag == True:
    print("No")

Submission status: Wrong Answer

Solution code:
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
a3=list(map(int,input().split()))
n=int(input())
a=a1+a2+a3
b=set([int(input()) for _ in range(n)])

c1=set(a[0::3])
c2=set(a[1::3])
c3=set(a[2::3])
c4=set([a1[0],a2[1],a3[2]])
c5=set([a1[2],a2[1],a3[0]])
c=[c1,c2,c3,c4,c5]
j = any(len(b&x)==3 for x in c)
print('Yes' if j else 'No')

Submission status: Wrong Answer

Solution code:
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

for i in range(3):
    for j in a[i]:
        if j != 0:
            break
    else:
        print('Yes')
        break
    if a[0][i] == 0 and a[1][i] == 0 and a[2][i] == 0:
        print('Yes')
        break
    if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

Solution code:
lsa=list(map(int,input().split()))
lsb=list(map(int,input().split()))
lsc=list(map(int,input().split()))
n=int(input())
called=[int(input()) for i in range(n)]

lsaa=[lsa[0],lsb[0],lsc[0]]
lsbb=[lsa[1],lsb[1],lsc[1]]
lscc=[lsa[2],lsb[2],lsc[2]]

lsx=[lsa[0],lsb[1],lsc[2]]
lsy=[lsa[2],lsb[1],lsc[0]]

ls=[lsa,lsb,lsc,lsaa,lsbb,lscc,lsx,lsy]

for i in ls:
    flag=False
    for j in i:
        if j not in called:
            break
        flag=True
    if flag:
        break

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

Submission status: Wrong Answer

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

for h in range(3):
    for w in range(3):
        for i in range(N):
            if b[i] == A[h][w]:
                A[h][w] = 0
if [0,0,0] in A:
    print('Yes')
else:
    ans = 'No'
    for i in zip(*A):
        if i == (0,0,0):
            ans = 'Yes'
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
import math
arr=[]
for i in range(3):
	temp=list(map(int,input().split()))
	arr.append(temp)
d={}
n=int(input())
for i in range(n):
	x=int(input())
	if x in d:
		d[x]+=1
	else:
		d[x]=1
brr=[]
for i in range(3):
	brr.append([])
for i in range(3):
	for j in range(3):
		if arr[i][j] in d:
			brr[i].append(1)
		else:
			brr[i].append(0)
flag=False
if brr[0][0]==1 and brr[0][1]==1 and brr[0][2]==1:
	flag=True
if brr[0][0]==1 and brr[1][1]==1 and brr[2][2]==1:
	flag=True
if brr[2][0]==1 and brr[1][1]==1 and brr[0][2]==1:
	flag=True
if brr[0][0]==1 and brr[1][0]==1 and brr[2][0]==1:
	flag=True
if brr[1][0]==0 and brr[1][1]==1 and brr[1][2]==1:
	flag=True
if brr[2][0]==1 and brr[2][1]==1 and brr[2][2]==1:
	flag=True
if brr[0][1]==1 and brr[1][1]==1 and brr[2][1]==1:
	flag=True 
if brr[0][2]==1 and brr[1][2]==1 and brr[2][2]==1:
	flag=True
if flag:
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
a = []
for i in range(3):
    a.append([int(x) for x in input().split()])
bing = [([0]*3),([0]*3),([0]*3)]

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

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

def isbingo(board):
    for i in range(3):
        if sum(board[i])==3:
            return True
    for i in range(3):
        if sum([board[i][j] for j in range(3)])==3:
            return True
    if (sum([board[0][0],board[1][1],board[2][2]])):
        return True
    if (sum([board[0][2],board[1][1],board[2][0]])):
        return True
    return False
    
print('Yes'if isbingo(bing) else 'No')

Submission status: Wrong Answer

Solution code:
import sys

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] = -1

for i in range(3):
    for j in range(3):
        if A[i][j] != -1:
            break
    else:
        print('Yes')
        sys.exit(0)

for i in range(3):
    for j in range(3):
        if A[j][i] != -1:
            break
    else:
        print('Yes')
        sys.exit(0)

for i in range(3):
    if A[i][i] != -1:
        break
    else:
        print('Yes')
        sys.exit(0)

for i in range(3):
    if A[i][2-i] != -1:
        break
    else:
        print('Yes')
        sys.exit(0)

print('No')