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:
# -*- coding: utf-8 -*-
a, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, i = map(int, input().split())
n = int(input())
bango = [int(input()) for k in range(n)]
if a in bango and b in bango and c in bango:
    print("Yes")
elif d in bango and e in bango and f in bango:
    print("Yes")
elif g in bango and h in bango and i in bango:
    print("Yes")
elif a in bango and d in bango and g in bango:
    print("Yes")
elif b in bango and e in bango and h in bango:
    print("Yes")
elif c in bango and f in bango and i in bango:
    print("Yes")
elif a in bango and e in bango and i in bango:
    print("Yes")
elif c in bango and e in bango and g in bango:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))

#A_11,A_12,A_13=(int(x) for x in input().split())
#B_11,B_12,B_13=(int(x) for x in input().split())
#C_11,C_12,C_13=(int(x) for x in input().split())
N=int(input())
#A=list(map(int, input().split()))

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

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

else:
    print('No')

Submission status: Accepted

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

# カードの数字を読み込み
for i in range(3):
    string = input()
    for j in range(3):
        a[i][j] = int(string.split()[j])

# N個の数を読み込み
n = int(input())
for i in range(n):
    b.append(int(input()))

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

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

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

Submission status: Accepted

Solution code:
import sys

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

row = A
column = [[] for _ in range(3)]
for i in range(3):
    column[i] = [A[0][i], A[1][i], A[2][i]]
cross = [[A[0][0], A[1][1], A[2][2]], [A[2][0], A[1][1], A[0][2]]]

for i in range(3):
    if set(row[i]) <= set(B) or set(column[i]) <= set(B):
        print('Yes')
        sys.exit()

for i in range(2):
    if set(cross[i]) <= set(B):
        print('Yes')
        sys.exit()
else:
    print('No')

Submission status: Accepted

Solution code:
def resolve():
    a = list(map(int, input().split()))
    a.extend(list(map(int, input().split())))
    a.extend(list(map(int, input().split())))
    n = int(input())
    for i in range(n):
        b = int(input())
        for j in range(len(a)):
            if a[j] == b:
                a[j] = -1
    x1 = a[0:3].count(-1)
    x2 = a[3:6].count(-1)
    x3 = a[6:9].count(-1)
    y1 = a[0:7:3].count(-1)
    y2 = a[1:8:3].count(-1)
    y3 = a[2:9:3].count(-1)
    nn = a[0:9:4].count(-1)
    nn2 = a[2:7:2].count(-1)

    if x1 == 3 or x2 == 3 or x3 == 3 or y1 == 3 or y2 == 3 or y3 == 3 or nn == 3 or nn2 == 3:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
bingo = []

for i in range(3):
    bingo.append(input().split(" "))

n = int(input())

for i in range(n):
    num = input()
    for j in range(3):
        for k in range(3):
            if num == bingo[j][k]:
                bingo[j][k] = 0

result = False

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

if bingo[0][0] == 0 and bingo[1][1] == 0 and bingo[2][2] == 0:
    result = True

if bingo[0][2] == 0 and bingo[1][1] == 0 and bingo[2][0] == 0:
    result = True

if result == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = [a[0], b[0], c[0]]
e = [a[1], b[1], c[1]]
f = [a[2], b[2], c[2]]
g = [a[0], b[1], c[2]]
h = [a[2], b[1], c[0]]

n = int(input())

bs = []
for _ in range(n):
    bs.append(int(input()))

for l in [a, b, c, d, e, f, g, h]:
    if (l[0] in bs) and (l[1] in bs) and (l[2] in bs):
        print("Yes")
        break
else:
    print("No")

Submission status: Accepted

Solution code:

import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)


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


def II():
    return int(input())


directions = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact


def serch(x, count):
    #print("top", x, count)

    for d in directions:
        nx = d+x
        # print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)

    return count


field = []
for i in range(3):
    field.append(acinput())

N = int(input())


def chk(x):
    for i in range(3):
        for j in range(3):
            if field[i][j] == x:
                field[i][j] = -1


for i in range(N):
    chk(II())

#print(field)

for i in range(3):
    state = False
    for j in range(3):
        if field[i][j] != -1:
            break
        if j == 2:
            print("Yes")
            sys.exit()

for j in range(3):
    state = False
    for i in range(3):
        if field[i][j] != -1:
            break
        if i == 2:
            print("Yes")
            sys.exit()

state = False
for i in range(3):
    if field[i][i] != -1:
        break
    if i == 2:
        print("Yes")
        sys.exit()



for i in range(3):
    if field[2-i][i] != -1:
        break
    if i == 2:
        print("Yes")
        sys.exit()

print("No")

Submission status: Accepted

Solution code:
l=[[]]*3
for k in range(3):
  l[k]=list(map(int,input().split()))
n=int(input())
ll=[[0]*3 for i in range(3)]
for k in range(n):
  i=int(input())
  for j in range(3):
    if i in l[j]:
      ll[j][l[j].index(i)]=1
a=0
if ll[0][0]==1:
  if ll[0][1]==1 and ll[0][2]==1:
    a=1
  if ll[1][1]==1 and ll[2][2]==1:
    a=1
  if ll[1][0]==1 and ll[2][0]==1:
    a=1
if ll[0][1]==1 and ll[1][1]==1 and ll[2][1]==1:
  a=1
if ll[0][2]==1:
  if ll[1][1]==1 and ll[2][0]==1:
    a=1
  if ll[1][2]==1 and ll[2][2]==1:
    a=1
if ll[1][0]==1:
  if ll[1][1]==1 and ll[1][2]==1:
    a=1
if ll[2][0]==1:
  if ll[2][1]==1 and ll[2][2]==1:
    a=1
if a==0:
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
# import sys
# # sys.setrecursionlimit(1000000)
# input = sys.stdin.readline
# # from bisect import *
# from collections import *
# # from heapq import *
# # INF = 500000
# mod = 10**9+7
#
# class UnionFind:
#
#     def __init__(self, n):
#         self.n = n
#         self.par = [i for i in range(n)]
#         self.height = [0] * n
#         self.size = [1] * n
#
#     def find(self, x):
#         if self.par[x] == x:
#             return x
#         self.par[x] = self.find(self.par[x])
#         return self.par[x]
#
#     def getsize(self, x):
#         return self.size[self.find(x)]
#
#     def unite(self, x, y):
#         x, y = self.find(x), self.find(y)
#         if x == y:
#             return
#         if self.height[x] < self.height[y]:
#             self.par[x] = y
#             self.size[y] += self.size[x]
#         else:
#             self.par[y] = self.par[x]
#             self.size[x] += self.size[y]
#             if self.height[x] == self.height[x]:
#                 self.height[x] += 1
#
#     def same(self, x, y):
#         return self.find(x) == self.find(y)
#
# N, M, K = map(int, input().split())
# es = [[] for i in range(N)]
# for i in range(M):
#     u, v = map(int, input().split())
#     u -= 1
#     v -= 1
#     es[u].append(v)
#     es[v].append(u)
# uf = UnionFind(N)
# g = [-1]*N
# def dfs(v, num):
#     g[v] = num
#     for u in es[v]:
#         if g[u] == -1:
#             uf.unite(v, u)
#             dfs(u, num)
# num = 0
# for v in range(N):
#     if g[v] == -1:
#         dfs(v, num)
#         num += 1
# ans = [uf.getsize(v)-len(es[v])-1 for v in range(N)]
# for i in range(K):
#     u, v = map(int, input().split())
#     u -= 1
#     v -= 1
#     if uf.same(u, v):
#         ans[u] -= 1
#         ans[v] -= 1
# print(*ans)

A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
for i in range(N):
    x = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == x:
                A[i][j] = 0
flg = 0
for i in range(3):
    for j in range(3):
        if sum(A[i]) == 0:
            flg = 1
for j in range(3):
    s = 0
    for i in range(3):
        s += A[i][j]
    if s == 0:
        flg = 1
flg |= 0 == sum([A[i][i] for i in range(3)])
flg |= 0 == sum([A[2-i][i] for i in range(3)])
if flg:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a = []
for i in range(3):
         a.append( list(map(int,input().split())))
n = int(input())
b = [int(input()) for j in range(n)]
for k in range(3):
         for l in range(3):
                  for m in range(n):
                           if a[k][l] == b[m]:
                                    a[k][l] = -1
if a[0][0] == a[0][1] == a[0][2] == -1 or  a[1][0] == a[1][1] == a[1][2] == -1 or  a[2][0] == a[2][1] == a[2][2] == -1 or  a[0][0] == a[1][0] == a[2][0] == -1 or  a[0][1] == a[1][1] == a[2][1] == -1 or  a[0][2] == a[1][2] == a[2][2] == -1 or  a[0][0] == a[1][1] == a[2][2] == -1 or  a[0][2] == a[1][1] == a[2][0] == -1 :
         print("Yes")
else:
         print("No")

Submission status: Accepted

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

for i in range(N):
  for j in range(3):
    if A[j] == b[i]:
      A[j] = 0
    if B[j] == b[i]:
      B[j] = 0
    if C[j] == b[i]:
      C[j] = 0
      
if max(A) == 0 or max(B) == 0 or max(C) == 0:
  print("Yes")
elif A[0] == 0 and B[0] == 0 and C[0] == 0:
  print("Yes")
elif A[1] == 0 and B[1] == 0 and C[1] == 0:
  print("Yes")
elif A[2] == 0 and B[2] == 0 and C[2] == 0:
  print("Yes")
elif A[0] == 0 and B[1] == 0 and C[2] == 0:
  print("Yes")
elif A[2] == 0 and B[1] == 0 and C[0] == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
b = []
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
b.append(a1)
b.append(a2)
b.append(a3)
n = int(input())
c = [int(input()) for i in range(n)]
a = []
d = [[0 for i in range(3)] for j in range(3)]
flg = False
for i in c:
	for j in range(3):
		for k in range(3):
			if b[j][k] == i:
				d[j][k] = 1
	for l in range(3):
		if d[l][0] == 1 and d[l][1] == 1 and d[l][2] == 1:
			flg = True
		if d[0][l] == 1 and d[1][l] == 1 and d[2][l] == 1:
			flg = True
	if d[0][0] == 1 and d[1][1] == 1 and d[2][2] == 1:
		flg = True
	if d[0][2] == 1 and d[1][1] == 1 and d[2][0] == 1:
		flg = True
	if flg == True:
		print ("Yes")
		exit()
print ("No")

Submission status: Accepted

Solution code:
# B - Bingo
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
s3 = list(map(int, input().split()))

n = (int)(input())
result = [[False, False, False], [False, False, False], [False, False, False]]

for i in range(0, n):
    b = (int)(input())

    if s1[0] == b:
        result[0][0] = True
    elif s1[1] == b:
        result[0][1] = True
    elif s1[2] == b:
        result[0][2] = True

    if s2[0] == b:
        result[1][0] = True
    elif s2[1] == b:
        result[1][1] = True
    elif s2[2] == b:
        result[1][2] = True

    if s3[0] == b:
        result[2][0] = True
    elif s3[1] == b:
        result[2][1] = True
    elif s3[2] == b:
        result[2][2] = True

if result[0][0] & result[0][1] & result[0][2]:
    print('Yes')
elif result[1][0] & result[1][1] & result[1][2]:
    print('Yes')
elif result[2][0] & result[2][1] & result[2][2]:
    print('Yes')
elif result[0][0] & result[1][0] & result[2][0]:
    print('Yes')
elif result[0][1] & result[1][1] & result[2][1]:
    print('Yes')
elif result[0][2] & result[1][2] & result[2][2]:
    print('Yes')
elif result[0][0] & result[1][1] & result[2][2]:
    print('Yes')
elif result[0][2] & result[1][1] & result[2][0]:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

N=int(input())

for _ in range(N):
    temp=int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==temp:
                ans[i][j]=1

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

for i in range(3):
    temp=0
    for item in ans:
        temp+=item[i]
    if temp==3:
        print("Yes")
        exit()

if ans[0][0]+ans[1][1]+ans[2][2]==3 or ans[0][2]+ans[1][1]+ans[2][0]==3:
    print("Yes")
    exit()

print("No")

Submission status: Accepted

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

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

    flag = False
    for i in range(3):
        for j in range(3):
                if(j+2 < 3 and A[i][j] == 0 and A[i][j+1] == 0 and A[i][j+2] == 0):
                    flag = True
                    break
                if(i+2 < 3 and A[i][j] == 0 and A[i+1][j] == 0 and A[i+2][j] == 0):
                    flag = True
                    break
                if(i+2 < 3 and j+2 < 3 and A[i][j] == 0 and A[i+1][j+1] == 0 and A[i+2][j+2] == 0):
                    flag = True
                    break
                if(i-2 >= 0 and j-2 >= 0 and A[i][j] == 0 and A[i-1][j-1] == 0 and A[i-2][j-2] == 0):
                    flag = True
                    break
                if(i-2 >= 0 and j+2 < 3 and A[i][j] == 0 and A[i-1][j+1] == 0 and A[i-2][j+2] == 0):
                    flag = True
                    break
                if(i+2 < 3 and j-2 >= 0 and A[i][j] == 0 and A[i+1][j-1] == 0 and A[i+2][j-2] == 0):
                    flag = True
                    break
        if(flag):
            break

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

if __name__ == "__main__":
    main()

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())
r1 = {a11, a12, a13}
r2 = {a21, a22, a23}
r3 = {a31, a32, a33}
c1 = {a11, a21, a31}
c2 = {a12, a22, a32}
c3 = {a13, a23, a33}
cr1 = {a11, a22, a33}
cr2 = {a31, a22, a13}
A = [r1, r2, r3, c1, c2, c3, cr1, cr2]

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


for C in A:
    if C.issubset(B):
        print('Yes')
        quit()

print('No')

Submission status: Accepted

Solution code:
bingo = list(map(int, input().split()))
bingo.extend(list(map(int, input().split())))
bingo.extend(list(map(int, input().split())))

N = int(input())

res = "No"

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

  for (index, value) in enumerate(bingo):
    if value == num:
      bingo[index] = 0


## 斜め判定
if bingo[0] == bingo[4] == bingo[8] == 0 or bingo[2] == bingo[4] == bingo[6] == 0:
  res = "Yes"

else:
  ## 縦判定
  for i in range(3):
    if (bingo[i] == bingo[i+3] == bingo[i+6] == 0 or bingo[3 * i] == bingo[3 * i + 1] == bingo[3 * i + 2] == 0):
      res = "Yes"
      break
  
print(res)

Submission status: Accepted

Solution code:
l = [list(map(int, input().split())) for _ in range(3)]
#print(l)
n = int(input())
bingo = [int(input()) for _ in range(n)]
#print(bingo)

for i in range(3):
    for j in range(3):
        if l[i][j] in bingo:
            l[i].pop(j)
            l[i].insert(j,0)
#print(l)

if len(set(l[0])) == 1 or len(set(l[1])) == 1 or len(set(l[2])) == 1:
    print('Yes')
    exit()

if l[0][0] == l[1][0] == l[2][0] or l[0][1] == l[1][1] == l[2][1] or l[0][2] == l[1][2] == l[2][2]:
    print('Yes')
    exit()

if l[0][0] == l[1][1] == l[2][2] or l[0][2] == l[1][1] == l[2][0]:
    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()))
N=int(input())
for i in range(N):
    b=int(input())
    if b in A1:
        x=A1.index(b)
        A1[x]=0
    elif b in A2:
        x=A2.index(b)
        A2[x]=0
    elif b in A3:
        x=A3.index(b)
        A3[x]=0
D=[sum(A1),sum(A2),sum(A3)]
D.append(A1[0]+A2[0]+A3[0])
D.append(A1[1]+A2[1]+A3[1])
D.append(A1[2]+A2[2]+A3[2])
D.append(A1[0]+A2[1]+A3[2])
D.append(A1[2]+A2[1]+A3[0])
if 0 in D:
    print("Yes")
else:print("No")

Submission status: Accepted

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

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

if A[0]==[0,0,0] or A[1]==[0,0,0] or A[2]==[0,0,0] or A[0][0]==A[1][0]==A[2][0]==0 or A[0][1]==A[1][1]==A[2][1]==0 or A[0][2]==A[1][2]==A[2][2]==0 or A[0][0]==A[1][1]==A[2][2]==0 or A[0][2]==A[1][1]==A[2][0]==0:
	print('Yes')
else:
	print('No')

Submission status: Accepted

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

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

#ゴミコードだなぁ……

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

Submission status: Accepted

Solution code:
up = list(input().split())
mid = list(input().split())
down = list(input().split())

table = [up, mid, down]

nums = []
while True:
    try:
        nums.append(input())
    except EOFError:
        break

for i in range(3):
  for j in range(3):
    if table[i][j] in nums:
      table[i][j] = 'T'

flag = False

for i in range(3):
  if table[i].count('T') == 3:
    print('Yes')
    flag = True
    if flag == True:
      break

if flag == False:
  if table[0][0]=='T' and table[1][0]=='T' and table[2][0]=='T':
    print('Yes')
    flag = True
    
if flag == False:
  if table[0][1]=='T' and table[1][1]=='T' and table[2][1]=='T':
    print('Yes')
    flag = True
    
if flag == False:
  if table[0][2]=='T' and table[1][2]=='T' and table[2][2]=='T':
    print('Yes')
    flag = True

if flag == False:
  if table[0][0]=='T' and table[1][1]=='T' and table[2][2]=='T':
    print('Yes')
    flag = True
    
if flag == False:
  if table[0][2]=='T' and table[1][1]=='T' and table[2][0]=='T':
    print('Yes')
    flag = True
    
if flag == False:
  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 = [int(input()) for i in range(N)]

flag = True
for i in range(3):
    if (A1[0] in B) and (A1[1] in B) and (A1[2] in B):
        print('Yes')
        flag = False
        break
    elif (A2[0] in B) and (A2[1] in B) and (A2[2] in B):
        print('Yes')
        flag = False
        break
    elif (A3[0] in B) and (A3[1] in B) and (A3[2] in B):
        print('Yes')
        flag = False
        break
    elif (A1[i] in B) and (A2[i] in B) and (A3[i] in B):
        print('Yes')
        flag = False
        break 
    elif (A1[0] in B) and (A2[1] in B) and (A3[2] in B):
        print('Yes')
        flag = False
        break 
    elif (A1[2] in B) and (A2[1] in B) and (A3[0] in B):
        print('Yes')
        flag = False
        break 
if flag == True:
    print('No')

Submission status: Accepted

Solution code:
A1=input().split()
A2=input().split()
A3=input().split()
N = int(input())
b = list(input() for i in range(N))

ListA = [A1,A2,A3]
for i in range(3):
  if set(ListA[i]).issubset(b):
      print("Yes")
      exit()

B1 = [A1[0],A2[0],A3[0]]
B2 = [A1[1],A2[1],A3[1]]
B3 = [A1[2],A2[2],A3[2]]
ListB = [B1,B2,B3]

for i in range(3):
    if set(ListB[i]).issubset(b):
      print("Yes")
      exit()
    
C1 = [A1[0],A2[1],A3[2]]
C2 = [A1[2],A2[1],A3[0]]
ListC = [C1,C2]

for i in range(2):
    if set(ListC[i]).issubset(b):
      print("Yes")
      exit()

print("No")

Submission status: Accepted

Solution code:
a = [int(j) for i in range(3) for j in input().split(' ')]
n = int(input())
nn = [int(input()) for i in range(n)]

cnt = 0
for ni in nn:
  if ni in a:
    cnt += 1
    a[a.index(ni)] = 0

judge = "No"
for i in range(3):
  if sum(a[i::3])==0 or sum(a[i*3:i*3+3])==0:
    judge = "Yes"
    
if sum(a[::4])==0 or (a[2]+a[4]+a[6])==0:
  judge = "Yes"
  
print(judge)

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

A = [a11,a12,a13,a21,a22,a23,a31,a32,a33]


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

if \
(A[0]+A[1]+A[2]) *\
(A[3]+A[4]+A[5]) *\
(A[6]+A[7]+A[8]) *\
(A[0]+A[3]+A[6]) *\
(A[1]+A[4]+A[7]) *\
(A[2]+A[5]+A[8]) *\
(A[0]+A[4]+A[8]) *\
(A[2]+A[4]+A[6])  == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

yoko_1 = [int(i) for i in input().split()]
yoko_2 = [int(i) for i in input().split()]
yoko_3 = [int(i) for i in input().split()]
tate_1 = [yoko_1[0], yoko_2[0], yoko_3[0]]
tate_2 = [yoko_1[1], yoko_2[1], yoko_3[1]]
tate_3 = [yoko_1[2], yoko_2[2], yoko_3[2]]
naname_1 = [yoko_1[0], yoko_2[1], yoko_3[2]]
naname_2 = [yoko_1[2], yoko_2[1], yoko_3[0]]

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

def bingo(card, call):
    cnt = 0
    for i in card:
        for j in call:
            if i == j:
                cnt += 1
                break
    if cnt == 3:
        return 1
    else:
        return 0

if bingo(yoko_1, bs) + \
bingo(yoko_2, bs) + \
bingo(yoko_3, bs) + \
bingo(tate_1, bs) + \
bingo(tate_2, bs) + \
bingo(tate_3, bs) + \
bingo(naname_1, bs) + \
bingo(naname_2, bs) > 0:
    print("Yes")
else:
    print("No")

# print(bingo(yoko_1, bs))

Submission status: Accepted

Solution code:
ans="No"
A=3
t=[0]*A
x=[0]*A
y=[0]*A
for i in range(A):
    t[i], x[i], y[i] = map(int, input().split())
#print(x[1])

N=int(input())
S=[]
for _ in range(N):
  S.append(input())
#print(S[0])
S1=[int(s) for  s in S]
for i in range(A):
  if t[i] in S1:
    t[i]=0
  if x[i] in S1:
    x[i]=0
  if y[i] in S1:
    y[i]=0
#print(t[0])
if t.count(0)==3:
  ans="Yes"
if x.count(0)==3:
  ans="Yes"
if y.count(0)==3:
  ans="Yes"
if t[0]==0 and x[1]==0 and y[2]==0:
  ans="Yes"
if t[2]==0 and x[1]==0 and y[0]==0:
  ans="Yes"
if t[0]==0 and x[0]==0 and y[0]==0:
  ans="Yes"
if t[1]==0 and x[1]==0 and y[1]==0:
  ans="Yes"
if t[2]==0 and x[2]==0 and y[2]==0:
  ans="Yes"
print(ans)

Submission status: Accepted

Solution code:
a = [input().split() for l in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]
ans = 'No'
for i in range(3):
        for j in range(3):
                a[i][j] = int(a[i][j])
                for k in range(N):
                        if a[i][j] == b[k]:
                                a[i][j] = 0
for i in range(3):
        if a[i][0] + a[i][1] + a[i][2] == 0:
                ans = 'Yes'
for i in range(3):
        if a[0][i] + a[1][i] + a[2][i] == 0:
                ans = 'Yes'
if a[0][0] + a[1][1] + a[2][2] == 0:
        ans = 'Yes'
if a[0][2] + a[1][1] + a[2][0] == 0:
        ans = 'Yes'


print(ans)

Submission status: Accepted

Solution code:
def haha():    
    A=[]
    for i in range(3):
        A.extend(list(map(int, input().split())))
    N = int(input())
    n=[]
    while N>0:
        inp = int(input())
        if inp in A:
            n.append(inp)
        N-=1

    A = [A[:3],A[3:6],A[6:9], [A[0], A[4], A[8]], [A[2], A[4], A[6]], [A[0], A[3], A[6]], [A[1], A[4], A[7]], [A[2], A[5], A[8]]]

    for ele in A:
        if ele[0] in n and ele[1]in n and ele[2]in n:
            return 'Yes'
    return 'No'

print(haha())

Submission status: Accepted

Solution code:
a = [list(map(int,input().split())) for i in range(3)]
for i in range(int(input())):
  i = int(input())
  bo = True
  while(bo):
    for k,a_1 in enumerate(a[0]):
      if a_1 == i:
        a[0][k] = None
        bo = False
    for k,a_2 in enumerate(a[1]):
      if a_2 == i:
        a[1][k] = None
        bo = False
    for k,a_3 in enumerate(a[2]):
      if a_3 == i:
        a[2][k] = None
        bo = False
    bo = False
s = "No"
while(s == "No"):
  if (a[0][0] == a[1][1]) and (a[1][1] == a[2][2]):
    s = "Yes"
  if (a[2][0] == a[1][1]) and (a[1][1] == a[0][2]):
    s = "Yes"
  for l in a:
    if len(set(l)) == 1:
      s = "Yes"
  for i in range(3):
    if len(set([a[0][i], a[1][i], a[2][i]])) == 1:
      s = "Yes"
  break
print(s)

Submission status: Accepted

Solution code:
def b():
    a = {}
    for i in range(3):
        arr = list(map(int, input().split()))
        for j in range(3):
            a[i, j] = arr[j]

    N = int(input())
    for n in range(N):
        b = int(input())
        keys = [k for k, v in a.items() if v == b]
        # print(b, keys)
        for l in keys:
            a[l] = 0

    # print(a)
    for i in range(3):
        if (
            (a[i, 0] + a[i, 1] + a[i, 2] == 0)
            or (a[0, i] + a[1, i] + a[2, i] == 0)
        ):
            print('Yes')
            return
    if (
        (a[0, 0] + a[1, 1] + a[2, 2] == 0)
        or (a[0, 2] + a[1, 1] + a[2, 0] == 0)
    ):
        print('Yes')
        return

    print('No')
    return


##########
b()

Submission status: Accepted

Solution code:
l = []
l.append(list(map(int, input().split())))
l.append(list(map(int, input().split())))
l.append(list(map(int, input().split())))
# print(l)

x = int(input())
for i in range(x):
  n = int(input())
  for x in range(3):
    for y in range(3):
      if l[x][y] == n:
        l[x][y] = -1
# print(l)
isBingo = False
if l[0][0] * l[0][1] * l[0][2] == -1:
  isBingo = True
if l[1][0] * l[1][1] * l[1][2] == -1:
  isBingo = True
if l[2][0] * l[2][1] * l[2][2] == -1:
  isBingo = True
if l[0][0] * l[1][0] * l[2][0] == -1:
  isBingo = True
if l[0][1] * l[1][1] * l[2][1] == -1:
  isBingo = True
if l[0][2] * l[1][2] * l[2][2] == -1:
  isBingo = True
if l[0][0] * l[1][1] * l[2][2] == -1:
  isBingo = True
if l[2][0] * l[1][1] * l[0][2] == -1:
  isBingo = True
if isBingo:
  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] = 0
flag = False
for i in range(3):
    tmp = 0
    for j in range(3):
        tmp += bingo[i][j]
    if tmp == 0:
        flag = True
for j in range(3):
    tmp = 0
    for i in range(3):
        tmp += bingo[i][j]
    if tmp == 0:
        flag = True
if bingo[0][0] + bingo[1][1] + bingo[2][2] == 0:
    flag = True
if bingo[0][2] + bingo[1][1] + bingo[2][0] == 0:
    flag = True
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a=[]
for t in range(3):
    d,e,f=map(int,input('').split(' '))
    a.append([d,e,f])

n=int(input(''))
b=[]
for t in range(n):
    r=int(input(''))
    b.append(r)

hit=[[0,0,0],[0,0,0],[0,0,0]]

for t in b:
    for i in range(3):
        for j in range(3):
            if a[i][j]==t:
                hit[i][j]=1

h=0
if hit[0][0]==1 and hit[0][1]==1 and hit[0][2]==1:
    h=1
elif hit[1][0]==1 and hit[1][1]==1 and hit[1][2]==1:
    h=1
elif hit[2][0]==1 and hit[2][1]==1 and hit[2][2]==1:
    h=1
elif hit[0][0]==1 and hit[1][0]==1 and hit[2][0]==1:
    h=1
elif hit[0][1]==1 and hit[1][1]==1 and hit[2][1]==1:
    h=1
elif hit[0][2]==1 and hit[1][2]==1 and hit[2][2]==1:
    h=1
elif hit[0][0]==1 and hit[1][1]==1 and hit[2][2]==1:
    h=1
elif hit[0][2]==1 and hit[1][1]==1 and hit[2][0]==1:
    h=1
else:
    h=0

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