Problem:


Score : 200 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

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

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

1 \leq N \leq 10

1 \leq b_i \leq 100

b_i \neq b_j (i \neq j)

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

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

Sample Output 1

Yes

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

Sample Input 2

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

Sample Output 2

No

We will mark nothing.

Sample Input 3

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

Sample Output 3

Yes

We will mark all the squares.



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


Sample output:
Yes

Submission status: Accepted

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

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

def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    ans=[[1,2,3],[4,5,6],[7,8,9]]
    for i in range(N):
        for j in range(3):
            for k in range(3):
                if b[i]==A[j][k]:
                    ans[j][k]="."
    for i in range(3):
        if len(set(ans[i]))==1:
            print(YES)
            exit()
        if ans[0][i]==ans[1][i]==ans[2][i]:
            print(YES)
            exit()
    if ans[0][0]==ans[1][1]==ans[2][2]:
        print(YES)
        exit()
    if ans[0][2]==ans[1][1]==ans[2][0]:
        print(YES)
        exit()
    print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
arr = []
ans = []
for i in range(3):
  arr.extend(list(map(int,input().split())))
N = int(input())
for j in range(N):
  num = int(input())
  if num in arr:
    ans.append(arr.index(num))
ans = set(ans)
if (set([0,1,2])<=ans)or(set([3,4,5])<=ans)or(set([6,7,8])<=ans)or(set([0,3,6])<=ans)or(set([1,4,7])<=ans)or(set([2,5,8])<=ans)or(set([0,4,8])<=ans)or(set([2,4,6])<=ans):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
def main():
    A=[]
    for _ in range(3):
        a1,a2,a3=map(int,input().split())
        A.append(a1); A.append(a2); A.append(a3)
    Flag=[False]*9
    n=int(input())
    B=[int(input().strip()) for _ in range(n)]
    for b in B:
        for i,a in enumerate(A):
            if b==a:
                Flag[i]=True
    if Flag[0] and Flag[1] and Flag[2]:
        return 'Yes'
    if Flag[3] and Flag[4] and Flag[5]:
        return 'Yes'
    if Flag[6] and Flag[7] and Flag[8]:
        return 'Yes'
    if Flag[0] and Flag[3] and Flag[6]:
        return 'Yes'
    if Flag[1] and Flag[4] and Flag[7]:
        return 'Yes'
    if Flag[2] and Flag[5] and Flag[8]:
        return 'Yes'
    if Flag[0] and Flag[4] and Flag[8]:
        return 'Yes'
    if Flag[2] and Flag[4] and Flag[6]:
        return 'Yes'
    return 'No'

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

Submission status: Accepted

Solution code:
import numpy as np

grid = []
for i in range(3):
    array = list(map(int,input().strip().split()))
    grid.append(array)
    
grid = np.array(grid)

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

for i in s:
    grid = np.where(grid==i,0,grid)
    
#print(grid)
    
if grid[0][0]==0 and grid[0][1]==0 and grid[0][2]==0:
    han = "Yes"
elif grid[1][0]==0 and grid[1][1]==0 and grid[1][2]==0:
    han = "Yes"
elif grid[2][0]==0 and grid[2][1]==0 and grid[2][2]==0:
    han = "Yes"
elif grid[0][0]==0 and grid[1][0]==0 and grid[2][0]==0:
    han = "Yes"
elif grid[0][1]==0 and grid[1][1]==0 and grid[2][1]==0:
    han = "Yes"
elif grid[0][2]==0 and grid[1][2]==0 and grid[2][2]==0:
    han = "Yes"
elif grid[0][0]==0 and grid[1][1]==0 and grid[2][2]==0:
    han = "Yes"
elif grid[0][2]==0 and grid[1][1]==0 and grid[2][0]==0:
    han = "Yes"
else:
    han = "No"
print(han)

Submission status: Accepted

Solution code:
#python3

def main():
    a = []
    for _ in range(3):
        x, y, z = map(int, input().split())
        a.append((x, y, z))
    n = int(input())
    b = []
    for _ in range(n):
        b.append(int(input()))

    g = [[0 for _ in range(3)] for _ in range(3)]

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


    bingo = False
    #横
    for i in range(3):
        if sum(g[i]) == 3:
            bingo = True
    #縦
    if g[0][0]+g[1][0]+g[2][0] == 3:
        bingo = True
    if g[0][1]+g[1][1]+g[2][1] == 3:
        bingo = True
    if g[0][2]+g[1][2]+g[2][2] == 3:
        bingo = True 
    #斜め
    if g[0][0]+g[1][1]+g[2][2] == 3:
        bingo = True
    if g[0][2]+g[1][1]+g[2][0] == 3:
        bingo = True
    
    if bingo:
        print('Yes')
    else:
        print('No')
main()

Submission status: Accepted

Solution code:
A = [0]*3
for i in range(0,3):
    A[i] = list(map(int, input().split()))
N = int(input())
b = [int(input()) for i in range(N)]
 
c = 0
while c < N:
    for i in range(0,3):
      for j in range(0,3):
        if b[c] == A[i][j]:
          A[i][j] = 0
    c += 1
            
 
hoge = [0]*3                
for i in range(0,3):
  for j in range(0,3):
    hoge[i] += A[i][j]#横
 
fuga = [0]*3
for i in range(0,3):
  for j in range(0,3):
    fuga[i] += A[j][i]
    
 
hogehoge = A[0][0] + A[1][1] + A[2][2]
fugafuga = A[0][2] + A[1][1] + A[0][2]
 
if hoge[0] == 0:
    print("Yes")
elif hoge[1] == 0:
    print("Yes")
elif hoge[2] == 0:
    print("Yes")
elif fuga[0] == 0:
    print("Yes") 
elif fuga[1] == 0:
    print("Yes") 
elif fuga[2] == 0:
    print("Yes") 
elif hogehoge == 0:
  print("Yes")
elif fugafuga == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
bingo=[]
for i in range(3):
    a_1,a_2,a_3=map(int,input().split())
    bingo.append(a_1)
    bingo.append(a_2)
    bingo.append(a_3)
n=int(input())
for j in range(n):
    b=int(input())
    for k in range(9):
        if(bingo[k]==b):
            bingo[k]=0
a_1=[]
a_1.append(bingo[0])
a_1.append(bingo[1])
a_1.append(bingo[2])
a_2=[]
a_2.append(bingo[3])
a_2.append(bingo[4])
a_2.append(bingo[5])
a_3=[]
a_3.append(bingo[6])
a_3.append(bingo[7])
a_3.append(bingo[8])
a_4=[]
a_4.append(bingo[0])
a_4.append(bingo[3])
a_4.append(bingo[6])
a_5=[]
a_5.append(bingo[1])
a_5.append(bingo[4])
a_5.append(bingo[7])
a_6=[]
a_6.append(bingo[2])
a_6.append(bingo[5])
a_6.append(bingo[8])
a_7=[]
a_7.append(bingo[0])
a_7.append(bingo[4])
a_7.append(bingo[8])
a_8=[]
a_8.append(bingo[2])
a_8.append(bingo[4])
a_8.append(bingo[6])
if(a_1==[0,0,0]):
    print("Yes")
elif(a_2==[0,0,0]):
    print("Yes")
elif(a_3==[0,0,0]):
    print("Yes")
elif(a_4==[0,0,0]):
    print("Yes")
elif(a_5==[0,0,0]):
    print("Yes")
elif(a_6==[0,0,0]):
    print("Yes")
elif(a_7==[0,0,0]):
    print("Yes")
elif(a_8==[0,0,0]):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

for i in range(3):
    yoko=0
    for j in range(3):
        if a[i][j]==0:
            yoko+=1
            if yoko == 3:
                print("Yes")
                exit()
if (a[0][0] == 0 and a[1][1] == 0 and a[2][2]==0) or (a[0][2] == 0 and a[1][1] == 0 and a[2][0]==0):
    print("Yes")
    exit()
for i in range(3):
    tate=0
    for j in range(3):
        if a[j][i]==0:
            tate+=1
            if tate == 3:
                print("Yes")
                exit()
print("No")

Submission status: Accepted

Solution code:
import sys
bingo = [[],[],[]]
 
for i in range(3):
  a, b, c = map(int,input().split())
  bingo[i].append(a)
  bingo[i].append(b)
  bingo[i].append(c)
  
N = int(input())
  
for i in range(N):
  S = int(input())
  for j in range(3):
    if S in bingo[j]:
      for k in range(3):
        if S == bingo[j][k]:
          bingo[j][k] = 'ok'
          
ANS = 0
 
for i in range(3):
  for j in range(3):
    if bingo[i][j] == 'ok':
      ANS += 1
      if ANS == 3:
        print("Yes")
        sys.exit()
  ANS = 0
 
for i in range(3):
  for j in range(3):
    if bingo[j][i] == 'ok':
      ANS += 1
      if ANS == 3:
        print("Yes")
        sys.exit()
  ANS = 0
 
if bingo[1][1] == 'ok':
  if bingo[0][0] == 'ok' and bingo[2][2] == 'ok':
    print("Yes")
    sys.exit()
  elif bingo[0][2] == 'ok' and bingo[2][0] == 'ok':
    print("Yes")
    sys.exit()
  else:
    print("No")
    sys.exit()
print("No")

Submission status: Accepted

Solution code:
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())

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

import numpy as np
A = np.array([A1, A2, A3])

bingo = np.zeros((3, 3), dtype=bool)
for b in B:
  bingo += (A == b)

if bingo.all(axis=0).any() or \
   bingo.all(axis=1).any() or \
   np.diag(bingo).all() or \
   np.diag(np.fliplr(bingo)).all():
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:

def check(A):
    for i in A:
       if i.count("x") == 3:
           return True
    for n in range(3):
        if A[0][n] == "x" and A[1][n] == "x" and  A[2][n] == "x":
            return True
    if A[0][0] == "x" and A[1][1] == "x" and A[2][2] == "x":
        return True
    if A[0][2] == "x" and A[1][1] == "x" and A[2][0] == "x":
        return True
    
    return False
    
        
        
                
     

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



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

if check(A):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np
a=[[int(j) for j in input().split()] for i in range(3)]
a=np.array(a)

N=int(input())
for n in range(N):
    s=int(input())
    a=np.where(a-s==0,0,a)

for a1 in zip(*a):
    if len(set(a1))==1:
        print("Yes")
        exit(0)
for a1 in a:
    if len(set(a1))==1:
        print("Yes")
        exit(0)
x=np.diag(a)
if len(set(x))==1:
    print("Yes")
    exit(0)
y=np.diag(np.rot90(a))

if len(set(y))==1:
    print("Yes")
    exit(0)
print("No")

Submission status: Accepted

Solution code:
def my_index(l,x):
    if x in l:
        return l.index(x)+1
    else:
        return 0
    
A_1_1,A_1_2,A_1_3=map(int,input().split())
A_2_1,A_2_2,A_2_3=map(int,input().split())
A_3_1,A_3_2,A_3_3=map(int,input().split())
N=int(input())
A=[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]

for i in range(N):
    bi=int(input())
    for j in range(len(A)):
        if A[j]==bi:
            if j==0:
                A_1_1=0
            elif j==1:
                A_1_2=0
            elif j==2:
                A_1_3=0
            elif j==3:
                A_2_1=0
            elif j==4:
                A_2_2=0
            elif j==5:
                A_2_3=0
            elif j==6:
                A_3_1=0
            elif j==7:
                A_3_2=0
            elif j==8:
                A_3_3=0
            else:
                pass
        else:
            pass

bingo_1=[A_1_1,A_1_2,A_1_3]
bingo_2=[A_2_1,A_2_2,A_2_3]
bingo_3=[A_3_1,A_3_2,A_3_3]
bingo_4=[A_1_1,A_2_1,A_3_1]
bingo_5=[A_1_2,A_2_2,A_3_2]
bingo_6=[A_1_3,A_2_3,A_3_3]
bingo_7=[A_1_1,A_2_2,A_3_3]
bingo_8=[A_1_3,A_2_2,A_3_1]

ans=0

if sum(bingo_1)==0:
    ans=1
elif sum(bingo_2)==0:
    ans=1
elif sum(bingo_3)==0:
    ans=1
elif sum(bingo_4)==0:
    ans=1
elif sum(bingo_5)==0:
    ans=1
elif sum(bingo_6)==0:
    ans=1
elif sum(bingo_7)==0:
    ans=1
elif sum(bingo_8)==0:
    ans=1
else:
    ans=0

if ans==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 = [int(input()) for i in range(N)]# ソートを行う

hit = list()

ans = "No"
for i in range(N):
        if b[i] == A[0]:
                hit.append(1)
        if b[i] == A[1]:
                hit.append(2)
        if b[i] == A[2]:
                hit.append(3)
        if b[i] == B[0]:
                hit.append(4)
        if b[i] == B[1]:
                hit.append(5)
        if b[i] == B[2]:
                hit.append(6)
        if b[i] == C[0]:
                hit.append(7)
        if b[i] == C[1]:
                hit.append(8)
        if b[i] == C[2]:
                hit.append(9)

dct = sorted(hit)


if 1 in dct:
        if 2 in dct:
                if 3 in dct:
                        ans = "Yes"
        if 4 in dct:
                if 7 in dct:
                        ans = "Yes"
        if 5 in dct:
                if 9 in dct:
                        ans = "Yes"
if 2 in dct:
        if 5 in dct:
                if 8 in dct:
                        ans = "Yes"

if 3 in dct:
        if 6 in dct:
                if 9 in dct:
                        ans = "Yes"
        if 5 in dct:
                if 7 in dct:
                        ans = "Yes"

if 4 in dct:
        if 5 in dct:
                if 6 in dct:
                        ans = "Yes"

if 7 in dct:
        if 8 in dct:
                if 9 in dct:
                        ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    bingo = [list(map(int, input().split())) for _ in range(3)]
    N = int(input())
    bn = [int(input()) for _ in range(N)]
    hit = [[0] * 3 for _ in range(3)]
    cnt = 0
    hitz = []
    hzb, hb = False, False
    for b in bn:
        for v, i in enumerate(bingo):
            for w, j in enumerate(i):
                if b == j:
                    if j in hit:
                        continue
                    hit[w][v] = 1
                    cnt += 1
    hitz = list(map(list, zip(*hit)))
    for i in hitz:
        if sum(i) == 3:
            hzb = True
            break
    for i in hit:
        if sum(i) == 3:
            hb = True
            break
    if cnt >= 3 and (
        hzb == True
        or hb == True
        or hit[0][0] == hit[1][1] == hit[2][2] == 1
        or hit[0][2] == hit[1][1] == hit[2][0] == 1
    ):
        print("Yes")

    else:
        print("No")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

b = []

for i in range(n):
  b.append(int(input()))


for i in range(len(b)):
  for a_i in range(len(A[0])):
    for a_j in range(len(A[1])):
      if A[a_i][a_j] == b[i]:
        A[a_i][a_j] = 0

ok = 0

# print(all([i == 0 for i in A[0]]))

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

for i in range(3):
  if (A[0][i] == 0 and A[1][i] == 0 and A[2][i] == 0):
    ok += 1

for i in range(3):
  if A[i][i] != 0:
    break
  if i == 2:
    ok += 1

if A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0:
  ok += 1

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

aa = []
aa.append(a1)
aa.append(a2)
aa.append(a3)

a = aa[:]
for _ in range(n):
  for i in range(3):
    for j in range(3):
      if aa[i][j] == b[_]:
        a[i][j] = 0

if a[0][0] == a[0][1] and a[0][1] == a[0][2] :
  print("Yes")
elif a[1][0] == a[1][1] and a[1][1] == a[1][2] :
  print("Yes")
elif a[2][0] == a[2][1] and a[2][1] == a[2][2] :
  print("Yes")
elif a[0][0] == a[1][0] and a[1][0] == a[2][0]:
  print("Yes")
elif a[0][1] == a[1][1] and a[1][1] == a[2][1]:
  print("Yes")
elif a[0][2] == a[1][2] and a[1][2] == a[2][2]:
  print("Yes")
elif a[0][0] == a[1][1] and a[1][1] == a[2][2]:
  print("Yes")
elif a[0][2] == a[1][1] and a[1][1] == a[2][0]:
  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()))
result = 'No'

n = int(input())
for i in range(n):
	In = int(input())
    
	a1 = ['' if a1[j] == In else a1[j] for j in range(3)]
	a2 = ['' if a2[j] == In else a2[j] for j in range(3)]
	a3 = ['' if a3[j] == In else a3[j] for j in range(3)]
    
# tate
for i in range(3):
	if a1[i] == '' and a2[i] == '' and a3[i] == '':
		result = 'Yes'
		break
# yoko
if a1.count('') == 3:
		result = 'Yes'
if a2.count('') == 3:
		result = 'Yes'
if a3.count('') == 3:
		result = 'Yes'

# naname
if a1[0] == '' and a2[1] == '' and a3[2] == '':
		result = 'Yes'
    
if a1[2] == '' and a2[1] == '' and a3[0] == '':
		result = 'Yes'
print(result)

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, x = map(int, input().split())
num_count = int(input())
number_list = [0] * num_count
for i in range(num_count):
    number_list[i] = int(input())

bingo_map = [[a, b, c], [d, e, f], [g, h, x]]
bingo_answer = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

def bingo(bingo_map, number_list):
    for number in number_list:
        for i, bingo_row in enumerate(bingo_map):
            if number in bingo_row:
                for j, bingo_number in enumerate(bingo_row):
                    if bingo_number == number:
                        bingo_answer[i][j] = 1


def check_bingo():
    return (all(bingo_answer[0]) or all(bingo_answer[1]) or all(bingo_answer[2]) or
    all([bingo_answer[0][0], bingo_answer[1][0], bingo_answer[2][0]]) or
    all([bingo_answer[0][1], bingo_answer[1][1], bingo_answer[2][1]]) or
    all([bingo_answer[0][2], bingo_answer[1][2], bingo_answer[2][2]]) or
    all([bingo_answer[0][0], bingo_answer[1][1], bingo_answer[2][2]]) or
    all([bingo_answer[2][0], bingo_answer[1][1], bingo_answer[0][2]]))

bingo(bingo_map, number_list)

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

Submission status: Accepted

Solution code:
import math
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a = []
a.append(a1)
a.append(a2)
a.append(a3)

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

bingo = [ [0 for _ in range(3)] for __ in range(3)]

for bt in b:
  for i, at in enumerate(a1):
    if at == bt:
      bingo[0][i] = 1
  for i, att in enumerate(a2):
    if att == bt:
      bingo[1][i] = 1
  for i, attt in enumerate(a3):
    if attt == bt:
      bingo[2][i] = 1

for l in range(3):
  if sum(bingo[l]) == 3:
    print("Yes")
    quit()
  if bingo[0][l] + bingo[1][l] +bingo[2][l] == 3:
    print("Yes")
    quit()
if bingo[0][0] + bingo[1][1] +bingo[2][2] == 3:
    print("Yes")
    quit()
if bingo[0][2] + bingo[1][1] +bingo[2][0] == 3:
    print("Yes")
    quit()

print("No")

Submission status: Accepted

Solution code:
a = input().split()
a += input().split()
a += input().split()
n = int(input())
b = set([(input()) for i in range(n)])

bingo = False
if set([a[0], a[1], a[2]]).issubset(b):
	bingo = True
if set([a[3], a[4], a[5]]).issubset(b):
	bingo = True
if set([a[6], a[7], a[8]]).issubset(b):
	bingo = True
if set([a[0], a[3], a[6]]).issubset(b):
	bingo = True
if set([a[1], a[4], a[7]]).issubset(b):
	bingo = True
if set([a[2], a[5], a[8]]).issubset(b):
	bingo = True
if set([a[0], a[4], a[8]]).issubset(b):
	bingo = True
if set([a[2], a[4], a[6]]).issubset(b):
	bingo = True
if bingo:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
def main():
    A11, A12, A13 = map(int, input().split())
    A21, A22, A23 = map(int, input().split())
    A31, A32, A33 = map(int, input().split())
    N = int(input())
    #N, *b_list = map(int, open(0).read().split())
    b_list = []
    for i in range(1,N+1) :
        bi = int(input())
        b_list.append(bi)
    if A11 in b_list and A12 in b_list and A13 in b_list :
        print ("Yes")
    elif A21 in b_list and A22 in b_list and A23 in b_list :
        print("Yes")
    elif A31 in b_list and A32 in b_list and A33 in b_list :
        print("Yes")
    elif A11 in b_list and A21 in b_list and A31 in b_list :
        print("Yes")
    elif A12 in b_list and A22 in b_list and A32 in b_list :
        print("Yes")
    elif A13 in b_list and A23 in b_list and A33 in b_list :
        print("Yes")
    elif A11 in b_list and A22 in b_list and A33 in b_list :
        print("Yes")
    elif A13 in b_list and A22 in b_list and A31 in b_list :
        print("Yes")
    else :
        print("No")

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    A=[[] for _ in range(3)]
    for i in range(3):
        A[i]=LI()
    N=I()
    for _ in range(N):
        b=I()
        for i in range(3):
            for j in range(3):
                if A[i][j]==b:
                    A[i][j]=0
                    
    f=0
                
    for i in range(3):
        a=0
        for j in range(3):
            a+=A[i][j]
        if a==0:
            f=1
            
    for j in range(3):
        a=0
        for i in range(3):
            a+=A[i][j]
        if a==0:
            f=1
    a=0        
    for i in range(3):
        a+=A[i][i]
    if a==0:
        f=1
            
    a=A[2][0]+A[1][1]+A[0][2]
    if a==0:
        f=1
        
    if f==1:
        print("Yes")
    else:
        print("No")
            
    
        
        
            
        
                
        
    

main()

Submission status: Accepted

Solution code:
c = []
A = []
for i in range(3):
  c = input().split()
  c = [int(i) for i in c]
  A.append(c)
N = int(input())
a = 0
b = []
for i in range(N):
  a = int(input())
  b.append(a)
#print('A=', A)
#print('N=', N)
#print('b=', b)

A1 = A[0]
A2 = A[1]
A3 = A[2]
A4 = [A[0][0], A[1][0], A[2][0]]
A5 = [A[0][1], A[1][1], A[2][1]]
A6 = [A[0][2], A[1][2], A[2][2]]
A7 = [A[0][0], A[1][1], A[2][2]]
A8 = [A[0][2], A[1][1], A[2][0]]
#print('A1=', A1, 'A2=', A2, 'A3=', A3, 'A4=', A4, 'A5=', A5, 'A6=', A6, 'A7=', A7, 'A8=', A8)

A_ = [A1, A2, A3, A4, A5, A6, A7, A8]

count = 0

for i in range(8):
  if set(A_[i]) <= set(b):
    count += 1
    
if count > 0:
  print('Yes')
else:
  print('No')

#print('count=', count)

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

A =[a11,a12,a13,a21,a22,a23,a31,a32,a33]
n = int(input())
B =[]
for i in range(n):
    s = int(input())
    B.append(s)

bingo = [[0, 0, 0] for i in range(3)]

for i in B:
    for s, k in enumerate(A):
        if i == k:
            bingo[int(s/3)][s % 3] = 1

if (bingo[0][0] == 1 and bingo[0][1] == 1 and bingo[0][2] ==1 ) or \
(bingo[1][0] == 1 and bingo[1][1] == 1 and bingo[1][2] ==1) or \
    (bingo[2][0] == 1 and bingo[2][1] == 1 and bingo[2][2] ==1) or \
        (bingo[0][0] == 1 and bingo[1][0] == 1 and bingo[2][0] ==1) or \
            (bingo[0][1] == 1 and bingo[1][1] == 1 and bingo[2][1] ==1) or \
                (bingo[0][2] == 1 and bingo[1][2] == 1 and bingo[2][2] ==1) or \
                    (bingo[0][0] == 1 and bingo[1][1] == 1 and bingo[2][2] ==1) or \
                        (bingo[0][2] == 1 and bingo[1][1] == 1 and bingo[2][0] ==1):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# B
a = []
for i in range(3):
    a1, a2, a3 = map(int, input().split())
    a.append(a1)
    a.append(a2)
    a.append(a3)
    
n = int(input())
b = []
for i in range(n):
    bb = int(input())
    b.append(bb)
    
for i in range(n):
    while a.count(b[i]) > 0:
        a[a.index(b[i])] = 0
        
if a[0] == a[3] == a[6] == 0:
    print('Yes')
elif a[1] == a[4] == a[7] == 0:
    print('Yes')
elif a[2] == a[5] == a[8] == 0:
    print('Yes')
elif a[0] == a[1] == a[2] == 0:
    print('Yes')
elif a[3] == a[4] == a[5] == 0:
    print('Yes')
elif a[6] == a[7] == a[8] == 0:
    print('Yes')
elif a[0] == a[4] == a[8] == 0:
    print('Yes')
elif a[2] == a[4] == a[6] == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

bingo_list = [[],[], []]
bingo_list[0] = list(map(int, input().split()))
bingo_list[1] = list(map(int, input().split()))
bingo_list[2] = list(map(int, input().split()))
n = int(input())
b_list = [int(input()) for i in range(n)]

selected_num_list = []

# 選ばれた数字とビンゴカードが一致するか調べる
for b in b_list:
    for i in range(3):
        for j in range(3):
            if b == bingo_list[i][j]:
                selected_num_list.append((i, j))

# ビンゴかどうか調べる
bingo_flag = False
for i in range(3):
    line_flag = False
    for j in range(3):
        if (i, j) in selected_num_list:
            line_flag = True
        else:
            line_flag = False
            break
    if line_flag == True:
        bingo_flag = True
        break

# 縦
for i in range(3):
    row_flag = False
    for j in range(3):
        if (j, i) in selected_num_list:
            row_flag = True
        else:
            row_flag = False
            break
    if row_flag == True:
        bingo_flag = True
        break

# 斜め
cross_flag = False
for i in range(3):
    for j in range(3):
        if i == j:
            if (i, j) in selected_num_list:
                cross_flag = True
            else:
                cross_flag = False
    if cross_flag == False:
        break


if cross_flag == True:
    bingo_flag = True

# 逆斜め
cross_flag = False
if (0, 2) in selected_num_list:
    if (1, 1) in selected_num_list:
        if (2, 0) in selected_num_list:
            bingo_flag = True


# 表示
if bingo_flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a = [input().split() for l in range(3)]
N=int(input())
b = [input() for i in range(N)]
if((b.count(a[0][0])==1 and b.count(a[0][1])==1 and b.count(a[0][2])==1) or 
   (b.count(a[1][0])==1 and b.count(a[1][1])==1 and b.count(a[1][2])==1) or
   (b.count(a[2][0])==1 and b.count(a[2][1])==1 and b.count(a[2][2])==1) or
   (b.count(a[0][0])==1 and b.count(a[1][0])==1 and b.count(a[2][0])==1) or
   (b.count(a[0][1])==1 and b.count(a[1][1])==1 and b.count(a[2][1])==1) or
   (b.count(a[0][2])==1 and b.count(a[1][2])==1 and b.count(a[2][2])==1) or
   (b.count(a[0][0])==1 and b.count(a[1][1])==1 and b.count(a[2][2])==1) or
   (b.count(a[2][0])==1 and b.count(a[1][1])==1 and b.count(a[0][2])==1) ):
  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()))
A = list()
A.extend(A1)
A.extend(A2)
A.extend(A3)
N = int(input())
B = list()
result = list()
for _ in range(N):
    B.append(int(input()))
for e in B:
    if e in A:
        result.append(A.index(e))
loopflag = False
result.sort()
# print(result)
if N >= 3:
    for i in range(len(result)):
        for j in range(len(result)):
            for k in range(len(result)):
                if (i!=j and j!=k and k!=i):
                    if((result[i] % 3 == result[j] % 3 == result[k] % 3 ) or (result[i] // 3 == result[j] // 3 == result[k] // 3) or (result[i] == 0 and result[j] == 4 and result[k] ==8 ) or (result[i] == 2 and result[j]  == 4 and result[k] == 6 )):
                        loopflag = True
    if loopflag:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
a1 = [int(x) for x in input().split()]
a2 = [int(x) for x in input().split()]
a3 = [int(x) for x in input().split()]
n = int(input())
b = []
for _ in range(n):
    b.append(int(input()))
res = []
for x in b:
    for i in range(3):
        if x == a1[i]:
            res += "1"
        if x == a2[i]:
            res += "2"
        if x == a3[i]:
            res += "3"
    if x == a1[0] or x == a2[0] or x == a3[0]:
        res += "4"
    if x == a1[1] or x == a2[1] or x == a3[1]:
        res += "5"
    if x == a1[2] or x == a2[2] or x == a3[2]:
        res += "6"
    if x == a1[0] or x == a2[1] or x == a3[2]:
        res += "7"
    if x == a1[2] or x == a2[1] or x == a3[0]:
        res += "8"
if res.count("1")>=3 or res.count("2")>=3 or res.count("3")>=3 or res.count("4")>=3 or res.count("5")>=3 or res.count("6")>=3 or res.count("7")>=3 or res.count("8")>=3:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

#print(L)
n = int(input())
li = []
for i in range(n):
    li.append(int(input()))
    
for i in range(3):
    if (L[i][0] in li) and (L[i][1] in li) and (L[i][2] in li ):
        print("Yes")
        exit()
if (L[0][0] in li) and (L[1][1] in li) and (L[2][2] in li ):
    print("Yes")
    exit()
if (L[0][2] in li) and (L[1][1] in li) and (L[2][0] in li ):
    print("Yes")
    exit()
for i in range(3):
    if (L[0][i] in li) and (L[1][i] in li) and (L[2][i] in li ):
        print("Yes")
        exit()

print("No")

Submission status: Accepted

Solution code:
row1=list(map(int,input().split()))
row2=list(map(int,input().split()))
row3=list(map(int,input().split()))
num=int(input())
list=[int(input()) for i in range(num)]

for n in list:
  row1 = [0 if i == n else i for i in row1]
  row2 = [0 if i == n else i for i in row2]
  row3 = [0 if i == n else i for i in row3]

# 横
if row1.count(0) == 3 or row2.count(0) == 3 or row3.count(0) == 3:
  print('Yes')

# 縦
elif row1[0]==0 and row2[0]==0 and row3[0]==0:
  print('Yes')
elif row1[1]==0 and row2[1]==0 and row3[1]==0:
  print('Yes')
elif row1[2]==0 and row2[2]==0 and row3[2]==0:
  print('Yes')

# ななめ
elif row2[1] == 0:
  if row1[0] == 0 and row3[2] == 0:
    print('Yes')
  elif row1[2] == 0 and row3[0] == 0:
    print('Yes')
  else:
    print('No')
else:
  print('No')

Submission status: Accepted

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


for i in range(len(b)):
  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]+a[i][1]+a[i][2] == 0:
    ans = 'Yes'
    break
  if a[0][i]+a[1][i]+a[2][i] == 0:
    ans = 'Yes'
    break

if a[0][0]+a[1][1]+a[2][2] == 0 or a[0][2]+a[1][1]+a[2][0] == 0:
    ans = 'Yes'

print(ans)