Problem:


Score : 200 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

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

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

1 \leq N \leq 10

1 \leq b_i \leq 100

b_i \neq b_j (i \neq j)

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

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

Sample Output 1

Yes

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

Sample Input 2

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

Sample Output 2

No

We will mark nothing.

Sample Input 3

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

Sample Output 3

Yes

We will mark all the squares.



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


Sample output:
Yes

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a = [LI() for _ in range(3)]
n = I()
b = [I() for _ in range(n)]
if n < 3:
    print('No')
    quit()
for i in range(3):
    for j in range(3):
        if a[i][j] not in b:
            break
    else:
        print('Yes')
        quit()

for i in range(3):
    for j in range(3):
        if a[j][i] not in b:
            break
    else:
        print('Yes')
        quit()

for i in range(3):
    if a[i][i] not in b:
        break
else:
    print('Yes')
    quit()

for i in range(3):
    if a[i][-(i+1)] not in b:
        break
else:
    print('Yes')
    quit()

print('No')

Submission status: Accepted

Solution code:
import sys
import math
import collections
#n = int(input())
a1, a2, a3 = map(int, input().split())
a4, a5, a6 = map(int, input().split())
a7, a8, a9 = map(int, input().split())
#s = input()
#x = list(map(int, input().split()))
a = [a1, a2, a3, a4, a5, a6, a7, a8, a9]
c = [0 for k in range(9)]
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(9):
        if a[j] == b:
            c[j] = 1

if c[0] + c[1] + c[2] == 3:
    print("Yes")
    sys.exit()
if c[4] + c[5] + c[3] == 3:
    print("Yes")
    sys.exit()
if c[7] + c[8] + c[6] == 3:
    print("Yes")
    sys.exit()
if c[0] + c[3] + c[6] == 3:
    print("Yes")
    sys.exit()
if c[1] + c[4] + c[7] == 3:
    print("Yes")
    sys.exit()
if c[2] + c[5] + c[8] == 3:
    print("Yes")
    sys.exit()
if c[0] + c[4] + c[8] == 3:
    print("Yes")
    sys.exit()
if c[2] + c[4] + c[6] == 3:
    print("Yes")
    sys.exit()

print("No")

Submission status: Accepted

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

ans='No'
#tate
for i in range(3):
  if a[0][i]+a[1][i]+a[2][i]==0:
    ans='Yes'
#yoko
for i in range(3):
  if sum(a[i])==0:
    ans='Yes'
#naname
if a[0][0]+a[1][1]+a[2][2]==0 or a[0][2]+a[1][1]+a[2][0]==0:
  ans='Yes'
print(ans)

Submission status: Accepted

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

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

ok = False
for x, y, dx, dy in dirs:
    o = True
    for i in range(3):
        o = o and opened[x + i * dx][y + i * dy]
    ok = ok or o

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

Submission status: Accepted

Solution code:
a=[]
for i in range(3):
    a1,a2,a3=map(int, input().split())
    a.append(a1)
    a.append(a2)
    a.append(a3)
n=int(input())
for i in range(n): #bingo判定
    b=int(input())
    for j in range(9):
        if b==a[j]:
            a[j]=0
            break
if a[0]==a[1]==a[2]==0 or a[3]==a[4]==a[5]==0 or a[6]==a[7]==a[8]==0:
    print('Yes')
elif a[0]==a[3]==a[6]==0 or a[1]==a[4]==a[7]==0 or a[2]==a[5]==a[8]==0:
    print('Yes')
elif a[0]==a[4]==a[8]==0 or a[2]==a[4]==a[6]==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:


As = []
for i in range(3):
    As.append(list(map(int, input().split())))
N = int(input())
Bs = []
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if As[i][j] == b:
                As[i][j] = -1

for i in range(3):
    if set(As[i]) == {-1}:
        print("Yes")
        exit(0)
for j in range(3):
    if As[0][j] == -1 and As[1][j] == -1 and As[2][j] == -1:
        print("Yes")
        exit(0)

if set(As[i][i] for i in range(3)) == {-1}:
    print("Yes")
    exit(0)
if set(As[i][2-i] for i in range(3)) == {-1}:
    print("Yes")
    exit(0)
print("No")

Submission status: Accepted

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

cond = 0

for i in range(3):
	if A[i].count(1) == 3:
		cond = 1
for j in range(3):
	if sum([A[k][j] for k in range(3)]) == 3:
		cond = 1


if sum([A[k][k] for k in range(3)]) == 3:
	cond = 1

if A[0][2]+A[1][1]+A[2][0] == 3:
	cond = 1

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

Submission status: Accepted

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

N = int(input())
opened = set()
for _ in range(N):
    opened.add(int(input()))


def check():
    for i in range(3):
        if all(A[i][j] in opened for j in range(3)):
            print("Yes")
            return

    for j in range(3):
        if all(A[i][j] in opened for i in range(3)):
            print("Yes")
            return

    if all(A[i][i] in opened for i in range(3)):
        print("Yes")
        return

    if all(A[i][2-i] in opened for i in range(3)):
        print("Yes")
        return

    print("No")
    return


check()

Submission status: Accepted

Solution code:
a=[list(map(int,input().split())) for _ in range(3)]
a = sum(a,[])
n=int(input())
flag = [0]*9
for _ in range(n):
    b = int(input())
    if b in set(a):
        a_index = a.index(b)
        flag[a_index] = 1
w = [sum(flag[j*3+i] for i in range(3)) for j in range(3)]
h = [sum(flag[j+i*3] for i in range(3)) for j in range(3)]
d = [flag[0]+flag[4]+flag[8],flag[2]+flag[4]+flag[6]]
count = w+h+d
print('Yes' if max(count) == 3 else 'No')

Submission status: Accepted

Solution code:
L=[]
for i in range(3):
    a,b,c=map(int,input().split())
    L+=[a,b,c]
N=int(input())
l= [int(input()) for i in range(N)]
a=[0]*9
for i in l:
    for j in range(9):
        if i==L[j]:
            a[j]=1
if a[0]*a[1]*a[2] or a[3]*a[4]*a[5] or a[6]*a[7]*a[8] or a[0]*a[3]*a[6] or a[1]*a[4]*a[7] or a[2]*a[5]*a[8] or a[0]*a[4]*a[8] or a[6]*a[4]*a[2]:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# Author: cr4zjh0bp
# Created: Sun Mar  1 12:01:00 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

A = nan(3)
n = ni()
b = nin(n)

d = [[0] * 3 for _ in range(3)]

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

flag = False
for i in range(3):
    c = 0
    for j in range(3):
        if d[i][j] == 1:
            c += 1
    if c == 3:
        flag = True

for i in range(3):
    c = 0
    for j in range(3):
        if d[j][i] == 1:
            c += 1
    if c == 3:
        flag = True

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

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

Submission status: Accepted

Solution code:
lst = []
for i in range(3):
    lst.append(list(map(int, input().split())))
arr = []
N  = int(input())
for i in range(N):
    arr.append(int(input()))
for i in range(3):
    for j in range(3):
        if lst[i][j] in arr:
            lst[i][j] = True
        else:
            lst[i][j] = False

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

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

Submission status: Accepted

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

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

for i in range(n):
    for j in range(3):
        for k in range(3):
            if b[i]==a[j][k]:
                bingo[j][k]=True
flag=False
for i in range(3):
    if all([bingo[i][0], bingo[i][1], bingo[i][2]]):
        flag=True

for i in range(3):
    if all([bingo[0][i],bingo[1][i],bingo[2][i]]):
        flag=True

if all([bingo[0][0],bingo[1][1],bingo[2][2]]):
        flag=True

if all([bingo[0][2],bingo[1][1],bingo[2][0]]):
    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)]
c = [[0,0,0] for _ in range(3)]
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))
for i in b:
  for j in range(3):
    for k in range(3):
      if a[j][k] == i:
        c[j][k] = 1
if sum(c[0]) == 3 or sum(c[1])==3 or sum(c[2])==3:
  print("Yes")
else:
  for i in range(3):
    s = c[0][i]+c[1][i]+c[2][i]
    if s == 3:
      print("Yes")
      quit()
  if c[0][0]+c[1][1]+c[2][2]==3 or c[2][0]+c[1][1]+c[0][2]==3:
    print("Yes")
    quit()
  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)]

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

ans = "No"
for i in range(3):
    if chk[i][0] == chk[i][1] == chk[i][2] == 1:
        ans = "Yes"
        break
    if chk[0][i] == chk[1][i] == chk[2][i] == 1:
        ans = "Yes"
        break
if chk[0][0] == chk[1][1] == chk[2][2] == 1:
    ans = "Yes"
elif chk[0][2] == chk[1][1] == chk[2][0] == 1:
    ans = "Yes"

print(ans)

Submission status: Accepted

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

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

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

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

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

print('No')

Submission status: Accepted

Solution code:
import itertools

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

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

yes = False
for p in itertools.permutations(B, 3):
    if p in hit:
        print("Yes")
        yes = True
        exit()

if not yes:
    print("No")

Submission status: Accepted

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

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

f = False
for i in range(3):
    f |= c[0][i] & c[1][i] & c[2][i]
    f |= c[i][0] & c[i][1] & c[i][2]

f |= c[0][0] & c[1][1] & c[2][2]
f |= c[0][2] & c[1][1] & c[2][0]

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

Submission status: Accepted

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

X = [0] * 101

for k in range(N):
    t = int(input())
    X[t] = 1

if X[a]*X[e]*X[i] == 1 or X[a]*X[b]*X[c] == 1 or X[d]*X[e]*X[f] == 1 or X[g]*X[h]*X[i] == 1 or X[a]*X[d]*X[g] == 1 or X[b]*X[e]*X[h] == 1 or X[c]*X[f]*X[i] == 1 or X[c]*X[e]*X[g] == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys

# S = input()
# N, M = map(int, input().split())
# nums = list(map(int, input().split()))
# nums_2d = [list(map(int, input().split())) for _ in range(N)]


def main():

    A1 = list(map(int, input().split()))
    A2 = list(map(int, input().split()))
    A3 = list(map(int, input().split()))

    As = [A1, A2, A3]

    N = int(input())
    idxs = list()

    for i in range(N):
        b = int(input())
        for j, A in enumerate(As):
            if b in A:
                idx = A.index(b)
                idxs.append((j, idx))

    answer = 'No'

    # check rows
    for i in range(3):
        if (i, 0) in idxs and (i, 1) in idxs and (i, 2) in idxs:
            answer = 'Yes'

    # check columns
    for i in range(3):
        if (0, i) in idxs and (1, i) in idxs and (2, i) in idxs:
            answer = 'Yes'

    if (0, 0) in idxs and (1, 1) in idxs and (2, 2) in idxs:
        answer = 'Yes'

    if (0, 2) in idxs and (1, 1) in idxs and (2, 0) in idxs:
        answer = 'Yes'

    print(answer)


if __name__ == '__main__':
    main()

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

B = [[0]*3 for _ in range(3)]
for _ in range(N):
    b = int(input())
    for j in range(3):
        for i in range(3):
            if A[j][i]==b:
                B[j][i]=1

if (B[0][0]+B[0][1]+B[0][2]==3) or (B[1][0]+B[1][1]+B[1][2]==3) or (B[2][0]+B[2][1]+B[2][2]==3) or (B[0][0]+B[1][0]+B[2][0]==3) or (B[0][1]+B[1][1]+B[2][1]==3) or (B[0][2]+B[1][2]+B[2][2]==3) or (B[0][0]+B[1][1]+B[2][2]==3) or (B[2][0]+B[1][1]+B[0][2]==3):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
A = [list(map(int,input().split())) 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 A[j][k]==b:
                A[j][k] = -1

aa = False

while(1):
    #縦
    for i in range(3):
        for j in range(3):
            if A[i][j] != -1:
                break
        else:
            print("Yes")
            aa = True
            break
    if aa:
        break

    #yoko
    for i in range(3):
        for j in range(3):
            if A[j][i] != -1:
                break
        else:
            print("Yes")
            aa = True
            break
    if aa:
        break
    
    #斜め
    if A[0][0]==-1 and A[1][1]==-1 and A[2][2]==-1:
        print("Yes")
        break
    if A[2][0]==-1 and A[1][1]==-1 and A[0][2]==-1:
        print("Yes")
        break

    print("No")
    break

Submission status: Accepted

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

A = []
for _ in range(3):
    A.append([int(x) for x in input().split()])
N = int(input())
b = []
for _ in range(N):
    b.append(int(input()))

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

flag = 0

for k in A:
    if k[0] == 0 and k[1] == 0 and k[2] == 0:
        flag = 1

for k in range(3):
    flag_2 = 1
    for j in range(3):
        if A[j][k] != 0:
            flag_2 = 0
    if flag_2:
        flag = 1

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

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

Submission status: Accepted

Solution code:
a=[ list(map(int,input().split())) for j in range(3)]
n=int(input())
kk=101
for i in range(n):
  s=int(input())
  for j in range(3):
    for k in range(3):
      if s==a[j][k]:
        a[j][k]=kk
count=0
ans=0
for j in range(3):
  count=0
  for k in range(3):
    if a[j][k]==kk:
      count+=1
  if count==3:
    ans=1
    break
    
for j in range(3):
  count=0
  for k in range(3):
    if a[k][j]==kk:
      count+=1
  if count==3:
    ans=1
    break
if a[0][0]==kk and a[1][1]==kk and a[2][2]==kk:
  ans=1
if a[0][2]==kk and a[1][1]==kk and a[2][0]==kk:
  ans=1
if ans==1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
bingo = []
for i in range(3):
    bingo.append(list(map(int, input().split())))
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if bingo[j][k] == b:
                bingo[j][k] = None
for i in range(3):
    row = True
    column = True
    for j in range(3):
        if bingo[i][j] != None:
            column = False
        if bingo[j][i] != None:
            row = False
    if column or row:
        print("Yes")
        exit()
naname = False
if bingo[0][0] == bingo[1][1] == bingo[2][2] == None or bingo[0][2] == bingo[1][1] == bingo[2][0] == None:
    naname = True
if row or column or naname:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a1=LIST()
    a2=LIST()
    a3=LIST()
    a=[]
    a.append(a1)
    a.append(a2)
    a.append(a3)
    n=INT()
    num=[]
    for i in range(n):
        num.append(INT())
    for i in num:
        for k in a:
            if i in k:
                temp=k.index(i)
                k[temp]=0
    flg=0
    for i in a:
        if i==[0,0,0]:
            flg=1
    for i in range(3):
        if a[0][i]==0 and a[1][i]==0 and a[2][i]==0:
            flg=1
    if a[0][0]==0 and a[1][1]==0 and a[2][2]==0:
        flg=1
    if a[2][0]==0 and a[1][1]==0 and a[0][2]==0:
        flg=1
    if flg==1:
        print('Yes')
    else:
        print('No')
    
if __name__ == '__main__':
    do()

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

def is_bingo(A, B):
    if A[0][0] in B and A[0][1] in B and A[0][2] in B:
        return True
    if A[1][0] in B and A[1][1] in B and A[1][2] in B:
        return True
    if A[2][0] in B and A[2][1] in B and A[2][2] in B:
        return True

    if A[0][0] in B and A[1][0] in B and A[2][0] in B:
        return True
    if A[0][1] in B and A[1][1] in B and A[2][1] in B:
        return True
    if A[0][2] in B and A[1][2] in B and A[2][2] in B:
        return True

    if A[0][0] in B and A[1][1] in B and A[2][2] in B:
        return True
    if A[0][2] in B and A[1][1] in B and A[2][0] in B:
        return True

    return False

print('Yes' if is_bingo(A, B) else 'No')

Submission status: Accepted

Solution code:
import numpy as np
sheet = np.zeros((3,3))
for i in range(3):
    sheet[i] = list(map(int, input().split()))

N = int(input())

for _ in range(N):
    b = int(input())
    for r in range(3):
        for c in range(3):
            if sheet[r,c] == b:
                sheet[r,c] = 0

rows = np.sum(sheet, axis=0)
if 0 in list(rows):
    print("Yes")
    exit()
cols = np.sum(sheet, axis=1)
if 0 in list(cols):
    print("Yes")
    exit()
if (sheet[0,0] + sheet[1,1] + sheet[2,2]) == 0:
    print("Yes")
    exit()
if (sheet[0,2] + sheet[1,1] + sheet[2,0]) == 0:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:

bingo = [[int(x) for x in input().split()] for _ in range(3)]

N = int(input())

# replace pushed sectors to -1
for _ in range(N):
    push = int(input())
    for i in range(3):
        if push in bingo[i]:
            bingo[i][bingo[i].index(push)] = -1

is_bingo = False
# horizontal / Vertical
for i in range(3):
    if bingo[i][0] == -1 and bingo[i][1] == -1 and bingo[i][2] == -1:
        is_bingo = True
    if bingo[0][i] == -1 and bingo[1][i] == -1 and bingo[2][i] == -1:
        is_bingo = True

# Tilted

if bingo[0][0] == -1 and bingo[1][1] == -1 and bingo[2][2] == -1:
    is_bingo = True

if bingo[2][0] == -1 and bingo[1][1] == -1 and bingo[0][2] == -1:
    is_bingo = True

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

Submission status: Accepted

Solution code:
A = [list(map(int,input().split())) for i in range(3)]
N = int(input())
for _ in range(N):
    a = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k] == a:
                A[j][k] = 0
result = "No"
for i in range(3):
    if sum(A[i]) == 0:
        result = "Yes"
    elif A[0][i] + A[1][i] + A[2][i] == 0:
        result = "Yes"
    elif A[0][0] + A[1][1] + A[2][2] == 0 or A[0][2] + A[1][1] + A[2][0] == 0:
        result = "Yes"
    else:
        None
print(result)

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())
b = []
c = [0]*9
for i in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                c[i*3+j] = 1
ans = 'No'
if c[0]==c[3]==c[6]==1 or c[1]==c[4]==c[7]==1 or c[2]==c[5]==c[8]==1:
    ans = 'Yes'
elif c[0]==c[1]==c[2]==1 or c[3]==c[4]==c[5]==1 or c[6]==c[7]==c[8]==1:
    ans = 'Yes'
elif c[0]==c[4]==c[8]==1 or c[2]==c[4]==c[6]==1:
    ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    a = [[0] * 3 for _ in range(3)]
    b = [[0] * 3 for _ in range(3)]

    for i in range(3):
        a[i] = list(map(int,ipti().split()))

    n = int(input())

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

    flag = False

    for i in range(3):
        for j in range(3):
            if b[i][j] != 1:
                break
        else:
            flag = True

    for i in range(3):
        for j in range(3):
            if b[j][i] != 1:
                break
        else:
            flag = True

    if b[1][1] == 1:
        if b[0][0] == 1:
            if b[2][2] ==1:
                flag = True
        if b[2][0] == 1:
            if b[0][2] ==1:
                flag = True

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



if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(3):
    flag = True
    for j in range(3):
        if not a[i][j] in b:
            flag = False
            break
    if flag:
        print("Yes")
        exit()

for i in range(3):
    flag = True
    for j in range(3):
        if not a[j][i] in b:
            flag = False
            break
    if flag:
        print("Yes")
        exit()

flag = True
for i in range(3):
    if not a[i][i] in b:
        flag = False
if flag:
    print("Yes")
    exit()

flag = True
if a[0][2] in b and a[1][1] in b and a[2][0] in b:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
for i in b:
    for j in range(3):
        for k in range(3):
            if i == a[j][k]:
                a[j][k] = 0
for i in range(3):
    if a[i][0] == a[i][1] == a[i][2] == 0:
        print('Yes')
        break
else: 
    for i in range(3):
        if a[0][i] == a[1][i] == a[2][i] == 0:
            print('Yes')
            break
    else:
        if a[0][0] == a[1][1] == a[2][2] == 0:
            print('Yes')
        elif a[2][0] == a[1][1] == a[0][2] == 0:
            print('Yes')
        else: print('No')

Submission status: Accepted

Solution code:
import sys
import math
import fractions
import itertools
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

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 l in A:
        for c in range(3):
            if l[c] == i:
                l[c] = -1
for i in A:
    if set(i) == {-1}:
        print('Yes')
        sys.exit()
for i in range(3):
    if A[0][i] == A[1][i] == A[2][i] == -1:
        print("Yes")
        sys.exit()
if A[0][0] == A[1][1] == A[2][2]:
    print("Yes")
    sys.exit()
if A[2][0] == A[1][1] == A[0][2] == -1:
    print("Yes")
    sys.exit()
print("No")

Submission status: Accepted

Solution code:
a = [[0 for i in range(3)] for j in range(3)]
f = [[False for i in range(3)] for j in range(3)]

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

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

ans = (f[0][0] and f[1][1] and f[2][2]) or (f[0][2] and f[1][1] and f[2][0])
for i in range(3):
  ans = ans or (f[i][0] and f[i][1] and f[i][2])
  ans = ans or (f[0][i] and f[1][i] and f[2][i])

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

Submission status: Accepted

Solution code:
def main():
    bingo=[list(map(int,input().split())) for i in range(3)]
    n=int(input())
    b={int(input()) for i in range(n)}
    
    X=[[0]*3 for _ in range(3)]
    for i in range(3):
        for j in range(3):
            if bingo[i][j] in b:
                X[i][j]=1
    
    flag=False
    for i in range(3):
        if (X[i][0]&X[i][1]&X[i][2])==1:
            flag=True
            print('Yes')
            exit()
        if (X[0][i]&X[1][i]&X[2][i])==1:
            flag=True
            print('Yes')
            exit()
    if (X[0][0]&X[1][1]&X[2][2])==1:
        flag=True
        print('Yes')
        exit()
    
    if (X[0][2]&X[1][1]&X[2][0])==1:
        flag=True
        print('Yes')
        exit()
    print('No')

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
a3=list(map(int,input().split()))
a=[a1,a2,a3]
n=int(input())
b=[0 for _ in range(n)]
for i in range(n):
  b[i]=int(input())
bingo=[[0,0,0],[0,0,0],[0,0,0]]
for i in range(3):
  for j in range(3):
    if a[i][j] in b:
      bingo[i][j]=1
for i in range(3):
  if bingo[i]==[1,1,1]:
    print('Yes')
    exit()
for j in range(3):
  if bingo[0][j]==1 and bingo[1][j]==1 and bingo[2][j]==1:
    print('Yes')
    exit()
if bingo[0][0]==1 and bingo[1][1]==1 and bingo[2][2]==1:
  print('Yes')
  exit()
if bingo[0][2]==1 and bingo[1][1]==1 and bingo[2][0]==1:
  print('Yes')
  exit()


print('No')

Submission status: Accepted

Solution code:
def main():

    A = []
    for i in range(3):
        A.append(list(map(int, input().split())))
    cand = []
    for j in range(3):
        cand += [sorted(A[j])]
        cand += [sorted([A[i][j] for i in range(3)])]
    cand += [sorted([A[i][i] for i in range(3)])]
    cand += [sorted([A[i][2-i] for i in range(3)])]
    # print(cand)

    b = []
    N = int(input())
    for i in range(N):
        b.append(int(input()))
    b = set(sorted(b))
    # print(b)
    for i in range(len(cand)):
        if cand[i][0] in b and cand[i][1] in b and cand[i][2] in b:
            return "Yes"

    return "No"

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

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
l = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
L = [None]*N
for i in range(N):
    L[i] = int(input())

for i in range(N):
    elm = L[i]
    for j in range(3):
        for k in range(3):
            if l[j][k]==elm:
                l[j][k] = 0
for i in range(3):
    if sum(l[i])==0:
        print('Yes')
        exit()
    if (l[0][i]+l[1][i]+l[2][i])==0:
        print('Yes')
        exit()
if l[0][0]+l[1][1]+l[2][2]==0:
    print('Yes')
    exit()
if l[0][2]+l[1][1]+l[2][0]==0:
    print('Yes')
    exit()
print('No')