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:
ban=[]
result=[False]*9
for i in range(3):
    a,b,c=map(int,input().split())
    ban.append(a)
    ban.append(b)
    ban.append(c)
n=int(input())
sen=[]
for i in range(n):
    temp=int(input())
    for i in range(9):
        if(ban[i]==temp):
            result[i]=True

ans=False
check=[[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 c in check:
    if(result[c[0]] and result[c[1]] and result[c[2]]):
       ans=True

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

Submission status: Accepted

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

N = int(input())

b_list = []

for _ in range(N):
	b_list.append(int(input()))

for b in b_list:
	for i, row in enumerate(card):
		for j, A in enumerate(row):
			if A == b:
				card_after[i][j] = True

card = card_after
bingo = False

# horiontal
if card[0][0] == card[0][1] == card[0][2] or card[1][0] == card[1][1] == card[1][2] or card[2][0] == card[2][1] == card[2][2]:
	bingo = True

# vertical
if card[0][0] == card[1][0] == card[2][0] or card[0][1] == card[1][1] == card[2][1] or card[0][2] == card[1][2] == card[2][2]:
	bingo = True

# diagonal
if card[0][0] == card[1][1] == card[2][2] or card[2][0] == card[1][1] == card[2][0]:
	bingo = True

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

Submission status: Accepted

Solution code:

A = list()
for _ in range(3):
    a1, a2, a3 = list(map(int, input().split()))
    A.append(a1)
    A.append(a2)
    A.append(a3)

N = int(input())

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

if sum(A[0:3]) == 0 or sum(A[3:6]) == 0 or sum(A[6:9]) == 0:
    print("Yes")
elif A[0] + A[3] + A[6] == 0 or A[1] + A[4] + A[7] == 0 or A[2] + A[5] + A[8] == 0:
    print("Yes")
elif A[0] + A[4] + A[8] == 0 or A[2] + A[4] + A[6] == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a,b,c=input().split()
d,e,f=input().split()
g,h,i=input().split()
n=int(input())
l=[]
for _ in range(n):
   l.append(input())
if e in l:
    if i in l and a in l or b in l and h in l or c in l and g in l or d in l and f in l:
        print('Yes')
    else:
        print('No')
elif a in l:
    if d in l and g in l or b in l and c in l:
        print('Yes')
    else:
        print('No')
elif i in l:
    if c in l and f in l or g in l and h in l:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import OrderedDict


a = OrderedDict()
for i in range(3):
    for j in input().split():
        a[j] = 0

n = int(input())
for i in range(n):
    inp = input()
    if inp in a.keys():
        a[inp] = 1

anss = list(a.values())
lines = [(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 x,y,z in lines:
    if anss[x] + anss[y] + anss[z] == 3:
        print("Yes")
        exit()
print("No")

Submission status: Accepted

Solution code:
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N = int(input())
bg1, bg2, bg3 = [0]*3, [0]*3, [0]*3
for i in range(N):
  b = int(input())
  for j in range(3):
    if b == A1[j]:
      bg1[j] = 1
    if b == A2[j]:
      bg2[j] = 1
    if b == A3[j]:
      bg3[j] = 1
if sum(bg1) == 3 or sum(bg2) == 3 or sum(bg3) == 3:
  print("Yes")
elif bg1[0]+bg2[0]+bg3[0]==3 or bg1[1]+bg2[1]+bg3[1]==3 or bg1[2]+bg2[2]+bg3[2]==3:
  print("Yes")
elif bg1[0]+bg2[1]+bg3[2]==3 or bg1[2]+bg2[1]+bg3[0]==3:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import numpy as np
card = []
for _ in range(3):
  card.append(list(map(int, input().split())))

N = int(input())
card = np.array(card)
atari = np.zeros((3,3))

for _ in range(N):
  b = int(input())
  atari[card==b] = 1


# if any([(card==0).all(axis=0).any() , (card==0).all(axis=1).any(), (card[[0,0], [1,1], [2,2]]==0).all(), (card[[0,2], [1,1], [2,0]]==0).all()]):
if any([atari.all(axis=0).any(), atari.all(axis=1).any(), all([atari[0,0], atari[1,1], atari[2,2]]), all([atari[0,2], atari[1,1], atari[2,0]])]):
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

n = int(input())
b = []
for _ in range(n):
    _b = int(input())
    b.append(_b)
    for i in range(3):
        for j in range(3):
            if a[i][j] == _b:
                a[i][j] = 0

if 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 or a[0][0] == a[0][1] == a[0][2] == 0 or a[1][0] == a[1][1] == a[1][2] == 0 or a[2][0] == a[2][1] == a[2][2] == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
AA = []

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

N = int(input())
for i in range(N):
    bi = input()
    for i in range(3):
        aa = AA[i]
        for a in range(3):
            if bi == aa[a]:
                AA[i][a] = 'B'
            
# yoko
flag = 0
for i in range(3):
    aa = AA[i]
    flag = 1
    for j in range(3):
        if aa[j] != 'B':
            flag = 0 
    if flag == 1:
        break
# tate        
if flag == 0:
    for i in range(3):
        flag = 1
        for j in range(3):
            if AA[j][i] != 'B':
                flag = 0
        if flag == 1:
            break

# naname
if flag == 0:
    flag = 1
    for i in range(3):
        if AA[i][i] != 'B':
            flag = 0
if flag ==0: 
    flag = 1
    for i in range(3):
        if AA[i][2-i] != 'B':
            flag = 0

# print(AA)
            
if flag == 0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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


def main(A, N, lst_b):
    
    matrix_result = [[False]*3 for i in range(3)]
    flag_bingo = False

    for b in lst_b:
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    matrix_result[i][j] = True
        
    for i in range(3):
        # check tate
        if (matrix_result[0][i] and matrix_result[1][i] and matrix_result[2][i]):
            flag_bingo = True
        # check yoko
        if (matrix_result[i][0] and matrix_result[i][1] and matrix_result[i][2]):
            flag_bingo = True
    
    # check naname
    if (matrix_result[0][0] and matrix_result[1][1] and matrix_result[2][2]):
        flag_bingo = True
    elif (matrix_result[0][2] and matrix_result[1][1] and matrix_result[2][0]):
        flag_bingo = True
    
    if flag_bingo: return "Yes"
    else         : return "No"
    

if __name__ == "__main__":

    answer = main(A, N, lst_b)
    print(answer)

Submission status: Accepted

Solution code:
a=[[0,0,0] for i in range(3)]
for i in range(3):
    *a[i], = map(int, input().split())    
def check(b):
    for i in range(3):
        for j in range(3):
            if b==a[i][j]:
                a[i][j]=0
                break
def bingo():
    if a[0][0]==0 and a[1][1]==0 and a[2][2]==0:
        return True
    if a[0][2]==0 and a[1][1]==0 and a[2][0]==0:
        return True    
    for i in range(3):
         if a[i][0]==0 and a[i][1]==0 and a[i][2]==0:
                return True
    for j in range(3):
         if a[0][j]==0 and a[1][j]==0 and a[2][j]==0:
                return True
    return False

n=int(input())
for i  in range(n):
    check(int(input()))

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

Submission status: Accepted

Solution code:
import numpy as np

def bingo(A):
    for i in range(3):
        if (A[i,0] == 0) and (A[i,1] == 0) and (A[i,2] == 0):
            return True
        
        if (A[0,i] == 0) and (A[1,i] == 0) and (A[2,i] == 0):
            return True
    
    if A[1, 1] == 0:
        if (A[0, 0] == 0) and (A[2, 2] == 0):
            return True
        if (A[0, 0] == 0) and (A[2, 2] == 0):
            return True
        if (A[2, 0] == 0) and (A[0, 2] == 0):
            return True
        if (A[2, 0] == 0) and (A[2, 0] == 0):
            return True
    else:
        return False
    
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
A1 = np.array(A1)
A2 = np.array(A2)
A3 = np.array(A3)
A = np.array([A1,A2,A3])

n = int(input())


for i in range(n):
    b = int(input())
    A = np.where(A == b, 0, A)

if bingo(A) == True:
    print("Yes")

else:
    print("No")

Submission status: Accepted

Solution code:
#157 b
a=[]
call_num=[]
for i in range(3):
    x,y,z=map(int,input().split())
    a.append(x)
    a.append(y)
    a.append(z)
n=int(input())
for i in range(n):
    x=int(input())
    if x in a:
        call_num.append(a.index(x))
bingo=False
ans=[[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 x in ans:
    flag=True
    for y in x:
        if y not in call_num:
            flag=False
    if flag:
        print("Yes")
        bingo=True
        break
if bingo!=True:
    print("No")

Submission status: Accepted

Solution code:
a1 = input().split(" ")
a2 = input().split(" ")
a3 = input().split(" ")
A = [a1, a2, a3]
N = int(input())
for i in range(N):
    j = input()
    for k in A:
        for l in k:
            if l == j:
                x = k.index(l)
                k.pop(x)
                k.insert(x, "○")
            else:
                pass
ans = 0
for i in A:
    if len(set(i)) == 1:
        ans += 1
    else:
        pass
if a1[0] =="○":
    if a2[0] == "○":
        if a3[0] == "○":
            ans += 1
if a1[1] == "○":
    if a2[1] == "○":
        if a3[1] == "○":
            ans += 1
if a1[2] == "○":
    if a2[2] == "○":
        if a3[2] == "○":
            ans += 1
if a1[0] == "○":
    if a2[1] == "○":
        if a3[2] == "○":
            ans += 1
if a1[2] == "○":
    if a2[1] == "○":
        if a3[0] == "○":
            ans += 1
if ans >= 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys

a1i = list(map(int, input().split()))
a2i = list(map(int, input().split()))
a3i = list(map(int, input().split()))
n = int(input())
bi = [int(input()) for i in range(n)]

for b in bi:
    a1i = [0 if a == b else a for a in a1i]
    a2i = [0 if a == b else a for a in a2i]
    a3i = [0 if a == b else a for a in a3i]
    
for i in range(3):
    if (a1i[i] == 0 and a2i[i] == 0 and a3i[i] == 0):
        print('Yes')
        sys.exit()

if (a1i[0] == 0 and a2i[1] == 0 and a3i[2] == 0) \
    or (a1i[2] == 0 and a2i[1] == 0 and a3i[0] == 0):
        print('Yes')
        sys.exit()
        
if (len(set(a1i)) == 1 or len(set(a2i)) == 1 or len(set(a3i)) == 1):
    print('Yes')
    sys.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()))
n = int(input())
bs = []
for i in range(n):
    bs.append(int(input()))

bs = set(bs)

atari = (set(row1) <= bs or
set(row2) <= bs or
set(row3) <= bs or
set([row1[0], row2[0], row3[0]]) <= bs or
set([row1[1], row2[1], row3[1]]) <= bs or
set([row1[2], row2[2], row3[2]]) <= bs or
set([row1[0], row2[1], row3[2]]) <= bs or
set([row1[2], row2[1], row3[0]]) <= bs
)

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    A = [tuple(map(int, input().split())) for _ in range(3)]
    N = int(input())
    B = [int(input()) for _ in range(N)]

    ans = [[[] for _ in range(3)] for _ in range(3)]
    for i, A_ in enumerate(A):
        for j, a in enumerate(A_):
            ans[i][j] = a in B

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

from fractions import gcd
import math
from math import ceil,floor
import collections

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# list = list(map(int, input().split()))

def func(a):
   return tmp

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

ans="No"

for i in range(0,N):
    for j in range(0,3):
        for k in range(0,3):
            if B[i]==A[j][k]:
                A[j][k]=0
                
for i in range(0,3):
    if A[i][0]==0 and A[i][1]==0 and A[i][2]==0:
        ans = "Yes"

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

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

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

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
def a():
    A = []
    A += list(map(int,input().split()))
    A += list(map(int,input().split()))
    A += list(map(int,input().split()))
    N = int(input())
    d = defaultdict(int)
    for _ in range(N):
        d[int(input())] = 1

    B = list(map(lambda x:d[x],A))

    if B[4]:
        if B[0] * B[8] + B[2] * B[6]:
            return 1
    
    for i in range(3):
        if sum(B[i*3:i*3+3]) == 3:
            return 1
        if sum(B[i::3]) == 3:
            return 1
    
    return 0

print(["No","Yes"][a()])

Submission status: Accepted

Solution code:
data_list = [ list(map(int,input().split(" "))) for i in range(3)]
n = int(input())
b_list = []
for _ in range(n):
    b_list.append(int(input()))



for k in range(n):
    for i in range(3):
        for j in range(3):
            if data_list[i][j] == b_list[k]:
                data_list[i][j] = -1

ans = []

for i in range(3):
    s = data_list[i]
    ans.append(sum(s))

for i in range(3):
    s = data_list[0][i] + data_list[1][i] + data_list[2][i]
    ans.append(s)

ans.append(data_list[0][0] + data_list[1][1] + data_list[2][2])
ans.append(data_list[0][2] + data_list[1][1] + data_list[2][0])

if ans.count(-3) != 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# numpy使えたら早いだろうな・・・
L1 = list(map(int,input().split()))
L2 = list(map(int,input().split()))
L3 = list(map(int,input().split()))
N = int(input())
B = [int(input()) for _ in range(N)]

Flag = False

LL = L1 + L2 + L3
# print(LL)
# print(B)

for i in B:
    if i in LL:
        LL[LL.index(i)] = 0

# 横
for i in range(3):
    t = LL[3*i] + LL[3*i+1] + LL[3*i+2]
    if t == 0:
        Flag = True

# 縦
for i in range(3):
    t = t = LL[i] + LL[i+3] + LL[i+6]
    if t == 0:
        Flag = True

# 斜め
t = LL[0] + LL[4] + LL[8]
if t == 0:
    Flag = True
t = LL[2] + LL[4] + LL[6]
if t == 0:
    Flag = True

if Flag == True:
    print('Yes')
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)]
atari=[]

for i in range(3):
    atari.append([a[i][0],a[i][1],a[i][2]])
for i in range(3):
    atari.append([a[0][i],a[1][i],a[2][i]])
    
atari.append([a[0][0],a[1][1],a[2][2]])
atari.append([a[0][2],a[1][1],a[2][0]])

for k in range(len(atari)):
    if len(list(set(atari[k]) & set(b)))==3:
        print("Yes")
        break
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np
Flg = "No"
A = [[0]*3 for i in range(3)]
for i in range(3):
    A[i][0], A[i][1], A[i][2] = map(int, input().split())    
N = int(input())
b = [0]*N
for j in range(N):
    b[j] = int(input())

for i in range(3):
    for j in range(3):
        for k in range(N):
            if(A[i][j] == b[k]):
                A[i][j] = "*"
A_T = np.array(A).T
                
for i in range(3):
    if(A[i][0] == A[i][1] == A[i][2] == "*"):
        Flg = "Yes"        
        break
    if(A_T[i][0] == A_T[i][1] == A_T[i][2] == "*"):
        Flg = "Yes"
        break

if(A[0][0] == A[1][1] == A[2][2] == "*"):
    Flg = "Yes"

if(A[0][2] == A[1][1] == A[2][0] == "*"):
    Flg = "Yes"

print(Flg)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
a = a + list(map(int,input().split()))
a = a + list(map(int,input().split()))

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

for i in call:
	if i in a:
		a[a.index(i)] = 0

ans = 'No'

if a[0] == 0:
	if a[1] == 0 and a[2] == 0:
		ans = 'Yes'
	if a[3] == 0 and a[6] == 0:
		ans = 'Yes'
	if a[4] == 0 and a[8] == 0:
		ans = 'Yes'
if a[1] == 0:
	if a[4] == 0 and a[7] == 0:
		ans = 'Yes'
if a[2] == 0:
	if a[5] == 0 and  a[8] == 0:
		ans = 'Yes'
	if a[4] == 0 and a[6] == 0:
		ans = 'Yes'
if a[3] == 0:
	if a[4] == 0 and a[5] == 0:
		ans = 'Yes'
if a[6] == 0:
	if a[7] == 0 and a[8] == 0:
		ans = 'Yes'
		
print(ans)

Submission status: Accepted

Solution code:
[A11,A12,A13] = list(map(int,input().split()))
[A21,A22,A23] = list(map(int,input().split()))
[A31,A32,A33] = list(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]

#フラグ
sheet=[0]*9

for i in range(N):
    for j in range(9):
        if b[i]==A[j]:
            sheet[j]=1

if sheet[0]==1 and sheet[1]==1 and sheet[2]==1:
    print("Yes")
elif sheet[3]==1 and sheet[4]==1 and sheet[5]==1:
    print("Yes")
elif sheet[6]==1 and sheet[7]==1 and sheet[8]==1:
    print("Yes")
elif sheet[0]==1 and sheet[3]==1 and sheet[6]==1:
    print("Yes")
elif sheet[1]==1 and sheet[4]==1 and sheet[7]==1:
    print("Yes")
elif sheet[2]==1 and sheet[5]==1 and sheet[8]==1:
    print("Yes")
elif sheet[0]==1 and sheet[4]==1 and sheet[8]==1:
    print("Yes")
elif sheet[2]==1 and sheet[4]==1 and sheet[6]==1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
bingo_dict = dict()
i=1
j=1
for a in [int(i) for i in input().split()]:
    bingo_dict[a] = i*10+j
    j+=1
i=2
j=1
for a in [int(i) for i in input().split()]:
    bingo_dict[a] = i*10+j
    j+=1
i=3
j=1
for a in [int(i) for i in input().split()]:
    bingo_dict[a] = i*10+j
    j+=1

N = int(input())

s = set()
for b in [int(input()) for n in range(N)]:
    if b in bingo_dict:
        s.add(bingo_dict[b])

patterns = [
    [11,12,13],
    [21,22,23],
    [31,32,33],
    [11,21,31],
    [12,22,32],
    [13,23,33],
    [11,22,33],
    [13,22,31]
]

for p in patterns:
    b = True
    for v in p:
        if v not in s:
            b = False
            break
    if b:
        print('Yes')
        exit()

print('No')

Submission status: Accepted

Solution code:
A = [[False, False, False], [False, False, False], [False, False, False]]

def checker():
    for i in range(3):
        if A[i][0] & A[i][1] & A[i][2]:
            return True
        elif A[0][i] & A[1][i] & A[2][i]:
            return True
    if A[0][0] & A[1][1] & A[2][2]:
        return True
    elif A[0][2] & A[1][1] & A[2][0]:
        return True
    return False

a0 = list(map(int, input().split()))
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))

n = int(input())

for i in range(n):
    b = int(input())
    for j in range(3):
        if b == a0[j]:
            A[0][j] = True
            break
        elif b == a1[j]:
            A[1][j] = True
            break
        elif b == a2[j]:
            A[2][j] = True
            break

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

Submission status: Accepted

Solution code:
Card = [[],[],[]]
for k in range(3):
    Card[k] = list(map(int,input().split()))
N = int(input())
Call = [int(input()) for k in range(N)]
Bin = [[0,0,0],[0,0,0],[0,0,0]]
for k in range(N):
    for l in range(3):
        for m in range(3):
            if Card[l][m] == Call[k]:
                Bin[l][m] =1
ans = 0
for k in range(3):
    if Bin[k][0] == Bin[k][1] and Bin[k][1] == Bin[k][2] and Bin[k][0] ==1:
        ans = 1
    if Bin[0][k] == Bin[1][k] and Bin[1][k] == Bin[2][k] and Bin[2][k] ==1:
        ans = 1
if Bin[0][0] == Bin[1][1] and Bin[1][1] == Bin[2][2] and Bin[2][2] ==1:
    ans = 1 
if Bin[0][2] == Bin[1][1] and Bin[1][1] == Bin[2][0] and Bin[2][0] == 1:
    ans = 1

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

Submission status: Accepted

Solution code:
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
g,h,i=map(int,input().split())

z1=[]
z2=[]
z3=[]
z4=[]
z5=[]
z6=[]
z7=[]
z8=[]
z1.append(a)
z1.append(b)
z1.append(c)

z2.append(d)
z2.append(e)
z2.append(f)

z3.append(g)
z3.append(h)
z3.append(i)

z4.append(a)
z4.append(d)
z4.append(g)

z5.append(b)
z5.append(e)
z5.append(h)

z6.append(c)
z6.append(f)
z6.append(i)

z7.append(a)
z7.append(e)
z7.append(i)

z8.append(c)
z8.append(e)
z8.append(g)

n=int(input())
for i in range(n):
    x=int(input())
    if x in z1:z1.remove(x)
    if x in z2:z2.remove(x)
    if x in z3:z3.remove(x)
    if x in z4:z4.remove(x)
    if x in z5:z5.remove(x)
    if x in z6:z6.remove(x)
    if x in z7:z7.remove(x)
    if x in z8:z8.remove(x)

if len(z1)==0 or len(z2)==0 or len(z3)==0 or len(z4)==0 or len(z5)==0 or len(z6)==0 or len(z7)==0 or len(z8)==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A=[]
for i in range(3):
    a=list(map(int,input().split()))
    A.append(a)
V=[[0]*3 for i in range(3)]
n=int(input())
for i in range(n):
    t=int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k]==t:
                V[j][k]=1
if V[0][0]==V[1][0]==V[2][0]==1:
    print('Yes')
    exit()
elif V[0][1]==V[1][1]==V[2][1]==1:
    print('Yes')
    exit()
elif V[0][2]==V[1][2]==V[2][2]==1:
    print('Yes')
    exit()
elif V[0][0]==V[0][1]==V[0][2]==1:
    print('Yes')
    exit()
elif V[1][0]==V[1][1]==V[1][2]==1:
    print('Yes')
    exit()
elif V[2][0]==V[2][1]==V[2][2]==1:
    print('Yes')
    exit()
elif V[0][0]==V[1][1]==V[2][2]==1:
    print('Yes')
    exit()
elif V[0][2]==V[1][1]==V[2][0]==1:
    print('Yes')
    exit()
else:
    print('No')

Submission status: Accepted

Solution code:
li1 = list(map(int,input().split()))
li2 = list(map(int,input().split()))
li3 = list(map(int,input().split()))
N = int(input())
b = [int(input()) for i in range(N)]
A = li1+li2+li3

hit = []
for i in b:
    if i in A:
        hit.append(A.index(i)+1)

if (1 in hit and 2 in hit and 3 in hit)\
or (4 in hit and 5 in hit and 6 in hit)\
or (7 in hit and 8 in hit and 9 in hit)\
or (1 in hit and 4 in hit and 7 in hit)\
or (2 in hit and 5 in hit and 8 in hit)\
or (3 in hit and 6 in hit and 9 in hit)\
or (1 in hit and 5 in hit and 9 in hit)\
or (3 in hit and 5 in hit and 7 in hit):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
Alist=list(map(int,input().split()))
Blist=list(map(int,input().split()))
Clist=list(map(int,input().split()))
#print(Alist)
#print(Blist)
#print(Clist)
N=int(input())
mylist=[]
flaglist=[0,0,0,0,0,0,0,0] #8個のフラッグリスト
for i in range(N):
    mylist.append(int(input()))
    #print(mylist)
    
for i in range(3):
    for j in range(N):
        if Alist[i]==mylist[j]:
            flaglist[0]+=1
            
for i in range(3):
    for j in range(N):
        if Blist[i]==mylist[j]:
            flaglist[1]+=1
            
            
for i in range(3):
    for j in range(N):
        if Clist[i]==mylist[j]:
            flaglist[2]+=1
#ここまで横の列

for i in range(N):
    if Alist[0]==mylist[i]:
        flaglist[3]+=1
    elif Blist[0]==mylist[i]:
        flaglist[3]+=1
    elif Clist[0]==mylist[i]:
        flaglist[3]+=1
        
for i in range(N):
    if Alist[1]==mylist[i]:
        flaglist[4]+=1
    elif Blist[1]==mylist[i]:
        flaglist[4]+=1
    elif Clist[1]==mylist[i]:
        flaglist[4]+=1

for i in range(N):
    if Alist[2]==mylist[i]:
        flaglist[5]+=1
    elif Blist[2]==mylist[i]:
        flaglist[5]+=1
    elif Clist[2]==mylist[i]:
        flaglist[5]+=1
        
for i in range(N):
    if Alist[2]==mylist[i]:
        flaglist[6]+=1
    elif Blist[1]==mylist[i]:
        flaglist[6]+=1
    elif Clist[0]==mylist[i]:
        flaglist[6]+=1
        
for i in range(N):
    if Alist[0]==mylist[i]:
        flaglist[7]+=1
    elif Blist[1]==mylist[i]:
        flaglist[7]+=1
    elif Clist[2]==mylist[i]:
        flaglist[7]+=1
        
if max(flaglist)>=3:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
num1 =input().rstrip().split()
num2 =input().rstrip().split()
num3 =input().rstrip().split()
numbers=[int(num1[0]),int(num1[1]),int(num1[2]),int(num2[0]),int(num2[1]),int(num2[2]),int(num3[0]),int(num3[1]),int(num3[2])]
#print(numbers)
N =int(input())
calls =[]
for i in range(N):
    calls.append(int(input()))
#print(calls)
for i in range(9):
    for call in calls:
        if call == numbers[i]:
            numbers[i]=0
#print(numbers)
a=numbers[0]+numbers[1]+numbers[2]
b=numbers[3]+numbers[4]+numbers[5]
c=numbers[6]+numbers[7]+numbers[8]
d=numbers[0]+numbers[3]+numbers[6]
e=numbers[1]+numbers[4]+numbers[7]
f=numbers[2]+numbers[5]+numbers[8]
g=numbers[0]+numbers[4]+numbers[8]
h=numbers[2]+numbers[4]+numbers[6]

if a*b*c*d*e*f*g*h==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:

X = dict()
cc = 0
for _ in range(3):
    a, b, c = map(int, input().split())
    X[a] = cc
    cc += 1 
    X[b] = cc
    cc += 1 
    X[c] = cc
    cc += 1 

Q = int(input())
ss = set()
for _ in range(Q):
    c = int(input())
    if c in X:
        ss.add(X[c])
if 0 in ss and 1 in ss and 2 in ss:
    print("Yes")
elif 3 in ss and 4 in ss and 5 in ss:
    print("Yes")
elif 6 in ss and 7 in ss and 8 in ss:
    print("Yes")
elif 0 in ss and 3 in ss and 6 in ss:
    print("Yes")
elif 1 in ss and 4 in ss and 7 in ss:
    print("Yes")
elif 2 in ss and 5 in ss and 8 in ss:
    print("Yes")
elif 0 in ss and 4 in ss and 8 in ss:
    print("Yes")
elif 2 in ss and 4 in ss and 6 in ss:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a = [list(map(int, input().rstrip().split())) for _ in range(3)]
c = [[0]*3 for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

for x in b:
  for i in range(3):
    for j in range(3):
      c[j][i] = c[j][i] or (a[j][i] == x)

bingo = 0
for j in range(3):
  bingo = bingo or all(c[j])
for i in range(3):
  bingo = bingo or all([c[j][i] for j in range(3)])

bingo = bingo or all([c[i][i] for i in range(3)]) or all([c[i][2-i] for i in range(3)])

if bingo:
  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 _ in range(N)]
A = [
    A1,
    A2,
    A3,
    [A1[0],A2[0],A3[0]],
    [A1[1],A2[1],A3[1]],
    [A1[2],A2[2],A3[2]],
    [A1[0],A2[1],A3[2]],
    [A1[2],A2[1],A3[0]],
]

for al in A:
    res = True
    for a in al:
        if not a in B:
            res = False
    if res:
        print('Yes')
        exit()

print('No')

Submission status: Accepted

Solution code:
card = [list(map(int, input().split())) for _ in range(3)]
# is_open = [[False, False, False]] * 3
n = int(input())
B = [int(input()) for _ in range(n)]

is_open = []
for b in B:
    for j in range(3):
        for i in range(3):
            if card[j][i] == b:
                is_open.append((i, j))

is_open_list = [True if (i, j) in is_open else False for i in range(3) for j in range(3)]

for i in range(3):
    if is_open_list[i] and is_open_list[i + 3] and is_open_list[i + 6]:
        print('Yes')
        exit()
    elif is_open_list[3 * i] and is_open_list[3 * i + 1] and is_open_list[3 * i + 2]:
        print('Yes')
        exit()

if is_open_list[0] and is_open_list[4] and is_open_list[8]:
    print('Yes')
    exit()
elif is_open_list[2] and is_open_list[4] and is_open_list[6]:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

Solution code:
import sys
a = [[0] * 3 for i in range(3)]
ans = [[0] * 3 for i in range(3)]
for i in range(3):
    a[i][0],a[i][1],a[i][2] = map(int, input().split())
N = int(input())
b = [input() for i in range(N)]
for i in range(3):
    for j in range(3):
        if ans[i][j] == 1:
            break
        for k in range(N):
            if a[i][j] == int(b[k]):
                ans[i][j] = 1
                break
for i in range(3):
    if ans[i][0] == 1 and ans[i][1] == 1 and ans[i][2] == 1:
        print('Yes')
        sys.exit()
for j in range(3):
    if ans[0][j] == 1 and ans[1][j] == 1 and ans[2][j] == 1:
        print('Yes')
        sys.exit()
if ans[0][0] == 1 and ans[1][1] == 1 and ans[2][2] == 1:
    print('Yes')
    sys.exit()
if ans[0][2] == 1 and ans[1][1] == 1 and ans[2][0] == 1:
    print('Yes')        
    sys.exit()
print('No')

Submission status: Accepted

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

n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == b:
                bingo[i][j] = "o"

for i in range(3):
    flag = 0
    for j in range(3):
        if bingo[i][j] == "o":
            flag += 1
    if flag == 3:
        print("Yes")
        exit()
    flag = 0
    for j in range(3):
        if bingo[j][i] == "o":
            flag += 1
    if flag == 3:
        print("Yes")
        exit()
# 斜め
if (
    bingo[0][0] == bingo[1][1] == bingo[2][2] == "o"
    or bingo[0][2] == bingo[1][1] == bingo[2][0] == "o"
):
    print("Yes")
    exit()
print("No")