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=list(int(input()) for i in range(n))
for i in range(3):
  for j in range(n):
    if a1[i]==b[j]:
      a1[i]=0
    elif a2[i]==b[j]:
      a2[i]=0
    elif a3[i]==b[j]:
      a3[i]=0
if a1[0]==a2[0]==a3[0]:
  print('Yes')
elif a1[0]==a2[1]==a3[2]:
  print('Yes')
elif a1[0]==a1[1]==a1[2]:
  print('Yes')
elif a1[1]==a2[1]==a3[1]:
  print('Yes')
elif a1[2]==a2[2]==a3[2]:
  print('Yes')
elif a1[2]==a2[1]==a3[0]:
  print('Yes')
elif a2[0]==a2[1]==a2[2]:
  print('Yes')
elif a3[0]==a3[1]==a3[2]:
  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 i in range(n)]
for i in range(3):
    for j in range(n):
        if a1[i] == b[j]:
            a1[i] = 1
        elif a2[i] == b[j]:
            a2[i] = 1
        elif a3[i] == b[j]:
            a3[i] = 1
 
if a1[0] == a1[1] == a1[2]:
    print("Yes")
elif a2[0] == a2[1] == a2[2]:
    print("Yes")
elif a3[0] == a3[1] == a3[2]:
    print("Yes")
elif a1[0] == a2[0] == a3[0]:
    print("Yes")
elif a1[1] == a2[1] == a3[1]:
    print("Yes")
elif a1[2] == a2[2] == a3[2]:
    print("Yes")
elif a1[0] == a2[1] == a3[2]:
    print("Yes")
elif a1[2] == a2[1] == a3[0]:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a = []
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
n = int(input())
b = []
bingo_cnt = 3
cnt1 = 0
cnt2 = 0
cnt3 = 0
cnt_diag = 0
cnt_diag_rev = 0
is_bingo = False

for i in range(n):
    b.append(int(input()))
    
for i in range(len(a)):
    cnt = 0
    for j in range(len(a[i])):
        if a[i][j] in b:
            cnt = cnt + 1
            if j is 0:
                cnt1 = cnt1 + 1
            if j is 1:
                cnt2 = cnt2 + 1
            if j is 2:
                cnt3 = cnt3 + 1
            if i == j:
                cnt_diag = cnt_diag + 1
                cnt_diag_rev = cnt_diag_rev + 1
            if (i is 0 and j is 2) or (j is 0 and i is 2):
                cnt_diag_rev = cnt_diag_rev + 1
        
        if (cnt is 3 or cnt1 is 3 or cnt2 is 3 or cnt3 is 3 or cnt_diag is 3 or cnt_diag_rev is 3) and not is_bingo:
            print("Yes")
            is_bingo = True
            break

if is_bingo is False:
    print("No")

Submission status: Accepted

Solution code:
import sys
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = []
cnt = 0
for _ in range(n):
    b.append(int(input()))
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            cnt += 1
            a[i][j] = 0
if cnt < 3:
    print("No")
else:
    if a[0][0]==a[1][1]==a[2][2]:
        print("Yes")
        sys.exit()
    elif a[2][0]==a[1][1]==a[0][2]:
        print("Yes")
        sys.exit()
    else:
        for k in range(3):
            if a[k][0]==a[k][1]==a[k][2] or a[0][k]==a[1][k]==a[2][k]:
                print("Yes")
                sys.exit()
    print("No")

Submission status: Accepted

Solution code:
A_1=list(map(int,input().split()))
A_2=list(map(int,input().split()))
A_3=list(map(int,input().split()))
N=int(input())
b=[(int(input())) for _ in range(N)]
Z_1=[0,0,0]
Z_2=[0,0,0]
Z_3=[0,0,0]

for i in range(3):
    for j in range(N):
        if A_1[i]==b[j]:
            Z_1[i]=1
        elif A_2[i]==b[j]:
            Z_2[i]=1 
        elif A_3[i]==b[j]:
            Z_3[i]=1

if Z_1[0] == Z_1[1] == Z_1[2] == 1:
    print("Yes")
elif Z_2[0] == Z_2[1] == Z_2[2] == 1:
    print("Yes")
elif Z_3[0] == Z_3[1] == Z_3[2] == 1:
    print("Yes")
elif Z_1[0] == Z_2[0] == Z_3[0] == 1:
    print("Yes")
elif Z_1[1] == Z_2[1] == Z_3[1] == 1:
    print("Yes")
elif Z_1[2] == Z_2[2] == Z_3[2] == 1:
    print("Yes")
elif Z_1[0] == Z_2[1] == Z_3[2] == 1:
    print("Yes")
elif Z_1[2] == Z_2[1] == Z_3[0] == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

N = int(input())
is_called = [False]*9
for _ in range(N):
    b = int(input())
    if b in a:
        idx = a.index(b)
        is_called[idx] = True


def isBingo(a) -> bool:
    ret = False
    # よこ
    ret |= all([a[0], a[1], a[2]])
    ret |= all([a[3], a[4], a[5]])
    ret |= all([a[6], a[7], a[8]])
    # たて
    ret |= all([a[0], a[3], a[6]])
    ret |= all([a[1], a[4], a[7]])
    ret |= all([a[2], a[5], a[8]])
    # ななめ
    ret |= all([a[0], a[4], a[8]])
    ret |= all([a[2], a[4], a[6]])
    return ret


print("Yes" if isBingo(is_called) else "No")

Submission status: Accepted

Solution code:
*inputs, = map(int, open(0).read().split())
A = inputs[:9]
B = inputs[9:]

C = [0] * 9
for b in B:
  if b in A:
    C[A.index(b)] = 1
    
if any([
     all(C[:3]), all(C[3:6]), all(C[6:]),
     all(C[::3]), all(C[1::3]), all(C[2::3]),
     all([C[0], C[4], C[8]]), all([C[2], C[4], C[6]])
    ]):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
a = input().split()
b = input().split()
c = input().split()
n = int(input())
key = []
ans = []
for i in range(n):
    key.append(input())
for i in key:
    if i in a:
        ans.append(a.index(i)+1)
for i in key:
    if i in b:
        ans.append(b.index(i)+4)
for i in key:
    if i in c:
        ans.append(c.index(i)+7)
ans.sort()
x = 0
if 1 in ans and 2 in ans and 3 in ans:
    x += 1
if 4 in ans and 5 in ans and 6 in ans:
    x += 1
if 7 in ans and 8 in ans and 9 in ans:
    x += 1
if 1 in ans and 4 in ans and 7 in ans:
    x += 1
if 2 in ans and 5 in ans and 8 in ans:
    x += 1
if 3 in ans and 6 in ans and 9 in ans:
    x += 1
if 1 in ans and 5 in ans and 9 in ans:
    x += 1
if 3 in ans and 5 in ans and 7 in ans:
    x += 1
if x > 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) for _ in range(3)]
rec = [[0] * 3 for _ 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:
                rec[j][k] = 1
Lotto = False

for i in range(3):
    if sum(rec[i]) == 3:
        Lotto = True
        break

for i in range(3):
    if rec[0][i] == rec[1][i] and rec[1][i] == rec[2][i]:
        if rec[0][i] == 1:
            Lotto = True
            break

if rec[1][1] == 1:
    if rec[0][0] == rec[2][2] and rec[0][0] == 1:
        Lotto = True
    if rec[0][2] == rec[2][0] and rec[0][2] == 1:
        Lotto = True

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

Submission status: Accepted

Solution code:
bingo = [
    [0, 0, 0],
    [0, 0, 0],
    [0, 0, 0]
]

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

N = int(input())

B = []
for i in range(N):
    B.append(int(input()))
    
for b in B:
    for i, ai in enumerate(A):
        for j, aij in enumerate(ai):
            if b == aij:
                bingo[i][j] = 1
                break
                
if bingo[0][0] == bingo[0][1] == bingo[0][2] == 1:
    print('Yes')
elif bingo[1][0] == bingo[1][1] == bingo[1][2] == 1:
    print('Yes')
elif bingo[2][0] == bingo[2][1] == bingo[2][2] == 1:
    print('Yes')
elif bingo[0][0] == bingo[1][0] == bingo[2][0] == 1:
    print('Yes')
elif bingo[0][1] == bingo[1][1] == bingo[2][1] == 1:
    print('Yes')
elif bingo[0][2] == bingo[1][2] == bingo[2][2] == 1:
    print('Yes')
elif bingo[0][0] == bingo[1][1] == bingo[2][2] == 1:
    print('Yes')
elif bingo[0][2] == bingo[1][1] == bingo[2][0] == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
A_1 = list(map(int, input().split()))
A_2 = list(map(int, input().split()))
A_3 = list(map(int, input().split()))
N = int(input())
b = [(int(input())) for _ in range(N)]
Z_1 = [0, 0, 0]
Z_2 = [0, 0, 0]
Z_3 = [0, 0, 0]
for i in range(3):
    for j in range(N):
        if A_1[i] == b[j]:
            Z_1[i] = 1
        elif A_2[i] == b[j]:
            Z_2[i] = 1
        elif A_3[i] == b[j]:
            Z_3[i] = 1


if Z_1[0] == Z_1[1] == Z_1[2] == 1:
    print("Yes")
elif Z_2[0] == Z_2[1] == Z_2[2] == 1:
    print("Yes")
elif Z_3[0] == Z_3[1] == Z_3[2] == 1:
    print("Yes")
elif Z_1[0] == Z_2[0] == Z_3[0] == 1:
    print("Yes")
elif Z_1[1] == Z_2[1] == Z_3[1] == 1:
    print("Yes")
elif Z_1[2] == Z_2[2] == Z_3[2] == 1:
    print("Yes")
elif Z_1[0] == Z_2[1] == Z_3[2] == 1:
    print("Yes")
elif Z_1[2] == Z_2[1] == Z_3[0] == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A_1 = list(map(int, input().split()))
A_2 = list(map(int, input().split()))
A_3 = list(map(int, input().split()))
N = int(input())
b = [(int(input())) for _ in range(N)]
for i in range(3):
    for j in range(N):
        if A_1[i] == b[j]:
            A_1[i] = 1
        elif A_2[i] == b[j]:
            A_2[i] = 1
        elif A_3[i] == b[j]:
            A_3[i] = 1


if A_1[0] == A_1[1] == A_1[2]:
    print("Yes")
elif A_2[0] == A_2[1] == A_2[2]:
    print("Yes")
elif A_3[0] == A_3[1] == A_3[2]:
    print("Yes")
elif A_1[0] == A_2[0] == A_3[0]:
    print("Yes")
elif A_1[1] == A_2[1] == A_3[1]:
    print("Yes")
elif A_1[2] == A_2[2] == A_3[2]:
    print("Yes")
elif A_1[0] == A_2[1] == A_3[2]:
    print("Yes")
elif A_1[2] == A_2[1] == A_3[0]:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#Bingo
A = [ [] for _ in range(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 = [int(input()) for _ in range(N)]
L = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

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

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

Submission status: Accepted

Solution code:
import sys
A1 = list(map(int, sys.stdin.readline().split()))
A2 = list(map(int, sys.stdin.readline().split()))
A3 = list(map(int, sys.stdin.readline().split()))
N = int(sys.stdin.readline())
b = [int(sys.stdin.readline()) for _ in range(N)]
A = A1 + A2 + A3
i = 0
while i <= 8:
  if b.count(A[i]):
    A[i] = 101
  i += 1
bingoFlag = False
k = 0
while k <= 2:
  if A[k] == A[k+3] == A[k+6] or A[k*3] == A[k*3 + 1] == A[k*3 + 2]:
    bingoFlag = True
    break
  k += 1
if A[0] == A[4] == A[8] or A[2] == A[4] == A[6]:
  bingoFlag = True
if bingoFlag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
A=[list(map(int,input().split())) for _ in range(3)]
N=int(input())
bn=[int(input()) for _ in range(N)]
ans=False
for ver in zip(*A):
    if all(item in bn for item in ver):
        ans=True
for wide in A:
    if all(item in bn for item in wide):
        ans=True
if all(A[i][i] in bn for i in range(3)):
    ans=True
if all(A[i][3-i-1] in bn for i in range(3)):
    ans=True
if ans==True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A = [None] * 3
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()]
N = int(input())
b = [0] * N
for i in range(N):
  b[i] = int(input())

c = [[False for _ in range(3)] for _ in range(3)]
for _b in b:
  for i in range(3):
    for j in range(3):
      if A[i][j] == _b:
        c[i][j] = True

is_bingo = False
for i in range(3):
  if c[i][0] and c[i][1] and c[i][2]:
    is_bingo = True
  if c[0][i] and c[1][i] and c[2][i]:
    is_bingo = True
if c[0][0] and c[1][1] and c[2][2]:
  is_bingo = True
if c[2][0] and c[1][1] and c[0][2]:
  is_bingo = True

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

Submission status: Accepted

Solution code:
lst = (
    list(int(x) for x in input().split())
    + list(int(x) for x in input().split())
    + list(int(x) for x in input().split())
)

N = int(input())
lst2 = [int(input()) for _ in range(N)]
for i, n in enumerate(lst):
    if lst2.count(n) > 0:
        lst[i] = 0

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

Submission status: Accepted

Solution code:
bingo = []
for i in range(3):
    a = list(map(int, input().split()))
    bingo += a
tmp = [0] * 9
n = int(input())
for i in range(n):
    b = int(input())
    if b in bingo:
        tmp[bingo.index(b)] = 1

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

Submission status: Accepted

Solution code:
bingonum=[[0,0,0],[0,0,0],[0,0,0]]
bingo=[["False","False","False"],["False","False","False"],["False","False","False"]]
for i in range(3):
    bingonum[i][0],bingonum[i][1],bingonum[i][2] = map(int,input().split())
N = int(input())
b=[]
for _ in range(N):
    b.append(int(input()))
for x in range(N):
    for i in range(3):
        for j in range(3):
            if bingonum[i][j]==b[x]:
                bingo[i][j]="True"
IsBingo = "No"
for i in range(3):
    if bingo[i][0]=="True" and bingo[i][1]=="True" and bingo[i][2]=="True":
        IsBingo="Yes"
    if bingo[0][i]=="True" and bingo[1][i]=="True" and bingo[2][i]=="True":
        IsBingo="Yes"
if (bingo[0][0]=="True" and bingo[1][1]=="True" and bingo[2][2]=="True") or (bingo[0][2]=="True" and bingo[1][1]=="True" and bingo[2][0]=="True"):
    IsBingo="Yes"
print(IsBingo)

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)]
ati = [[a[0][i],a[1][i],a[2][i]] for i in range(3)]
an1 = [a[0][0],a[1][1],a[2][2]]
an2 = [a[0][2],a[1][1],a[2][0]]
for i in a:
  if all(j in b for j in i):
    print('Yes')
    exit()
for i in ati:
  if all(j in b for j in i):
    print('Yes')
    exit()
if all(j in b for j in an1):
  print('Yes')
  exit()
if all(j in b for j in an2):
  print('Yes')
  exit()
print('No')

Submission status: Accepted

Solution code:
a = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
ati=[[a[0][i],a[1][i],a[2][i]] for i in range(3)]
an1 = [a[0][0],a[1][1],a[2][2]]
an2 = [a[2][0],a[1][1],a[0][2]]
for i in a:
  if all(j in b for j in i):
    print('Yes')
    exit()
for i in ati:
  if all(j in b for j in i):
    print('Yes')
    exit()
for i in [an1,an2]:
  if all(j in b for j in i):
    print('Yes')
    exit()
print('No')

Submission status: Accepted

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

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

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

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

for i in range(3):
    t = []
    for j in range(3):
        if a[i].count(-1) == 3:
            print("Yes")
            exit()
        t.append(a[j][i])
    if t.count(-1) == 3:
        print("Yes")
        exit()

print("No")

Submission status: Accepted

Solution code:
Ass = []

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

N = int(input())

for i in range(N) :
  b = int(input())
  for i in range(3):
    for j in range(3):
      if Ass[i][j] == b :
        Ass[i][j] = 0

for i in range(3):
  bingo1 = True
  for j in range(3):
    if Ass[i][j] != 0 :
      bingo1 = False
  if bingo1 :
    print("Yes")
    exit()

for i in range(3):
  bingo1 = True
  for j in range(3):
    if Ass[j][i] != 0 :
      bingo1 = False
  if bingo1 :
    print("Yes")
    exit()

bingo1 = True
for i in range(3):
  if Ass[i][i] != 0 :
    bingo1 = False
if bingo1 :
  print("Yes")
  exit()

bingo1 = True
for i in range(3):
  if Ass[i][2-i] != 0 :
    bingo1 = False
if bingo1 :
  print("Yes")
  exit()

print("No")

Submission status: Accepted

Solution code:
a=[[int(j) for j in input().split()]for i in range(3)]
n=int(input())
s=set()
for i in range(n):
    b=int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k]==b:
                s.add((j+1,k+1))

for i in range(1,4):
    p,q=0,0
    for j in range(1,4):
        if (i,j) in s:
            p+=1
        if (j,i) in s:
            q+=1
    if p==3 or q==3:
        print("Yes")
        exit()
p,q=0,0
for i in range(1,4):
    if (i,i) in s:
        p+=1
    if (i,4-i) in s:
        q+=1
if p==3 or q==3:
    print("Yes")
    exit()

print("No")

Submission status: Accepted

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

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

for i in range(n):
    number = b[i]
    for j in range(3):
        for k in range(3):
            if bingo[j][k] == number:
                check[j][k] = True

check_t = [list(x) for x in zip(*check)]

for i in range(3):
    if sum(check[i]) == 3 or sum(check_t[i]) == 3:
        print("Yes")
        exit()

if check[0][0] == check[1][1] == check[2][2] == True or check[2][0] == check[1][1] == check[0][2] == 1:
    print("Yes")
    exit()

print("No")

Submission status: Accepted

Solution code:
def main():
    a = [list(map(int, input().split())) for i in range(3)]
    n = int(input())
    result = [[0,0,0],[0,0,0],[0,0,0]]
    for i in range(n):
        b = int(input())
        flag = False
        for i in range(3):
            for j in range(3):
                if a[i][j] == b:
                    flag = True
                    result[i][j] = 1
                    break
            if flag:
                break
    for i in range(3):
        ans = 0
        for j in range(3):
            ans += result[i][j]
        if ans == 3:
            break
    if ans == 3:
        print("Yes")
        return
    for i in range(3):
        ans = 0
        for j in range(3):
            ans += result[j][i]
        if ans == 3:
            break
    if ans == 3:
        print("Yes")
        return
    if result[0][0]+result[1][1]+result[2][2]==3 or result[0][2]+result[1][1]+result[2][0]==3:
        print("Yes")
        return
    print("No")
main()

Submission status: Accepted

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

Submission status: Accepted

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

flag = False
for row in A:
    if all(item in bn for item in row):
        flag = True

for col in zip(*A):
    if all(item in bn for item in col):
        flag = True

if all(A[i][i] in bn for i in range(3)):
    flag = True

if all(A[i][3-1-i] in bn for i in range(3)):
    flag = True

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

Submission status: Accepted

Solution code:
import sys
a = [[int(j) for j in input().split()] for i in range(3)]
n = int(input())
for i in range(n):
    n = int(input())
    for j in range(3):
        for k in range(3):
            if(a[j][k] == n):
                a[j][k] = "."

for i in range(3):
    if(a[i] == [".", ".", "."] or (a[0][i] == a[1][i]
    and a[2][i]) == "."):
        print("Yes")
        sys.exit()

if(a[0][0] == a[1][1] and a[2][2] == "." or (a[0][2] == a[1][1] and a[2][0] == ".")):
    print("Yes")
    sys.exit()

print("No")

Submission status: Accepted

Solution code:
A = [[int(a) for a in 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:
        A[i][j] = 0
        
bingo = False
# row
for i in range(3):
  bingo |= (A[i][0] == 0 and A[i][1] == 0 and A[i][2] == 0)
# col
for j in range(3):
  bingo |= (A[0][j] == 0 and A[1][j] == 0 and A[2][j] == 0)
# cross
bingo |= (A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0)
bingo |= (A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0)

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

Submission status: Accepted

Solution code:
BINGO_ROW_NO = 3

A  = []
for i in range(BINGO_ROW_NO):
    A.append(input().split())

N = int(input())


# ２次元配列検索処理
def SetBingo(A, b):
    for y in range(BINGO_ROW_NO):
        for x in range(BINGO_ROW_NO):
            if A[y][x] == b:
                A[y][x] = ''
                return 
    return 

for _ in range(N):
    b = input()
    SetBingo(A, b)

isBingo = False

# ビンゴチェック
for i in range(BINGO_ROW_NO):
    if A[i][0] == '' and A[i][1] == '' and A[i][2] == '':
        isBingo = True

for i in range(BINGO_ROW_NO):
    if A[0][i] == '' and A[1][i] == '' and A[2][i] == '':
        isBingo = True

if A[0][0] == '' and A[1][1] == '' and A[2][2] == '':
    isBingo = True

if A[0][2] == '' and A[1][1] == '' and A[2][0] == '':
    isBingo = True

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

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

po = [-1 for i in range(101)]

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

for i in range(3):
    b = l()
    for j in range(3):
        po[b[j]] = i*3 + j

n = onem()

for i in range(n):
    o = onem()
    if po[o] != -1:
        a[po[o]//3][po[o]%3] = 1

fl = False

for i in range(3):
    if sum(a[i]) == 3:
        fl = True

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

if a[0][0] + a[1][1] + a[2][2] == 3:
    fl = True

if a[0][2] + a[1][1] + a[2][0] == 3:
    fl = True

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

Submission status: Accepted

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

N = int(input())
b=[]
for _ in range(N):
    b.append(int(input()))
for x in range(N):
    for i in range(3):
        for j in range(3):
            if bingonum[i][j]==b[x]:
                bingo[i][j]="True"

IsBingo = "No"
for i in range(3):
    if bingo[i][0] =="True" and bingo[i][1] =="True" and bingo[i][2] =="True":
        IsBingo="Yes"
    if bingo[0][i] =="True" and bingo[1][i] =="True" and bingo[2][i] =="True":
        IsBingo="Yes"
if (bingo[0][0] =="True" and bingo[1][1] =="True" and bingo[2][2] =="True") or (bingo[0][2] =="True" and bingo[1][1] =="True" and bingo[2][0]=="True"):
    IsBingo="Yes"
print(IsBingo)

Submission status: Accepted

Solution code:
#Biginner Contest 157 B-Bingo
#二次元配列を使う(3*3)
bingonum=[[0,0,0],[0,0,0],[0,0,0]]
bingo=[["False","False","False"],["False","False","False"],["False","False","False"]]
for i in range(3):
    bingonum[i][0],bingonum[i][1],bingonum[i][2] = map(int,input().split())

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

for x in range(N):
    for i in range(3):
        for j in range(3):
            if bingonum[i][j]==b[x]:
                bingo[i][j]="True"

IsBingo = "No"
for i in range(3):
    if bingo[i][0] =="True" and bingo[i][1] =="True" and bingo[i][2] =="True":
        IsBingo="Yes"
    elif bingo[0][i] =="True" and bingo[1][i] =="True" and bingo[2][i] =="True":
        IsBingo="Yes"
if (bingo[0][0] =="True" and bingo[1][1] =="True" and bingo[2][2] =="True") or (bingo[0][2] =="True" and bingo[1][1] =="True" and bingo[2][0]=="True"):
    IsBingo="Yes"
print(IsBingo)

Submission status: Accepted

Solution code:
#Biginner Contest 157 B-Bingo
#二次元配列を使う(3*3)
bingonum=[[0,0,0],[0,0,0],[0,0,0]]
bingo=[["False","False","False"],["False","False","False"],["False","False","False"]]
for i in range(3):
    bingonum[i][0],bingonum[i][1],bingonum[i][2] = map(int,input().split())

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

for x in range(N):
    for i in range(3):
        for j in range(3):
            if bingonum[i][j]==b[x]:
                bingo[i][j]="True"

IsBingo = "No"
for i in range(3):
    if bingo[i][0] =="True" and bingo[i][1] =="True" and bingo[i][2] =="True":
        IsBingo="Yes"
    if bingo[0][i] =="True" and bingo[1][i] =="True" and bingo[2][i] =="True":
        IsBingo="Yes"
if (bingo[0][0] =="True" and bingo[1][1] =="True" and bingo[2][2] =="True") or (bingo[0][2] =="True" and bingo[1][1] =="True" and bingo[2][0]=="True"):
    IsBingo="Yes"
print(IsBingo)

Submission status: Accepted

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

for k in range(3):
  if sum(A[k][:])==0:
    print('Yes')
    exit(0)

ri = [[a[k] for a in A]for k in range(3)]

for k in range(3):
  if sum(ri[:][k])==0:
    print('Yes')
    exit(0)
    
if (A[0][0]+A[1][1]+A[2][2]==0)or(A[2][0]+A[1][1]+A[0][2]==0): 
    print('Yes')
    exit(0)
    
print('No')

Submission status: Accepted

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

for k in range(3):
  if A[k][:]==[-1,-1,-1]:
    print('Yes')
    exit(0)

ri = [[_[k] for _ in A]for k in range(3)]

for k in range(3):
  if ri[:][k]==[-1,-1,-1]:
    print('Yes')
    exit(0)
    
if (A[0][0]==A[1][1]==A[2][2]==-1)or(A[2][0]==A[1][1]==A[0][2]==-1): 
    print('Yes')
    exit(0)
    
print('No')

Submission status: Accepted

Solution code:
def main():
    import numpy as np

    card = np.array([list(map(int, input().split())) for _ in range(3)])
    n = int(input())
    for _ in range(n):
        b = int(input())
        card = np.where(card == b, 0, card)

    is_bingo = False
    is_row_bingo = np.sum(card, axis=0).min() == 0
    is_column_bingo = np.sum(card, axis=1).min() == 0
    is_diag_bingo1 = np.sum(np.diag(card)) == 0
    is_diag_bingo2 = np.sum(np.diag(np.fliplr(card))) == 0

    print('Yes' if is_row_bingo or is_column_bingo or is_diag_bingo1 or is_diag_bingo2 else 'No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

def hantei(h1, h2, h3):
    if h1 is True and h2 is True and h3 is True:
        return True
    else:
        return False


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

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

for i in range(3):
    if hantei(A[i][0], A[i][1], A[i][2]):
        print("Yes")
        sys.exit()
    elif hantei(A[0][i], A[1][i], A[2][i]):
        print("Yes")
        sys.exit()

if hantei(A[0][0], A[1][1], A[2][2]) or hantei(A[0][2], A[1][1], A[2][0]):
    print("Yes")
    sys.exit()

print("No")