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:
alist=[]
clist=[0]*9
for i in range(3):
    aalist = list(map(int, input().split()))
    for aal in aalist:
        alist.append(aal)

n=int(input())
blist=[]
for i in range(n):
    b=int(input())
    if b in alist:
        numb=alist.index(b)
        clist[numb]=1

#print(clist)

answer=0
if clist[0]==1 and clist[1]==1 and clist[2]==1:
    answer=1
if clist[3]==1 and clist[4]==1 and clist[5]==1:
    answer=1
if clist[6]==1 and clist[7]==1 and clist[8]==1:
    answer=1
if clist[0]==1 and clist[3]==1 and clist[6]==1:
    answer=1
if clist[1]==1 and clist[4]==1 and clist[7]==1:
    answer=1
if clist[2]==1 and clist[5]==1 and clist[8]==1:
    answer=1
if clist[0]==1 and clist[4]==1 and clist[8]==1:
    answer=1
if clist[2]==1 and clist[4]==1 and clist[6]==1:
    answer=1

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

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 = [int(input()) for i in range(N)]

B = set(B)
bingo = False
for i in range(3):
    if all(A[i][j] in B for j in range(3)) or all(A[j][i] in B for j in range(3)):
        bingo = True

if all(A[j][j] in B for j in range(3)) or all(A[2 - j][j] in B for j in range(3)):
    bingo = True

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

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

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(n):
    for j in range(3):
        for k in range(3):
            if a[j][k]==b[i]:
                a[j][k]=1000

# print(a)
for i in range(3):
    if a[i][0]==1000 and a[i][1]==1000 and a[i][2]==1000:
        print("Yes")
        quit()

for i in range(3):
    if a[0][i]==1000 and a[1][i]==1000 and a[2][i]==1000:
        print("Yes")
        quit()

if a[0][0]==1000 and a[1][1]==1000 and a[2][2]==1000:
    print("Yes")
    quit()

if a[0][2]==1000 and a[1][1]==1000 and a[2][0]==1000:
    print("Yes")
    quit()

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] = None
for i in range(3):
    if [None,None,None] == A[i]:
        print("Yes")
        exit(0)
for i in range(3):
    if [None,None,None] == [A[0][i],A[1][i], A[2][i]]:
        print("Yes")
        exit(0)
if [A[i][i] for i in range(3)] == [None,None,None]:
    print("Yes")
    exit(0)
if [A[0][2],A[1][1], A[2][0]] == [None,None,None]:
    print("Yes")
    exit(0)
print("No")

Submission status: Accepted

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

flag = 0
for i in range(3):
	if a[i][0] == -1 and a[i][1] == -1 and a[i][2] == -1:
		flag = 1
	if a[0][i] == -1 and a[1][i] == -1 and a[2][i] == -1:
		flag = 1

if a[0][0]+a[1][1]+a[2][2] == -3 or a[0][2]+a[1][1]+a[2][0] == -3:
	flag = 1

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

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)]
#print(a)
for k in range(n):
    for i in range(3):
        for j in range(3):
            if a[i][j] == b[k]:
                a[i][j] = -1
ans = "No"
for i in range(3):
    if a[i][0] == -1 and (a[i][1] == -1 and a[i][2] == -1):
        ans = "Yes"
for i in range(3):
    if a[0][i] == -1 and (a[1][i] == -1 and a[2][i] == -1):
        ans = "Yes"
if a[0][0] == -1 and (a[1][1] == -1 and a[2][2] == -1):
    ans = "Yes"
if a[0][2] == -1 and (a[1][1] == -1 and a[2][0] == -1):
    ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

A = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(3)]
N = int(sys.stdin.buffer.readline())
B = [int(sys.stdin.buffer.readline()) for _ in range(N)]

A = np.array(A, dtype=int)
board = np.zeros((3, 3), dtype=bool)
for b in B:
    board[A == b] = True

ok = False
for i in range(3):
    ok |=np.all(board[i])
    ok |=np.all(board[:, i])
a = True
b = True
for i in range(3):
    a &= board[i][i]
    b &= board[i][~i]
ok |= a
ok |= b
if ok:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from sys import exit

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

t = [0]*9
for bt in b:
    for j,a in enumerate(A):
        if a==bt:
            t[j] = 1

for i in [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]:
    f = True
    for j in i:
        if t[j]==0:
            f=False
    if f:
        print('Yes')
        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)]
# row
for i in range(3):
    ok = True
    for j in range(3):
        if A[i][j] not in b:
            ok = False
            break
    if ok:
        print('Yes')
        exit()
# column
for i in range(3):
    ok = True
    for j in range(3):
        if A[j][i] not in b:
            ok = False
            break
    if ok:
        print('Yes')
        exit()
# diagonal
ok = True
for i in range(3):
    if A[i][i] not in b:
        ok = False
        break
if ok:
    print('Yes')
    exit()
ok = True
for i in range(3):
    if A[i][2-i] not in b:
        ok = False
        break
if ok:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

    flag = False
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A[i][j] = "-1"
                flag = True
                break
        if flag:
            break

flag = False
if A[0][0] == A[1][1] == A[2][2] or A[2][0] == A[1][1] == A[0][2]:
    flag = True

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

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

Submission status: Accepted

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

n=int(input())
b=[]
for i in range(n):
    v=int(input())
    b.append(v)

if Bi[0][0] in b:
    if Bi[0][1] in b:
        if Bi[0][2] in b:
            print("Yes")
            exit()

if Bi[1][0] in b:
    if Bi[1][1] in b:
        if Bi[1][2] in b:
            print("Yes")
            exit()
if Bi[2][0] in b:
    if Bi[2][1] in b:
        if Bi[2][2] in b:
            print("Yes")
            exit()

if Bi[0][0] in b:
    if Bi[1][0] in b:
        if Bi[2][0] in b:
            print("Yes")
            exit()

if Bi[0][1] in b:
    if Bi[1][1] in b:
        if Bi[2][1] in b:
            print("Yes")
            exit()
if Bi[0][2] in b:
    if Bi[1][2] in b:
        if Bi[2][2] in b:
            print("Yes")
            exit()

if Bi[0][0] in b:
    if Bi[1][1] in b:
        if Bi[2][2] in b:
            print("Yes")
            exit()

if Bi[0][2] in b:
    if Bi[1][1] in b:
        if Bi[2][0] in b:
            print("Yes")
            exit()

print("No")

Submission status: Accepted

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

TF = [[False]*3 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:
        TF[j][k] = True

for i in range(3):
  res = True
  for j in range(3):
    res *= TF[i][j]
  if res:
    print('Yes')
    quit()

for i in range(3):
  res = True
  for j in range(3):
    res *= TF[j][i]
  if res:
    print('Yes')
    quit()

res = True
for i in range(3):
  res *= TF[i][i]
if res:
  print('Yes')
  quit()

res = TF[2][0] * TF[1][1] * TF[0][2]
if res:
  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)]

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

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

if [A[0][0],A[1][1],A[2][2]]==[0,0,0]:
    ans = 'Yes'

if [A[0][2],A[1][1],A[2][0]]==[0,0,0]:
    ans = 'Yes'

print(ans)

Submission status: Accepted

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

def bingo():
    print('Yes')
    exit()

for i in range(3):
    s = 0
    for j in range(3): s += X[i][j]
    if s==3:
        bingo()
        
for j in range(3):
    s = 0
    for i in range(3): s += X[i][j]
    if s==3:
        bingo()

if X[0][0]+X[1][1]+X[2][2]==3: bingo()
if X[0][2]+X[1][1]+X[2][0]==3: bingo()

print('No')

Submission status: Accepted

Solution code:
def main():
    bingo = []
    for i in range(3):
        a,b,c = [int(n) for n in input().split()]
        bingo.append([a,b,c])
    N = int(input())
    for i in range(N):
        a = int(input())
        for i, row in enumerate(bingo):
            for j in range(3):
                if bingo[i][j] == a:
                    bingo[i][j] = -1
    flag = False
    for i in range(3):
        if bingo[i][0] == bingo[i][1] == bingo[i][2]:
            flag = True
        if bingo[0][i] == bingo[1][i] == bingo[2][i]:
            flag = True
    if bingo[0][0] == bingo[1][1] == bingo[2][2]:
        flag = True
    if bingo[2][0] == bingo[1][1] == bingo[0][2]:
        flag = True
    print("Yes" if flag else "No")
main()

Submission status: Accepted

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

if __name__ == "__main__":
    A = [[0] * 3 for _ in range(3)]
    for i in range(3):
        tmp = list(map(int, input().split()))
        for j in range(3):
            A[i][j] = tmp[j]
    
    N = int(input())
    b = [0] * N
    for i in range(N):
        b[i] = int(input())

    check = [[0]*3 for _ in range(3)]
    for v in b:
        for i in range(3):
            for j in range(3):
                if A[i][j] == v:
                    check[i][j] = 1
    ok = False
    for i in range(3):
        cnt = 0
        for j in range(3):
            if check[i][j] == 1:
                cnt += 1
        if cnt == 3:
            ok = True

    for j in range(3):
        cnt = 0
        for i in range(3):
            if check[i][j] == 1:
                cnt += 1
        if cnt == 3:
            ok = True
    
    cnt = 0
    for i in range(3):
        if check[i][i] == 1:
            cnt += 1;
    if cnt == 3:
        ok = True
    
    cnt = 0
    for i in range(3):
        if check[i][2-i] == 1:
            cnt += 1;
    if cnt == 3:
        ok = True
    
    if ok == True:
        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 = []
for i in range(N):
    B.append(int(input()))

O1 = [0,0,0]
O2 = [0,0,0]
O3 = [0,0,0]

output ="No"

for i in range(N):
    for j in range(3):
        if B[i]==A1[j]:
            O1[j]=1
        if B[i]==A2[j]:
            O2[j]=1
        if B[i]==A3[j]:
            O3[j]=1

if sum(O1)>=3:
    output = "Yes"
if sum(O2)>=3:
    output = "Yes"
if sum(O3)>=3:
    output = "Yes"
if O1[0]+O2[0]+O3[0]>=3:
    output = "Yes"
if O1[1]+O2[1]+O3[1]>=3:
    output = "Yes"
if O1[2]+O2[2]+O3[2]>=3:
    output = "Yes"
if O1[0]+O2[1]+O3[2]>=3:
    output = "Yes"
if O1[1]+O2[1]+O3[0]>=3:
    output = "Yes"
print(output)

Submission status: Accepted

Solution code:
a = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
hit = [[0,0,0] for i in range(3)]
for i in range(n):
  b = int(input())
  for ii in range(3):
    for jj in range(3):
      if b == a[ii][jj]:
        hit[ii][jj] = 1
bingo=False
for i in range(3):
  f = True
  for j in range(3):
    if hit[i][j] == 1:
      continue
    else:
      f = False
  bingo = f
  if bingo:
    break
if not bingo:
  for j in range(3):
    f = True
    for i in range(3):
      if hit[i][j] == 1:
        continue
      else:
        f = False
    bingo = f
    if bingo:
      break
if not bingo:
  if hit[0][0] == 1 and hit[1][1] == 1 and hit[2][2] == 1:
    bingo = True
  elif hit[2][0] == 1 and hit[1][1] == 1 and hit[0][2] == 1:
    bingo = True
print('Yes' if bingo else 'No')

Submission status: Accepted

Solution code:
a11, a12, a13 = map(int, input().split())
a21, a22, a23 = map(int, input().split())
a31, a32, a33 = map(int, input().split())
n = int(input())
b = list(int(input()) for i in range(n))

if a11 in b and a12 in b and a13 in b:
    print('Yes')
    exit()

if a21 in b and a22 in b and a23 in b:
    print('Yes')
    exit()

if a31 in b and a32 in b and a33 in b:
    print('Yes')
    exit()

if a11 in b and a21 in b and a31 in b:
    print('Yes')
    exit()

if a12 in b and a22 in b and a32 in b:
    print('Yes')
    exit()

if a13 in b and a23 in b and a33 in b:
    print('Yes')
    exit()

if a11 in b and a22 in b and a33 in b:
    print('Yes')
    exit()

if a31 in b and a22 in b and a13 in b:
    print('Yes')
    exit()

print('No')
exit()

Submission status: Accepted

Solution code:
def examA():
    N = I()
    ans = N//2 + N%2
    print(ans)
    return

def examB():
    A = [LI()for _ in range(3)]
    N = I()
    B = [I()for _ in range(N)]
    grid = [[False]*3 for _ in range(3)]
    ans = "No"
    for b in B:
        for i in range(3):
            for j in range(3):
                if A[i][j]==b:
                    grid[i][j] = True
    for i in range(3):
        flag = True
        for j in range(3):
            if not grid[i][j]:
                flag = False
        if flag:
            ans = "Yes"
    for i in range(3):
        flag = True
        for j in range(3):
            if not grid[j][i]:
                flag = False
        if flag:
            ans = "Yes"
    flag = True
    for i in range(3):
        if not grid[i][i]:
            flag = False
    if flag:
        ans = "Yes"
    flag = True
    for i in range(3):
        if not grid[i][2-i]:
            flag = False
    if flag:
        ans = "Yes"
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""

Submission status: Accepted

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

for i in range(3):
    count = 0
    for j in range(3):
        if a[i][j] in b:
            count += 1
    if count == 3:
        check = True
        break
for i in range(3):
    count = 0
    for j in range(3):
        if a[j][i] in b:
            count += 1
    if count == 3:
        check = True
        break
if (a[0][0] in b) and (a[1][1] in b) and (a[2][2] in b):
    check = True
if (a[2][0] in b) and (a[1][1] in b) and (a[0][2] in b):
    check = True
if check == False:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

if sum(c[0])==3 or sum(c[1])==3 or sum(c[2])==3:
  print('Yes')
  sys.exit()
if c[0][0]+c[1][0]+c[2][0]==3 or c[0][1]+c[1][1]+c[2][1]==3 or c[0][2]+c[1][2]+c[2][2]==3:
  print('Yes')
  sys.exit()
if c[0][0]+c[1][1]+c[2][2]==3 or c[0][2]+c[1][1]+c[2][0]==3:
  print('Yes')
  sys.exit()
print('No')

Submission status: Accepted

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

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

for i in range(N):
  for a in range(3):
    for b in range(3):
      if A[a][b]==B[i]:
        K[a][b]=1
        
out='No'
for i in range(3):
  if K[i][0]+K[i][1]+K[i][2]==3:
    out='Yes'
  if K[0][i]+K[1][i]+K[2][i]==3:
    out='Yes'
if K[0][0]+K[1][1]+K[2][2]==3:
  out='Yes'
if K[0][2]+K[1][1]+K[2][0]==3:
  out='Yes'
print(out)

Submission status: Accepted

Solution code:
bingo = [list(map(int, input().split())) for i in range(3)]
b = [[False] * 3 for i in range(3)]
N = int(input())
for i in range(N):
  n = int(input())
  for h in range(3):
    for w in range(3):
      if bingo[h][w] == n:
        b[h][w] = True

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

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for _ in range(3)]
C = [[0]*3 for _ in range(3)]
n = int(input())
for _ in range(n):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        C[i][j] = 1
def hoge():
  print("Yes")
  exit()
 
if C[0][0] & C[0][1] & C[0][2]:
  hoge()
if C[1][0] & C[1][1] & C[1][2]:
  hoge()
if C[2][0] & C[2][1] & C[2][2]:
  hoge()
if C[0][0] & C[1][0] & C[2][0]:
  hoge()
if C[0][1] & C[1][1] & C[2][1]:
  hoge()
if C[0][2] & C[1][2] & C[2][2]:
  hoge()
if C[0][0] & C[1][1] & C[2][2]:
  hoge()
if C[0][2] & C[1][1] & C[2][0]:
  hoge()
print("No")

Submission status: Accepted

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

for i in range(n):
  for x in range(3):
    for y in range(3):
      if A[x][y] == b[i]:
        A[x][y] = -1
        
flag = 0
for i in range(3):
  if A[i][0]==-1 and A[i][1]==-1 and A[i][2]==-1:
    flag = 1
  if A[0][i]==-1 and A[1][i]==-1 and A[2][i]==-1:
    flag = 1
    
if A[0][0]==-1 and A[1][1]==-1 and A[2][2]==-1:
  flag = 1
if A[2][0]==-1 and A[1][1]==-1 and A[0][2]==-1:
  flag = 1
  
if flag==1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
a = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
l = []
for i in range(3):
  t = []
  for j in range(3):
    t.append(a[i][j])
  l.append(t)
for j in range(3):
  t = []
  for i in range(3):
    t.append(a[i][j])
  l.append(t)
l.append([a[0][0], a[1][1], a[2][2]])
l.append([a[0][2], a[1][1], a[2][0]])
for t in l:
  s = [0] * 3
  for x in b:
    for i in range(3):
      if x == t[i]: s[i] = 1
  if sum(s) == 3:
    print("Yes")
    exit(0)
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 n in range(N)]
C = [[0,0,0],[0,0,0],[0,0,0]]
F = "No"

for i in range(3):
  for j in range(3):
    if A[i][j] in B:
      C[i][j] = 1

for i in range(3):
  if C[i][0]+C[i][1]+C[i][2]==3:
    F = "Yes"

for i in range(3):
  if C[0][i]+C[1][i]+C[2][i]==3:
    F = "Yes"

for i in range(3):
  if C[0][0]+C[1][1]+C[2][2]==3 or C[0][2]+C[1][1]+C[2][0]==3:
    F = "Yes"

print(F)

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

P = [[0 for j in range(3)] for i in range(3)]

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

if P[0][0]+P[0][1]+P[0][2] == 3 or P[1][0]+P[1][1]+P[1][2] == 3 or P[2][0]+P[2][1]+P[2][2] == 3 or P[0][0]+P[1][0]+P[2][0] == 3 or P[0][1]+P[1][1]+P[2][1] == 3 or P[0][2]+P[1][2]+P[2][2] == 3 or P[0][0]+P[1][1]+P[2][2] == 3 or P[2][0]+P[1][1]+P[0][2] == 3:
    print('Yes')
else:
    print('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)]
    T = [[0]*3 for _ in range(3)]
    for b in B:
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    T[i][j] = 1
    ans = 'No'
    for i in range(3):
        if T[i][0]*T[i][1]*T[i][2] > 0:
            ans = 'Yes'
    for i in range(3):
        if T[0][i]*T[1][i]*T[2][i] > 0:
            ans = 'Yes'
    if T[0][0]*T[1][1]*T[2][2] > 0:
        ans = 'Yes'
    if T[0][2]*T[1][1]*T[2][0] > 0:
        ans = 'Yes'
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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


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

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

ok = False
for i in range(3):
    bi = True
    for j in range(3):
        if S[i][j] != -1:
            bi = False
    if bi: ok = True

for j in range(3):
    bi = True
    for i in range(3):
        if S[i][j] != -1:
            bi = False
    if bi: ok = True

if S[0][0] == -1 and S[1][1] == -1 and S[2][2] == -1:
    ok = True
if S[0][2] == -1 and S[1][1] == -1 and S[2][0] == -1:
    ok = True

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

Submission status: Accepted

Solution code:
def Bingo():
    for a in bingo:
        if sum(a) == 0:
            return True
    for b in range(len(bingo)):
        if sum([bingo[i][b] for i in range(3)]) == 0:
            return True
    if bingo[0][0] + bingo[1][1] + bingo[2][2] == 0:
        return True
    if bingo[1][1] + bingo[2][0] + bingo[0][2] == 0:
        return True
    return False

bingo = [[int(i) for i in input().split()] for i in range(3)]
valid = False
N = int(input())
for a in range(N):
    num = int(input())
    for b in range(len(bingo)):
        if num in bingo[b]:
            bingo[b][bingo[b].index(num)] = 0
    if Bingo():
        valid = True
        break
if valid:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def main():
    a = [[int(x) for x in input().split()] for _ in range(3)]
    n = int(input())

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

    for _ in range(n):
        b = int(input())
        for r in range(3):
            for c in range(3):
                if a[r][c] == b:
                    t[r][c] = 1

    for r in range(3):
        if t[r][0] == t[r][1] == t[r][2] == 1:
            print('Yes')
            return

    for c in range(3):
        if t[0][c] == t[1][c] == t[2][c] == 1:
            print('Yes')
            return

    if t[0][0] == t[1][1] == t[2][2] == 1:
        print('Yes')
        return

    if t[0][2] == t[1][1] == t[2][0] == 1:
        print('Yes')
        return

    print('No')


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

Submission status: Accepted

Solution code:
from itertools import combinations
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
ans = []
for i in b:
  for x in range(3):
    for y in range(3):
      if i == a[x][y]:
        ans.append(3*x+y)
if len(ans) <= 2:
  print("No")
  exit()
ans.sort()
for i,j,k in combinations(ans,3):
  if (i,j,k) in ((0,1,2),(0,4,8),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(2,4,6)):
    print("Yes")
    break
else:
  print("No")

Submission status: Accepted

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

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

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

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

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

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

print("No")

Submission status: Accepted

Solution code:
import sys

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def input(): return sys.stdin.readline().strip()

mat = []
for i in range(3):
    mat.append(get_array())

n = int(input())
for i in range(n):
    x = int(input())
    for j in range(3):
        for k in range(3):
            if mat[j][k]==x:
                mat[j][k]=-1

flag = 0
if mat[0][0]==mat[0][1]==mat[0][2]==-1:
    flag = 1
elif mat[1][0]==mat[1][1]==mat[1][2]==-1:
    flag = 1
elif mat[2][0]==mat[2][1]==mat[2][2]==-1:
    flag = 1
elif mat[0][0]==mat[1][0]==mat[2][0]==-1:
    flag = 1
elif mat[0][1]==mat[1][1]==mat[2][1]==-1:
    flag = 1
elif mat[0][2]==mat[1][2]==mat[2][2]==-1:
    flag = 1
elif mat[0][0]==mat[1][1]==mat[2][2]==-1:
    flag = 1
elif mat[0][2]==mat[1][1]==mat[2][0]==-1:
    flag = 1
if flag==0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
def main():
    aa = []
    for _ in xrange(3):
        aa.extend(map(int, raw_input().split()))
    n = input()
    for _ in xrange(n):
        b = input()
        try:
            aa[aa.index(b)] = 0
        except ValueError:
            continue
    for i in xrange(3):
        if sum(aa[i*3:i*3+3]) == 0:
            print 'Yes'
            return
        if sum(aa[i::3]) == 0:
            print 'Yes'
            return
    if sum(aa[::4]) == 0:
        print 'Yes'
        return
    if sum(aa[2:7:2]) == 0:
        print 'Yes'
        return
    print 'No'

main()

Submission status: Accepted

Solution code:
lst = []
atari = [0 for _ in range(9)]
for _ in range(3):
	a, b, c = map(int, input().split())
	lst.append(a)
	lst.append(b)
	lst.append(c)

N = int(input())

for _ in range(N):
	b = int(input())
	if b in lst:
		atari[lst.index(b)] = 1
	
if atari[0] * atari[1] * atari[2] == 1 or atari[3] * atari[4] * atari[5] == 1 or atari[6] * atari[7] * atari[8] == 1 or atari[0] * atari[3] * atari[6] == 1 or atari[1] * atari[4] * atari[7] == 1 or atari[2] * atari[5] * atari[8] == 1 or atari[0] * atari[4] * atari[8] == 1 or atari[2] * atari[4] * atari[6] == 1:
	print("Yes")
else:
	print("No")

Submission status: Accepted

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

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

ans = False
for i in range(3):
    if sum(flag[i]) == 3:
        ans = True

flag_t = [list(x) for x in zip(*flag)]
for i in range(3):
    if sum(flag_t[i]) == 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:
a=[[int(i) for i in 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]=1000
ans=False
for i in range(3):
    if a[i][0]==a[i][1]==a[i][2]==1000:
        ans=True
    elif a[0][i]==a[1][i]==a[2][i]==1000:
        ans=True
if a[0][0]==a[1][1]==a[2][2]==1000:
    ans=True
elif a[0][2]==a[1][1]==a[2][0]==1000:
    ans=True
print("Yes" if ans else "No")