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

for i in b:
    for num, j in enumerate(a):
        if i in j:
            a[num][a[num].index(i)] = True
tmp = []
for i in a:
    tmp.extend(i)

tmp2 = []
for i, num in enumerate(tmp):
    if num is True:
        tmp2.append(i + 1)

ans_arr = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
    [1, 4, 7],
    [2, 5, 8],
    [3, 6, 9],
    [1, 5, 9],
    [3, 5, 7],
]
for i in ans_arr:
    count = 0
    for j in tmp2:
        if j not in i:
            pass
        else:
            count += 1
    if count == 3:
        ans = "Yes"
        break

print(ans)

Submission status: Accepted

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

N = int(input())
bs = [int(input()) for _ in range(0, N)]

ans1 = [0, 0, 0]
ans2 = [0, 0, 0]
ans3 = [0, 0, 0]

def bingo_column():
    return ans1 == [1,1,1] or ans2 == [1,1,1] or ans3 == [1,1,1]

def bingo_row():
    if ans1[0] == 1 and ans2[0] == 1 and ans3[0] == 1:
        return True
    if ans1[1] == 1 and ans2[1] == 1 and ans3[1] == 1:
        return True
    if ans1[2] == 1 and ans2[2] == 1 and ans3[2] == 1:
        return True
    
    return False

def bingo_naname():
    if ans1[0] == 1 and ans2[1] == 1 and ans3[2] == 1:
        return True
    if ans1[2] == 1 and ans2[1] == 1 and ans3[0] == 1:
        return True
    return False

bingo = False
for b in bs:
    if b in A1:
        ix = A1.index(b)
        ans1[ix] = 1
    if b in A2:
        ix = A2.index(b)
        ans2[ix] = 1
    if b in A3:
        ix = A3.index(b)
        ans3[ix] = 1

    if bingo_column():
        bingo = True
    if bingo_row():
        bingo = True
    if bingo_naname():
        bingo = True

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

Submission status: Accepted

Solution code:
L1 = [int(x) for x in input().split()]
L2 = [int(x) for x in input().split()]
L3 = [int(x) for x in input().split()] 
AL = L1 + L2 + L3
N = int(input())
for x in range(N):
    IN = int(input())
    if IN in AL:
        AL[AL.index(IN)] = 0
for x in range(3):
    if AL[0+x] == AL[3+x] == AL[6+x] == 0:
        print("Yes")
        exit()
if AL[0] == AL[4] == AL[8] == 0:
    print("Yes")
    exit()
elif AL[2] == AL[4] == AL[6] == 0:
    print("Yes")
    exit()
elif AL[0] == AL[1] == AL[2] == 0:
    print("Yes")
    exit()
elif AL[3] == AL[4] == AL[5] == 0:
    print("Yes")
    exit()
elif AL[6] == AL[7] == AL[8] == 0:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

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

for i in range(N):
    b = int(input())
    for I in range(3):
        for J in range(3):
            if A[I][J] == b:
                A[I][J] = 0

bingo = False
#print(*A, sep='\n')
#print(A[0][:])
#print(A[:][0])
# 横
#print('i')
for i in range(3):
    #print(i, A[i][:])
    if A[i][:] == [0, 0, 0]:
        bingo = True
# 縦
#print('j')
for j in range(3):
    #print(j, [A[0][j], A[1][j], A[2][j]])
    if [A[0][j], A[1][j], A[2][j]] == [0, 0, 0]:
        bingo = True

# 斜め
#print('h')
#print([A[0][0], A[1][1], A[2][2]])
if [A[0][0], A[1][1], A[2][2]] == [0, 0, 0]:
    bingo = True

#print('g')
#print([A[0][2], A[1][1], A[2][0]])
if [A[0][2], A[1][1], A[2][0]] == [0, 0, 0]:
    bingo = True

if bingo == 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 = set([int(input()) for _ in range(N)])
flag = False
# yoko
for i in range(3):
    if all([a in b for a in A[i]]):
        flag = True

if not flag:
    for j in range(3):
        tmp = [A[0][j], A[1][j], A[2][j]]
        if all([a in b for a in tmp]):
            flag = True

if not flag:
    tmp = [A[0][0], A[1][1], A[2][2]]
    if all([a in b for a in tmp]):
        flag = True

if not flag:
    tmp = [A[0][2], A[1][1], A[2][0]]
    if all([a in b for a in tmp]):
        flag = True

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

Submission status: Accepted

Solution code:
def cal(lst1, lst2):
    lst3 = [0, 0, 0]
    for i in range(3):
        if lst1[i] in lst2:
            lst3[i] = 1
    return lst3

def judge(a, b, c):
    if (a == 1) and (a == b == c):
        return True
    else:
        return False

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

C_1 = []
C_2 = []
C_3 = []

C_1 = cal(A_1, b)
C_2 = cal(A_2, b)
C_3 = cal(A_3, b)

a = judge(C_1[0], C_2[0], C_3[0])
b = judge(C_1[1], C_2[1], C_3[1])
c = judge(C_1[2], C_2[2], C_3[2])

d = judge(C_1[0], C_1[1], C_1[2])
e = judge(C_2[0], C_2[1], C_2[2])
f = judge(C_3[0], C_3[1], C_3[2])

g = judge(C_1[0], C_2[1], C_3[2])
h = judge(C_1[2], C_2[1], C_3[0])

lst = [a, b, c, d, e, f, g, h]

if True in lst:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def isBingo(input):
  for i in range(3):
    if input[i][0] is None and input[i][1] is None and input[i][2] is None:
      return True
  for i in range(3):
    if input[0][i] is None and input[1][i] is None and input[2][i] is None:
      return True
  if input[0][0] is None and input[1][1] is None and input[2][2] is None:
    return True
  if input[0][2] is None and input[1][1] is None and input[2][0] is None:
  	return True

bingoCard=[] 
bingoCard.append(list(map(int,input().split())))
bingoCard.append(list(map(int,input().split())))
bingoCard.append(list(map(int,input().split())))

readTimes = int(input())
readNumbers = [int(input()) for i in range(readTimes)]

for row in range(3):
  for col in range(3):
    if bingoCard[row][col] in readNumbers:
      bingoCard[row][col] = None
if isBingo(bingoCard):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
b=[]
c=[0]*9
for i in range(3):
  a=input().split()
  b.append(int(a[0]))
  b.append(int(a[1]))
  b.append(int(a[2]))
N=int(input())
for i in range(N):
  e=int(input())
  for j in range(9):
    if(e==b[j]):
      c[j]=1
if(c[0]==c[1]==c[2]==1):
  print('Yes')
elif(c[3]==c[4]==c[5]==1):
  print('Yes')
elif(c[6]==c[7]==c[8]==1):
  print('Yes')
elif(c[0]==c[4]==c[8]==1):
  print('Yes')
elif(c[2]==c[4]==c[6]==1):
  print('Yes')
elif(c[0]==c[3]==c[6]==1):
  print('Yes')
elif(c[1]==c[4]==c[7]==1):
  print('Yes')
elif(c[2]==c[5]==c[8]==1):
  print('Yes')
else:
  print('No')

Submission status: Accepted

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


n = int(input())

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


ans1 = False
for i in range(3):
    a = True
    for j in range(3):
        if ls[i][j] in bs:
            continue
        else:
            a = False
    if a == True:
        ans1 = True
        break
    else:
        continue

ans4 = False
for i in range(3):
    a = True
    for j in range(3):
        if ls[j][i] in bs:
            continue
        else:
            a = False
    if a == True:
        ans4 = True
        break
    else:
        continue

ans2 = False
if (ls[0][0] in bs) and (ls[1][1] in bs) and (ls[2][2] in bs):
    ans2 = True

ans3 = False
if (ls[2][0] in bs) and (ls[1][1] in bs) and (ls[0][2] in bs):
    ans3 = True


if (ans1 == True) or (ans2 == True) or (ans3 == True) or (ans4 == True):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
a = [0]*9
bit = [[0]*3 for _ in range(3)]
for i in range(3):
    a[i*3],a[i*3+1],a[i*3+2] = map(int,input().split())
#print(a)
n = int(input())
for i in range(n):
    b = int(input())
    if b in a:
        k = a.index(b)
        bit[k//3][k%3] = 1
#print(bit)
for i in range(3):
    if bit[i][0]*bit[i][1]*bit[i][2] == 1:
        print("Yes")
        exit()
    if bit[0][i]*bit[1][i]*bit[2][i] == 1:
        print("Yes")
        exit()
if bit[0][0]*bit[1][1]*bit[2][2] == 1 or bit[2][0]*bit[1][1]*bit[0][2] == 1:
    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())
b=[int(input()) for i in range(N)]

B=[A1[0], A2[1], A3[2]]
C=[A1[2], A2[1], A3[0]]
D=[A1[0], A2[0], A3[0]]
E=[A1[1], A2[1], A3[1]]
F=[A1[2], A2[2], A3[2]]


answer='No'
if len(set(A1) & set(b))>2:
  answer='Yes'
if len(set(A2) & set(b))>2:
  answer='Yes'
if len(set(A3) & set(b))>2:
  answer='Yes'
if len(set(B) & set(b))>2:
  answer='Yes'
if len(set(C) & set(b))>2:
  answer='Yes'
if len(set(D) & set(b))>2:
  answer='Yes'
if len(set(E) & set(b))>2:
  answer='Yes'
if len(set(F) & set(b))>2:
  answer='Yes'
print(answer)

Submission status: Accepted

Solution code:
nmap = {}

for i in range(3):
    row = [int(n) for n in input().split()]
    for j in range(3):
        number = row[j]
        nmap[number] = [i, j]

N = int(input())

b = [None] * N

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

lines = [
    [[0, 0], [0, 1], [0, 2]],
    [[1, 0], [1, 1], [1, 2]],
    [[2, 0], [2, 1], [2, 2]],

    [[0, 0], [1, 0], [2, 0]],
    [[0, 1], [1, 1], [2, 1]],
    [[0, 2], [1, 2], [2, 2]],

    [[0, 0], [1, 1], [2, 2]],
    [[2, 0], [1, 1], [0, 2]],
]

for number in b:
    if number in nmap:
        for line in lines:
            if nmap[number] in line:
                line.remove(nmap[number])

ans = "No"
for line in lines:
    if len(line) == 0:
        ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
import math
size = 3
bingo = []
for i in range(size):
    line = [int(i) for i in input().split(' ')]
    bingo.append(line)
n = int(input())
bs = []
for i in range(n):
    b = int(input())
    bs.append(b)

flag = False
cnt1 = 0
cnt2 = 0
for i in range(size):
    if bingo[i][i] in bs:
        for j in range(size):
            if bingo[i][j] in bs:
                continue
            else:
                break
        else:
            flag = True
        for j in range(size):
            if bingo[j][i] in bs:
                continue
            else:
                break
        else:
            flag = True
        cnt1 += 1
    if bingo[i][size-i-1] in bs:
        cnt2 += 1
if (cnt1 == size) or (cnt2 == size):
    flag = True

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

Submission status: Accepted

Solution code:
cards = []
for i in range(3):
    cards.append([ int(x) for x in input().split()])

N = int(input())

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

checklist = [[0,0,0],[0,0,0],[0,0,0]]

for idx1, nums in enumerate(cards):
    for idx2, num  in enumerate(nums):
        for boll in bolls:
            if num == boll:
                checklist[idx1][idx2] = 1

ans = 'No'

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

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

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

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

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


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

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

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

print(ans)

Submission status: Accepted

Solution code:
bingo1 = [int(x) for x in input().split()]
bingo2 = [int(x) for x in input().split()]
bingo3 = [int(x) for x in input().split()]

N = int(input())
for _ in range(N):
    b = int(input())
    bingo1 = [0 if x == b else x for x in bingo1]
    bingo2 = [0 if x == b else x for x in bingo2]
    bingo3 = [0 if x == b else x for x in bingo3]

bingos = [bingo1, bingo2, bingo3]
flag = "No"
if sum(bingo1) * sum(bingo2) * sum(bingo3) == 0:
    flag = "Yes"
else:
    tbingo1 = [x[0] for x in bingos]
    tbingo2 = [x[1] for x in bingos]
    tbingo3 = [x[2] for x in bingos]
    if sum(tbingo1) * sum(tbingo2) * sum(tbingo3) == 0:
        flag = "Yes"
    else:
        nbingo1 = [0 if bingos[i][i] == b else bingos[i][i] for i, x in enumerate(bingos)]
        nbingo2 = [0 if bingos[i][2-i] == b else bingos[i][2-i] for i, x in enumerate(bingos)]
        if sum(nbingo1) * sum(nbingo2) == 0:
            flag = "Yes"
print(flag)

Submission status: Accepted

Solution code:
import numpy as np

if __name__ == "__main__":
  _data_list = []
  tmp_list = list(map(int, input().split()))
  _data_list.append(tmp_list)
  _rows = len(tmp_list)
  for i in range(_rows-1):
    _data_list.append(list(map(int, input().split())))
  _data_list = np.array(_data_list)

  flag_matrix = np.zeros((3,3),dtype=np.bool)
  _n = int(input())
  _b = []
  for i in range(_n):
    _b.append(int(input()))

  for data in _b:
    flag_matrix = np.logical_or(flag_matrix,_data_list == data)

  if np.all(flag_matrix[0]) or np.all(flag_matrix[1]) or np.all(flag_matrix[2]) or np.all(flag_matrix[:,0]) or np.all(flag_matrix[:,1]) or np.all(flag_matrix[:,2]) or (flag_matrix[0,0]*flag_matrix[1,1]*flag_matrix[2,2]) or (flag_matrix[0,2]*flag_matrix[1,1]*flag_matrix[2,0]):
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np
ans=[0]*9
A=[0]*3
answer=0
for i in range(3):
    A[i]=list(map(int,input().split()))
N=int(input())
b=[0]*N
for j in range(N):
    b[j]=int(input())
def checkyoko(card):
    a=0
    for k in range(3):
        if card[k]==[1,1,1]:
            a=1
    return a
def checktate(card):
    a=0
    for l in range(3):
        if [card[0][l],card[1][l],card[2][l]]==[1,1,1]:
            a=1
    return a
def nanamecheck(card):
    a=0
    if [card[0][0],card[1][1],card[2][2]]==[1,1,1] or [card[0][2],card[1][1],card[2][0]]==[1,1,1]:
        a=1
    return a
counter=0
for m in range(3):
    for n in range(3):
        if A[m][n]in b:
            ans[counter]=1
        counter+=1
ans=np.array(ans)
ans=ans.reshape(3,3)
ans=ans.tolist()
answer=(checktate(ans)==1 or checkyoko(ans)==1 or nanamecheck(ans)==1)

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

Submission status: Accepted

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

n = int(input())
b = [0] * n
for i in range(n):
    b[i] = int(input())


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

f = 0
for i in range(3):
    if sum(a[i]) == 0:
        f = 1
        break

for i in range(3):
    tmp = 0
    for j in range(3):
        tmp += a[j][i]
    if tmp == 0:
        f = 1
        break

if a[0][0] + a[1][1] + a[2][2] == 0:
    f = 1
if a[0][2] + a[1][1] + a[2][0] == 0:
    f = 1

if f == 1:
    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
 
List=[]
                
sum = 0
for i in range(3):
    sum=0
    for j in range(3):
        sum=sum+A[i][j]
    List.append(sum)
 
sum = 0
for i in range(3):
    sum=0
    for j in range(3):
        sum=sum+A[j][i]
    List.append(sum)
 
sum = 0
for i in range(3):
    sum=sum+A[i][i]
List.append(sum)
 
sum= 0
for i in range(3):
    sum =sum+A[i][2-i]
List.append(sum)
 
ans=0
for i in range(len(List)):
    if List[i]==0:
        ans = ans +1
 
if ans !=0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
P = [input().split() for i in range(3)]
N = int(input())
b = [input() for i in range(N)]

P_ = [[0,0,0] for _ in range(3)]
for j in range(3):
    for i in range(3):
        if P[i][j] in b:
            P_[i][j] = 1
        else:
            P_[i][j] = 0
            
ans = 'No'

# 横
for i in range(3):
    if [P_[i][j] for j in range(3)] == [1,1,1]:
        ans = 'Yes'
        
# 縦
for i in range(3):
    if [P_[j][i] for j in range(3)] == [1,1,1]:
        ans = 'Yes'
        
if [P_[i][2 - i] for i in range(3)] == [1,1,1]:
    ans = 'Yes'
        
if [P_[i][i] for i in range(3)] == [1,1,1]:
    ans = 'Yes'
    
print(ans)

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

a_ = [[0]*3 for _ in range(3)]
for i in b:
    for j in range(3):
        for k in range(3):
            if a[j][k] == i:
                a_[j][k] = 1
                
count = 0
for i in range(3):
    count += (a_[i][0]+a_[i][1]+a_[i][2])//3
    count += (a_[0][i]+a_[1][i]+a_[2][i])//3
    
count += (a_[0][0]+a_[1][1]+a_[2][2])//3
count += (a_[0][2]+a_[1][1]+a_[2][0])//3

if count > 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

A_list=[[int(j) for j in input().split()] for i in range(3)]
N = int(input().strip())
b_list=[int(input().strip()) for _ in range(N)]
#-----

for num in b_list:
    for ai in range(3):
        for aj in range(3):
            if num == A_list[ai][aj]:
                A_list[ai][aj] = "O"

Flag=False
for i in range(3):
    if A_list[i][0]==A_list[i][1]==A_list[i][2]=="O":
        Flag = True
    if A_list[0][i]==A_list[1][i]==A_list[2][i]=="O":
        Flag = True

if A_list[0][0]==A_list[1][1]==A_list[2][2]=="O":
    Flag = True
if A_list[2][0]==A_list[1][1]==A_list[0][2]=="O":
    Flag = True

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

Submission status: Accepted

Solution code:
import math


def ag(li):
    return (li[0][0] and li[0][1] and li[0][2]) \
        or (li[1][0] and li[1][1] and li[1][2]) \
        or (li[2][0] and li[2][1] and li[2][2]) \
        or (li[0][0] and li[1][0] and li[2][0]) \
        or (li[0][1] and li[1][1] and li[2][1]) \
        or (li[0][2] and li[1][2] and li[2][2]) \
        or (li[0][0] and li[1][1] and li[2][2]) \
        or (li[0][2] and li[1][1] and li[2][0])


card = [list(map(int, input().split())) for i in range(3)]
n = int(input())
bList = [input() for _ in range(n)]
tList = [[False, False, False], [False, False, False], [False, False, False]]

for i, b in enumerate(bList):
    for j, c1 in enumerate(card):
        for k, c2 in enumerate(c1):
            if c2 == int(b):
                tList[k][j] = True

if ag(tList):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import itertools

A = []
A1 = [int(i) for i in input().split()]
A.append(A1)
A2 = [int(i) for i in input().split()]
A.append(A2)
A3 = [int(i) for i in input().split()]
A.append(A3)

f = [[0] * 3 for i in range(3)]

#print(A)


N = int(input ())
b = [input().split() for i in range(N)]
b= list(itertools.chain.from_iterable(b))
b = list(map(int, b))

for i in range(3):
    for j in range(3):
        for x in b:
            if A[i][j] == x:
                f[i][j] = 1
s = 0

for i in range(3):
    if sum(f[i]) == 3:
        s = 1
    if f[0][0] + f[1][1] + f[2][2] == 3:
        s = 1
    if f[0][2] + f[1][1] + f[2][0] == 3:
        s = 1
    for j in range(3):
        if f[0][j] + f[1][j] + f[2][j] == 3:
            s = 1
        
                
        
if s == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = list(map(int, input().split()))

n = int(input())
li_call = []
for i in range(n):
  li_call.append(int(input()))
for i in range(n):
  for j in range(3):
    if li_a[j] == li_call[i]:
      li_a[j] = 0
  for k in range(3):
    if li_b[k] == li_call[i]:
      li_b[k] = 0
  for l in range(3):
    if li_c[l] == li_call[i]:
      li_c[l] = 0
li_o = [0, 0, 0]
li_d = [li_a[0], li_b[0], li_c[0]]
li_e = [li_a[1], li_b[1], li_c[1]]
li_f = [li_a[2], li_b[2], li_c[2]]
li_g = [li_a[0], li_b[1], li_c[2]]
li_h = [li_a[2], li_b[1], li_c[0]]
if li_a == li_o:
  print("Yes")
elif li_b == li_o:
  print("Yes")
elif li_c == li_o:
  print("Yes")
elif li_d == li_o:
  print("Yes")
elif li_e == li_o:
  print("Yes")
elif li_f == li_o:
  print("Yes")
elif li_g == li_o:
  print("Yes")
elif li_h == li_o:
  print("Yes")

else:
  print("No")

Submission status: Accepted

Solution code:
li=[list(map(int,input().split())) for _ in range(3)]
n = int(input())
for i in range(n):
    b=int(input())
    for i in range(3):
        li[i] = [0 if j == b else j for j in li[i]]
for i in range(3):
    if li[i][0]==0 and li[i][1]==0 and li[i][2]==0:
        print("Yes")
        exit(0)
for i in range(3):
    if li[0][i]==0 and li[1][i]==0 and li[2][i]==0:
        print("Yes")
        exit(0)
if li[0][0]==0 and li[1][1]==0 and li[2][2]==0:
    print("Yes")
    exit(0)
if li[2][0]==0 and li[1][1]==0 and li[0][2]==0:
    print("Yes")
    exit(0)
print("No")

Submission status: Accepted

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

N = int(input())

for n in range(N):
    b = int(input())
    for i in range(3):
        for l in range(3):
            if A[i][l] == b:
                A[i][l] = 0
                
if (
    (A[0][0] == 0 and A[0][1] ==0 and A[0][2] ==0 ) or #横0行目
    (A[1][0] == 0 and A[1][1] ==0 and A[1][2] ==0 ) or #横1行目
    (A[2][0] == 0 and A[2][1] ==0 and A[2][2] ==0 ) or #横2行目
    (A[0][0] == 0 and A[1][0] ==0 and A[2][0] ==0 ) or # 縦
    (A[0][1] == 0 and A[1][1] ==0 and A[2][1] ==0 ) or # 縦
    (A[0][2] == 0 and A[1][2] ==0 and A[2][2] ==0 ) or # 縦
    (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")
else:
    print("No")

Submission status: Accepted

Solution code:
A_11,A_12,A_13 = map(int, input().split())
A_21,A_22,A_23 = map(int, input().split())
A_31,A_32,A_33 = map(int, input().split())
N=int(input())
b = []
for _ in range(N):
    b.append(int(input()))

A_11j,A_12j,A_13j,A_21j,A_22j,A_23j,A_31j,A_32j,A_33j=[0,0,0,0,0,0,0,0,0]
r=[]
if A_11 in b:
  A_11j=1
if A_12 in b:
  A_12j=1
if A_13 in b:
  A_13j=1
if A_21 in b:
  A_21j=1
if A_22 in b:
  A_22j=1
if A_23 in b:
  A_23j=1
if A_31 in b:
  A_31j=1
if A_32 in b:
  A_32j=1
if A_33 in b:
  A_33j=1

  
if(A_11j==1)&(A_12j==1)&(A_13j==1):
  r="Yes"
elif(A_21j==1)&(A_22j==1)&(A_23j==1):
  r="Yes"
elif(A_31j==1)&(A_32j==1)&(A_33j==1):
  r="Yes"
elif(A_11j==1)&(A_21j==1)&(A_31j==1):
  r="Yes"
elif(A_12j==1)&(A_22j==1)&(A_32j==1):
  r="Yes"
elif(A_13j==1)&(A_23j==1)&(A_33j==1):
  r="Yes"
elif(A_11j==1)&(A_22j==1)&(A_33j==1):
  r="Yes"
elif(A_13j==1)&(A_22j==1)&(A_31j==1):
  r="Yes"
else:
  r="No"
  
print(r)

Submission status: Accepted

Solution code:
line1 = input()
line2 = input()
line3 = input()
bingo = [0 for i in range(9)]
ans_bingo = [0 for i in range(9)]

bingo[0], bingo[1], bingo[2] = line1.split(" ")
bingo[3], bingo[4], bingo[5] = line2.split(" ")
bingo[6], bingo[7], bingo[8] = line3.split(" ")

n = input()
for i in range(int(n)):
    b = input()
    if b in bingo:
        index = bingo.index(b)
        ans_bingo[index] = "1"

if ans_bingo[0] == "1" and ans_bingo[1] == "1" and ans_bingo[2] == "1":
    print("Yes")
elif ans_bingo[3] == "1" and ans_bingo[4] == "1" and ans_bingo[5] == "1":
    print("Yes")
elif ans_bingo[6] == "1" and ans_bingo[7] == "1" and ans_bingo[8] == "1":
    print("Yes")
elif ans_bingo[0] == "1" and ans_bingo[3] == "1" and ans_bingo[6] == "1":
    print("Yes")
elif ans_bingo[1] == "1" and ans_bingo[4] == "1" and ans_bingo[7] == "1":
    print("Yes")
elif ans_bingo[2] == "1" and ans_bingo[5] == "1" and ans_bingo[8] == "1":
    print("Yes")
elif ans_bingo[0] == "1" and ans_bingo[4] == "1" and ans_bingo[8] == "1":
    print("Yes")
elif ans_bingo[2] == "1" and ans_bingo[4] == "1" and ans_bingo[6] == "1":
    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)]

bingo=[[0]*3 for _ in range(3)]
for i in range(n):
  for ai in range(3):
    for aj in range(3):
      if A[ai][aj]==B[i]:
        bingo[ai][aj]=1
flag=False
if bingo[0][0]==bingo[0][1]==bingo[0][2]==1: flag=True
if bingo[1][0]==bingo[1][1]==bingo[1][2]==1: flag=True
if bingo[2][0]==bingo[2][1]==bingo[2][2]==1: flag=True
  
if bingo[0][0]==bingo[1][0]==bingo[2][0]==1: flag=True
if bingo[0][1]==bingo[1][1]==bingo[2][1]==1: flag=True
if bingo[0][2]==bingo[1][2]==bingo[2][2]==1: flag=True
  
if bingo[0][0]==bingo[1][1]==bingo[2][2]==1: flag=True
if bingo[0][2]==bingo[1][1]==bingo[2][0]==1: flag=True
if flag:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:

a_1 = input().split()
a_2 = input().split()
a_3 = input().split()
a = [a_1,a_2,a_3]
n = int(input())
b = []
for i in range(n):
    b.append(input())



def ana(card,nums):
    for i in range(len(card)):
        for n in nums:
            replaced = ["0" if k == n else k for k in card[i]]
            card[i] = replaced





def bingo_or_not(list):
    flag = 0
    if len(set(list[0])) == 1 or len(set(list[1])) == 1 or len(set(list[2])) == 1:
        flag = 1
    elif list[0][0] == list[1][0] and list[0][0] == list[2][0]:
        flag = 1
    elif list[0][1] == list[1][1] and list[0][1] == list[2][1]:
        flag = 1
    elif list[0][2] == list[1][2] and list[0][2] == list[2][2]:
        flag = 1
    elif list[0][0] == list[1][1] and list[0][0] == list[2][2]:
        flag = 1
    elif list[0][2] == list[1][1] and list[0][2] == list[2][0]:
        flag = 1
    if flag == 0:
        return False
    else:
        return True


ana(a,b)


if bingo_or_not(a) == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A_0 = [int(i) for i in input().split()]
A_1 = [int(i) for i in input().split()]
A_2 = [int(i) for i in input().split()]
A = [A_0,A_1,A_2]
N = int(input())
B = set()
for i in range(N):
    B.add(int(input()))
for i in range(3):
    C = {A[k][i] for k in range(3)}
    D = {A[i][k] for k in range(3)}
    if C <= B or D <= B:
            print("Yes")
            break
else:
    if {A[0][0],A[1][1],A[2][2]} <= B or {A[0][2],A[1][1],A[2][0]} <= B:
        print("Yes")
    else :
        print("No")

Submission status: Accepted

Solution code:
def main():
    A = [list(map(int, input().split())) for _ in range(3)]
    N = int(input())
    B = [int(input()) for _ in range(N)]
    ans = [[0] * 3 for _ in range(3)]
    for b in B:
        for i, a in enumerate(A):
            g = my_index(a, b)
            if g != 'no':
                ans[i][g] = 1
    for r in range(3):
        if 1 == ans[0][r] == ans[1][r] == ans[2][r]:
            print('Yes')
            exit()
    for r in range(3):
        if 1 == ans[r][0] == ans[r][1] == ans[r][2]:
            print('Yes')
            exit()
    if 1 == ans[0][0] == ans[1][1] == ans[2][2]:
        print('Yes')
        exit()
    if 1 == ans[0][2] == ans[1][1] == ans[2][0]:
        print('Yes')
        exit()
    print('No')

def my_index(l, x):
    return l.index(x) if x in l else 'no'

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
bingo = [[0] * 3 for i in range(3)]
score = [[0] * 3 for i in range(3)]
for i in range(3):
    bingo[i][0], bingo[i][1], bingo[i][2] = map(int,input().split())

N=int(input())

A=[]

for i in range(N):
    A.append(int(input()))
ans = list(set(A))

for i in range(3):
    for j in range(3):
        if bingo[i][j] in ans: score[i][j]=1

flg=0

col=[0]*3
# 縦
for i in range(3):
    col[0]+=score[i][0]
    col[1]+=score[i][1]
    col[2]+=score[i][2]

for i in range(3):
    if col[i] == 3: flg=1
        
# 横
for i in score:
    if sum(i) == 3: flg=1

# 斜め
S1=score[0][0]+score[1][1]+score[2][2]
S2=score[2][0]+score[1][1]+score[0][2]

if S1 == 3: flg=1
if S2 == 3: flg=1
    
print("Yes" if flg==1 else "No")

Submission status: Accepted

Solution code:
# n = int(input())
# H = list(map(int,input().split()))


A1 = list(input().split())
A2 = list(input().split())
A3 = list(input().split())
n = int(input())

if n <= 2:
    print("No")
    exit()

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

for i in B:
    if i in A1:
        A1[A1.index(i)] = "#"
    if i in A2:
        A2[A2.index(i)] = "#"
    if i in A3:
        A3[A3.index(i)] = "#"


flag = 0
for i in range(3):
    if A1[i] == "#":
        flag += 1
    if A2[i] == "#":
        flag += 1
    if A3[i] == "#":
        flag += 1
    if flag != 3:
        flag = 0
    if flag == 3:
        print("Yes")
        exit()

if A1[0] == "#" and A1[1] == "#" and A1[2] == "#":
    print("Yes")
    exit()

if A2[0] == "#" and A2[1] == "#" and A2[2] == "#":
    print("Yes")
    exit()

if A3[0] == "#" and A3[1] == "#" and A3[2] == "#":
    print("Yes")
    exit()

if A1[0] == "#" and A2[1] == "#" and A3[2] == "#":
    print("Yes")
    exit()

if A3[0] == "#" and A2[1] == "#" and A1[2] == "#":
    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()))
alist = [a1[0] ,a1[1] ,a1[2], a2[0], a2[1], a2[2], a3[0], a3[1], a3[2]]
n = int(input())
b = [int(input()) for _ in range(n)]
ans = 'No'
for i in b:
    for ji, jv in enumerate(alist):
        if i == jv:
            alist[ji] = 0

if sum(alist[0:3]) == 0:
    ans = 'Yes'
if sum(alist[3:6]) == 0:
    ans = 'Yes'
if sum(alist[6:9]) == 0:
    ans = 'Yes'
if sum(alist[0::3]) == 0:
    ans = 'Yes'
if sum(alist[1::3]) == 0:
    ans = 'Yes'
if sum(alist[2::3]) == 0:
    ans = 'Yes'
if (alist[0] + alist[4] + alist[8]) == 0:
    ans = 'Yes'
if (alist[2] + alist[4] + alist[6]) == 0:
    ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
a=[0]
a.extend(list(map(int,input().split())))
a.extend(list(map(int,input().split())))
a.extend(list(map(int,input().split())))
n=int(input())
for i in range(n):
    b=int(input())
    for k in range(10):
        if a[k]==b:
            a[k]=0
t="No"
if a[1]==0 and a[2]==0 and a[3]==0:
    t="Yes"
if a[4]==0 and a[5]==0 and a[6]==0:
    t="Yes"
if a[7]==0 and a[8]==0 and a[9]==0:
    t="Yes"
if a[1]==0 and a[4]==0 and a[7]==0:
    t="Yes"
if a[2]==0 and a[5]==0 and a[8]==0:
    t="Yes"
if a[3]==0 and a[6]==0 and a[9]==0:
    t="Yes"
if a[1]==0 and a[5]==0 and a[9]==0:
    t="Yes"
if a[3]==0 and a[5]==0 and a[7]==0:
    t="Yes"

print(t)