Problem:


Score : 200 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

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

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

1 \leq N \leq 10

1 \leq b_i \leq 100

b_i \neq b_j (i \neq j)

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

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

Sample Output 1

Yes

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

Sample Input 2

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

Sample Output 2

No

We will mark nothing.

Sample Input 3

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

Sample Output 3

Yes

We will mark all the squares.



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


Sample output:
Yes

Submission status: Accepted

Solution code:
import numpy as np


def main():
    A0 = [int(x) for x in input().split()]
    A1 = [int(x) for x in input().split()]
    A2 = [int(x) for x in input().split()]
    A = [A0,A1,A2]

    Ainv = dict()
    for i in range(3):
        for j in range(3):
            Ainv[A[i][j]] = (i,j)

    N = int(input())
    rows = [0]*3
    cols = [0]*3
    cross = [0]*2
    for _ in range(N):
        b = int(input())
        if b not in Ainv:
            continue
        row, col = Ainv[b]
        rows[row]+=1
        cols[col]+=1
        if row==col:
            cross[0] += 1
        if row+col==2:
            cross[1] += 1
        if any([rows[row]==3, cols[col]==3, cross[0]==3, cross[1]==3]):
            print("Yes")
            return
    print("No")
    return



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A = []
for _ in range(3):
  a,b,c = map(int,input().split())
  A.append([a,b,c])
B = [[1]*3 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 x == A[i][j]:
        B[i][j] = 0
Answer = 'No'
for i in range(3):
  if sum(B[0])*sum(B[1])*sum(B[2])==0:
    print('Yes')
    exit()
  if (B[0][0]+B[1][0]+B[2][0])*(B[0][1]+B[1][1]+B[2][1])*(B[0][2]+B[1][2]+B[2][2])==0:
    print('Yes')
    exit()
  if (B[0][0]+B[1][1]+B[2][2])*(B[2][0]+B[1][1]+B[0][2])==0:
    print('Yes')
    exit()
print(Answer)

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=int(input())
    B.append(b)
for i in range(3):
    if A1[i] in B:
        A1.remove(A1[i])
        A1.insert(i,1)
    else:
        A1.remove(A1[i])
        A1.insert(i,0)
for i in range(3):
    if A2[i] in B:
        A2.remove(A2[i])
        A2.insert(i,1)
    else:
        A2.remove(A2[i])
        A2.insert(i,0)
for i in range(3):
    if A3[i] in B:
        A3.remove(A3[i])
        A3.insert(i,1)
    else:
        A3.remove(A3[i])
        A3.insert(i,0)
A=[A1,A2,A3]
if A1[0]==A1[1]==A1[2]==1 or A2[0]==A2[1]==A2[2]==1 or \
A3[0]==A3[1]==A3[2]==1 or A1[0]==A2[0]==A3[0]==1 or A1[1]==A2[1]==A3[1]==1 or \
A1[2]==A2[2]==A3[2]==1 or A1[0]==A2[1]==A3[2]==1 or A1[2]==A2[1]==A3[0]==1:
    print("Yes")
else:
    print("No")

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)]
ans_flag = True
ans_flag2 = True
ans = [[False, False, False], [False, False, False], [False, False, False]]

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

for i in range(3):
    if ans[0][i] and ans[1][i] and ans[2][i]:
        print('Yes')
        sys.exit()
    if ans[i][0] and ans[i][1] and ans[i][2]:
        print('Yes')
        sys.exit()
    if not ans[i][i]:
        ans_flag = False
    if not ans[i][2-i]:
        ans_flag2 = False

if ans_flag or ans_flag2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a1 = list(map(lambda x: int(x), input().split()))
a2 = list(map(lambda x: int(x), input().split()))
a3 = list(map(lambda x: int(x), input().split()))
card = [a1, a2, a3]

n = int(input())

number = []
for num in range(0, n):
  b = int(input())
  number.append(b)

def bingo(bingolist):
  x = 0
  for n in bingolist:
    if n in number:
      x += 1
  if x == 3:
    print("Yes")
    exit()

bingo(a1)
bingo(a2)
bingo(a3)
for num in range(0, 3):
	bingo([a1[num], a2[num], a3[num]])

bingo([a1[0], a2[1], a3[2]])
bingo([a1[2], a2[1], a3[0]])
print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
A = [list(map(int,input().split())) for i in range(3)]
N = int(input())
for k in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if b == A[i][j]:
                A[i][j] = True
for i in range(3):
    if A[i][0] == A[i][1] == A[i][2] == True:
        print("Yes")
        exit()
    elif A[0][i] == A[1][i] == A[2][i] == True:
        print("Yes")
        exit()
if A[0][0] == A[1][1] == A[2][2] == True:
    print("Yes")
    exit()
if A[0][2] == A[1][1] == A[2][0] == True:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
A = [[],[],[]]
A[0] = list(map(int, input().split()))
A[1] = list(map(int, input().split()))
A[2] = list(map(int, input().split()))

complete = [[False, False, False] for i in range(3)]

N = int(input())
for i in range(N):
    val = int(input())

    for y in range(3):
        for x in range(3):
            if A[y][x] == val: complete[y][x] = True

bingo = False
for y in range(3):
    if all(complete[y]): bingo = True

for x in range(3):
    if (all(complete[i][x] for i in range(3))): bingo = True

if all(complete[i][i] for i in range(3)): bingo = True
if all(complete[i][3-i-1] for i in range(3)): bingo = True

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

Submission status: Accepted

Solution code:
x=[list(map(str,input().split())) for _ in range(3)]
N=int(input())
B=[input() for _ in range(N)]
flag=0
for i in range(3):
  for j in range(3):
    if x[i][j] in B:
      x[i][j]=True

for p in range(3):
  if x[p].count(True)==3:
    flag=1
lis=[]
lis2=[]
for a in range(3):
  for b in range(3):
    lis2.append(x[b][a])
  else:
    lis.append(lis2)
    lis2=[]

for q in range(3):
  if lis[q].count(True)==3:
    flag=1
if x[0][0]==True and x[1][1]==True and x[2][2]==True:
  flag=1
elif  x[0][2]==True and x[1][1]==True and x[2][0]==True:
  flag=1
if flag==1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
def checkRows(grid):
    for row in grid:
        if all([n == True for n in row]):
            return True
    return False


def checkCols(grid):
    for j in range(3):
        if all([n == True for n in [grid[i][j] for i in range(3)]]):
            return True
    return False


def checkDiags(grid):
    return all([n == True for n in [grid[i][i] for i in range(3)]]) or \
           all([n == True for n in [grid[i][2 - i] for i in range(3)]])


if __name__ == '__main__':
    grid = [[0] * 3 for i in range(3)]
    idx = {}

    for i in range(3):
        grid[i] = [int(s) for s in input().strip().split()]
        for j in range(3):
            idx[grid[i][j]] = (i, j)

    n = int(input())
    bs = [-1] * n

    for i in range(n):
        bs[i] = int(input())
        if bs[i] in idx.keys():
            a, b = idx[bs[i]]
            grid[a][b] = True

    if checkRows(grid) or checkCols(grid) or checkDiags(grid):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
A = [[] for i in range(3)]
A[0] = list(map(int, input().split(' ')))
A[1] = list(map(int, input().split(' ')))
A[2] = list(map(int, input().split(' ')))
bingo = [[0, 0, 0] for i in range(3)]
N = int(input())
for i in range(N):
    num = int(input())
    for j in range(3):
        for k in range(3):
            bingo[j][k] = 1 if A[j][k] == num else bingo[j][k]
            # print(num, A[j][k])

flag = False
if (bingo[0][0] and bingo[1][1] and bingo[2][2]) or (bingo[0][2] and bingo[1][1] and bingo[2][0]):
    flag = True

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

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

Submission status: Accepted

Solution code:
# m = int(input())
bi = {}
ans = []
count = 0
for i in range(3):
    l = list(map(int, input().split()))
    for j in range(1,3+1):
        count += 1
        bi[l[j-1]] = count


n = int(input())
for i in range(n):
    k = int(input())
    if k in bi:
        ans.append(bi[k])



if 5 in ans and 1 in ans and 9 in ans:
    print("Yes")
    exit()

if  3 in ans and 5 in ans and 7 in ans:
    print("Yes")
    exit()

count = 1
for i in range(3):
    if (count) in ans and (count+1) in ans and (count+2) in ans:
        print("Yes")
        exit()
    else:
        count += 3

count = 1
for i in range(1,4):
    if (count) in ans and (count+3) in ans and (count+6) in ans:
        print("Yes")
        exit()
    else:
        count += 1

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

s=[]
t=[]
cross_1=0
cross_2=0

ans="No"

for i in b:
    for j in range(3):
        if i in A[j]:
            s.append(j)
            t.append(A[j].index(i))
            if j==A[j].index(i):
                cross_1+=1
                if j==1:
                    cross_2+=1
            elif j==2-A[j].index(i):
                cross_2+=1
                
for k in range(3):
    if s.count(k)==3:
        ans="Yes"
for l in range(3):
    if t.count(l)==3:
        ans="Yes"
if cross_1==3:
    ans="Yes"
elif cross_2==3:
    ans="Yes"

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

mat = []

for i in range(3):
	(a,b,c)= input().split(' ')
	mat.append((int(a),int(b),int(c)))

mat = np.array(mat).reshape(3,3)


num = int(input())
ball=[]
for i in range(num):
  ball.append(int(input()))

ball = set(ball)

for h in range(3):
  x = set(mat[h,:])
  res = ball.intersection(x) == x
  if res:
    print('Yes')
    exit()

for w in range(3):
  x = set(mat[:, w])
  res = ball.intersection(x) == x
  if res:
    print('Yes')
    exit()

x = {mat[0,0],mat[1,1], mat[2,2]}
res = ball.intersection(x) == x
if res:
  print('Yes')
  exit()

x = {mat[2,0],mat[1,1], mat[0,2]}  
res = ball.intersection(x) == x
if res:
  print('Yes')
  exit()
  
print('No')

Submission status: Accepted

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

# 横
if A_1[0] in b:
  if A_1[1] in b:
    if A_1[2] in b:
      print('Yes')
      exit(0)
      
if A_2[0] in b:
  if A_2[1] in b:
    if A_2[2] in b:
      print('Yes')
      exit(0)

if A_3[0] in b:
  if A_3[1] in b:
    if A_3[2] in b:
      print('Yes')
      exit(0)
  
# 縦
for j in range(3):
  if A_1[j] in b:
    if A_2[j] in b:
      if A_3[j] in b:
        print('Yes')
        exit(0)
# 斜め
if A_1[0] in b:
  if A_2[1] in b:
    if A_3[2] in b:
      print('Yes')
      exit(0)
      
if A_1[2] in b:
  if A_2[1] in b:
    if A_3[0] in b:
      print('Yes')
      exit(0)

print('No')

Submission status: Accepted

Solution code:
e = list(map(int,input().split()))
f = list(map(int,input().split()))
g = list(map(int,input().split()))

c = [e[0],e[1],e[2],f[0],f[1],f[2],g[0],g[1],g[2]]
d = [0,0,0,0,0,0,0,0,0]

n=int(input())

for i in range(n):
    b = int(input())
    for j in range(9):
        if c[j] == b:
            d[j] = 1

if (d[0]==1) and (d[1]==1) and (d[2]==1):
    print('Yes')
elif (d[3]==1) and (d[4]==1) and (d[5]==1):
    print('Yes')
elif (d[6]==1) and (d[7]==1) and (d[8]==1):
    print('Yes')
elif (d[0]==1) and (d[3]==1) and (d[6]==1):
    print('Yes')
elif (d[1]==1) and (d[4]==1) and (d[7]==1):
    print('Yes')
elif (d[2]==1) and (d[5]==1) and (d[8]==1):
    print('Yes')
elif (d[0]==1) and (d[4]==1) and (d[8]==1):
    print('Yes')
elif (d[2]==1) and (d[4]==1) and (d[6]==1):
    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())
aa = 0
bb = 0
cc = 0
dd = 0
ee = 0
ff = 0
gg = 0
hh = 0
ii = 0

j = int(input())

for k in range(j):
  l = int(input())
  if a == l:
    aa = 1
  elif b == l:
    bb = 1
  elif c == l:
    cc = 1
  elif d == l:
    dd = 1
  elif e == l:
    ee = 1
  elif f == l:
    ff = 1
  elif g == l:
    gg = 1
  elif h == l:
    hh = 1
  elif i == l:
    ii = 1
if aa == 1 and bb == 1 and cc == 1:
  print('Yes')
elif dd == 1 and ee == 1 and ff == 1:
  print('Yes')
elif gg == 1 and hh == 1 and ii == 1:
  print('Yes')
elif aa == 1 and dd == 1 and gg == 1:
  print('Yes')
elif bb == 1 and ee == 1 and hh == 1:
  print('Yes')
elif cc == 1 and ff == 1 and ii == 1:
  print('Yes')
elif aa == 1 and ee == 1 and ii == 1:
  print('Yes')
elif cc == 1 and ee == 1 and gg == 1:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
# print(a)
# print(b)
# print(c)
n = int(input())
d = [int(input()) for i in range(n)]
# print(d)

if (a[0]in d) and (a[1]in d) and(a[2]in d):
    print("Yes")
    exit()
if (b[0]in d)and(b[1]in d)and(b[2]in d):
    print("Yes")
    exit()
if (c[0]in d)and(c[1]in d)and(c[2]in d):
    print("Yes")
    exit()
if (a[2]in d)and(b[1]in d)and(c[0]in d):
    print("Yes")
    exit()
if (a[0]in d)and(b[1]in d)and(c[2]in d):
    print("Yes")
    exit()
if (a[0]in d)and(b[0]in d)and(c[0]in d):
    print("Yes")
    exit()
if (a[2]in d)and(b[2]in d)and(c[2]in d):
    print("Yes")
    exit()
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np
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()))

flag = 0
for i in range(N):
  for j in range(3):
    if b[i] == A1[j]:
      A1[j] = 0
    elif b[i] == A2[j]:
      A2[j] = 0
    elif b[i] == A3[j]:
      A3[j] = 0
if A2[1] == 0:
  if A2[0] == 0 and A2[2] == 0:
    flag = 1
  elif A1[1] == 0 and A3[1] == 0:
    flag = 1
  elif A1[0] == 0 and A3[2] == 0:
    flag = 1
  elif A1[2] == 0 and A3[0] == 0:
    flag = 1
elif A1[0] == 0 and A1[1] == 0 and A1[2] == 0:
  flag = 1
elif A1[0] == 0 and A2[0] == 0 and A3[0] == 0:
  flag = 1
elif A1[2] == 0 and A2[2] == 0 and A3[2] == 0:
  flag = 1
elif A3[0] == 0 and A3[1] == 0 and A3[2] == 0:
  flag = 1
  
if flag == 1:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
def bingo(b):
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                B[i][j] = 1

def judge():
    for i in range(3):
        if B[i][0] and B[i][1] and B[i][2]:
            return True
        if B[0][i] and B[1][i] and B[2][i]:
            return True
    if B[0][0] and B[1][1] and B[2][2]:
            return True
    if B[0][2] and B[1][1] and B[2][0]:
            return True
    return False

A = [[int(i) for i in input().split()] for _ in range(3)]
B = [[0]*3 for _ in range(3)]
N = int(input())
for _ in range(N):
    b = int(input())
    bingo(b)
if judge():
    print("Yes")
else:
    print("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())
num = []
for i in range(N):
    num.append(int(input()))

if (a11 in num and a12 in num and a13 in num) == True:
    print('Yes')
elif (a21 in num and a22 in num and a23 in num) == True:
    print('Yes')
elif (a31 in num and a32 in num and a33 in num) == True:
    print('Yes')
elif (a11 in num and a21 in num and a31 in num) == True:
    print('Yes')
elif (a12 in num and a22 in num and a32 in num) == True:
    print('Yes')
elif (a13 in num and a23 in num and a33 in num) == True:
    print('Yes')
elif (a11 in num and a22 in num and a33 in num) == True:
    print('Yes')
elif (a31 in num and a22 in num and a13 in num) == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#coding:utf-8
a =[list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
#print(b)
check = [[0, 0, 0] for _ in range(3)]
#print(check)


for i in range(n):
    for j in range(0, 3):
        for k in range(0, 3):
            if int(b[i]) == int(a[j][k]):
                check[j][k] = 1



#print(sum(check[0]))

if sum(check[0]) == 3 or sum(check[1]) == 3 or sum(check[2]) == 3:
    print('Yes')
    exit()
elif check[0][0]+check[1][0]+check[2][0] == 3 or check[0][1]+check[1][1]+check[2][1]== 3 or check[0][2]+check[1][2]+check[2][2] == 3:
    print('Yes')
    exit()
elif check[0][0]+check[1][1]+check[2][2] == 3 or check[0][2]+check[1][1]+check[2][0] == 3:
    print('Yes')
    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())
b = list(int(input()) for _ in range(n))

for i in b:
    if i in a :
        a[a.index(i)] = "h"

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

Submission status: Accepted

Solution code:
a = [int(i) for i in input().split()]
for i in range(2):
	a.extend([int(i) for i in input().split()])
n = int(input())
b = []
for i in range(n):
	b = int(input())
	if b in a:
		a[a.index(b)] = 0
if a.count(0) < 3:
	print("No")		
elif a[0] == 0 and a[1] == 0 and a[2] == 0:
	print("Yes")
elif a[3] == 0 and a[4] == 0 and a[5] == 0:
	print("Yes")
elif a[6] == 0 and a[7] == 0 and a[8] == 0:
	print("Yes")
elif a[0] == 0 and a[3] == 0 and a[6] == 0:
	print("Yes")
elif a[1] == 0 and a[4] == 0 and a[7] == 0:
	print("Yes")
elif a[2] == 0 and a[5] == 0 and a[8] == 0:
	print("Yes")
elif a[0] == 0 and a[4] == 0 and a[8] == 0:
	print("Yes")
elif a[2] == 0 and a[4] == 0 and a[6] == 0:
	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())

r = {
    'r0': 0,
    'r1': 0,
    'r2': 0,
    'c0': 0,
    'c1': 0,
    'c2': 0,
    'x0': 0,
    'x1': 0,

}

for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                r['r{}'.format(j)] += 1
                r['c{}'.format(k)] += 1
                if j == k:
                    r['x0'] += 1
                if (j == 0 and k == 2) or (j == 1 and k == 1) or (j == 2 and k == 0):
                    r['x1'] += 1

for b in r.values():
    if b == 3:
        print('Yes')
        exit() 
print('No')

Submission status: Accepted

Solution code:
from itertools import combinations as comb

A = [[int(i) for i in input().split(' ')] for j in  range(3)]
n = int(input())
B = [int(input()) for i in range(n)]

flat = A[0] + A[1] + A[2]
ls = [b for b in B if b in flat]
ls = list(sorted(c) for c in comb(ls, 3))

bingo = [
	sorted(A[0]),
	sorted(A[1]),
	sorted(A[2]),
	sorted([A[0][0], A[1][0], A[2][0]]),
	sorted([A[0][1], A[1][1], A[2][1]]),
	sorted([A[0][2], A[1][2], A[2][2]]),
	sorted([A[0][0], A[1][1], A[2][2]]),
	sorted([A[0][2], A[1][1], A[2][0]])
]

ans = 'No'
for b in bingo:
  if b in ls:
    ans = 'Yes'
    break

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

N = int(input())

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


result = 'No'

for i in range(3):
    if set(A[i]) <= set(b):
        result = 'Yes'

for i in range(3):
    if set([A[0][i], A[1][i], A[2][i]]) <= set(b):
        result = 'Yes'

if set([A[0][0], A[1][1], A[2][2]]) <= set(b):
    result = 'Yes'

if set([A[0][2], A[1][1], A[0][2]]) <= set(b):
    result = 'Yes'

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()))
list=[A1,A2,A3]
N=int(input())
b=[]
for i in range(N):
  b.append(int(input()))
for k in range(N):
  for i in range(3):
    for j in range(3):
      if list[i][j]==b[k]:
        list[i][j]=0
if list[0][0]==list[1][1]==list[2][2]==0 or list[0][2]==list[1][1]==list[2][0]==0 or list[0][0]==list[0][1]==list[0][2]==0 or list[1][0]==list[1][1]==list[1][2]==0 or list[2][0]==list[2][1]==list[2][2]==0 or list[0][0]==list[1][0]==list[2][0]==0 or list[0][1]==list[1][1]==list[2][1]==0 or list[0][2]==list[1][2]==list[2][2]==0 :
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

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

    ans = 'No'

    for bbb in list(B):
        for i in range(3):
            if A[i][0] == bbb:
                A[i][0] = 1000
            if A[i][1] == bbb:
                A[i][1] = 1000
            if A[i][2] == bbb:
                A[i][2] = 1000

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

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

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

    print(ans)


resolve()

Submission status: Accepted

Solution code:
A = [[]*3]*3

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

N = int(input())

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

result = "No"

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

print(result)

Submission status: Accepted

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

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


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    
    line = [a for a in A]
    
    line.append([A[i][0] for i in range(3)])
    line.append([A[i][1] for i in range(3)])
    line.append([A[i][2] for i in range(3)])
    line.append([A[0][0], A[1][1], A[2][2]])
    line.append([A[0][2], A[1][1], A[2][0]])

    #print(line)
    #print(b)
    for Al in line:
        #print(Al)
        if len(set(b) & set(Al)) == 3:
            print(YES)
            sys.exit()
    print(NO)

    return



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)] for _ in range(3)]  # type: "List[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:
bingo = [list(map(int, input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

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

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 = []
for _ in range(N):
    B.append(int(input()))
ans =  [0]*9
for i in range(N):
    if B[i] in A:
        ans[A.index(B[i])] = 1

if (ans[0] == 1 and ans[1] == 1 and ans[2] == 1) or \
    (ans[3] == 1 and ans[4] == 1 and ans[5] == 1) or \
    (ans[6] == 1 and ans[7] == 1 and ans[8] == 1) or \
    (ans[0] == 1 and ans[3] == 1 and ans[6] == 1) or \
    (ans[1] == 1 and ans[4] == 1 and ans[7] == 1) or \
    (ans[2] == 1 and ans[5] == 1 and ans[8] == 1) or \
    (ans[0] == 1 and ans[4] == 1 and ans[8] == 1) or \
    (ans[2] == 1 and ans[4] == 1 and ans[6] == 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 _ in range(N):
    K = int(input())
    for i in range(3):
        for j in range(3):        
            if K == bingo[i][j]:
                bingo[i][j] = 1000

ans = False
for i in range(3):
    if set(bingo[i]) == {1000}:
        ans = True

for i in range(3):
    cnt = []
    for k in range(3):
        cnt.append(bingo[k][i])
    if set(cnt) == {1000}:
        ans = True
cnt1 = []
cnt2 = []
cnt3 = []
cnt4 = []
for i in range(3):    
    k = 2-i
    cnt1.append(bingo[i][k])
    cnt2.append(bingo[k][i])
    cnt3.append(bingo[i][i])
    cnt4.append(bingo[k][k])
if set(cnt1) == {1000}:
    ans = True
if set(cnt2) == {1000}:
    ans = True
if set(cnt3) == {1000}:
    ans = True
if set(cnt4) == {1000}:
    ans = True
if ans:
    print("Yes")
if ans == False:
    print("No")

Submission status: Accepted

Solution code:
A = []
for _ in range(3):
    A += [int(v) for v in input().strip().split()]
N = int(input())
nums = [int(input()) for _ in range(N)]

for n in nums:
    try:
        A[A.index(n)] = -1
    except ValueError:
        pass

def _(A):
    for i in range(3):
        if len(set(A[i*3:(i*3+3)])) == 1:
            return "Yes"
    for i in range(3):
        if len(set(A[i::3])) == 1:
            return "Yes"
    if A[0] * A[4] * A[8] == -1:
        return "Yes"
    if A[2] * A[4] * A[6] == -1:
        return "Yes"
    return "No"

print(_(A))

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 n in range(N):
  a = int(input())
  for i in range(3):
    for j in range(3):
      if A[i][j] == a:
        A[i][j] = -1
      
for i in range(3):
  if all(a == -1 for a in A[i]):
    print('Yes')
    exit()
        
for j in range(3):
  if all(a[j] == -1 for a in A):
    print('Yes')
    exit()

if all(a == -1 for a in [A[0][0], A[1][1], A[2][2]]):
  print('Yes')
  exit()

if all(a == -1 for a in [A[0][2], A[1][1], A[2][0]]):
  print('Yes')
  exit()

print('No')

Submission status: Accepted

Solution code:
lst1 = list(map(int, input().split()))
lst2 = list(map(int, input().split()))
lst3 = list(map(int, input().split()))
n = int(input())
lst = []
for i in range(n):
    # lst.append(int(input()))
    inp = int(input())
    if inp in lst1:
        lst.append((1, lst1.index(inp)+1))
    if inp in lst2:
        lst.append((2, lst2.index(inp)+1))
    if inp in lst3:
        lst.append((3, lst3.index(inp)+1))
row_wise = [[(1, 1), (1, 2), (1, 3)], [(2, 1), (2, 2), (2, 3)],
            [(3, 1), (3, 2), (3, 3)]]
column_wise = [[(1, 1), (2, 1), (3, 1)], [
    (1, 2), (2, 2), (3, 2)], [(1, 3), (2, 3), (3, 3)]]
diagonal_wise = [[(1, 1), (2, 2), (3, 3)], [(3, 1), (2, 2), (1, 3)], ['Blank']]

is_bingo = False
for i in range(3):
    if all(elem in lst for elem in row_wise[i]):
        is_bingo = True
        print('Yes')
        break
    if all(elem in lst for elem in column_wise[i]):
        is_bingo = True
        print('Yes')
        break
    if all(elem in lst for elem in diagonal_wise[i]):
        is_bingo = True
        print('Yes')
        break
if not is_bingo:
    print('No')

Submission status: Accepted

Solution code:
A = []
for i in range(3):
    p,q,r = map(int, input().split())
    A.append(p)
    A.append(q)
    A.append(r)
n = int(input())
for i in range(n):
    b = int(input())
    if b in A:
        A[A.index(b)] = 0

if A[0]==A[1]==A[2]==0 or A[3]==A[4]==A[5]==0 or A[6]==A[7]==A[8]==0 or A[0]==A[3]==A[6]==0 or A[1]==A[4]==A[7]==0 or A[2]==A[5]==A[8]==0 or 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:
a_1 = list(map(int,input().split()))
a_2 = list(map(int,input().split()))
a_3 = list(map(int,input().split()))
n = int(input())
b_n = [int(input()) for i in range(n)]

for b in b_n:
    for i in range(3):
        if a_1[i] == b:
            a_1[i] = 0
        if a_2[i] == b:
            a_2[i] = 0
        if a_3[i] == b:
            a_3[i] = 0
            
            
#print(a_1,a_2,a_3)
flag = "No"
if a_1[0] == 0 and a_1[1] == 0 and a_1[2] == 0:
    flag = "Yes"
if a_2[0] == 0 and a_2[1] == 0 and a_2[2] == 0:
    flag = "Yes"
if a_3[0] == 0 and a_3[1] == 0 and a_3[2] == 0:
    flag = "Yes"

for i in range(3):
    if a_1[i] == 0 and a_2[i] == 0 and a_3[i] == 0:
        flag = "Yes"
       
     
if a_1[0] == 0 and a_2[1] == 0 and a_3[2] == 0:
    flag = "Yes"
if a_3[0] == 0 and a_2[1] == 0 and a_1[2] == 0:
    flag = "Yes"

print(flag)

Submission status: Accepted

Solution code:
import itertools
L = [list(map(int, input().split())) for i in range(3)]
L = list(itertools.chain.from_iterable(L))
bool_L = [[False, False, False] for i in range(3)]
N = int(input())
b_L = [int(input()) for i in range(N)]

for b in b_L:
    if b in L:
        index = L.index(b)
        show = index // 3
        amari = index % 3
        bool_L[show][ amari] = True
        
flag = "No"
for i in bool_L:
    if i == [True, True, True]:
        flag = "Yes"
        break
        
for j in range(3):
    temp_l = []
    for i in range(3):
        temp_l.append(bool_L[i][j])
    if temp_l == [True, True, True]:
        flag = "Yes"
        break

if [bool_L[0][0],bool_L[1][1],bool_L[2][2]] == [True, True, True]:
    flag = "Yes"
elif [bool_L[2][0],bool_L[1][1],bool_L[0][2]] == [True, True, True]:
     flag = "Yes"
print(flag)