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:
import sys

AList = []
BingoList = [[0, 0, 0],
             [0, 0, 0],
             [0, 0, 0]]

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

N = int(input())

tmp = -1
for i in range(N):
    tmp = int(input())
    for p in range(3):
        for q in range(3):
            if AList[p][q] == tmp:
                BingoList[p][q] = 1

for i in range(3):
    if BingoList[i][0] == 1 and BingoList[i][1] == 1 and BingoList[i][2] == 1:
        print('Yes')
        sys.exit(0)

for i in range(3):
    if BingoList[0][i] == 1 and BingoList[1][i] == 1 and BingoList[2][i] == 1:
        print('Yes')
        sys.exit(0)

if BingoList[0][0] == 1 and BingoList[1][1] == 1 and BingoList[2][2] == 1:
    print('Yes')
elif BingoList[2][0] == 1 and BingoList[1][1] == 1 and BingoList[0][2] == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
C = []
result = [[0]*3 for i in range(3)]
ans = "No"
for i in range(3):
    a = list(map(int, input().split()))
    C.append(a)

def check():
    b = int(input())
    for i in range(3):
        for j in range(3):
            a = C[i][j]
            if b == a:
                result[i][j] = 1

def column():
    for j in range(3):
        for i in range(3):
            if result[i][j] == 0:
                break
        else:
            global ans
            ans = "Yes"

def row():
    for i in range(3):
        for j in range(3):
            if result[i][j] == 0:
                break
        else:
            global ans
            ans = "Yes"

def naname():
    global ans
    for j in range(3):
        if result[j][j] == 0:
            break
    else:
        ans = "Yes"
    for j in range(3):
        if result[j][2-j] == 0:
            break
    else:
        ans = "Yes"

N = int(input())
for i in range(N):
    check()
    column()
    row()
    naname()

print(ans)

Submission status: Accepted

Solution code:
a11, a12, a13 = list(map(int, input().split()))
a21, a22, a23 = list(map(int, input().split()))
a31, a32, a33 = list(map(int, input().split()))
n = int(input())
b = [0]*n
for i in range(n):
  b[i] = int(input())
  if a11 == b[i]:
    a11 = -1
  if a12 == b[i]:
    a12 = -1
  if a13 == b[i]:
    a13 = -1
  if a21 == b[i]:
    a21 = -1
  if a22 == b[i]:
    a22 = -1
  if a23 == b[i]:
    a23 = -1
  if a31 == b[i]:
    a31 = -1
  if a32 == b[i]:
    a32 = -1
  if a33 == b[i]:
    a33 = -1
flag = False
if a11 == -1 and a12 == -1 and a13 ==-1:
  flag = True
if a21 == -1 and a22 == -1 and a23 ==-1:
  flag = True
if a31 == -1 and a32 == -1 and a33 ==-1:
  flag = True
if a11 == -1 and a21 == -1 and a31 ==-1:
  flag = True
if a12 == -1 and a22 == -1 and a32 ==-1:
  flag = True
if a13 == -1 and a23 == -1 and a33 ==-1:
  flag = True
if a11 == -1 and a22 == -1 and a33 ==-1:
  flag = True
if a13 == -1 and a22 == -1 and a31 ==-1:
  flag = True
if flag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
def main():
    A = [list(map(int, input().split())) for i in range(3)]
    M = [[False] * 3 for i in range(3)]

    N = int(input())
    for i in range(N):
        b = int(input())
        for j, r in enumerate(A):
            for k, c in enumerate(r):
                if c == b:
                    M[j][k] = True

    for i in M:
        if all(i):
            print('Yes')
            return

    for i in list(zip(*M)):
        if all(i):
            print('Yes')
            return

    if (M[0][0] and M[1][1] and M[2][2]):
        print('Yes')
        return

    if (M[0][2] and M[1][1] and M[2][0]):
        print('Yes')
        return

    print('No')


main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))

a = [a1, a2, a3]

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

a_hit = [[False, False, False],
         [False, False, False],
         [False, False, False]]

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

if (a_hit[0][0]) and (a_hit[0][1]) and (a_hit[0][2]):
    print("Yes")
elif (a_hit[1][0]) and (a_hit[1][1]) and (a_hit[1][2]):
    print("Yes")
elif (a_hit[2][0]) and (a_hit[2][1]) and (a_hit[2][2]):
    print("Yes")
elif (a_hit[0][0]) and (a_hit[1][0]) and (a_hit[2][0]):
    print("Yes")
elif (a_hit[0][1]) and (a_hit[1][1]) and (a_hit[2][1]):
    print("Yes")
elif (a_hit[0][2]) and (a_hit[1][2]) and (a_hit[2][2]):
    print("Yes")
elif (a_hit[0][0]) and (a_hit[1][1]) and (a_hit[2][2]):
    print("Yes")
elif (a_hit[0][2]) and (a_hit[1][1]) and (a_hit[2][0]):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

#print(A)
#print(B)

match = []
for A_line in A:
  match.append([(a in B) for a in A_line])

#print(match)
ans = False
# 横
for m in match:
  ans = ans or all(m)

# 縦
match_v = [[m[i] for m in match] for i in range(3)]
#print(match_v)
for m in match_v:
  ans = ans or all(m)
# 斜め
ans = ans or all([match[i][i] for i in range(3)])
ans = ans or all([match[2-i][i] for i in range(3)])

print('Yes' if ans else 'No')

Submission status: Accepted

Solution code:
def main():
    A = [list(map(int, input().split())) for _ in range(3)]
    n = int(input())
    B = [int(input()) for _ in range(n)]
    ans =  [None]*8
    AT = list(zip(*A))
    ans[0] = set(A[0])
    ans[1] = set(A[1])
    ans[2] = set(A[2])
    ans[3] = set(AT[0])
    ans[4] = set(AT[1])
    ans[5] = set(AT[2])
    ans[6] = set([A[i][i] for i in range(3)])
    ans[7] = set([A[i][2-i] for i in range(3)])

    for b in B:
        for a in ans:
            if b in a:
                a -= {b}
                if not a:
                    print("Yes")
                    return
    print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest
def resolve():
    a1=list(map(int,input().strip().split()))
    a2=list(map(int,input().strip().split()))
    a3=list(map(int,input().strip().split()))
    n = int(input().strip())
    b=[]
    for i in range(n):
        tmp=int(input().strip())
        b.append(tmp)

    if a1[0] in b and a1[1] in b and a1[2] in b:
        print("Yes")
        return
    
    if a2[0] in b and a2[1] in b and a2[2] in b:
        print("Yes")
        return
    
    if a3[0] in b and a3[1] in b and a3[2] in b:
        print("Yes")
        return

    # t
    if a1[0] in b and a2[0] in b and a3[0] in b:
        print("Yes")
        return
    
    if a1[1] in b and a2[1] in b and a3[1] in b:
        print("Yes")
        return
    
    if a1[2] in b and a2[2] in b and a3[2] in b:
        print("Yes")
        return

    # na
    if a1[0] in b and a2[1] in b and a3[2] in b:
        print("Yes")
        return

    if a1[2] in b and a2[1] in b and a3[0] in b:
        print("Yes")
        return
    print("No")
    return

resolve()

Submission status: Accepted

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

def check(seen):
    ans = 0
    if seen[0][0] and seen[0][1] and seen[0][2]:
        ans = 1
    if seen[1][0] and seen[1][1] and seen[1][2]:
        ans = 1
    if seen[2][0] and seen[2][1] and seen[2][2]:
        ans = 1
    if seen[0][0] and seen[1][0] and seen[2][0]:
        ans = 1
    if seen[0][1] and seen[1][1] and seen[2][1]:
        ans = 1
    if seen[0][2] and seen[1][2] and seen[2][2]:
        ans = 1
    if seen[0][0] and seen[1][1] and seen[2][2]:
        ans = 1
    if seen[2][0] and seen[1][1] and seen[0][2]:
        ans = 1
    if ans == 1:
        print("Yes")
        exit()
    else:
        print("No")

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:
                seen[j][k] = True

check(seen)

Submission status: Accepted

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"
				#print("sss")
		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(ans)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# 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: Accepted

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

def main():
    a = inpll(3)
    n = inp()
    b = inplm(n)
    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):
        flag = True
        for j in range(3):
            if a[i][j] != 0:
                flag = False
        if flag:
            print('Yes')
            return
    for i in range(3):
        flag = True
        for j in range(3):
            if a[j][i] != 0:
                flag = False
        if flag:
            print('Yes')
            return
    flag = True
    for i in range(3):
        if a[i][i] != 0:
            flag = False
    if flag:
        print('Yes')
        return
    flag = True
    for i in range(3):
        if a[i][2-i] != 0:
            flag = False
    if flag:
        print('Yes')
        return
    print('No')
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a_ = [[int(x) for x in input().split()] for _ in range(3)]
n = int(input())
b = []
for _ in range(n): b.append(int(input()))
a = []
for i in range(3):
    for a_i in a_[i]:
        a.append(a_i)
for b_i in b:
    if b_i not in a: continue
    else:
        a[a.index(b_i)] = 0
ans = "No"
for i in range(3):
    if a[i*3] == 0 and a[i*3+1] == 0 and a[i*3+2] == 0:
        ans = "Yes"
        break
for i in range(3):
    if a[i] == 0 and a[i+3] == 0 and a[i+6] == 0:
        ans = "Yes"
        break
if a[2] == 0 and a[4] == 0 and a[6] == 0: ans = "Yes"
if a[0] == 0 and a[4] == 0 and a[8] == 0: ans = "Yes"
print(ans)

Submission status: Accepted

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

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

flag = False


#yoko
for al in Amat:
    if all([a == -1 for a in al]):
        flag = True
        break

#tate
for i in range(3):
    if all([Amat[j][i] == -1 for j in range(3)]):
        flag = True
        break
        
#naname
if all([Amat[0][0]==-1, Amat[1][1]==-1, Amat[2][2]==-1]) or all([Amat[0][2]==-1,Amat[1][1]==-1,Amat[2][0]==-1]):
    flag = True

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

bingo = [
    [[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]],
    [[0, 2], [1, 1], [2, 0]]]

for B in bingo:
    for b in B:
        if A[b[0]][b[1]] != 0:
            break
    else:
        print('Yes')
        break
else:
    print('No')

Submission status: Accepted

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
    f4 = True
    for i in range(3):
        if a[i][i] not in b: f1 = False
        if a[i][-1-i] not in b: f4 = 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 or f4 else "No"


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

Submission status: Accepted

Solution code:
import math
import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

a = []
for i in range(3):
  n = IL()
  for j in n:
    a.append(j)

N = I()
used = [False]*9
for _ in range(N):
  n = I()
  for i in range(9):
    if a[i] == n:
      used[i] = True

f = 0
if all(used[0:3]) or all(used[3:6]) or all(used[6:9]):
  f = 1
if (used[0] and used[3] and used[6]) or (used[1] and used[4] and used[7]) or (used[2] and used[5] and used[8]):
  f = 1
if (used[0] and used[4] and used[8]):
  f = 1
if (used[2] and used[4] and used[6]):
  f = 1
if f == 0:
  print("No")
else:
  print("Yes")

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

if A[0][0] in B and A[0][1] in B and A[0][2] in B:
  print('Yes')
elif A[1][0] in B and A[1][1] in B and A[1][2] in B:
  print('Yes')
elif A[2][0] in B and A[2][1] in B and A[2][2] in B:
  print('Yes')
elif A[0][0] in B and A[1][0] in B and A[2][0] in B:
  print('Yes')
elif A[0][1] in B and A[1][1] in B and A[2][1] in B:
  print('Yes')
elif A[0][2] in B and A[1][2] in B and A[2][2] in B:
  print('Yes')
elif A[0][0] in B and A[1][1] in B and A[2][2] in B:
  print('Yes')
elif A[2][0] in B and A[1][1] in B and A[0][2] in B:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())

B = list(int(input()) for i in range(N))

def check(A, B):
    for k in range(N):
        for j in range(3):
            if A[j] == B[k]:
                A[j] = 0
    return A

A1 = check(A1, B)
A2 = check(A2, B)
A3 = check(A3, B)

if sum(A1) == 0 or sum(A2) == 0 or sum(A3) == 0:
    print("Yes")
elif (A1[0] + A2[0] + A3[0] == 0) or (A1[1] + A2[1] + A3[1] == 0) or (A1[2] + A2[2] + A3[2] == 0):
    print("Yes")
elif (A1[0] + A2[1] + A3[2] == 0) or (A1[2] + A2[1] + A3[0] == 0):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
A3=list(map(int,input().split()))
A=A1+A2+A3
N=int(input())
ans=[0]*9
a='No'
for i in range(N):
    b=int(input())
    if b in A:
        ans[A.index(b)]=1
cheack=[ans[0:3],ans[3:6],ans[6:9],ans[0::3],ans[1::3],ans[2::3],ans[0::4],ans[2:7:2]]
for C in cheack:
    if sum(C)==3:
        a='Yes'
        break
print(a)

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())
n = int(input())

ab = False
bb = False
cb = False
db = False
eb = False
fb = False
gb = False
hb = False
ib = False

for k in range(n):
  inp = int(input())
  if inp == a:
    ab = True
  elif inp == b:
    bb = True
  elif inp == c:
    cb = True
  elif inp == d:
    db = True
  elif inp == e:
    eb = True
  elif inp == f:
    fb = True
  elif inp == g:
    gb = True
  elif inp == h:
    hb = True
  elif inp == i:
    ib = True
    
if ab and bb and cb:
  print('Yes')
elif db and eb and fb:
  print('Yes')
elif gb and hb and ib:
  print('Yes')
elif ab and db and gb:
  print('Yes')
elif bb and eb and hb:
  print('Yes')
elif cb and fb and ib:
  print('Yes')
elif ab and eb and ib:
  print('Yes')
elif cb and eb and gb:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:


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

n = int(input())

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

# 横方向の判定
for line in board:
    result = True
    for v in line:
        if v in nums:
            pass
        else:
            result = False
            break
    if result:
        print('Yes')
        exit()

# 縦方向の判定
for i in range(3):
    result = True
    for j in range(3):
        if board[j][i] in nums:
            pass
        else:
            result = False
            break
    if result:
        print('Yes')
        exit()

# 斜め方向の判定
if board[0][0] in nums and board[1][1] in nums and board[2][2] in nums:
    print('Yes')
    exit()

if board[0][2] in nums and board[1][1] in nums and board[2][0] in nums:
    print('Yes')
    exit()


print('No')

Submission status: Accepted

Solution code:
import numpy as np
A = [list(map(int, input().split()))]
A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))
A = np.array(A)
result = A
for _ in range(int(input())):
    result[A == int(input())] = 0
ans = "No"
for i in range(3):
    if sum(result[i, :] == 0) == 3:
        ans = "Yes"
for j in range(3):
    if sum(result[:, j] == 0) == 3:
        ans = "Yes"
if sum([result[0, 0], result[1, 1], result[2, 2]]) == 0:
    ans = "Yes"
if sum([result[2, 0], result[1, 1], result[0, 2]]) == 0:
    ans = "Yes"
print(ans)

Submission status: Accepted

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

lst = [[0]*3 for _ in range(3)]
for i in range(N):
  num = int(input())
  for j in range(3):
    for k in range(3):
      if A[j][k] == num:
        lst[j][k] = 1
ans = 'No'
if (lst[0][0] == 1 and lst[0][1] == 1 and lst[0][2] == 1):
  ans = 'Yes'
elif (lst[1][0] == 1 and lst[1][1] == 1 and lst[2][2] == 1):
  ans = 'Yes'
elif (lst[2][0] == 1 and lst[2][1] == 1 and lst[2][2] == 1):
  ans = 'Yes'
elif (lst[0][0] == 1 and lst[1][0] == 1 and lst[2][0] == 1):
  ans = 'Yes'
elif (lst[0][1] == 1 and lst[1][1] == 1 and lst[2][1] == 1):
  ans = 'Yes'
elif (lst[0][2] == 1 and lst[1][2] == 1 and lst[2][2] == 1):
  ans = 'Yes'
elif (lst[0][0] == 1 and lst[1][1] == 1 and lst[2][2] == 1):
  ans = 'Yes'
elif (lst[2][0] == 1 and lst[1][1] == 1 and lst[0][2] == 1):
  ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
a = []

b = {}

for i in range(3):
    x = map(int, input().split())
    a += x

n = int(input())

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

for i in range(n):
    x = int(input())
    if x in a:
        index = a.index(x)
        ans[index] = 1

# print(a)
# print(ans)

flag = False

for i in range(3):
    if ans[i * 3] + ans[i * 3 + 1] + ans[i * 3 + 2] == 3:
        flag = True
        break
    if ans[i] + ans[i + 3] + ans[i + 6] == 3:
        flag = True
        break

if ans[0] + ans[4] + ans[8] == 3:
    flag = True
elif ans[2] + ans[4] + ans[6] == 3:
    flag = True

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

Submission status: Accepted

Solution code:
a = []
for j in range(3):
    a.append([int(x) for x in input().split()])
n = int(input())
b = [int(input()) for i in range(n)]
def hasbingo(ps):
    for x, y in ps:
        if a[y][x] not in b:
            return False
    return True

def hasany():
    for i in range(3):
        if hasbingo([(i, 0),(i, 1),(i, 2)]):
            return True
        if hasbingo([(0, i), (1, i), (2, i)]):
            return True
    if hasbingo([(0,0),(1,1),(2,2)]):
        return True
    return hasbingo([(0,2),(1,1), (2,0)])

if hasany():
    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 i in range(n)]

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

ans = "No"
for i in range(3):
    if sum(a[i]) == 0:
        ans = "Yes"

for i in range(3):
    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:
a = []
for i in range(3):
    s = list(map(int,input().split()))
    a.append(s)
n = int(input())
b = [int(input()) for i in range(n)]
for i in range(n):
    for j in range(3):
        for k in range(3):
            if a[j][k] == b[i]:
                a[j][k] = -1
cnt = 0
tate = 0
for i in range(3):
    cnt = 0
    for j in range(3):
        if a[j][i] == -1:
            cnt +=1
    if cnt ==3:
        tate = 1
        break
cnt = 0
yoko = 0
for i in range(3):
    cnt = 0
    for j in range(3):
        if a[i][j] == -1:
            cnt+=1
    if cnt == 3:
        yoko = 1
        break
cnt = 0
naname1 = 0
for i in range(3):
    if a[i][i] == -1:
        cnt+=1
if cnt == 3:
    naname1 = 1
cnt = 0
naname2 = 0
for i in range(3):
    if a[i][2-i] == -1:
        cnt +=1
if cnt == 3:
    naname2 = 1
if tate == 1 or yoko == 1 or naname1 == 1 or naname2 == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

x = 0
x = A[0][2]+A[1][1]+A[2][0]
if x == 0:
    f = 1

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

Submission status: Accepted

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

for bi in b:
    if bi in a:
        a[a.index(bi)] = 0

bingo = [
    a[0] + a[1] + a[2],
    a[3] + a[4] + a[5],
    a[6] + a[7] + a[8],
    a[0] + a[3] + a[6],
    a[1] + a[4] + a[7],
    a[2] + a[5] + a[8],
    a[0] + a[4] + a[8],
    a[2] + a[4] + a[6],
]

if min(bingo) == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def main():
    a =[]
    for i in range(3):
        aa =list(map(int,input().split()))
        a.append(aa)
    n = int(input())
    b = []
    for _ in range(n):
        bb = int(input())
        b.append(bb)

    ans = [[0] * 3 for i in range(3)]
    # print(ans)
    for i, bb in enumerate(b):
        f = 0
        for j , aa in enumerate(a):
            if bb in aa:
                f = 1
                break
        if f ==1:
            ans[j][aa.index(bb)] = 1
    if sum(ans[0]) == 3 or sum(ans[1]) == 3 or sum(ans[2]) == 3 :
        print('Yes')
        return
    if ans[0][0] + ans[1][0] + ans[2][0] == 3 or ans[0][1] + ans[1][1] + ans[2][1] == 3 or ans[0][2] + ans[1][2] + ans[2][2] == 3:
        print('Yes')
        return
    if ans[0][0] + ans[1][1] + ans[2][2] == 3 or ans[0][2] + ans[1][1] + ans[2][0] == 3:
        print('Yes')
        return
    print('No')
    # print(ans)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
ListA=[list(map(int,input().split())) for i in range(3)] # N行C列・・・Cは任意
ListB=[[0,0,0] for i in range(3)]                # N行C列・・・Cは任意
N=int(input())                                          # 1行1列
ListC=[int(input()) for i in range(N)]                   # N行1列

for i in ListC:
	for y in range(3):
		for x in range(3):
			if ListA[y][x] == i:
				ListB[y][x] = 1

if ListB[0][0] == 1 and ListB[0][1] and ListB[0][2]:
	print('Yes')
elif ListB[1][0] == 1 and ListB[1][1] and ListB[1][2]:
	print('Yes')
elif ListB[2][0] == 1 and ListB[2][1] and ListB[2][2]:
	print('Yes')
elif ListB[0][0] == 1 and ListB[1][0] and ListB[2][0]:
	print('Yes')
elif ListB[0][1] == 1 and ListB[1][1] and ListB[2][1]:
	print('Yes')
elif ListB[0][2] == 1 and ListB[1][2] and ListB[2][2]:
	print('Yes')
elif ListB[0][0] == 1 and ListB[1][1] and ListB[2][2]:
	print('Yes')
elif ListB[0][2] == 1 and ListB[1][1] and ListB[2][0]:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
a3=list(map(int,input().split()))
t1=[a1[0],a2[0],a3[0]]
t2=[a1[1],a2[1],a3[1]]
t3=[a1[2],a2[2],a3[2]]
n1=[a1[0],a2[1],a3[2]]
n2=[a1[2],a2[1],a3[0]]
n=int(input())
b=[int(input()) for i in range(n)]
def f(list):
  if list[0] in b and list[1] in b and list[2] in b:
    return True
  else:
    return False
if f(a1) or f(a2) or f(a3) or f(t1) or f(t2) or f(t3) or f(n1) or f(n2):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
#import re
import sys
input = sys.stdin.readline
#import heapq
#import bisect
#from collections import deque
#import math

def main():
    B = [[]*3 for i in range(3)]
    for i in range(3):
        B[i] = list(map(int, input().split()))
    
    C = [[0]*3 for i in range(3)]
    n = int(input())
    for i in range(n):
        check = int(input())
        for i in range(3):
            for j in range(3):
                if B[i][j] == check:
                    C[i][j] = 1
    ans = "No"
    for i in range(3):
        if (C[i][0] == 1 and C[i][1] == 1 and C[i][2] == 1):
            ans = "Yes"
            break
        if (C[0][i] == 1 and C[1][i] == 1 and C[2][i] == 1):
            ans = "Yes"
            break
        if (C[0][0] == 1 and C[1][1] == 1 and C[2][2] == 1):
            ans = "Yes"
            break
        if (C[2][0] == 1 and C[1][1] == 1 and C[0][2] == 1):
            ans = "Yes"
            break
    
    print("Yes") if ans == "Yes" else print("No")
            
            


    
if __name__ == '__main__':
    main()