Problem:


Score : 200 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

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

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

1 \leq N \leq 10

1 \leq b_i \leq 100

b_i \neq b_j (i \neq j)

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

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

Sample Output 1

Yes

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

Sample Input 2

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

Sample Output 2

No

We will mark nothing.

Sample Input 3

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

Sample Output 3

Yes

We will mark all the squares.



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


Sample output:
Yes

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]
flag = [[False]*3 for _ in range(3)]
for i in range(3):
    for j in range(3):
        if A[i][j] in B:
            flag[i][j] = True
ans = False
# 横
for a in flag:
    if all(a):
        ans = True
# 縦
for i in range(3):
    tmp = 0
    for j in range(3):
        if flag[j][i]:
            tmp += 1
    if tmp == 3:
        ans = True

# 斜めを見る
if flag[0][0] and flag[1][1] and flag[2][2]:
    ans = True
if flag[0][2] and flag[1][1] and flag[2][0]:
    ans = True

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

Submission status: Accepted

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

    n = int(input())
    nums = set()
    for i in range(n):
        b = int(input())
        nums.add(b)

    for i in range(3):
        found = True
        for j in range(3):
            if grid[i][j] not in nums:
                found = False
                break

        if found:
            print('Yes')
            return

    for i in range(3):
        found = True
        for j in range(3):
            if grid[j][i] not in nums:
                found = False
                break

        if found:
            print('Yes')
            return

    found = True
    for i in range(3):
        if grid[i][i] not in nums:
            found = False
            break

    if found:
        print('Yes')
        return

    found = True
    for i in range(3):
        if grid[i][3-i-1] not in nums:
            found = False
            break

    if found:
        print('Yes')
        return

    print('No')

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = [list(map(int,input().split())) for i in range(3)]
a = []
for i in h:
  a.append(i[0])
  a.append(i[1])
  a.append(i[2])
b = [0 for i in range(9)]
for i in range(int(input())):
  n = int(input())
  if n in a:
    b[a.index(n)] = 1
if b[0]==b[1]==b[2]==1 or b[3]==b[4]==b[5]==1 or b[6]==b[7]==b[8]==1 or b[0]==b[3]==b[6]==1 or b[1]==b[4]==b[7]==1 or b[2]==b[5]==b[8]==1 or b[0]==b[4]==b[8]==1 or b[2]==b[4]==b[6]==1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for _ in range(3)]
B = [[0 for _ in range(3)] for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            B[i][j] = 1
c = 0
for i in range(3):       
    if B[i][0] == B[i][1] == B[i][2] == 1:
        c = 1
    if B[0][i] == B[1][i] == B[2][i] == 1:
        c = 1
if B[0][0] == B[1][1] == B[2][2] == 1:
    c = 1
if B[0][2] == B[1][1] == B[2][0] == 1:
    c = 1
if c == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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] = -1
for i in range(3):
    if a[i].count(-1) == 3:
        print('Yes')
        exit()
for j in range(3):
    if a[0][j] == a[1][j] == a[2][j] == -1:
        print('Yes')
        exit()
if a[0][0] == a[1][1] == a[2][2] == -1:
    print('Yes')
    exit()
if a[0][2] == a[1][1] == a[2][0] == -1:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

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


def f(A,n):
    for i in range(3):
        for j in range(3):
            if A[i][j] == n:
                A[i][j] = 0
    return A

for b in B:
    A = f(A,b)
ret = "No"
for i in range(3):
    if sum(A[i]) == 0:
        ret = "Yes"

for i in range(3):
    t = A[0][i] + A[1][i] + A[2][i]
    if t == 0:
        ret = "Yes"

if A[0][0] + A[1][1] + A[2][2] == 0:
    ret = "Yes"

if A[0][2] + A[1][1] + A[2][0] == 0:
    ret ="Yes"

print(ret)

Submission status: Accepted

Solution code:
import math
nums= [list(map(int,input().split(" "))) for _ in range(3)]
ans = "No"
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 nums[i][j] == b:
                nums[i][j] = -1
# -1が3つ揃ったらビンゴ

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

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

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

Submission status: Accepted

Solution code:
Ass = [tuple(map(int, input().split())) for _ in range(3)]
N = int(input())
Bs = [int(input()) for _ in range(N)]

isFoundss = [[0]*(3) for _ in range(3)]
for B in Bs:
    for i in range(3):
        for j in range(3):
            if Ass[i][j] == B:
                isFoundss[i][j] = 1
#print('isFoundss:', isFoundss)

ans = 'No'
for i in range(3):
    for j in range(3):
        if isFoundss[i][j] == 0:
            break
    else:
        ans = 'Yes'

for j in range(3):
    for i in range(3):
        if isFoundss[i][j] == 0:
            break
    else:
        ans = 'Yes'

for i in range(3):
    if isFoundss[i][i] == 0:
        break
else:
    ans = 'Yes'

for i in range(3):
    if isFoundss[i][2-i] == 0:
        break
else:
    ans = 'Yes'

print(ans)

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


ans = False
for a in A:
    ans |= set(a) <= set(B)
    
for i in range(3):
    ans |= set([A[0][i], A[1][i], A[2][i]]) <= set(B)
    
ans |= set([A[0][0], A[1][1], A[2][2]]) <= set(B)
ans |= set([A[0][2], A[1][1], A[2][0]]) <= set(B)
    
print("Yes" if ans else "No")

Submission status: Accepted

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
flag = False
if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0 or A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0:
  flag = True
  
for i in range(3):
  tate = True
  yoko = True
  for j in range(3):
    if A[i][j] != 0:
      yoko = False
    if A[j][i] != 0:
      tate = False
  flag = flag or tate or yoko
print("Yes" if flag else "No")

Submission status: Accepted

Solution code:
import sys

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] = None
for i in range(3):
    if a[i][0] == a[i][1] == a[i][2] == None or a[0][i] == a[1][i] == a[2][i]:
        print("Yes")
        sys.exit(0)
if a[0][0] == a[1][1] == a[2][2] == None or a[2][0] == a[1][1] == a[0][2] == None:
    print("Yes")
else:
    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())
B = []
for i in range(N):
    b = int(input())
    B.append(b)

T = []
for i in range(3):
    T.append([False]*3)

for bi in B:
    for i in range(3):
        for j in range(3):
            if bi == A[i][j]:
                T[i][j] = True

# for i in range(3):
#     print(T[i])

ans = False
for i in range(3):
    if all(T[i]):
        ans = True

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

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

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

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

table = [False]*9

aaa1 = get_nums_l()
aaa2 = get_nums_l()
aaa3 = get_nums_l()
aaa = aaa1 + aaa2 + aaa3
n = int(input())
bbb = get_nums_n(n)

for b in bbb:
    for i,a in enumerate(aaa):
        if a == b:
            table[i] = True

check = [
    (0,3,6),
    (1,4,7),
    (2,5,8),
    (0,1,2),
    (3,4,5),
    (6,7,8),
    (0,4,8),
    (2,4,6)
]

for ch in check:
    for c in ch:
        if not table[c]:
            break
    else:
        print("Yes")
        exit()
print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

s = set()
for n in range(N):
    b = int(input())
    s.add(b)

table = [[0] * 3 for _ in range(3)]
for h in range(3):
    for w in range(3):
        a = As[h][w]
        table[h][w] = (a in s)

# for t in table:
#     print(t)

ans = False
for h in range(3):
    if table[h][0] == table[h][1] == table[h][2] == True: ans = True
for w in range(3):
    if table[0][w] == table[1][w] == table[2][w] == True: ans = True
if table[0][0] == table[1][1] == table[2][2] == True: ans = True
if table[0][2] == table[1][1] == table[2][0] == True: ans = True

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline

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

    check = [[0] * 3 for _ in range(3)]
    for b in B:
        for i in range(3):
            for j in range(3):
                if grid[i][j] == b:
                    check[i][j] = 1

    ok = 0
    for i in range(3):
        if sum(check[i]) == 3:
            ok = 1
    for j in range(3):
        flg = 0
        for i in range(3):
            flg += check[i][j]
        if flg == 3:
            ok = 1
    if check[0][0] == check[1][1] == check[2][2] == 1:
        ok = 1
    if check[0][2] == check[1][1] == check[2][0] == 1:
        ok = 1
    if ok:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

def hit(b):
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                return (i, j)
    return None
for b in bs:
    ret = hit(b)                
    if ret is None:
        continue
    else:
        bingo[ret[0]][ret[1]] = True

def detect():
    for i in range(3):
        if all(bingo[i]):
            return True
    
    for j in range(3):
        if all([bingo[i][j] for i in range(3)]):
            return True
    
    if bingo[0][0] and bingo[1][1] and bingo[2][2]:
        return True

    if bingo[2][0] and bingo[1][1] and bingo[0][2]:
        return True

    return False

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

Submission status: Accepted

Solution code:
a=list(map(int," ".join([input() for i in range(3)]).split()))
n=int(input())
b=[int(input())for i in range(n)]
for i in b:
    if i in a:
        p=a.index(i)
        a[p]="*"
p=0
for i in range(3):
    if a[i]==a[i+3]==a[i+6]=="*":
        p+=1
for i in range(3):
    if a[3*i]==a[3*i+1]==a[3*i+2]=="*":
        p+=1
if a[0]==a[4]==a[8]=="*" or a[2]==a[4]==a[6]=="*":
    p+=1
print("Yes") if p>0 else print("No")

Submission status: Accepted

Solution code:
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

sys.setrecursionlimit(10**9)
mod = 10**7+9
inf = 10**20

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

a = []
for i in range(3):
    a.append(LI())

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

n = I()
for i in range(n):
    b = I()
    for j in range(3):
        for k in range(3):
            if a[j][k]==b:
                ll[j][k]=1

for i in range(3):
    if ll[i]==[1,1,1]:
        print("Yes")
        exit()
for i in range(3):
    if ll[0][i]==1 and ll[1][i]==1 and ll[2][i]==1:
        print("Yes")
        exit()

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

print("No")

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
for i in range(n):
        x = int(input())
        for j in range(3):
                for k in range(3):
                        if a[j][k]==x: a[j][k] = 0
ans = dcnt1 = dcnt2 = 0
for i in range(3):
        vcnt = hcnt = 0
        for j in range(3):
                if a[i][j]==0: vcnt += 1
                if a[j][i]==0: hcnt += 1

        if a[i][i]==0: dcnt1 += 1
        if a[2-i][i]==0: dcnt2 += 1
        if vcnt==3 or hcnt==3: ans = 1
if dcnt1==3 or dcnt2==3: ans = 1

if ans: 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 = [[False]*3 for i in range(3)]

for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k] == b:
                B[j][k] = True

flag = False

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

if B[0][0] and B[1][1] and B[2][2]:
    flag = True

if B[0][2] and B[1][1] and B[2][0]:
    flag = True

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

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) for _ in range(3)]
A = [[0, 0, 0] for i 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:
                A[j][k] = 1

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

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

s = 0
for i in range(3):
    s += A[i][i]
if s == 3:
    ans = 1

s = 0
for i in range(3):
    s += A[i][2 - i]
if s == 3:
    ans = 1

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())
num = set([])
for _ in range(n):
  num.add(int(input()))
  
def func(a,b,c):
  if a in num and b in num and c in num:
    return 1
  else:
    return 0
  
r =func(*A[0]) or func(*A[1]) or func(*A[2])
c = func(A[0][0],A[1][0],A[2][0]) or func(A[0][1],A[1][1],A[2][1]) or func(A[0][2],A[1][2],A[2][2])
naname = func(A[0][0],A[1][1],A[2][2]) or func(A[2][0],A[1][1], A[0][2])

print('Yes' if r or c or naname else 'No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
#sys.setrecursionlimit(150000)

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


def solve(A: "List[int]", N: int, b: "List[int]"):
    for i in range(N):
        for j in range(9):
            if A[j]==b[i]:
                A[j]=0
    ans=NO
    #tate
    for i in range(3):
        if A[i]==A[i+3]==A[i+6]==0: ans=YES
    #yoko
    for i in range(3):
        if A[i*3]==A[i*3+1]==A[i*3+2]==0: ans=YES
    #naname
    if A[0]==A[4]==A[8]==0: ans=YES
    if A[2]==A[4]==A[6]==0: ans=YES

    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
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*3)]  # type: "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:
x=3
a=[]
for _ in range(x):
    a.append(list(map(int, input().split())))
n=int(input())
for _ in range(n):
    b=int(input())
    for ix in range(x):
        for iy in range(x):
            if a[ix][iy] == b:
                a[ix][iy]=-1

# 縦横
for i in range(x):
    if a[i][0] == -1 and a[i][1] == -1 and a[i][2] == -1:
        print('Yes')
        exit()
    if a[0][i] == -1 and a[1][i] == -1 and a[2][i] == -1:
        print('Yes')
        exit()

if a[0][0] == -1 and a[1][1] == -1 and a[2][2] == -1:
    print('Yes')
    exit()
if a[0][2] == -1 and a[1][1] == -1 and a[2][0] == -1:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

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

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

if((a[0]==-1 and a[3]==-1 and a[6]==-1) or
   (a[1]==-1 and a[4]==-1 and a[7]==-1) or
   (a[2]==-1 and a[5]==-1 and a[8]==-1) or
   (a[0]==-1 and a[1]==-1 and a[2]==-1) or
   (a[3]==-1 and a[4]==-1 and a[5]==-1) or
   (a[6]==-1 and a[7]==-1 and a[8]==-1) or
   (a[0]==-1 and a[4]==-1 and a[8]==-1) or
   (a[2]==-1 and a[4]==-1 and a[6]==-1)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

n = int(input())
for _ in range(n):
    m = int(input())
    if m in c:
        c[c.index(m)]=0

if c[0]==c[1]==c[2]==0 or c[3]==c[4]==c[5]==0 or c[6]==c[7]==c[8]==0 or c[0]==c[3]==c[6]==0 or c[1]==c[4]==c[7]==0 or c[5]==c[8]==c[2]==0 or c[0]==c[4]==c[8]==0 or c[2]==c[4]==c[6]==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)]
c = [[0, 0, 0] for _ in range(3)]
for k in range(n):
    for i in range(3):
        for j in range(3):
            if a[i][j] == b[k]:
                c[i][j] = 1

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

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

Submission status: Accepted

Solution code:
import sys
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
for i in range(n):
    b = int(input())
    for s in range(3):
        for t in range(3):
            if a[s][t] == b:
                a[s][t] = -1
    for t in range(3):
        if all(a[t][s]==-1 for s in range(3)):
            print("Yes")
            sys.exit()
    for t in range(3):
        if all(a[s][t]==-1 for s in range(3)):
            print("Yes")
            sys.exit()
    if all(a[s][s]==-1 for s in range(3)):
        print("Yes")
        sys.exit()
    if a[0][2]==-1 and a[1][1]==-1 and a[2][0]==-1:
        print("Yes")
        sys.exit()
print("No")

Submission status: Accepted

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

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

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

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

for i,j,k in [[(0,0),(1,1),(2,2)],[(0,2),(1,1),(2,0)]]:
    if A[i[0]][i[1]]+A[j[0]][j[1]]+A[k[0]][k[1]]==0:
        print("Yes")
        exit()

print("No")

Submission status: Accepted

Solution code:
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    As = [list(map(int, input().split())) for i 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 As[j][k] == b:
                    As[j][k] = -1

    for i in range(3):
        if As[i] == [-1, -1, -1]:
            print('Yes')
            return
        ri = [_[i] for _ in As]

        if ri == [-1,-1,-1]:
            print('Yes')
            return

    if As[0][0] == As[1][1] == As[2][2] == -1 or As[2][0] == As[1][1] == As[0][2] == -1:
        print('Yes')
        return
    
    print('No')


    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
bingo=[list(map(int,input().split())) for _ in range(3)]
N=int(input())
D=[[0]*3 for _ in range(3)]

for _ in range(N):
    b=int(input())
    for i in range(3):
        for j in range(3):
            if b==bingo[i][j]:
                D[i][j]=1
ans=set()
for d in D:
    ans.add(sum(d))
for d in zip(*D):
    ans.add(sum(d))
ans.add(D[0][0]+D[1][1]+D[2][2])
ans.add(D[0][2]+D[1][1]+D[2][0])
print('Yes' if 3 in ans else 'No')

Submission status: Accepted

Solution code:
a=[]
dp=[[0]*3 for i in range(3)]
for i in range(3):
    a1,a2,a3=map(int,input().split())
    a.append((a1,a2,a3))
n=int(input())
for i in range(n):
    b=int(input())
    for j in range(3):
        for h in range(3):
            if a[j][h]==b:
                dp[j][h]=1
flag=0
for i in range(3):
    count=0
    for j in range(3):
        if dp[i][j]==1:
            count+=1
    if count==3:
        flag=1
for i in range(3):
    count=0
    for j in range(3):
        if dp[j][i]==1:
            count+=1
    if count==3:
        flag=1
count=0
for i in range(3):
    if dp[i][i]==1:
        count+=1
if count==3:
    flag=1
count=0
for i in range(3):
    if dp[2-i][i]==1:
        count+=1
if count==3:
    flag=1
#print(dp)
print('Yes' if flag==1 else 'No')

Submission status: Accepted

Solution code:
def resolve():
    a = list(map(int, input().split()))
    a += list(map(int, input().split()))
    a += list(map(int, input().split()))
    n = int(input())
    b = [0]*n
    for i in range(n):
        b[i] = int(input())
    c = [False] * 9
    ans = False
    for i in range(9):
        c[i] = a[i] in b
    if c[0] and c[1] and c[2]:
        ans = True
    if c[3] and c[4] and c[5]:
        ans = True
    if c[6] and c[7] and c[8]:
        ans = True
    if c[0] and c[3] and c[6]:
        ans = True
    if c[1] and c[4] and c[7]:
        ans = True
    if c[2] and c[5] and c[8]:
        ans = True
    if c[0] and c[4] and c[8]:
        ans = True
    if c[2] and c[4] and c[6]:
        ans = True
    print("Yes" if ans else "No")


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:

A = []
A.append(list(map(int, input().split(" "))))
A.append(list(map(int, input().split(" "))))
A.append(list(map(int, input().split(" "))))

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


success = False
for i in range(3):
    if all([a == -1 for a in A[i]]):
        print("Yes")
        success = True
    elif all([a == -1 for a in [line[i] for line in A]]):
        print("Yes")
        success = True
    if success:
        break

if not(success) and A[0][0] == -1 and A[1][1] == -1 and A[2][2] == -1:
    print("Yes")
elif not(success) and A[2][0] == -1 and A[1][1] == -1 and A[0][2] == -1:
    print("Yes")
elif not(success):
    print("No")

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split(' '))
d, e, f = map(int, input().split(' '))
g, h, i = map(int, input().split(' '))
N = int(input())
z = set()
for _ in range(N):
    z.add(int(input()))

A = (a in z) and (b in z) and (c in z)
B = (d in z) and (e in z) and (f in z)
C = (g in z) and (h in z) and (i in z)

D = (a in z) and (d in z) and (g in z)
E = (b in z) and (e in z) and (h in z)
F = (c in z) and (f in z) and (i in z)

G = (a in z) and (e in z) and (i in z)
H = (c in z) and (e in z) and (g in z)

r = A or B or C or D or E or F or G or H

print('Yes' if r else '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):
    x = int(input())

    for i in range(3):
        for j in range(3):
            if a[i][j] == x:
                mark[i][j] = True

a = mark

for i in range(3):
    if all(a[i][j] == True for j in range(3)) or all(a[j][i] == True for j in range(3)):
        print('Yes')
        break
else:
    if all(a[i][i] == True for i in range(3)) or all(a[i][3-i-1] == True for i in range(3)):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
A_array = [list(map(int,input().split())) for _ in range(3)]
hit_array = [[0] * 3 for _ in range(3)]
N = int(input())
for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if b == A_array[j][k]:
                hit_array[j][k] = 1
for i in range(3):
    if hit_array[i][0] and hit_array[i][1] and hit_array[i][2]:
        print("Yes")
        exit()
    if hit_array[0][i] and hit_array[1][i] and hit_array[2][i]:
        print("Yes")
        exit()

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

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

print("No")

Submission status: Accepted

Solution code:
import sys

A = []

for i in range(3):

    x,y,z = map(int,input().split())
    A += [x,y,z]

N = int(input())

for i in range(N):

    b = int(input())

    for j in range(9):

        if A[j] == b:
            A[j] = 0

#print (A)

for i in range(3):

    i *= 3
    if A[i] == A[i+1] == A[i+2] == 0:
        print ("Yes")
        sys.exit()

for i in range(3):

    if A[i] == A[i+3] == A[i+6] == 0:
        print ("Yes")
        sys.exit()

if (A[2] == A[4] == A[6] == 0)or(A[0] == A[4] == A[8] == 0):
    print ("Yes")
    sys.exit()

print ("No")

Submission status: Accepted

Solution code:
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
A = [A1, A2, A3]
N = int(input())
l = [[-1] * 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:
                l[i][j] = 0
    if sum(l[0]) == 0 or sum(l[1]) == 0 or sum(l[2]) == 0:
        print('Yes')
        break
    if l[0][0] + l[1][0] + l[2][0] == 0 or l[0][1] + l[1][1] + l[2][1] == 0:
        print('Yes')
        break
    if l[0][2] + l[1][2] + l[2][2] == 0 or l[0][0] + l[1][1] + l[2][2] == 0:
        print('Yes')
        break
    if l[0][2] + l[1][1] + l[2][0] == 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()))
a = [a1, a2, a3]
bingo = [[0] * 3 for _ in range(3)]

n = int(input())
for i in range(n):
    num = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == num:
                bingo[i][j] = 1

is_bingo = 0
for i in range(3):
    if bingo[i][0] and bingo[i][1] and bingo[i][2]:
        is_bingo = 1
    elif bingo[0][i] and bingo[1][i] and bingo[2][i]:
        is_bingo = 1
if bingo[0][0] and bingo[1][1] and bingo[2][2]:
    is_bingo = 1
if bingo[2][0] and bingo[1][1] and bingo[0][2]:
    is_bingo = 1

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

Submission status: Accepted

Solution code:
nums = [list(map(int, input().split())) for _ in range(3)]
bingo = [[0, 0, 0] for _ in range(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 nums[i][j] == b:
				bingo[i][j] = 1
ans = 0
ans += bingo[0][0] * bingo[1][0] * bingo[2][0]
ans += bingo[0][1] * bingo[1][1] * bingo[2][1]
ans += bingo[0][2] * bingo[1][2] * bingo[2][2]
ans += bingo[0][0] * bingo[0][1] * bingo[0][2]
ans += bingo[1][0] * bingo[1][1] * bingo[1][2]
ans += bingo[2][0] * bingo[2][1] * bingo[2][2]
ans += bingo[0][0] * bingo[1][1] * bingo[2][2]
ans += bingo[2][0] * bingo[1][1] * bingo[0][2]

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