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:
import sys
import numpy as np


a=np.array([sys.stdin.readline().split() for _ in range(3)],dtype='int64')
n=int(sys.stdin.readline())
b=np.array([sys.stdin.readline() for _ in range(n)],dtype='int64')

for bi in b:
    a=np.where(a==bi,0,a)
ans=0

for i in range(3):
    if a[i,0]==a[i,1]==a[i,2]==0:
        ans=1
        break
    if a[0,i]==a[1,i]==a[2,i]==0:
        ans=1
        break
if a[0,0]==a[1,1]==a[2,2]==0:
    ans=1
elif a[0,2]==a[1,1]==a[2,0]==0:
    ans=1

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

Submission status: Accepted

Solution code:
def isBingo(a):
    for i in range(3):
        if a[i][0] == a[i][1] and a[i][0] == a[i][2] and a[i][0] == -1:
            return 'Yes'
        elif a[0][i] == a[1][i] and a[0][i] == a[2][i] and a[0][i] == -1:
            return 'Yes'
    if a[0][0] == a[1][1] and a[0][0] == a[2][2] and a[0][0] == -1:
        return 'Yes'
    elif a[0][2] == a[1][1] and a[0][2] == a[2][0] and a[0][2] == -1:
        return 'Yes'
    else:
        return 'No'
    
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 i in range(n):
    for j in range(3):
        if b[i] in a[j]:
            a[j][a[j].index(b[i])] = -1

print(isBingo(a))

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())
num = []
for _ in range(N):
  num.append(int(input()))
  
bingo = [
  [a11, a12, a13], 
  [a21, a22, a23], 
  [a31, a32, a33]
]
 
for n in range(3):
  for m in range(3): 
    if bingo[n][m] in num:
      bingo[n][m] = 0
 
row1 = bingo[0][0] + bingo[0][1] + bingo[0][2]
row2 = bingo[1][0] + bingo[1][1] + bingo[1][2]
row3 = bingo[2][0] + bingo[2][1] + bingo[2][2]
 
col1 = bingo[0][0] + bingo[1][0] + bingo[2][0]
col2 = bingo[0][1] + bingo[1][1] + bingo[2][1]
col3 = bingo[0][2] + bingo[1][2] + bingo[2][2]
 
cross1 = bingo[0][0] + bingo[1][1] + bingo[2][2]
cross2 = bingo[2][0] + bingo[1][1] + bingo[2][0]
 
if 0 in [row1, row2, row3, col1, col2, col3, cross1, cross2]:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
# Atcoder ABC 157
# Problem B

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

n = int(input())

for _ in range(n):  #b_n roop
   b = int(input())
   for i in range(3):
    for j in range(3):
      if b == a[i][j]:
        a[i][j] = 0  #make a 0
        
for i in range(3):
    bingo = False
    if sum(a[i]) == 0: #横チェック
     print("Yes")
     exit()
    if sum([a[0][i], a[1][i], a[2][i]]) == 0: #縦チェック
     print("Yes")
     exit()

if sum([a[0][0], a[1][1], a[2][2]]) == 0: #斜めチェック
    print("Yes")
    exit()

if sum([a[2][0], a[1][1], a[0][2]]) == 0: #逆斜めチェック
    print("Yes")
    exit()

#n(Yes)=0のとき
print("No")

Submission status: Accepted

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

s = set()
n = int(input())
for i in range(0,n):
    s.add(int(input()))
    
for i in range(0,3):
    for j in range(0,3):
        if a[i][j] in s:
            b[i][j] = 1
        else:
            b[i][j] = 0
            
b1 = b[0][0]*b[0][1]*b[0][2]
b2 = b[1][0]*b[1][1]*b[1][2]
b3 = b[2][0]*b[2][1]*b[2][2]
b4 = b[0][0]*b[1][0]*b[2][0]
b5 = b[0][1]*b[1][1]*b[2][1]
b6 = b[0][2]*b[1][2]*b[2][2]
b7 = b[0][0]*b[1][1]*b[2][2]
b8 = b[2][0]*b[1][1]*b[0][2]


if (b1 or b2 or b3 or b4 or b5 or b6 or b7 or b8) == 1:
	print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np
import itertools
A = np.array([[0]*3 for i in range(3)])
for i in range(3):
    A[i] = list(map(int, input().split()))
    
N = int(input())

b = np.array([0]*N)
for i in range(N):
    b[i] = int(input())
    
arr = np.array([[0]*3 for i in range(3)])

for i, x, y in itertools.product(range(N), range(3), range(3)):
    if A[x][y] == b[i]:
        arr[x][y] = 1

flag = False
for i in range(3):
    if sum(arr[i]) == 3:
        flag = True

for i in range(3):
    if sum(arr[:,i]) == 3:
        flag = True
        
if arr[0][0] + arr[1][1] + arr[2][2] == 3:
    flag = True

if arr[0][2] + arr[1][1] + arr[2][0] == 3:
    flag = True
    
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())
for _ in range(n):
  b = int(input())

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

for i in range(3):
  bingo = False
  if sum(a[i]) == 0:
    print('Yes')
    exit()
  if sum([a[0][i], a[1][i], a[2][i]]) == 0:
    print('Yes')
    exit()
if sum([a[0][0], a[1][1], a[2][2]]) == 0:
  print('Yes')
  exit()
if sum([a[2][0], a[1][1], a[0][2]]) == 0:
  print('Yes')
  exit()
print('No')

Submission status: Accepted

Solution code:
a_1 = [int(i) for i in input().split()]
a_2 = [int(i) for i in input().split()]
a_3 = [int(i) for i in input().split()]
n = int(input())


def chikan(b, items):
    return [True if i == b else i for i in items]


def alls(iterable):
    for element in iterable:
        if not type(element) is bool:
            return False
    return True


for i in range(n):
    b = int(input())
    a_1 = chikan(b, a_1)
    a_2 = chikan(b, a_2)
    a_3 = chikan(b, a_3)

a_4 = [a_1[0], a_2[0], a_3[0]]
a_5 = [a_1[1], a_2[1], a_3[1]]
a_6 = [a_1[2], a_2[2], a_3[2]]
a_7 = [a_1[0], a_2[1], a_3[2]]
a_8 = [a_1[2], a_2[1], a_3[0]]

if any([alls(a_1), alls(a_2), alls(a_3), alls(a_4), alls(a_5), alls(a_6), alls(a_7), alls(a_8)]):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
A = []
check = [[0,0,0],
         [0,0,0],
         [0,0,0]]
for i in range(3):
    A.append(list(map(int,input().split())))
N = int(input())
for i in range(N):
    p = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k] == p:
                check[j][k] = 1

flag = 0
for i in range(3):
    if check[i][0] == 1 and check[i][1] == 1 and check[i][2] == 1:
        flag = 1
    if check[0][i] == 1 and check[1][i] == 1 and check[2][i] == 1:
        flag = 1
if check[0][0] == 1 and check[1][1] == 1 and check[2][2] == 1:
    flag = 1
if check[0][2] == 1 and check[1][1] == 1 and check[2][0] == 1:
    flag = 1

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

Submission status: Accepted

Solution code:
A = []
B = [0]*9

# Aには [1, 2, 3, 4, 5, 6, 7, 8, 9] の形で格納.
for _ in range(3):
    A += [int(i) for i in input().split()]

# 印をつけた数字をBに残しておく.
n=int(input())
for _ in range(n):
    b = int(input())
    for i, a in enumerate(A):
        if b == a:
            B[i] = 1

#ビンゴの可能性がある組を作っておく.
C = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]]
flag = 0

# Bで1と記録が残っていれば真
for a,b,c in C:
    if B[a-1] and B[b-1] and B[c-1]:
        flag = 1
print('Yes' if flag else 'No')

Submission status: Accepted

Solution code:
a=[]
d={}
for _ in range(3):
	a.append(list(map(int,input().split())))
for i in range(3):
	for j in range(3):
		d[a[i][j]]=[i,j]
n=int(input())
b=[]
for _ in range(n):
	t=int(input())
	if t in d:
		a[d[t][0]][d[t][1]]=0
f=0
for i in range(3):
	if(a[i][0]==0 and a[i][1]==0 and a[i][2]==0):
		f=1
		break
for i in range(3):
	if(a[0][i]==0 and a[1][i]==0 and a[2][i]==0):
		f=1
		break
if(a[0][0]==0 and a[1][1]==0 and a[2][2]==0):
	f=1
if(a[0][2]==0 and a[1][1]==0 and a[2][0]==0):
	f=1
if f==1:
	print("Yes")
else:
	print("No")

Submission status: Accepted

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

N = int(input())
blist = []
for i in range(N):
    blist.append(int(input()))
bset = set(blist)

aplist = [
    [0, 3, 6],
    [1, 4, 7],
    [2, 5, 8],
    [0, 1, 2],
    [3, 4, 5],
    [6, 7, 8],
    [0, 4, 8],
    [2, 4, 6]
    ]
cset = set()

for i, n in enumerate(bingo):
    if n in bset:
        cset.add(i)
        
    # print(i, n)
# print(cset)

for tests in aplist:
    isok = True
    for test in tests:
        if test not in cset:
            isok = False
            break
    if isok:
        print("Yes")
        # print(tests)
        exit()
print("No")

Submission status: Accepted

Solution code:
#標準入力
a = []
b = []
for i in range(3):
    a2 = list(map(int,input().split()))
    a.append(a2)
n = int(input())
c = [0 for i in range(8)]
ok = False
#実際の処理
for i in range(n):
    b.append(int(input()))
b = set(b)
#print(b)
for p in b:
    #print(p)
    #縦の判定
    for j in range(3):
        for k in range(3):
            if a[j][k] == p:
                #print(j)
                c[j] += 1
                
    #横の判定
    for k in range(3):
        for j in range(3):
            if a[j][k] == p:
                c[k+3] +=1
                
    #斜め二通りの判定
    for l in range(3):
        if a[l][l] == p:
            c[6] += 1

    for m in range(3):
        if a[m][int(2-m)] == p:
            c[7] += 1
#print(c)
if str(3) in str(c):
    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]"):
    tf = [[False, False, False], [False, False, False], [False, False, False]]
    for num in b:
        for i in range(3):
            for j in range(3):
                tf[i][j] |= A[i][j] == num

    bingo = True
    for i in range(3):
        for j in range(3):
            bingo &= tf[i][j]
        if bingo:
            print(YES)
            return
        else:
            bingo = True

    bingo = True
    for j in range(3):
        for i in range(3):
            bingo &= tf[i][j]
        if bingo:
            print(YES)
            return
        else:
            bingo = True

    bingo1 = True
    bingo2 = True
    for i in range(3):
        bingo1 &= tf[i][i]
        bingo2 &= tf[i][2-i]

    if bingo1 or bingo2:
        print(YES)
        return
    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:
def create_hole(A: list, b:list):

    N = len(A)
    Hole = [[0 for i in range(N)] for j in range(N)]
    for i in range(3):
        for j in range(3):
            for value in b:
                if A[i][j] == value: Hole[i][j] = 1

    return Hole


def check_bingo(H: list):

    N = len(H)
    rowsum = sum([sum(row) == N for row in H])
    colsum = sum([sum(row) == N for row in map(list, zip(*H))])
    digsum = sum([H[i][i] for i in range(N)]) == N
    tdigsum = sum([H[i][N-i-1] for i in range(N)]) == N

    return rowsum + colsum + digsum + tdigsum > 0


def resolve():

    A = [list(map(int, input().split())) for i in range(3)]
    N = int(input())
    b = [int(input()) for i in range(N)]
    print('Yes' if check_bingo(create_hole(A, b)) else 'No')
    
resolve()

Submission status: Accepted

Solution code:
card = []       #リスト型の変数カードを定義する。
for i in range(3):      #変数カードに三列のリスト型の数字を三行文加える。
    card.append(list(map(int,input().split())))

N = int(input())        #呼ばれる数字の数を指定する。

result = [[0,0,0],[0,0,0],[0,0,0]]      #変数resultを定義する。
for _ in range(N):      #以下の動作をN回繰り返す。
    b = int(input())        #数字を読み上げる。
    for i in range(3):      #bがAijと対応していた場合、変数resultのAijと同じ位置に1を代入する。
        for j in range(3):
            if b == card[i][j]:
                result[i][j] = 1

judge = "No"        #以下の条件に当てはまらなければNoと表示する

for i in range(3):      #横のビンゴの確認
    if result[i][0] * result[i][1] * result[i][2] == 1:
        judge = "Yes"

for i in range(3):      #縦のビンゴの確認
    if result[0][i] * result[1][i] * result[2][i] == 1:
        judge = "Yes"

if result[0][0] * result[1][1] * result[2][2] == 1:     #斜めのビンゴの確認
    judge = "Yes"

if result[0][2] * result[1][1] * result[2][0] == 1:     #斜めのビンゴの確認
    judge = "Yes"

print(judge)

Submission status: Accepted

Solution code:
a = [[0] * 3 for i in range(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())

arr = [[0] * 3 for i in range(3)]
for i in range(n):
    for x in range(3):
        for y in range(3):
            if a[x][y] == b[i]:
                arr[x][y] = 1
flag = False
for x in range(3):
    count = 0
    for y in range(3):
        count += arr[x][y]
    if count == 3:
        flag = True

for x in range(3):
    count = 0
    for y in range(3):
        count += arr[y][x]
    if count == 3:
        flag = True

if arr[0][0] + arr[1][1] + arr[2][2] == 3:
    flag = True

if arr[0][2] + arr[1][1] + arr[2][0] == 3:
    flag = True

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

Submission status: Accepted

Solution code:
grid =  [list(map(int, input().split())) for i in range(3)]
n = int(input())
possi = []
for i in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if grid[i][j] == b:
                grid[i][j] = 0
can = True
for i in range(3):
    possi.append([grid[i][0], grid[i][1], grid[i][2]])
for i in range(3):
    possi.append([grid[0][i], grid[1][i], grid[2][i]])
possi.append([grid[0][0], grid[1][1], grid[2][2]])
possi.append([grid[0][2], grid[1][1], grid[2][0]])
for a, b, c in possi:
    if a == 0 and b == 0 and c== 0:
        print("Yes")
        can = False
        break
if can:
    print("No")

Submission status: Accepted

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

A = np.array([list((int(_) for _ in input().split())) for x in range(3)])
N = int(input())
b = {int(input()) for _ in range(N)}

ans = "No"
for i in range(3):
    if (set(A[i, :]) <= b) or (set(A[:, i]) <= b):
        ans = "Yes"
if ({A[0][0], A[1][1], A[2][2]} <= b) or ({A[0][2], A[1][1], A[2][0]} <= b):
    ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
import sys

li1 = list(map(int,input().split()))
li2 = list(map(int,input().split()))
li3 = list(map(int,input().split()))
n=int(input())
call = [int(input()) for i in range(n)]

li1.extend(li2)
li1.extend(li3)

bingo=[0,0,0,0,0,0,0,0,0]

for num in call:
    if num in li1:
        ind = li1.index(num)
        bingo[ind] = 1

if bingo[0] == bingo[1] == bingo[2] == 1:
    print('Yes')
    sys.exit()

if bingo[3] == bingo[4] == bingo[5] == 1:
    print('Yes')
    sys.exit()

if bingo[6] == bingo[7] == bingo[8] == 1:
    print('Yes')
    sys.exit()

if bingo[0] == bingo[3] == bingo[6] == 1:
    print('Yes')
    sys.exit()

if bingo[1] == bingo[4] == bingo[7] == 1:
    print('Yes')
    sys.exit()

if bingo[2] == bingo[5] == bingo[8] == 1:
    print('Yes')
    sys.exit()

if bingo[0] == bingo[4] == bingo[8] == 1:
    print('Yes')
    sys.exit()

if bingo[2] == bingo[4] == bingo[6] == 1:
    print('Yes')
    sys.exit()

print('No')

Submission status: Accepted

Solution code:
import numpy as np

a = np.array([list((int(_) for _ in input().split())) for x in range(3)])
n = int(input())
b = {int(input()) for _ in range(n)}

wk = "No"
for i in range(3):
    if (set(a[i, :]) <= b) or (set(a[:, i]) <= b):
        wk = "Yes"
if ({a[0][0], a[1][1], a[2][2]} <= b) or ({a[0][2], a[1][1], a[2][0]} <= b):
    wk = "Yes"
print(wk)

Submission status: Accepted

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

A = []
B = [a,b,c,d,e,f,g,h,i]
F =[]
q = 0
E = True

for X in range(N):
    A.append(input())
    
for Y in range(N):
    V = A[q] in B
    if V == E:
        F.append(B.index(A[q]))
        q += 1
    else:
        q += 1
W = sorted(F)
if B.index(a) in W and B.index(b) in W and B.index(c) in W:
    print('Yes')
elif B.index(d) in W and B.index(e) in W and B.index(f) in W:
    print('Yes')
elif B.index(g) in W and B.index(h) in W and B.index(i) in W:
    print('Yes')
elif B.index(a) in W and B.index(d) in W and B.index(g) in W:
    print('Yes')
elif B.index(b) in W and B.index(e) in W and B.index(h) in W:
    print('Yes')
elif B.index(c) in W and B.index(f) in W and B.index(i) in W:
    print('Yes')
elif B.index(a) in W and B.index(e) in W and B.index(i) in W:
    print('Yes')
elif B.index(c) in W and B.index(e) in W and B.index(g) in W:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
x=list(map(int,input().split()))
y=list(map(int,input().split()))
z=list(map(int,input().split()))
A=[x,y,z]
X=[A[0][0],A[1][0],A[2][0]]
Y=[A[0][1],A[1][1],A[2][1]]
Z=[A[0][2],A[1][2],A[2][2]]
P=[A[0][0],A[1][1],A[2][2]]
Q=[A[0][2],A[1][1],A[2][0]]
B=[]
for i in range(int(input())):
    B.append(int(input()))
C=[x,y,z,X,Y,Z,P,Q]
for c in C:
    if set(c)<=set(B):
        print("Yes")
        break
else:
    print("No")

Submission status: Accepted

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

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

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

if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
    f = True
elif A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0:
    f = True

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

Submission status: Accepted

Solution code:
# B
# get bingo sheet numbers
first_array = [int(i) for i in input().split()]
second_array = [int(i) for i in input().split()]
third_array = [int(i) for i in input().split()]
N = int(input())
bs = []
for i in range(N):
    bs.append(int(input()))

first_array = [(i in bs) for i in first_array]
second_array = [(i in bs) for i in second_array]
third_array = [(i in bs) for i in third_array]
check_array = [True for i in range(3)]
bingo = [first_array, second_array, third_array]
# [0][0] == first_array[0]

def main():
    bingo_count = int()
    # horizon
    for horizon in bingo:
        bingo_count += int(horizon == check_array)

    # vertical
    for i in range(3):
        vertical = []
        for j in range(3):
            vertical.append(bingo[j][i])
        bingo_count += int(vertical == check_array)

    # diagnal 1
    diagnal = [bingo[i][i] for i in range(3)]
    bingo_count += int(diagnal == check_array)

    # diagnal 2
    diagnal = [bingo[i][up] for up,i in enumerate(reversed(range(3)))]
    bingo_count += int(diagnal == check_array)
    
    # last bingo check
    if bingo_count > 0:
        print("Yes")
    else:
        print("No")
main()

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
A = []
bingo = 0
for i in range(3):
    a = list(map(int, input().split()))
    A.append(a)

n = int(input())

for i in range(n):
    b = int(input())
    for ai in A:
        if b in ai:
            ai[ai.index(b)] = None

for i in range(3):
    if A[i] == [None, None, None]:
        bingo = 1

    if [A[0][i], A[1][i], A[2][i]] == [None, None, None]:
        bingo = 1

if [A[0][0], A[1][1], A[2][2]] == [None, None, None] or [A[0][2], A[1][1], A[2][0]] == [None, None, None]:
    bingo = 1

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

Submission status: Accepted

Solution code:
card = [input().split() for i in range(3)]
N = int(input())
idx = [0, 1, 2]
# カードに穴を開ける
for i in range(N):
    tmp = str(input())
    for i in idx:
        if tmp in card[i]:
            card[i][card[i].index(tmp)] = "x"

# ビンゴの数を数える
is_True = False
d = {0: 0, 1: 0, 2: 0}
diago_r = {0: 0, 1: 0, 2: 0}
diago_l = {2: 0, 1: 0, 0: 0}


# １回目チェック
for j in idx:  # 段
    if card[j].count("x") == 3:
        is_True = True
        break
# ２回目チェック
for j in idx:  # 段
    for k in idx:  # 列
        if card[j][k] == "x":
            d[k] += 1
            if j == 0 and (k == 0 or k == 2):
                if k == 0:
                    diago_r[0] += 1
                else:
                    diago_l[2] += 1
            elif j == 1 and k == 1:
                diago_r[1] += 1
                diago_l[1] += 1
            elif j == 2 and (k == 0 or k == 2):
                if k == 0:
                    diago_l[0] += 1
                else:
                    diago_r[2] += 1

if is_True:
    pass
else:
    for a in d.values():
        if a == 3:
            is_True = True
        elif diago_r[0] == diago_r[1] == diago_r[2] == 1:
            is_True = True
        elif diago_l[0] == diago_l[1] == diago_l[2] == 1:
            is_True = True

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

Submission status: Accepted

Solution code:
a = [[], [], []]
a[0] = list(map(int, input().split()))
a[1] = list(map(int, input().split()))
a[2] = 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 b == a[j][k]:
                a[j][k] = 0
flag = False
for i in range(3):
    if sum(a[i]) == 0 or a[0][i] + a[1][i] + a[2][i] == 0:
        flag = True
if a[0][0] + a[1][1] + a[2][2] == 0 or a[0][2] + a[1][1] + a[2][0] == 0:
    flag = True
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    m = [input() for _ in range(3)]
    n = input()
    a = [int(input()) for _ in range(int(n))]
    c =[]
    for i in m:
        b = [int(j) for j in i.split()]
        c.append(b)

    for n,i in enumerate(c):
        for m,j in enumerate(i):
            if j in a:
                c[n][m] = -1
                
    re = []
    for i in range(3):
        tmp = []
        tmp2 = []
        for j in range(3):
            tmp.append([i,j])
            tmp2.append([j,i])
        re.append(tmp)
        re.append(tmp2)
    re.append([[0,2],[1,1],[2,0]])
    re.append([[0,0],[1,1],[2,2]])

    f = 0
    for i in re:
        flg =[]
        for n,j in enumerate(i):
            if c[j[0]][j[1]] == -1:
                flg.append(1)
            else:
                flg.append(0)
        if flg == [1,1,1]:
            f = 1
    
    if f == 1:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

N = int(input())

result = [[0, 0, 0],[0, 0, 0],[0, 0, 0]]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if b == card[i][j]:
                result[i][j] = 1

judge = 'No'

for i in range(3):
    if result[i][0] * result[i][1] * result[i][2] == 1:
        judge = 'Yes'

for i in range(3):
    if result[0][i] * result[1][i] * result[2][i] == 1:
        judge = 'Yes'

if result[0][0] * result[1][1] * result[2][2] == 1:
    judge = 'Yes'

if result[0][2] * result[1][1] * result[2][0] == 1:
    judge = 'Yes'

print(judge)

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)]
a=[[False]*3 for i in range(3)]
for i in range(3):
    for j in range(3):
        for b in B:
            if A[i][j]==b:
                a[i][j]=True
bingo=False
for i in range(3):
    if a[i][0] and a[i][1] and a[i][2]:
        bingo=True
for j in range(3):
    if a[0][j] and a[1][j] and a[2][j]:
        bingo=True
if a[0][0] and a[1][1] and a[2][2]:
    bingo=True
if a[2][0] and a[1][1] and a[2][0]:
    bingo=True
print("Yes" if bingo else "No")

Submission status: Accepted

Solution code:
import sys

A = []

flag_First = True
for Count in range(3):
    for x in input().split(' '):
        x.strip('\n')
        InputValue = int(x)
        if 1<=int(x)<=100:
            if flag_First==True:
                A.append (InputValue)
                flag_First = False
            else:
                for Index in A:
                    if Index == InputValue:
                        print('No')
                        sys.exit()

                A.append (InputValue)
        else:
            print('No')
            sys.exit()

N = int(input())
if N<=0 and N>10:
    print('No')
    sys.exit()

B = []
for Count in range(1,N+1):
    InputValue = int(input())
    if 1<=InputValue<=100:
        if Count == 1:
            B.append (InputValue)
        else:
            for Index in B:
                if Index == InputValue:
                    print('No')
                    sys.exit()

            B.append (InputValue)

Bingo =[0,0,0,0,0,0,0,0,0]

for Item_B in B:
    for Index,Item_A in enumerate(A):
        if Item_A == Item_B:
            Bingo[Index]= 1

def CheckHorizontalBingo(Start,End):

    Flag_Bingo = True
    for Index,Item in enumerate(Bingo):
        if Start<=Index<=End:
            if Item == 0 :
                Flag_Bingo = False

    if Flag_Bingo == True:
        print('Yes')
        sys.exit()

CheckHorizontalBingo(0,2)
CheckHorizontalBingo(3,5)
CheckHorizontalBingo(6,8)

def CheckVerticalBingo(One,Two,There):

    Flag_Bingo = True
    for Index,Item in enumerate(Bingo):
        if Index==One or Index==Two or Index==There:
            if Item == 0 :
                Flag_Bingo = False

    if Flag_Bingo == True:
        print('Yes')
        sys.exit()

CheckVerticalBingo(0,3,6)
CheckVerticalBingo(1,4,7)
CheckVerticalBingo(2,5,8)

def CheckDiagonalBingo(One,Two,There):

    Flag_Bingo = True
    for Index,Item in enumerate(Bingo):
        if Index==One or Index==Two or Index==There:
            if Item == 0 :
                Flag_Bingo = False

    if Flag_Bingo == True:
        print('Yes')
        sys.exit()

CheckDiagonalBingo(0,4,8)
CheckDiagonalBingo(2,4,6)

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 _ 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] = 0

flag = False
if A[0][0] == 0 and A[1][0] == 0 and A[2][0] == 0:
    flag = True
if A[0][1] == 0 and A[1][1] == 0 and A[2][1] == 0:
    flag = True
if A[0][2] == 0 and A[1][2] == 0 and A[2][2] == 0:
    flag = True
if A[0][0] == 0 and A[0][1] == 0 and A[0][2] == 0:
    flag = True
if A[1][0] == 0 and A[1][1] == 0 and A[1][2] == 0:
    flag = True
if A[2][0] == 0 and A[2][1] == 0 and A[2][2] == 0:
    flag = True
if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
    flag = True
if A[0][2] == 0 and A[1][1] == 0 and A[0][2] == 0:
    flag = True

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

Submission status: Accepted

Solution code:
bingo = []
bingo_ans = []
d = {}
for _ in range(3):
  bingo.append(list(map(int, input().split())))
  bingo_ans.append([False]*3)
  
n = int(input())
  
for _ in range(n):
  i = int(input())
  for j in range(3):
    if i in bingo[j]:
      index = bingo[j].index(i)
      bingo_ans[j][index] = True

ans = "No"

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

if bingo_ans[0][0] and bingo_ans[1][1] and bingo_ans[2][2]:
  ans = "Yes"
  
if bingo_ans[2][0] and bingo_ans[1][1] and bingo_ans[0][2]:
  ans = "Yes"
  
print(ans)

Submission status: Accepted

Solution code:
a = []
for i in range(3):
    a1 = list(map(int,input().split()))
    a.append(a1)
l = [[0,0,0] 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:
                l[j][k] = 1
ans = "No"
naname1 = 0
naname2 = 0
for i in range(3):
    tate = 0
    yoko = 0
    for j in range(3):
        if l[i][j] == 1:
            tate += 1
        if l[j][i] == 1:
            yoko += 1
    if tate == 3 or yoko == 3:
        ans = "Yes"
    if l[i][i] == 1:
        naname1 += 1
    if l[2-i][i] == 1:
        naname2 += 1
if naname2 == 3 or naname1 == 3:
    ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

grid = [list(map(int, inp().split())) for _ in range(3)]
N = int(inp())
for _ in range(N):
  b = int(inpS())
  for i in range(3):
    for j in range(3):
      if grid[i][j] == b:
        grid[i][j] = -1
ans = "No"        
for i in range(3):
  if grid[i][0] == grid[i][1] == grid[i][2]: ans = "Yes"
  if grid[0][i] == grid[1][i] == grid[2][i]: ans = "Yes"
if grid[0][0] == grid[1][1] == grid[2][2]: ans = "Yes"
if grid[0][2] == grid[1][1] == grid[2][0]: ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
def isBingo(card):
    for x in range(3):
        if "".join(map(str,card[x]))=="ooo":return True
        if "".join([str(r[x]) for r in card])=="ooo":return True
    if card[0][0]==card[1][1]==card[2][2]:return True
    if card[0][2]==card[1][1]==card[2][0]:return True
    return False

def check(cardlist,numlist):
    for n in numlist:
        for row in range(3):
            for col in range(3):
                if cardlist[row][col]==n:cardlist[row][col]="o"
    return cardlist

a=[[int(i) for i in input().split()] for l in range(3)]
n=int(input())
m=[int(input()) for i in range(n)]
l=check(a,m)
if isBingo(l):print("Yes")
else:print("No")

Submission status: Accepted

Solution code:
def bng(card, nums):
    inv = {card[i][j]: (i,  j) for i in range(3) for j in range(3)}
    bingo  = {(i, j): False for i in range(3) for j in range(3)}
    for num in nums:
        if  inv.get(num) is not None:
            bingo[inv[num]] = True
    for i in range(3):
        if all(bingo[i, j] for j in range(3)) or all(bingo[j, i] for j in range(3)):
            return 'Yes'
    if all(bingo[i, i] for i in range(3)) or all(bingo[i, 2 - i] for i in range(3)):
        return 'Yes'
    return 'No'

card = [input().split() for _ in range(3)]
n = int(input())
nums = [input() for  _  in range(n)]
print(bng(card, nums))