Problem:


Score : 200 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

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

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

1 \leq N \leq 10

1 \leq b_i \leq 100

b_i \neq b_j (i \neq j)

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

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

Sample Output 1

Yes

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

Sample Input 2

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

Sample Output 2

No

We will mark nothing.

Sample Input 3

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

Sample Output 3

Yes

We will mark all the squares.



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


Sample output:
Yes

Submission status: Accepted

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


def solve(inp):
    A = list(map(int, inp.readline().strip().split(' ')))
    A += list(map(int, inp.readline().strip().split(' ')))
    A += list(map(int, inp.readline().strip().split(' ')))
    N = int(inp.readline().strip())
    B = [int(inp.readline().strip()) for i in range(N)]

    for b in B:
        for i in range(9):
            if A[i] == b:
                A[i] = 0

    for a, b, c in [
        [0, 1, 2],
        [3, 4, 5],
        [6, 7, 8],
        [0, 3, 6],
        [1, 4, 7],
        [2, 5, 8],
        [0, 4, 8],
        [2, 4, 6],
    ]:
        if A[a] == A[b] == A[c] == 0:
            return "Yes"

    return "No"


def main():
    import sys
    result = solve(sys.stdin)
    if result is not None and result != '':
        print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

t0 = [0,1,2,0,2]
t1 = [0,1,2,1,1]
t2 = [0,1,2,2,0]

bingo = False
for i in range(N):
    for h in range(3):
        for w in range(3):
            if a[h][w] == b[i]:
                a[h][w] = 0
    for t in range(5):
        if a[0][t0[t]]+a[1][t1[t]]+a[2][t2[t]] == 0:
            bingo = True
    for y in range(3):
        if sum(a[y]) ==0:
            bingo = True
    if bingo: break

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

Submission status: Accepted

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

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

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

f = False
for i in range(3):
    f_tmp = True
    for j in range(3):
        if not(bingo[i][j] and f_tmp):
            f_tmp = False
    if f_tmp:
        f = True

for j in range(3):
    f_tmp = True
    for i in range(3):
        if not(bingo[i][j] and f_tmp):
            f_tmp = False
    if f_tmp:
        f = True

f_tmp = True
for i in range(3):
    if not(bingo[i][i] and f_tmp):
        f_tmp = False
if f_tmp:
    f = True

f_tmp = True
for i in range(3):
    if not(bingo[2-i][i] and f_tmp):
        f_tmp = False
if f_tmp:
    f = True

if f:
    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)]
hit = [[False] * 3 for _ in range(3)]

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

bingo = False

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

if hit[0][0] and hit[1][1] and hit[2][2]:
    bingo = True
elif hit[0][2] and hit[1][1] and hit[2][0]:
    bingo = True

print("Yes" if bingo else "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())

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

def ok(a, b, c):
    return B.__contains__(a) and B.__contains__(b) and B.__contains__(c)

print("Yes" if ok(a11, a12, a13) or ok(a21, a22, a23) or ok(a31, a32, a33) or ok(a11, a21, a31) or ok(a12, a22, a23) or ok(a13, a23, a33) or ok(a11, a22, a33) or ok(a13, a22, a31) else "No")

Submission status: Accepted

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

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

def is_bingo(row, B):
    count = 0 
    for b in B:
        if b in row:
            count += 1
    if count >= 3:
        return True
    else:
        False

def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    A = np.asarray(A)
    isbingo = False

    for row in A:
        if is_bingo(row, b):
            isbingo = True

    for col in A.T:
        if is_bingo(col, b):
            isbingo = True

    for diag in [np.diag(A), np.diag(np.fliplr(A))]:
        if is_bingo(diag, b):
            isbingo = True

    if isbingo:
        print(YES)
    else:
        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:
A = [[0 for _ in range(3)] for _ in range(3)]

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

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


flag = [[False for _ in range(3)] for _ in range(3)]

f = False
for b in B:
    for row in range(3):
        for col in range(3):
            if A[row][col] == b:
                flag[row][col] = True
                f = True
if not f:
    print("No")
    exit(0)
    
# check (--)
for row in range(3):
    f = True
    for col in range(3):
        if not flag[row][col]:
            f = False
            break
    if f:
        print("Yes")
        exit(0)

# check (|)
for row in range(3):
    f = True
    for col in range(3):
        if not flag[col][row]:
            f = False
            break
    if f:
        print("Yes")
        exit(0)

# check (diag)
if flag[0][0] and flag[1][1] and flag[2][2]:
    print("Yes")
elif flag[0][2] and flag[1][1] and flag[2][0]:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) 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:
                a[i][j] = 0
                break

flag = False
for i in a:
    if sum(i) == 0:
        flag = True
if flag == False:
    for i in range(3):
        if a[0][i] + a[1][i] + a[2][i] == 0:
            flag = True
if flag == False:
    if a[0][0] + a[1][1] + a[2][2] == 0:
        flag = True
    if a[0][2] + a[1][1] + a[2][0] == 0:
        flag = True
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline

A = [list(map(int, readline().split())) for _ in range(3)]
N, *b = map(int, read().split())
b = set(b)

for i in A:
    for j in i:
        if j not in b:
            break
    else:
        print('Yes')
        exit()

for i in range(3):
    for j in range(3):
        if A[j][i] not in b:
            break
    else:
        print('Yes')
        exit()

c1 = [(0, 0), (1, 1), (2, 2)]
c2 = [(0, 2), (1, 1), (2, 0)]
for i, j in c1:
    if A[i][j] not in b:
        break
else:
    print('Yes')
    exit()

for i, j in c2:
    if A[i][j] not in b:
        break
else:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

Solution code:
def check(card):
    for i in range(3):
        if all(card[i][j] == 'o' for j in range(3)):
            return True
    for j in range(3):
        if all(card[i][j] == 'o' for i in range(3)):
            return True
    if all(card[i][j] == 'o' for (i, j) in [(0, 0), (1, 1), (2, 2)]):
        return True
    if all(card[i][j] == 'o' for (i, j) in [(0, 2), (1, 1), (2, 0)]):
        return True
    return False


card = [[0] * 3 for _ in range(3)]
mapping = {}
for i in range(3):
    for j, x in enumerate(map(int, input().split())):
        card[i][j] = x
        mapping[x] = (i, j)
N = int(input())
for _ in range(N):
    y = int(input())
    if y in mapping:
        i, j = mapping[y]
        card[i][j] = 'o'

if check(card):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)


def read_values():
    return map(int, input().split())


def read_index():
    return map(lambda x: x - 1, map(int, input().split()))


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def functional(N, mod):
    F = [1] * (N + 1)
    for i in range(N):
        F[i + 1] = (i + 1) * F[i] % mod
    return F


def main():
    A = []
    for _ in range(3):
        a = read_list()
        A.extend(a)
    N = int(input())
    B = [False] * 9
    for _ in range(N):
        b = int(input())
        if b in A:
            c = A.index(b)
            B[c] = True

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A = [list(map(int,input().split())) for i in range(3)]
n = int(input())
B = [int(input()) for i in range(n)]
C = [[0] * 3 for i in range(3)]
for i in range(3):
    for j in range(3):
        for k in range(n):
            if A[i][j] == B[k] :
                C[i][j] += 1
y=0
for i in range(3):
    if sum(C[i]) == 3:
        y = 1
    if C[0][i] + C[1][i] + C[2][i] == 3:
        y = 1
if C[0][0] + C[1][1] + C[2][2] == 3:
    y = 1
if C[0][2] + C[1][1] + C[2][0] == 3:
    y = 1
if y == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

for _ in range(N):
  b=int(input())
  for i in range(3):
    for j in range(3):
      if b==A[i][j]:
        C[i][j]=1

for i in range(3):
  if C[i][0]==1 and C[i][1]==1 and C[i][2]==1:
    print("Yes")
    exit()
for i in range(3):
  if C[0][i]==1 and C[1][i]==1 and C[2][i]==1:
    print("Yes")
    exit()
if C[0][0]==1 and C[1][1]==1 and C[2][2]==1:
  print("Yes")
  exit()
if C[0][2]==1 and C[1][1]==1 and C[2][0]==1:
  print("Yes")
  exit()
print("No")

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) for i in range(3)]
f = [[False]*3 for i in range(3)]
n = int(input())
b = []
for i in range(n):
    b.append(int(input()))
for y in range(3):
    for x in range(3):
        if a[y][x] in b:
            f[y][x] = True
for y in range(3):
    if f[y][0] and f[y][1] and f[y][2]:
        print("Yes")
        exit()
for x in range(3):
    if f[0][x] and f[1][x] and f[2][x]:
        print("Yes")
        exit()
if f[0][0] and f[1][1] and f[2][2]:
    print("Yes")
    exit()
if f[2][0] and f[1][1] and f[0][2]:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_left # bisect_left(list, value)
#from fractions import gcd

sys.setrecursionlimit(10**7)
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]

chk = [[0] * 3 for _ in range(3)]

for bi in b:
    for i, row in enumerate(A):
        for j, col in enumerate(row):
            if col == bi:
                chk[i][j] = 1

#for row in chk:
#    print(row)

# check

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

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

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

    if chk[0][i] and chk[1][i] and chk[2][i]:
        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())

flag = [[False]*3 for i in range(3)]

for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if b==A[j][k]:
                flag[j][k]=True

for i in range(3):
    ans = True
    for j in range(3):
        if not flag[i][j]:
            ans=False
            break
    if ans:
        print("Yes")
        break

if not ans:
    for i in range(3):
        ans = True
        for j in range(3):
            if not flag[j][i]:
                ans=False
                break
        if ans:
            print("Yes")
            break

if not ans:
    ans = True
    for i in range(3):
        if not flag[i][i]:
            ans = False
            break
    if ans:
        print("Yes")

if not ans:
    ans = True
    for i in range(3):
        if not flag[i][2-i]:
            ans = False
            break
    if ans:
        print("Yes")

if not ans:
    print("No")

Submission status: Accepted

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


n = int(input())
B = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for i in range(n):
    num = int(input())
    for j in range(3):
        for i in range(3):
            if A[j][i] == num:
                B[j][i] = 1

ans = 0
for i in B:
    if len(set(i)) == 1 and i[0] == 1:
        ans = 1
for j in range(3):
    if B[0][j] == 1 and B[1][j] == 1 and B[2][j] == 1:
        ans = 1
if B[0][0] == 1 and B[1][1] == 1 and B[2][2] == 1:
    ans = 1
if B[0][2] == 1 and B[1][1] == 1 and B[2][0] == 1:
    ans = 1

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

Submission status: Accepted

Solution code:
A = [tuple(map(int, input().split())) for i in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]
B = [[False]*3 for i in range(3)]

for x in b:
    for i in range(3):
        for j in range(3):
            if A[i][j] == x:
                B[i][j] = True
                break


flag = False
for i in range(3):
    for j in range(3):
        if B[i][j] == False:
            break
        if j == 2:
            flag = True


for j in range(3):
    for i in range(3):
        if B[i][j] == False:
            break
        if i == 2:
            flag = True

for i in range(3):
    if B[i][i] == False:
        break
    if i == 2:
        flag = True
for i in range(3):
    if B[2 - i][i] == False:
        break
    if i == 2:
        flag = True

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

Submission status: Accepted

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

if b[0][0] + b[1][1] + b[2][2] == 3:
    print('Yes')
elif b[0][0] + b[0][1] + b[0][2] == 3:
    print('Yes')
elif b[1][0] + b[1][1] + b[1][2] == 3:
    print('Yes')
elif b[2][0] + b[2][1] + b[2][2] == 3:
    print('Yes')

elif b[0][0] + b[1][0] + b[2][0] == 3:
    print('Yes')
elif b[0][1] + b[1][1] + b[2][1] == 3:
    print('Yes')
elif b[0][2] + b[1][2] + b[2][2] == 3:
    print('Yes')

elif b[2][0] + b[1][1] + b[0][2] == 3:
    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())
for i in range(N):
  b = int(input())
  for j in range(3):
    if(A1[j] == b): A1[j] = 0
    if(A2[j] == b): A2[j] = 0
    if(A3[j] == b): A3[j] = 0
      
ans = 0      
if(A1[0]+A1[1]+A1[2] == 0): ans = 1
if(A2[0]+A2[1]+A2[2] == 0): ans = 1
if(A3[0]+A3[1]+A3[2] == 0): ans = 1
if(A1[0]+A2[0]+A3[0] == 0): ans = 1
if(A1[1]+A2[1]+A3[1] == 0): ans = 1
if(A1[2]+A2[2]+A3[2] == 0): ans = 1
if(A1[0]+A2[1]+A3[2] == 0): ans = 1
if(A1[2]+A2[1]+A3[0] == 0): ans = 1  
 
if(ans == 0): print('No')
else: print('Yes')

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
flag = [[False]*3 for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                flag[i][j] = True
ans = False
for i in range(3):
    if all(flag[i][j] for j in range(3)):
        ans = True
    if all(flag[j][i] for j in range(3)):
        ans = True
if all(flag[i][i] for i in range(3)):
    ans = True
if all(flag[2-i][i] for i in range(3)):
    ans = True
if ans:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a = [[int(i) for i in input().split()] for _ in range(3)]
c=[[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:
                c[i][j] = True
ok = False
for i in range(3):
    d = True
    for j in range(3):
        if c[i][j] == False:
            d = False
    if d:
        ok = True

for i in range(3):
    d = True
    for j in range(3):
        if c[j][i] == False:
            d = False
    if d:
        ok = True
d = True
for j in range(3):
    if c[j][j] == False:
        d = False
if d:
    ok = True

d = True
for j in range(3):
    if c[j][2-j] == False:
        d = False
if d:
    ok = True
print("Yes"if ok else"No")

Submission status: Accepted

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

N = int(input())
ans = "No"
for i in range(N):
    b = int(input())
    for y in range(3):
        for x in range(3):
            if a[y][x] == b:
                a[y][x] = 0

    for j in range(3):
        if sum(a[j]) == 0:
            ans = "Yes"
            break
    for j in range(3):
        s = 0
        for k in range(3):
            s += a[k][j]
        if s == 0:
            ans = "Yes"
            break
    if (a[0][0]+a[1][1]+a[2][2]) == 0 or (a[0][2]+a[1][1]+a[2][0]) == 0:
        ans = "Yes"
        break
    if ans == "Yes":
        break
print(ans)

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())
N = int(input())
blist = [int(input()) for i in range(N)]

if a11 in blist and a21 in blist and a31 in blist:
    print('Yes')
    exit(0)

if a12 in blist and a22 in blist and a32 in blist:
    print('Yes')
    exit(0)

if a13 in blist and a23 in blist and a33 in blist:
    print('Yes')
    exit(0)

if a11 in blist and a12 in blist and a13 in blist:
    print('Yes')
    exit(0)

if a21 in blist and a22 in blist and a23 in blist:
    print('Yes')
    exit(0)

if a31 in blist and a32 in blist and a33 in blist:
    print('Yes')
    exit(0)

if a11 in blist and a22 in blist and a33 in blist:
    print('Yes')
    exit(0)

if a13 in blist and a22 in blist and a31 in blist:
    print('Yes')
    exit(0)

print('No')

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    A = []
    for _ in range(3):
        A.extend(LI())
    N = I()
    for _ in range(N):
        b = I()
        for i, a in enumerate(A):
            if a == b:
                A[i] = -1
    nums = set()
    for i, a in enumerate(A):
        if a == -1:
            nums.add(i)
    bingo = False
    if 0 in nums and 1 in nums and 2 in nums:
        bingo = True
    if 3 in nums and 4 in nums and 5 in nums:
        bingo = True
    if 6 in nums and 7 in nums and 8 in nums:
        bingo = True
    if 0 in nums and 3 in nums and 6 in nums:
        bingo = True
    if 1 in nums and 4 in nums and 7 in nums:
        bingo = True
    if 2 in nums and 5 in nums and 8 in nums:
        bingo = True
    if 0 in nums and 4 in nums and 8 in nums:
        bingo = True
    if 2 in nums and 4 in nums and 6 in nums:
        bingo = True
    if bingo:
        print("Yes")
    else:
        print("No")


main()

Submission status: Accepted

Solution code:
A = [[int(i) for i in input().split()] for _ in range(3)]
N = int(input())
bingo = [[False] * 3 for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                bingo[i][j] = True

flag = False

if bingo[0][0] == bingo[1][1] == bingo[2][2] == True:
    flag = True
if bingo[0][2] == bingo[1][1] == bingo[2][0] == True:
    flag = True
for i in range(3):
    tmp = True
    for j in range(3):
        if not bingo[i][j]:
            tmp = False
    flag |= tmp
for i in range(3):
    tmp = True
    for j in range(3):
        if not bingo[j][i]:
            tmp = False
    flag |= tmp

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

Submission status: Accepted

Solution code:
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()))
ans = 'No'
for i in range(3):
    cnt = 0
    for j in range(3):
        if a[i][j] in b:
            cnt += 1
    if cnt == 3:
        ans = 'Yes'
for i in range(3):
    cnt = 0
    for j in range(3):
        if a[j][i] in b:
            cnt += 1
    if cnt == 3:
        ans = 'Yes'
if a[0][0] in b and a[1][1] in b and a[2][2] in b:
    ans = 'Yes'
if a[0][2] in b and a[1][1] in b and a[2][0] in b:
    ans = 'Yes'
print(ans)

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]"):
    punches = [[False for i in range(3)] for i in range(3)]
    for step in range(N):
        for i in range(3):
            for j in range(3):
                if A[i][j] == b[step]:
                    punches[i][j] = True
    for i in range(3):
        hasFalse = False
        for j in range(3):
            if not punches[i][j]:
                hasFalse = True
                break
        if not hasFalse:
            print("Yes")
            return
    for i in range(3):
        hasFalse = False
        for j in range(3):
            if not punches[j][i]:
                hasFalse = True
                break
        if not hasFalse:
            print("Yes")
            return
    if punches[0][0] and punches[1][1] and punches[2][2]:
        print("Yes")
        return
    if punches[0][2] and punches[1][1] and punches[2][0]:
        print("Yes")
        return
    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:
A = [[0 for _ in range(3)] for _ in range(3)]
for i in range(3):
    a1, a2, a3 = map(int, input().split())
    A[i] = [a1, a2, a3]
N = int(input())
board = [[False for _ in range(3)] for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                board[i][j] = True
# yoko
for i in range(3):
    if board[i][0] and board[i][1] and board[i][2]:
        print('Yes')
        exit(0)
# tate
for j in range(3):
    if board[0][j] and board[1][j] and board[2][j]:
        print('Yes')
        exit(0)

# naname
if board[0][0] and board[1][1] and board[2][2]:
    print('Yes')
    exit(0)
if board[0][2] and board[1][1] and board[2][0]:
    print('Yes')
    exit(0)
print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

F = [[0]*3 for i in range(3)]
A = [list(map(int,input().split())) for i 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:
        F[i][j] = 1
ans = 0
for i in range(3):
  f = 1
  for j in range(3):
    if F[i][j] != 1:
      f = 0
  if f ==1:
    ans = 1
for j in range(3):
  f = 1
  for i in range(3):
    if F[i][j] != 1:
      f = 0
  if f == 1:
    ans = 1
if F[0][0] and F[1][1] and F[2][2]:
  ans = 1
if F[0][2] and F[1][1] and F[2][0]:
  ans = 1
print("Yes" if ans else "No")
# print(F)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    # h_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    grid = [[int(x) for x in sys.stdin.readline().split()]
            for _ in range(3)]  # int grid
    N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]

    for b in v_list:
        for i in range(3):
            for j in range(3):
                if grid[i][j] == b:
                    grid[i][j] = True

    # 横
    for i in range(3):
        if grid[i][0] == True and grid[i][1] == True and grid[i][2] == True:
            print('Yes')
            return

            # たて
    for j in range(3):
        if grid[0][j] == True and grid[1][j] == True and grid[2][j] == True:
            print('Yes')
            return

    if grid[0][0] == True and grid[1][1] == True and grid[2][2] == True:
        print('Yes')
        return

    if grid[0][2] == True and grid[1][1] == True and grid[2][0] == True:
        print('Yes')
        return

    print('No')


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """41 7 46
26 89 2
78 92 8
5
6
45
16
57
17"""
        output = """No"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34"""
        output = """Yes"""
        self.assertIO(input, output)

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

bingo = [[0,0,0],[0,0,0],[0,0,0]]
# print(bingo)

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

ans = False
for i in range(3):
    if bingo[i] == [1,1,1]:
        ans = True
        break
    elif bingo[0][i] == 1 and bingo[1][i] == 1 and bingo[2][i] == 1:
        ans = True
        break
    elif bingo[0][0] == 1 and bingo[1][1] == 1 and bingo[2][2] == 1:
        ans = True
        break
    elif bingo[0][2] == 1 and bingo[1][1] == 1 and bingo[2][0] == 1:
        ans = True
        break
print('Yes' if ans else '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)]
items = [
    [(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)],
    [(0, 2), (1, 1), (2, 0)]
]

is_bingo = False
for item in items:
    is_bingo = \
        a[item[0][0]][item[0][1]] in b and \
        a[item[1][0]][item[1][1]] in b and \
        a[item[2][0]][item[2][1]] in b
    if is_bingo:
        print("Yes")
        exit(0)
print("No")

Submission status: Accepted

Solution code:
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
f = [[0] * 3 for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                f[i][j] = 1
res = "No"
if f[0][0] == 1 and f[0][1] == 1 and f[0][2] == 1:
    res = "Yes"
if f[1][0] == 1 and f[1][1] == 1 and f[1][2] == 1:
    res = "Yes"
if f[2][0] == 1 and f[2][1] == 1 and f[2][2] == 1:
    res = "Yes"
if f[0][0] == 1 and f[1][0] == 1 and f[2][0] == 1:
    res = "Yes"
if f[0][1] == 1 and f[1][1] == 1 and f[2][1] == 1:
    res = "Yes"
if f[0][2] == 1 and f[1][2] == 1 and f[2][2] == 1:
    res = "Yes"
if f[0][0] == 1 and f[1][1] == 1 and f[2][2] == 1:
    res = "Yes"
if f[2][0] == 1 and f[1][1] == 1 and f[0][2] == 1:
    res = "Yes"

print(res)