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:
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

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

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

Submission status: Accepted

Solution code:
import sys
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
B = list(int(x) for x in sys.stdin.read().split())
if len(B) < 3:
  print('No')
  exit()
comb = []
for b in B:
  if b in A1:
    comb.append("1" + str(A1.index(b) + 1))
  elif b in A2:
    comb.append("2" + str(A2.index(b) + 1))
  elif b in A3:
    comb.append("3" + str(A3.index(b) + 1))
bingo_cond = ["111213", "212223", "313233", "112131", "112233", "132231", "132333"]
from itertools import combinations
for c in combinations(comb, 3):
  s = "".join(x for x in sorted(c))
  if s in bingo_cond:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

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

for el in number:
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == el:
                bingo[i][j] = 0
flag = 0
for i in range(3):
    for j in range(3):
        if bingo[i][j] != 0:
            break
    else:
        flag = 1
        
for i in range(3):
    for j in range(3):
        if bingo[j][i] != 0:
            break
    else:
        flag = 1
    
if bingo[0][0] == 0:
    if bingo[1][1] == 0:
        if bingo[2][2] == 0:
            flag = 1
            
if bingo[0][2] == 0:
    if bingo[1][1] == 0:
        if bingo[2][0] == 0:
            flag = 1
            
if flag == 1:
    print("Yes")
    
else:
    print("No")

Submission status: Accepted

Solution code:
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
N = int(input())

A = a1 + a2 + a3

b = [0]*9
for i in range(N):
    bingo = int(input())
    for j in range(len(A)):
        if bingo == A[j]:
            b[j] = 1

flag = 0
if b[0] + b[1] + b[2]==3:
    flag = 1
if b[3] + b[4] + b[5]==3:
    flag = 1
if b[6] + b[7] + b[8]==3:
    flag = 1
if b[0] + b[3] + b[6]==3:
    flag = 1
if b[1] + b[4] + b[7]==3:
    flag = 1
if b[2] + b[5] + b[8]==3:
    flag = 1
if b[0] + b[4] + b[8]==3:
    flag = 1
if b[2] + b[4] + b[6]==3:
    flag = 1
if flag == 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())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                a[j][k] = 0

cross = 0
ucross = 0
for j in range(3):
    if sum(a[j][:]) == 0 or sum([row[j] for row in a]) == 0:
        print("Yes")
        exit()
    cross += a[j][j]
    ucross += a[2-j][j]
if cross == 0 or ucross == 0:
    print("Yes")
    exit()

print("No")

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    A = [[int(i) for i in input().split()] for _ in range(3)]
    O = [[False] * 3 for _ in range(3)]
    N = int(input())
    for _ in range(N):
        b = int(input())
        for i in range(3):
            for j in range(3):
                if A[i][j] == b: O[i][j] = True

    for i in range(3):
        if False in O[i]: continue
        else:
            print("Yes")
            break
    else:
        for i in range(3):
            if O[0][i] == O[1][i] == O[2][i] == True:
                print("Yes")
                break
        else:
            if O[0][0] == O[1][1] == O[2][2] == True: print("Yes")
            elif O[0][2] == O[1][1] == O[2][0] == True: print("Yes")
            else: print("No")

    return 0

if __name__ =="__main__":
    solve()

Submission status: Accepted

Solution code:
t = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
m = [int(input()) for i in range(n)]
x = 0
for i in range(3):
        if t[i][0] in m and t[i][1] in m and t[i][2] in m:
            print('Yes')
            break
        elif t[0][i] in m and t[1][i] in m and t[2][i] in m:
            print('Yes')
            break
        elif t[0][0] in m and t[1][1] in m and t[2][2] in m:
            print('Yes')
            break
        elif t[0][2] in m and t[1][1] in m and t[2][0] in m:
            print('Yes')
            break
        else:
            x += 1
if x == 3:
    print('No')

Submission status: Accepted

Solution code:
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 i in range(n)]
f=False
for i in range(3):
    for j in range(n):
        if l1[i]==b[j]:
            l1[i]=0
        elif l2[i]==b[j]:
            l2[i]=0
        elif l3[i]==b[j]:
            l3[i]=0
for i in range(3):
    if l1[i]==l2[i] and l2[i]==l3[i] and l1[i]==l3[i]:
        f=True
if l1[0]==l1[1] and l1[1]==l1[2] and l1[0]==l1[2]:
    f=True
elif l2[0]==l2[1] and l2[1]==l2[2] and l2[0]==l2[2]:
    f=True
elif l3[0]==l3[1] and l3[1]==l3[2] and l3[0]==l3[2]:
    f=True
elif l1[0]==0 and l2[1]==0 and l3[2]==0:
    f=True
elif l3[0]==0 and l1[2]==0 and l2[1]==0:
    f=True
    
if f==True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np
A = [list(map(int, input().split())) for i in range(0,3)]
N = int(input())
b_list =list([int(input()) for i in range(0,N)])
count = np.zeros((3,3))
for i in range(0,3):
    for j in range(0,3):
        if A[i][j] in b_list:
            count[i][j] = count[i][j] + 1
if (count.sum(axis=1)  ==3).any():
    print('Yes')
elif (count.sum(axis=0) ==3).any():
    print('Yes')
elif count[0][0] + count[1][1] + count[2][2]==3:
    print('Yes')
elif count[2][0] + count[1][1] + count[0][2]==3:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a = []
for i in range(3):
    row = list(map(int, input().split()))
    a += row
    
result = [1] * 9
    
n = int(input())
for j in range(n):
    k = int(input())
    try:
        c = a.index(k)
        result[c] = 0
    except ValueError:
        continue

if sum(result[:3]) == 0:
    print('Yes')
elif sum(result[3:6]) == 0:
    print('Yes')
elif sum(result[6:]) == 0:
    print('Yes')
elif result[0] + result[3] + result[6] == 0:
    print('Yes')
elif result[1] + result[4] + result[7] == 0:
    print('Yes')
elif result[2] + result[5] + result[8] == 0:
    print('Yes')
elif result[0] + result[4] + result[8] == 0:
    print('Yes')
elif result[2] + result[4] + result[6] == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
L = []
bingo = set()
Numbers = []
testor = 0
for i in range(3):
  a,b,c = map(int,input().split())
  L.append((a,b,c)) #00 10 20/ 01 11 21/ 02 12 22/00 11 22/ 20 11 02/
N = int(input())
for i in range(3):
  a = L[0][i] 
  b = L[1][i]
  c = L[2][i]
  L.append((a,b,c))
a = L[0][0]
b = L[1][1]
c = L[2][2]
L.append((a,b,c))
a = L[2][0] 
b = L[1][1]
c = L[0][2]
L.append((a,b,c))
for i in range(N):
  Numbers.append(int(input()))
for i in range(8): #8 bingos pattern
  bingo = L[i]
  for k in range(N):
    if Numbers[k] in bingo:
      testor += 1
    if testor == 3:
        print('Yes')
        sys.exit(0)
  testor = 0
print('No')

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    input = stdin.readline

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

    A[0][0],A[0][1],A[0][2] = map(int,input().split())
    A[1][0],A[1][1],A[1][2] = map(int,input().split())
    A[2][0],A[2][1],A[2][2] = map(int,input().split())

    N = int(input())

    B = []
    for _ in range(N):
        B.append(int(input()[:-1]))
    B.sort()
    
    for i in range(3):
        for j in range(3):
            for b in B:
                if(A[i][j] == b):
                    F[i][j] = True
                    break

    # 縦
    for i in range(3):
        if(F[i][0]) & (F[i][1]) & (F[i][2]):
            print("Yes")
            return
    for i in range(3):
        if(F[0][i]) & (F[1][i]) & (F[2][i]):
            print("Yes")
            return
    if (F[0][0]) & (F[1][1]) & (F[2][2]):
        print("Yes")
        return
    if (F[2][0]) & (F[1][1]) & (F[0][2]):
        print("Yes")
        return

    print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A1 = input().split()
A2 = input().split()
A3 = input().split()

A1 = [int(i) for i in A1]
A2 = [int(i) for i in A2]
A3 = [int(i) for i in A3]

A = []
A.append(A1)
A.append(A2)
A.append(A3)

B = [[0,0,0],[0,0,0],[0,0,0]]

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

for val in vals:
  if A[0][0] == val:
    B[0][0] = 1
  elif A[0][1] == val:
    B[0][1] = 1
  elif A[0][2] == val:
    B[0][2] = 1
  elif A[1][0] == val:
    B[1][0] = 1
  elif A[1][1] == val:
    B[1][1] = 1
  elif A[1][2] == val:
    B[1][2] = 1
  elif A[2][0] == val:
    B[2][0] = 1
  elif A[2][1] == val:
    B[2][1] = 1
  elif A[2][2] == val:
    B[2][2] = 1

isGood = False
for i in range(3):
  if B[i][0] + B[i][1] + B[i][2] == 3:
    isGood = True

for i in range(3):
  if B[0][i] + B[1][i] + B[2][i] == 3:
    isGood = True
    
if B[0][0] + B[1][1] + B[2][2] == 3:
  isGood = True

if B[2][0] + B[1][1] + B[0][2] == 3:
  isGood = True
  
if isGood == True:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
def check(A,b):
    for raw in range(3):
        for colomn in range(3):
            if A[raw][colomn] == b:
                A[raw][colomn] = -1
                return
    return

A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
is_bingo = 'No'
for _ in range(N):
    b = int(input())
    check(A,b)

for raw in range(3):
    if A[raw][0] + A[raw][1] + A[raw][2] == -3:
        is_bingo = 'Yes'

for colomn in range(3):
    if A[0][colomn] + A[1][colomn] + A[2][colomn] == -3:
        is_bingo = 'Yes'

if A[0][0] + A[1][1] + A[2][2] == -3:
    is_bingo = 'Yes'
if A[0][2] + A[1][1] + A[2][0] == -3:
    is_bingo = 'Yes'

print(is_bingo)

Submission status: Accepted

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


for j in range(n):
    for p in range(3):
        for q in range(3):
            if(a[p][q] == b[j]):
                a[p][q] = 0

        '''
        try:
            pos = (y, row.index("G"))
            break
        except ValueError:
            pass
        '''
if (a[0][0] == 0 and a[0][1] == 0 and a[0][2] == 0):
    print("Yes")
elif(a[1][0] == 0 and a[1][1] == 0 and a[1][2] == 0):
    print("Yes")
elif(a[2][0] == 0 and a[2][1] == 0 and a[2][2] == 0):
    print("Yes")
elif(a[0][0] == 0 and a[1][0] == 0 and a[2][0] == 0):
    print("Yes")
elif(a[0][1] == 0 and a[1][1] == 0 and a[2][1] == 0):
    print("Yes")
elif(a[0][2] == 0 and a[1][2] == 0 and a[2][2] == 0):
    print("Yes")
elif(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:
A=[[],[],[]]
for i in range(3):
  A[i]=[int(_) for _ in input().split()]  
N=int(input())
b=[]
for i in range(N):
  b.append(int(input()))
import sys
for i in range(3):
  if (A[i][0] in b) and (A[i][1] in b) and (A[i][2] in b):
    print('Yes')
    sys.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')
    sys.exit()

if (A[0][0] in b) and (A[1][1] in b) and (A[2][2]in b) or \
      (A[2][0] in b) and (A[1][1] in b) and (A[2][0]in b):
  print('Yes')
  sys.exit()
print('No')

Submission status: Accepted

Solution code:
def main():
    bingo = [input().split(" ") for _ in range(3)]
    n = int(input())
    line = [[], [], []]
    v_line = [[], [], []]
    cross1 = []
    cross2 = []
    for _ in range(n):
        num = input()
        found = False
        for i in range(3):
            for j in range(3):
                if bingo[i][j] == num:
                    found = True
                    if i == j:
                        cross1.append((i, j))
                    if i == 0 and j == 2:
                        cross2.append((i, j))
                    if i == 2 and j == 0:
                        cross2.append((i, j))
                    if i == 1 and j == 1:
                        cross2.append((i, j))
                    line[i].append((i, j))
                    v_line[j].append((i, j))
                    continue
            if found:
                continue
    for l in line:
        if len(l) == 3:
            print("Yes")
            return
    for l in v_line:
        if len(l) == 3:
            print("Yes")
            return
    if len(cross1) == 3:
        print("Yes")
    elif len(cross2) == 3:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
Ar1 = list(map(int, input().split()))
Ar2 = list(map(int, input().split()))
Ar3 = list(map(int, input().split()))
N = int(input())
b = []

Ac1 = [Ar1[0], Ar2[0], Ar3[0]]
Ac2 = [Ar1[1], Ar2[1], Ar3[1]]
Ac3 = [Ar1[2], Ar2[2], Ar3[2]]

naname1 = [Ar1[0], Ar2[1], Ar3[2]]
naname2 = [Ar1[2], Ar2[1], Ar3[0]]

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

for lines in [Ar1, Ar2, Ar3, Ac1, Ac2, Ac3, naname1, naname2] :
  if lines[0] in b and lines[1] in b and lines[2] in b :
    print("Yes")
    sys.exit()
  else :
    next
    
print("No")

Submission status: Accepted

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

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

for i in range(N):
    B.append(int(input()))
     
for b in B:
    for i in range(3):
        for j in range(3):
            if b == A[i][j]:
                A[i][j] = "x"
                
flag = False
            
for i in range(3):
    if A[i][0] == A[i][1] == A[i][2]:
        flag = True
        break
    if A[0][i] == A[1][i] == A[2][i]:
        flag = True
        break
    
if A[0][0] == A[1][1] == A[2][2] or A[0][2] == A[1][1] == A[2][0]:
    flag = True
    
if flag == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

done = 0
for i in range(3):
  if (a[i][0] == a[i][1] == a[i][2] == 0 or a[0][i] == a[1][i] == a[2][i] == 0) and done == 0:
    done = 1
    print('Yes')

if done == 0 and (a[0][0] == a[1][1] == a[2][2] == 0 or a[0][2] == a[1][1] == a[2][0] == 0) :
  print('Yes')
  done = 1

if done == 0:
  print('No')

Submission status: Accepted

Solution code:
import itertools

A = []
A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))
A = list(itertools.chain.from_iterable(A))
N = int(input())
for n in range(N):
    b = int(input())
    A = [0 if a == b else a for a in A]

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

Submission status: Accepted

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

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


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    bingo_arr = [
        A[0], A[1], A[2],
        [A[0][0], A[1][0], A[2][0]], [A[0][1], A[1][1], A[2][1]], [A[0][2], A[1][2], A[2][2]],
        [A[0][0], A[1][1], A[2][2]], [A[0][2], A[1][1], A[2][0]]
    ]
    for bingo in bingo_arr:
        cnt = 0
        for i in bingo:
            if i in b:
                cnt += 1
                if cnt == 3:
                    print(YES)
                    return
                continue
    print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [[int(next(tokens)) for _ in range(3)] for _ in range(3)]  # type: "List[List[int]]"
    N = int(next(tokens))  # type: int
    b = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(A, N, b)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#N行複数列の文字列複数を行列として入力
table = [input().split() for l in range(3)]
N = int(input())
array = [input() for i in range(N)]
bingo = ""

for k in range(3):
    for j in range(3):
        if table[k][j] in array:
            table[k][j] = 0

        table[k][j] = int(table[k][j])

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

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

if table[0][0] + table[1][1] + table[2][2] == 0 or table[2][0] + table[1][1] + table[2][0] ==0:
        bingo = "Yes"

if bingo == "":
    bingo = "No"

print(bingo)

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

import numpy as np
a = np.array(a)
# print(a)
# print(n)
# print(b)

# print(a[1,0])
# print(a[2,2])

# c = a[1,1]
# print(c)


for i in range(n):
    if b[i] in a:
        r = np.where(a==b[i])
        a[r[0][0],r[1][0]] = 0
    else:
        pass


# print(a)
# print(a[1,0])

if a[0,0]==0 and a[2,2]==0 and a[1,1]==0:
    print("Yes")
elif a[0,1]==0 and a[2,1]==0 and a[1,1]==0:
    print("Yes")
elif a[0,2]==0 and a[2,0]==0 and a[1,1]==0:
    print("Yes")
elif a[1,0]==0 and a[1,2]==0 and a[1,1]==0:
    print("Yes")
elif a[0,0]==0 and a[1,0]==0 and a[2,0]==0:
    print("Yes")
elif a[0,2]==0 and a[1,2]==0 and a[2,2]==0:
    print("Yes")
elif a[0,0]==0 and a[0,1]==0 and a[0,2]==0:
    print("Yes")
elif a[2,0]==0 and a[2,1]==0 and a[2,2]==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a11, a12, a13 = map(int, input().split())
a21, a22, a23 = map(int, input().split())
a31, a32, a33 = map(int, input().split())
card = {
    0: {0: a11, 1: a12, 2: a13},
    1: {0: a21, 1: a22, 2: a23},
    2: {0: a31, 1: a32, 2: a33}
}
n = int(input())
marks = [[0,0,0], [0,0,0], [0,0,0]]
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if card[j][k] == b:
                marks[j][k] = 1
if sum(marks[0]) == 3:
    print("Yes")
elif sum(marks[1]) == 3:
    print("Yes")
elif sum(marks[2]) == 3:
    print("Yes")
elif sum([marks[0][0],marks[1][0],marks[2][0]]) == 3:
    print("Yes")
elif sum([marks[0][1],marks[1][1],marks[2][1]]) == 3:
    print("Yes")
elif sum([marks[0][2],marks[1][2],marks[2][2]]) == 3:
    print("Yes")
elif sum([marks[0][0],marks[1][1],marks[2][2]]) == 3:
    print("Yes")
elif sum([marks[2][0],marks[1][1],marks[0][2]]) == 3:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

for h in range(3):
    for w in range(3):
        if array[h][w] in nums:
            array[h][w] = 0

i = 0
for h in range(3):
    if sum(array[:, h]) == 0:
        i = 1
for w in range(3):
    if sum(array[w]) == 0:
        i = 1
if sum(np.diag(np.fliplr(array))) == 0:
    i = 1
if sum(np.diag(array)) == 0:
    i = 1

if i == 1:
    print("Yes")
else:
    print('No')

Submission status: Accepted

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

for i in range(N):
  if b[i] in A1:
    if len(list(set(A1))) == 1:
      A1 = [0] * 3
    else:
      A1[A1.index(b[i])] = 0
  elif b[i] in A2:
    if len(list(set(A2))) == 1:
      A2 = [0] * 3
    else:
      A2[A2.index(b[i])] = 0
  elif b[i] in A3:
    if len(list(set(A3))) == 1:
      A3 = [0] * 3
    else:
      A3[A3.index(b[i])] = 0


if A1[0] == 0 and A1[0] == A2[0] == A3[0]:
  ans = "Yes"
elif A1[1] == 0 and A1[1] == A2[1] == A3[1]:
  ans = "Yes"
elif A1[2] == 0 and A1[2] == A2[2] == A3[2]:
  ans = "Yes"
elif A1[0] == 0 and A1[0] == A2[1] == A3[2]:
  ans = "Yes"
elif A1[2] == 0 and A1[2] == A2[1] == A3[0]:
  ans = "Yes"
elif A1 == [0] * 3 or A2 == [0] * 3 or A3 == [0] * 3:
  ans = "Yes"
else:
  ans = "No"

print(ans)

Submission status: Accepted

Solution code:
A = [None]*3
A[0] = list(map(int, input().split()))
A[1] = list(map(int, input().split()))
A[2] = list(map(int, input().split()))
N = int(input())
B = [None]*N
for i in range(N):
    B[i] = int(input())

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


S1 = 0
S2 = 0
for i in range(3):
    S1 += A[i][i]
    S2 += A[i][2-i]
if S1 == -3 or S2 == -3:
    print("Yes")
    quit()

for i in range(3):
    if sum(A[i]) == -3:
        print("Yes")
        break
    if A[0][i] + A[1][i] + A[2][i] ==-3:
        print("Yes")
        break
else:
    print("No")

Submission status: Accepted

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

for ans in range(n):
  ans = int(input())
  for i in range(3):
    for j in range(3):
      if l[i][j] == ans:
        l_ans[i][j] = 1

flag = 0
for i in l_ans:
  if sum(i) == 3:
    flag += 1

for i in range(3):
  temp = 0
  for j in range(3):
    temp += l_ans[j][i]
  if temp == 3:
    flag += 1

temp = 0
for i in range(3):
  temp += l_ans[i][i]
if temp == 3:
  flag += 1

temp = 0
for i in range(3):
  temp += l_ans[i][2 - i]
if temp == 3:
  flag += 1

if flag >= 1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
mat = [list(map(int, input().split())) for _ in range(3)]
d = {}
for idx, i in enumerate(mat):
    for idx2, j in enumerate(i):
        d[j] = [idx, idx2]

n = int(input())
mat2 = [[0]*3 for _ in range(3)]

for _ in range(n):
    b = int(input())
    if d.get(b) is None:
        pass
    else:
        i, j = d.get(b)
        mat2[i][j] = 1
        if sum([mat2[i][di] for di in range(3)])== 3:
            print('Yes')
            exit()
        
        if sum([mat2[di][j] for di in range(3)])== 3:
            print('Yes')
            exit()
        
        if sum([mat2[di][di] for di in range(3)])==3:
            print('Yes')
            exit()
        
        if mat2[2][0] + mat2[1][1] + mat2[0][2] == 3:
            print('Yes')
            exit()

print('No')

Submission status: Accepted

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

flag = 0 

for i in range(3):
    for j in range(3):
        if L[i][j] in l:
            dp[i][j] = 1
# dp = [[1,1,0],[0,1,0],[1,0,1]]
for i in range(3):
    if sum(dp[i]) ==3:
        flag = 1

for j in range(3):
    s = 0
    for i in range(3):
        s+= dp[i][j]
    if s == 3:
        flag = 1
s = 0
t = 0
for i in range(3):
    s+=  dp[i][i]
    t+= dp[i][2-i]
if s==3 or t == 3:
    flag = 1
    
if flag:
    print('Yes')
else:
    print('No')
# print(dp)

Submission status: Accepted

Solution code:
a=[]
b=[]
nums=[]
ans="No"

for i in range(3):
    l=list(map(int,input().split()))
    a.append(l)

n=int(input())

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

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
                num=10*(j+1)+k+1
                nums.append(num)

nums.sort()


if a[0][0]==a[0][1]==a[0][2]==0:
    ans="Yes"
if a[1][0]==a[1][1]==a[1][2]==0:
        ans="Yes"
if a[2][0]==a[2][1]==a[2][2]==0:
    ans="Yes"
if a[0][0]==a[1][0]==a[2][0]==0:
    ans="Yes"
if a[0][1]==a[1][1]==a[2][1]==0:
        ans="Yes"
if a[0][2]==a[1][2]==a[2][2]==0:
    ans="Yes"
        
if 11 in nums and 22 in nums and 33 in nums:
    ans="Yes"

if 13 in nums and 22 in nums and 31 in nums:
    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()))
A = A1 + A2 + A3

N = int(input())

# 印をつける
for i in range(N):
    b = int(input())
    
    for index in range(len(A)):
        a = A[index]
        if a == b:
            A[index] = 0     # 0を印とする

def isExistTatePair():
    for i in range(3):
        sum = 0
        for j in range(3):
            sum += A[3 * j + i]
        if sum == 0:
            return True
    return False

def isExistYokoPair():
    for i in range(3):
        sum = 0
        for j in range(3):
            sum += A[3 * i + j]
        if sum == 0:
            return True
    return False

def isExistNanamePair():
    sum = 0
    for i in range(3):
        sum += A[3 * i + i]
    if sum == 0:
        return True
    
    sum = 0
    for i in range(3):
        sum += A[3 * (i + 1) - (i + 1)]
    if sum == 0:
        return True
    return False

isExistPair = isExistTatePair() or isExistYokoPair() or isExistNanamePair()
print('Yes' if isExistPair else 'No')

Submission status: Accepted

Solution code:
A = [[int(i) for i in input().split()] for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

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

def solve():
    for a in A:
        if len(set(a)) == 1:
            return True
    for a in zip(*A):
        if len(set(a)) == 1:
            return True

    return len({A[0][0], A[1][1], A[2][2]}) == 1 or len({A[0][2], A[1][1], A[2][0]}) == 1

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# @Time    : 2020/3/1 19:59
# @Author  : DIRICHLET
# @File    : main.py


b=[[0,0,0],[0,0,0],[0,0,0]]
#print(b)
m={}
for i in range(3):
    t=list(map(int,input().split()))
    k=0
    for j in t:
        m[j]=(i,k)
        k+=1
n=int(input())
for i in range(n):
    t=int(input())
    if t in m:
        #print(m[t])
        b[m[t][0]][m[t][1]]=1
for i in b:
    ans=1
    for j in i:
        ans*=j
    if ans==1:
        print('Yes')
        exit()
for i in range(3):
    ans=1
    for j in range(3):
        ans*=b[j][i]
    if ans==1:
        print('Yes')
        exit()
if b[0][0]*b[1][1]*b[2][2]==1:
    print('Yes')
    exit()
if b[0][2]*b[1][1]*b[2][0]==1:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

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

n=int(input())
for i in range(n):
    a=int(input())
    bingo[bingo==a]=0

bin=False
for i in range(3):
    bin = bingo[i].sum()==0 or bin
    bin = bingo[:,i].sum()==0 or bin

bin = (bingo[0,0]+bingo[1,1]+bingo[2,2])==0 or bin
bin = (bingo[2,0]+bingo[1,1]+bingo[0,2])==0 or bin

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

Submission status: Accepted

Solution code:
import sys
a1 = list(map(str,input().split()))
a2 = list(map(str,input().split()))
a3 = list(map(str,input().split()))
M=int(input())
N = "N"
if M <= 2:
    print('No')
    sys.exit()

Num=[] #appendのために宣言が必要
while True:
    try:
        Num.append(input())

    except:
        break;

A1= ["N" if Num.count(i)!=0 else i for i in a1]
A2= ["N" if Num.count(i)!=0 else i for i in a2]
A3= ["N" if Num.count(i)!=0 else i for i in a3]

if A1[0] == N and A1[1] == N and A1[2] == N :
    print("Yes")
elif A2[0] == N and A2[1] == N and A2[2] == N :
    print("Yes")
elif A3[0] == N and A3[1] == N and A3[2] == N :
    print("Yes")
elif A1[0] == N and A2[0] == N and A3[0] == N :
    print("Yes")
elif A1[1] == N and A2[1] == N and A3[2] == N :
    print("Yes")
elif A1[2] == N and A2[2] == N and A3[2] == N :
    print("Yes")
elif A1[0] == N and A2[1] == N and A3[2] == N :
    print("Yes")
elif A1[2] == N and A2[1] == N and A3[0] == N :
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def bingo(A, B):
  for i in range(3):
    if A[i][0] == "o" and A[i][1] == "o" and A[i][2] == "o":
      return True
    elif A[0][i] == "o" and A[1][i] == "o" and A[2][i] == "o":
      return True
    
  if A[0][0] == "o" and A[1][1] == "o" and A[2][2] == "o":
    return True
  elif A[0][2] == "o" and A[1][1] == "o" and A[2][0] == "o":
    return True
    
  return False

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

for b in B:
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        A[i][j] = "o"

if bingo(A, B):
  print("Yes")
else:
  print("No")