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:
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = list(int(input()) for _ 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
                break

for i in range(3):
    if a[i][0] == 0 and a[i][1] == 0 and a[i][2] == 0:
        print("Yes")
        break
    elif a[0][i] == 0 and a[1][i] == 0 and a[2][i] == 0:
        print("Yes")
        break
else:
    if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
        print("Yes")
    elif a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
bingo = []
for i in range(3):
  bingo.append(input().split(' '))
  
n = int(input())

for j in range(n):
  b = input()
  for s in range(3):
    for t in range(3):
      if bingo[s][t] == b:
        bingo[s][t] = 'hit'
        
tenchi = [[0,0,0],[0,0,0],[0,0,0]]
for s in range(3):
  for t in range(3):
    tenchi[s][t] = bingo[t][s]
    
times = 0
for a in range(3):
  if bingo[a] == ['hit', 'hit', 'hit'] or tenchi[a] == ['hit', 'hit', 'hit']:
    times = 1
if (bingo[1][1] == 'hit' and bingo[2][2] == 'hit' and bingo[0][0] == 'hit') or (bingo[0][2] == 'hit' and bingo[1][1] == 'hit' and bingo[2][0] == 'hit'):
  times = 1

if times == 0:
  print('No')
else:
  print('Yes')

Submission status: Accepted

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

        for k in range(3):
            for l in range(3):
                if int(bingo[k][l]) == b:
                    bingo[k][l] = -1
    

    if [bingo[0][0],bingo[1][1],bingo[2][2]] == [-1,-1,-1] or [bingo[2][0],bingo[1][1],bingo[0][2]] == [-1,-1,-1]:
        print('Yes')
    else:
        for ii in range(3):    
            if bingo[ii][0:3] == [-1,-1,-1] or [bingo[0][ii],bingo[1][ii],bingo[2][ii]] == [-1,-1,-1]:
                
                print('Yes')
                break
        else:
            print('No')




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
bl = [int(input()) for _ in range(n)]
bingo = [[False, False, False] for _ in range(3)]
for b in bl:
    for i in range(3):
        if b in a[i]:
            bingo[i][a[i].index(b)] = True
# print(*bingo, sep='\n')

# yoko
yoko = [all(i) for i in bingo]

# tate
for i in range(3):
    for j in range(3):
        if bingo[j][i] == False:
            break
    else:
        tate = True
        break
else:
    tate = False

# naname
naname1 = False
for i in range(3):
    if bingo[i][i] == False:
        break
else:
    naname1 = True

naname2 = False
for i in range(3):
    if bingo[i][2-i] == False:
        break
else:
    naname2 = True

if True in yoko or tate or naname1 or naname2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
card = [
    list(map(int, input().split(' '))),
    list(map(int, input().split(' '))),
    list(map(int, input().split(' ')))
]

count = int(input())

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

for _ in range(count):
    b = int(input())
    for i, cc in enumerate(card):
        for j, c in enumerate(cc):
            if c == b:
                result[i][j] = 1

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

Submission status: Accepted

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

n = int(input())
for _ in range(n):
    b = int(input())
    for x in range(3):
        for y in range(3):
            if mat[x][y] == b:
                mat[x][y] = 101

flg = False
for x in range(3):
    if [mat[x][0], mat[x][1], mat[x][2]] == [101, 101, 101]:
        flg = True

for x in range(3):
    if [mat[0][x], mat[1][x], mat[2][x]] == [101, 101, 101]:
        flg = True

if [mat[0][0], mat[1][1], mat[2][2]] == [101, 101, 101]:
    flg = True

if [mat[0][2], mat[1][1], mat[2][0]] == [101, 101, 101]:
    flg = True

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

Submission status: Accepted

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


for number in numbers:
    for i in range(3):
        for j in range(3):
            if card[i][j] == number:
                card[i][j] = 0
    
bingo = False

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

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

if bingo:
    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()))
ans = 0

N = int(input())
b = []

for i in range(0, N):
	b_input = int(input())
	b.append(b_input)

for i in range(0, 3):
	for j in range(0, N):
		if A_1[i] == b[j]:
			A_1[i] = True
		if A_2[i] == b[j]:
			A_2[i] = True
		if A_3[i] == b[j]:
			A_3[i] = True

A = [A_1, A_2, A_3]

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

if A[0][0] == A[1][1] == A[2][2] == True or A[0][2] == A[1][1] == A[2][0]:
	ans = 1

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

Submission status: Accepted

Solution code:
bingo = [list(map(int,input().split())) for i in range(3)]
n = int(input())
num = [int(input()) for i in range(n)]
for i in num:
  for row in range(3):
    for col in range(3):
      if bingo[row][col] == i:
        bingo[row][col] = 0
if sum(bingo[0]) == 0 or sum(bingo[1]) == 0 or sum(bingo[2]) == 0 or sum([hoge[0] for hoge in bingo]) == 0 or sum([hoge[1] for hoge in bingo]) == 0 or sum([hoge[2] for hoge in bingo]) == 0 or sum([bingo[i][i] for i in range(3)]) == 0 or sum([bingo[i][2-i] for i in range(3)]) == 0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
bingo = [list(map(int,input().split())) for i in range(3)]
n = int(input())
num = [int(input()) for i in range(n)]
for i in num:
  for row in range(3):
    for col in range(3):
      if bingo[row][col] == i:
        bingo[row][col] = 0
if sum(bingo[0]) == 0 or sum(bingo[1]) == 0 or sum(bingo[2]) == 0 or sum([hoge[0] for hoge in bingo]) == 0 or sum([hoge[1] for hoge in bingo]) == 0 or sum([hoge[2] for hoge in bingo]) == 0 or sum([bingo[i][i] for i in range(3)]) == 0 or sum([bingo[i][2-i] for i in range(3)]) == 0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

for i in range(N):
    b = int(input())
    for j in range(len(bingo)):
      for k in range(len(bingo[j])):
            if b == bingo[j][k]:
                bingo[j][k] = 0

for i in range(len(bingo)):
    if sum(bingo[i]) == 0:
        print('Yes')
        sys.exit()
    if (bingo[0][i] + bingo[1][i] + bingo[2][i]) == 0:
        print('Yes')
        sys.exit()

for i in [0]:
  if (bingo[i][i] + bingo[i+1][i+1] + bingo[i+2][i+2]) == 0:
    print('Yes')
    sys.exit()
  if (bingo[i][i+2] + bingo[i+1][i+1] + bingo[i+2][i]) == 0:
    print('Yes')
    sys.exit()
  else:
    print("No")

Submission status: Accepted

Solution code:
# import math
# import bisect
# import heapq
# from collections import deque
# import numpy as np

# n, m = map(int, input().split())

a = [0] * 9
i = 0
for i in range(3):
    b,c,d = map(int, input().split())
    # print(b,c,d)
    a[3*i],a[3*i+1],a[3*i+2] = b,c,d

ans = 'No'

n = int(input())

b = [ int(input()) for i in range(n) ]
# print(b)
for i in range(n):
    for j in range(9):
        a[j] = -1 if b[i] == a[j] else a[j]

pairs = [
    [0,1,2],[3,4,5],[6,7,8],
    [0,3,6],[1,4,7],[2,5,8],
    [0,4,8],[2,4,6]]

for p in pairs:
    if a[p[0]] == -1 and a[p[1]] == -1 and a[p[2]] == -1:
        ans = 'Yes'


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

for i in range(3):
    if a1[i] in b and a2[i] in b and a3[i] in b:
        print("Yes")
        exit()

if a1[0] in b and a1[1] in b and a1[2] in b:
    print("Yes")
    exit()
if a2[0] in b and a2[1] in b and a2[2] in b:
    print("Yes")
    exit()
if a3[0] in b and a3[1] in b and a3[2] in b:
    print("Yes")
    exit()

if a1[0] in b and a2[1] in b and a3[2] in b:
    print("Yes")
    exit()
if a1[2] in b and a2[1] in b and a3[0] in b:
    print("Yes")
    exit()

print("No")

Submission status: Accepted

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

for i in b:
    for j in A:
        if i in j:
            A[A.index(j)][j.index(i)] = -1
for i in range(3):
    if A[i][0] == A[i][1] == A[i][2] == -1 or A[0][i] == A[1][i] == A[2][i] == -1:
        print('Yes')
        exit()
if A[0][0] == A[1][1] == A[2][2] == -1 or A[0][2] == A[1][1] == A[2][0] == -1:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

Solution code:
datalist = [list(map (int, input().split(" "))) for i in range(3)]
checktbl = [[0,0,0],[0,0,0],[0,0,0]]
num = int(input())
for i in range(num):
    data = int(input())
    for j in range(3):
        for k in range(3):
            if datalist[k][j] == data:
                checktbl[k][j] = 1

result = "No"
for i in range(3):
    if checktbl[i][0] == 1 and checktbl[i][1] == 1 and checktbl[i][2] == 1:
        result = "Yes"
for i in range(3):
    if checktbl[0][i] == 1 and checktbl[1][i] == 1 and checktbl[2][i] == 1:
        result = "Yes"
if checktbl[0][0] == 1 and checktbl[1][1] == 1 and checktbl[2][2] == 1:
    result = "Yes"
if checktbl[0][2] == 1 and checktbl[1][1] == 1 and checktbl[2][0] == 1:
    result = "Yes"

print(result)

Submission status: Accepted

Solution code:
S="012 345 678 036 147 258 048 246 "
A=sum([input().split()for i in range(4)],[])
for b in [input()for i in range(int(A[9]))]:
  if b in A:
    S=S.replace(str(A.index(b)),"")
print("NYoe s"["  "in S::2])

Submission status: Accepted

Solution code:
S="012 345 678 036 147 258 048 246 "
A=sum([input().split()for i in range(4)],[])
for b in [input()for i in range(int(A[9]))]:
  if b in A:
    S=S.replace(str(A.index(b)),"")
print("YNeos"[not"  "in S::2])

Submission status: Accepted

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

a_l = [list(map(int, input().split())) for i in range(3)]
n = int(input())
b_l = [int(input()) for i in range(n)]

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

f = False

if a_l[0][0] == a_l[0][1] == a_l[0][2] == 0:
    f = True
elif a_l[1][0] == a_l[1][1] == a_l[1][2] == 0:
    f = True
elif a_l[2][0] == a_l[2][1] == a_l[2][2] == 0:
    f = True
elif a_l[0][0] == a_l[1][0] == a_l[2][0] == 0:
    f = True
elif a_l[0][1] == a_l[1][1] == a_l[2][1] == 0:
    f = True
elif a_l[0][2] == a_l[1][2] == a_l[2][2] == 0:
    f = True
elif a_l[0][0] == a_l[1][1] == a_l[2][2] == 0:
    f = True
elif a_l[0][2] == a_l[1][1] == a_l[2][0] == 0:
    f = True

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

Submission status: Accepted

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

a_r_list = []
a_c_list = [[],[],[]]
a_table = []
for _ in range(3):
    a_list = list(map(int, input().split()))
    a_r_list.append(a_list)
    for i, a in enumerate(a_list):
        a_c_list[i].append(a)
    a_table.append(a_list)
a_list_list = a_r_list + a_c_list
a_list_list += [[a_table[0][0], a_table[1][1], a_table[2][2]]]
a_list_list += [[a_table[0][2], a_table[1][1], a_table[2][0]]]

N = int(input().split()[0])
is_ok = False
for _ in range(N):
    b = int(input().split()[0])
    for a_list in a_list_list:
        try:
            a_list.remove(b)
        except ValueError:
            pass
        if not a_list:
            is_ok = True
ans = "Yes" if is_ok else "No"
print(ans)

Submission status: Accepted

Solution code:
def main():
    num_list = []
    for _ in range(3):
        num_list.append(list(map(int,input().split())))
    n = int(input())
    b_list = [int(input()) for _ in range(n)]

    for i in range(3):
        for j in range(3):
            if num_list[i][j] in b_list:
                num_list[i][j] = '!'

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

    for i in range(3):
        count = 0
        for j in range(3):
            if num_list[j][i] == '!':
                count += 1
        if count == 3:
            print('Yes')
            exit()
    
    if num_list[0][0] == '!' and num_list[1][1] == '!' and num_list[2][2] == '!':
        print('Yes')
        exit()

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

    print('No')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S="012 345 678 036 147 258 048 246 "
A=sum([input().split()for i in range(4)],[])
for b in [input()for i in range(int(A[9]))]:
  if b in A:
    S=S.replace(str(A.index(b)),"")
print("YNeos"[S.find("  ")<0::2])

Submission status: Accepted

Solution code:
S="012 345 678 036 147 258 048 246 "
A=sum([input().split()for i in range(3)],[])
for b in [input()for i in range(int(input()))]:
  if b in A:
    S=S.replace(str(A.index(b)),"")
print("YNeos"[S.find("  ")<0::2])

Submission status: Accepted

Solution code:
S="012 345 678 036 147 258 048 246 "
A=sum([input().split()for i in range(3)],[])
for b in [input()for i in range(int(input()))]:
  if b in A:
    S=S.replace(str(A.index(b)),"")
print(["No","Yes"][S.find("  ")>-1])

Submission status: Accepted

Solution code:
S="012 345 678 036 147 258 048 246 "
A=[input().split()for i in range(3)]
B=A[0]+A[1]+A[2]
for b in [input()for i in range(int(input()))]:
  if b in B:
    S=S.replace(str(B.index(b)),"")
print(["No","Yes"][S.find("  ")>-1])

Submission status: Accepted

Solution code:
S="012 345 678 036 147 258 048 246 "
A=[input().split()for i in range(3)]
for b in [input()for i in range(int(input()))]:
  for l in range(9):
    S=S.replace(str([9,l][b==(A[0]+A[1]+A[2])[l]]),"")
print(["No","Yes"][S.find("  ")>-1])

Submission status: Accepted

Solution code:
S="012 345 678 036 147 258 048 246 "
A=[input().split()for i in range(3)]
B=A[0]+A[1]+A[2]
for b in [input()for i in range(int(input()))]:
  for l in range(9):
    S=S.replace(str([9,l][b==B[l]]),"")
print(["No","Yes"][S.find("  ")>-1])

Submission status: Accepted

Solution code:
S="012 345 678 036 147 258 048 246 "
A=[]
A.extend(list(map(int,input().split())) for i in range(3))
N=int(input())
for i in range(N):
  j=input()
  for l in range(3):
    for m in range(3):
      S=S.replace(str([9,l*3+m][A[l][m]==int(j)]),"")
print(["No","Yes"][S.find("  ")>-1])

Submission status: Accepted

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

for a in A:
    if a[0] in b and a[1] in b and a[2] in b:
        print('Yes')
        exit()

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

if A[0][0] in b and A[1][1] in b and A[2][2] in b:
    print('Yes')
    exit()

if A[0][2] in b and A[1][1] in b and A[2][0] in b:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

Solution code:
lst = []
for i in range(3):
    s = list(map(int, input().split()))
    lst.append(s)
N = int(input())
for i in range(N):
    num = int(input())
    for j in range(3):
        for k in range(3):
            if num == lst[j][k]:
                lst[j][k] = 0

for i in range(3):
    cnt = 0
    for j in range(3):
        if lst[i][j] == 0:
            cnt += 1
    if cnt == 3:
        print('Yes')
        exit()

for i in range(3):
    cnt = 0
    for j in range(3):
        if lst[j][i] == 0:
            cnt += 1
    if cnt == 3:
        print('Yes')
        exit()

cnt = 0
for i in range(3):
    if lst[i][i] == 0:
        cnt += 1
    if cnt == 3:
        print('Yes')
        exit()

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

print('No')

Submission status: Accepted

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

def disclose(card, n, lst):
  for i in range(n):
    for j in range(3):
      for k in range(3):
        if card[j][k] == lst[i]:
          card[j][k] = 0
  return card
          
def trans(matrix):
  tr = []
  for i in range(len(matrix[0])):
    vector = []
    for j in range(len(matrix)):
      vector.append(matrix[j][i])
    tr.append(vector)
  return tr

def bingo(card):
  if card[0] == [0,0,0]:
    return True
  if card[1] == [0,0,0]:
    return True
  if card[2] == [0,0,0]:
    return True
  card = trans(card)
  if card[0] == [0,0,0]:
    return True
  if card[1] == [0,0,0]:
    return True
  if card[2] == [0,0,0]:
    return True
  for i in range(3):
    if card[i][i] != 0:
      break
    if i == 2:
      return True
  for i in range(3):
    if card[i][2-i] != 0:
      break
    if i == 2:
      return True
  return False
    
def judge(x):
  if x:
    return "Yes"
  return "No"

print(judge(bingo(disclose(card, N, List))))

Submission status: Accepted

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

class Bingo():
    def __init__(self, board):
        self.board = board
        self.length = 3
        self.check = [[False] * self.length for i in range(self.length)]
    
    def punch(self, num):
        for i in range(self.length):
            for j in range(self.length):
                if self.board[i][j] == num:
                    self.check[i][j] = True

    def bingo_count(self):
        ret = 0
        # 横方向
        for i in range(self.length):
            ok = True
            for j in range(self.length):
                if not self.check[i][j]:
                    ok = False
                    break
            if ok:
                ret += 1
        # 縦方向
        for i in range(self.length):
            ok = True
            for j in range(self.length):
                if not self.check[j][i]:
                    ok = False
                    break
            if ok:
                ret += 1
        # ななめ
        ok = True
        for i in range(self.length):
            if not self.check[i][i]:
                ok = False
                break
        if ok:
            ret += 1
        
        ok = True
        for i in range(self.length):
            if not self.check[i][-i-1]:
                ok = False
                break
        if ok:
            ret += 1
        
        return ret

def main():
    bingo = Bingo([list(map(int, input().split())) for i in range(3)])
    N = int(input())

    for _ in range(N):
        b = int(input())
        bingo.punch(b)
    
    if bingo.bingo_count() > 0:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

for a in A:
    if a[0] in B and a[1] in B and a[2] in B:
        print('Yes')
        exit()

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

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

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

print('No')

Submission status: Accepted

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

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

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

yoko1 = [a[0][0],a[0][1],a[0][2]]
yoko2 = [a[1][0],a[1][1],a[1][2]]
yoko3 = [a[2][0],a[2][1],a[2][2]]
tate1 = [a[0][0],a[1][0],a[2][0]]
tate2 = [a[0][1],a[1][1],a[2][1]]
tate3 = [a[0][2],a[1][2],a[2][2]]
naname1 = [a[0][0],a[1][1],a[2][2]]
naname2 = [a[0][2],a[1][1],a[2][0]]
count = 0
d = [yoko1,yoko2,yoko3,tate1,tate2,tate3,naname1,naname2]
for i in range(8):
    if d[i][0] in b and d[i][1] in b and d[i][2] in b:
        count = 1
        break
if count == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A = []
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 = []
for i in range(N):
  B.append(int(input()))
  
A = [[A11,A12,A13],
     [A21,A22,A23],
     [A31,A32,A33]]

sets = []

for i in range(3):
  s = []
  for j in range(3):
  	s.append(A[i][j])
  sets.append(s)
  
for j in range(3):
  s = []
  for i in range(3):
  	s.append(A[i][j])
  sets.append(s)
  
sets.append([A11,A22,A33])
sets.append([A13,A22,A31])

for s in sets:
  count = 0
  for b in B:
    if b in s : 
      count+=1
  if count == 3:
    print("Yes")
    break
else:
  print("No")

Submission status: Accepted

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

bingo="No"

for k in range(n):
  for i in range(3):
    for j in range(3):
      if b[k]==a[i][j]:
        a[i][j]=0
        
for i in range(3):
  if a[i]==[0,0,0]:bingo="Yes"
  if a[0][i]==a[1][i]==a[2][i]==0:bingo="Yes"
if a[0][0]==a[1][1]==a[2][2]==0:bingo="Yes"
if a[2][0]==a[1][1]==a[0][2]==0:bingo="Yes"

print(bingo)

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from functools import lru_cache
from heapq import heappop,heappush
import time
import os
import sys
import datetime
readline=readline = sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s

#main
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from functools import lru_cache
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s

#main
A=[input().split() for a in range(3)]
C=[[False for b in range(3)] for a in range(3)]
N=int(input())
B=[]
for a in range(N):
    b=input()
    for c in range(3):
        for d in range(3):
            if A[c][d]==b:
                C[c][d]=True
f=False
for a in range(3):
    if C[a].count(True)==3:
        f=True
    if [C[0][a],C[1][a],C[2][a]].count(True)==3:
        f=True
if [C[0][0],C[1][1],C[2][2]].count(True)==3:
    f=True
if [C[0][2],C[1][1],C[2][0]].count(True)==3:
    f=True
Yn(f)

Submission status: Accepted

Solution code:
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
list_c = list(map(int, input().split()))

n = int(input())

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

# 該当箇所に-1を埋める
for i in list_s:
    for j in [list_a, list_b, list_c]:
        for k in range(3):
            if j[k] == i:
                j[k] = -1

# 判定
# 横の判定
for i in [list_a, list_b, list_c]:
    if i[0] == -1 and i[1] == -1 and i[2] == -1:
        print("Yes")
        exit()

# 縦の判定
for i in range(3):
    if list_a[i] == -1 and list_b[i] == -1 and list_c[i] == -1:
        print("Yes")
        exit()

# 斜め
if list_a[0] == -1 and list_b[1] == -1 and list_c[2] == -1:
    print("Yes")
    exit()

if list_a[2] == -1 and list_b[1] == -1 and list_c[0] == -1:
    print("Yes")
    exit()

print("No")