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:
def judge(board):
    for i in range(0, 3):
        if board[i][0] == board[i][1] == board[i][2] == 0 :
            return True
        if board[0][i] == board[1][i] == board[2][i] == 0:
            return True
    
    if board[0][0] == board[1][1] == board[2][2] == 0:
        return True
    if board[0][2] == board[1][1] == board[2][0] == 0:
        return True
    
    return False


upper  = list(map(int, input().split(" ")))
middle = list(map(int, input().split(" ")))
lower  = list(map(int, input().split(" ")))

board = (upper,middle,lower)

N = int(input())
bingos = list()

for i in range(0, N):
    bingos.append(int(input()))


"""
print(upper)
print(middle)
print(lower)
print(bingos)

for i in range(3):
    for j in range(3):
        print(f'board[', i, '][', j, '] =', board[i][j])
"""

for i in range(0, len(bingos)):
    for j in range(0, 3):
#        print('bingos[i] : j = ', bingos[i], j)
        if upper[j] == bingos[i]:
            board[0][j] = 0
#            print('find in upper')
            break
        elif middle[j] == bingos[i]:
            board[1][j] = 0
#            print('find in middle')
            break
        elif lower[j] == bingos[i]:
            board[2][j] = 0
#            print('find in lower')
            break
        else:
            pass
#    print('')

if judge(board):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

for _ in range(N):
  y = int(input())
  A = [0 if x == y else x for x in A]

if any((sum(A[::3]) == 0,
       sum(A[1::3]) == 0,
       sum(A[2::3]) == 0,
       sum(A[:3]) == 0,
       sum(A[3:6]) == 0,
       sum(A[6:]) == 0,
       sum(A[::4]) == 0,
       sum(A[2:7:2]) == 0)):
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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 pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    a = [LI() for _ in range(3)]
    n = I()
    b = [I() for _ in range(n)]
    f = [[False]*3 for _ in range(3)]
    for c in b:
        for i in range(3):
            for j in range(3):
                if c == a[i][j]:
                    f[i][j] = True

    for i in range(3):
        if all(f[i][j] for j in range(3)):
            return "Yes"
        if all(f[j][i] for j in range(3)):
            return "Yes"
    if all(f[i][i] for i in range(3)):
        return "Yes"
    if all(f[i][2-i] for i in range(3)):
        return "Yes"

    return "No"


print(main())

Submission status: Accepted

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

n = int(input())

bingo = [[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:
                bingo[i][j] = 1

ok = False

for i in range(3):
    count = 0
    for j in range(3):
        count += bingo[i][j]
    if count == 3:
        ok = True
for i in range(3):
    count = 0
    for j in range(3):
        count += bingo[j][i]
    if count == 3:
        ok = True
count = 0
for i in range(3):
    count += bingo[i][i]
    if count == 3:
        ok = True
count = 0
for i in range(3):
    count += bingo[2-i][i]
    if count == 3:
        ok = True

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

Submission status: Accepted

Solution code:
import math
import sys

sys.setrecursionlimit(1000000)
input = lambda: sys.stdin.readline().rstrip()

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

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

ok = False

ok |= all(A[0][i] in b for i in range(3))
ok |= all(A[1][i] in b for i in range(3))
ok |= all(A[2][i] in b for i in range(3))
ok |= all(A[i][0] in b for i in range(3))
ok |= all(A[i][1] in b for i in range(3))
ok |= all(A[i][2] in b for i in range(3))
ok |= all(A[i][i] in b for i in range(3))
ok |= all(A[i][2 - i] in b for i in range(3))

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

Submission status: Accepted

Solution code:
import sys

def BINGO():
    print("Yes")
    sys.exit()

Frow=list(map(int,input().split()))
Srow=list(map(int,input().split()))
Trow=list(map(int,input().split()))
Mybingo=[Frow,Srow,Trow]
n=int(input())

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

for i in range(3):
    for j in range(3):
        if Mybingo[i][j] in blist:
            Mybingo[i][j] = 1
        else:
            Mybingo[i][j] = 0

for i in range(3):
    if sum(Mybingo[i]) == 3:
        BINGO()
    elif Mybingo[0][i]+Mybingo[1][i]+Mybingo[2][i] == 3:
        BINGO()

if Mybingo[0][0]+Mybingo[1][1]+Mybingo[2][2] == 3 or Mybingo[0][2]+Mybingo[1][1]+Mybingo[2][0] ==3:
    BINGO()

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)]
bingo = "No"

for i in range(N):
    for a in range(3):
        for b in range(3):
            if(B[i]==A[a][b]):
                A[a][b] = 0
for i in range(3):
    if(A[i]==[0,0,0]):
        bingo = "Yes"
    if(A[0][i]==0 and A[1][i]==0 and A[2][i]==0):
        bingo = "Yes"
if(A[0][0]==0 and A[1][1]==0 and A[2][2]==0):
        bingo = "Yes"
if(A[0][2]==0 and A[1][1]==0 and A[2][0]==0):
        bingo = "Yes"

print(bingo)

Submission status: Accepted

Solution code:
cards = []
put = []

for i in range(3):
    a, b, c = map(int, input().split())
    cards.append(a)
    cards.append(b)
    cards.append(c)

num = int(input())

for s in range(num):
    tmp = int(input())
    if tmp in cards:
        put_index = cards.index(tmp)
        put.append(put_index)

Yes_flg = False

if len(put) < 3:
    pass
else:
    if 0 in put:
        if 1 in put and 2 in put:
            Yes_flg = True
        elif 3 in put and 6 in put:
            Yes_flg = True
        elif 4 in put and 8 in put:
            Yes_flg = True
    if 4 in put:
        if 3 in put and 5 in put:
            Yes_flg = True
        elif 1 in put and 7 in put:
            Yes_flg = True
        elif 2 in put and 6 in put:
            Yes_flg = True
    if 8 in put:
        if 6 in put and 7 in put:
            Yes_flg = True
        elif 2 in put and 5 in put:
            Yes_flg = True

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

Submission status: Accepted

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

cards = A[0] + A[1] + A[2]

for b in B:
    cards = [c if c != b else 0 for c in cards]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A=[[int(x) for x in input().split()] for _ in range(3)]
s=[[0 for i in range(3)] for j in range(3)] 

for i in range(int(input())):
  n=int(input())
  for y in range(3):
    for x in range(3):
      if A[y][x]==n:
        s[y][x]=1

a=[]
for i in range(3):
  a.append(s[0][i]*s[1][i]*s[2][i])
  a.append(s[i][0]*s[i][1]*s[i][2])
a.append(s[0][0]*s[1][1]*s[2][2])
a.append(s[0][2]*s[1][1]*s[2][0])

print('Yes' if 1 in a else 'No')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readlines()
nums = []
[[nums.append(num) for num in row.strip().split(" ")] for row in input[:3]]
bs = [i.strip() for i in input[4:]]
mat = [num in bs for num in nums]
patterns = [[0, 1, 2],
            [0, 4, 8],
            [0, 3, 6],
            [1, 4, 7],
            [2, 4, 6],
            [2, 5, 8],
            [3, 4, 5],
            [6, 7, 8]]
for pat in patterns:
    if mat[pat[0]] and mat[pat[1]] and mat[pat[2]]:
        print("Yes")
        sys.exit()
print("No")

Submission status: Accepted

Solution code:
import numpy as np
L=[]
bingo = np.zeros([3,3])
for i in range(3):
	L.append(input().split())
L = list(np.reshape(L,9))
N = int(input())
for i in range(N):
	l = input()
	if l in L:
		ptr = L.index(l)
		bingo[ptr/3,ptr%3]=1
#print(bingo)
ans = "No"
flg = 0
for i in range(3):
	flg = flg or bingo[i,0] and bingo[i,1] and bingo[i,2]
for i in range(3):
	flg = flg or bingo[0,i] and bingo[1,i] and bingo[2,i]
flg = flg or bingo[0,0] and bingo[1,1] and bingo[2,2]
flg = flg or bingo[2,0] and bingo[1,1] and bingo[0,2]
if flg == 1:
	ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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[0][2]:
    bingo = True
print("Yes" if bingo else "No")

Submission status: Accepted

Solution code:
a=[[] for _ in range(3)]
for i in range(3):
  a[i]=list(map(int,input().split()))
l=[]
N=int(input())
for i in range(N):
  n=int(input())
  for i in range(3):
    for j in range(3):
      if a[i][j]==n:
        l.append([i,j])

def judge(l):
  if len(l)<=2:
    return 'No'
  else:
    if [0,0] in l and [1,1] in l and [2,2] in l:
      return 'Yes'
    elif [0,2] in l and [1,1] in l and [2,0] in l:
      return 'Yes'
    else:
      dic1={}
      dic2={}
      for ij in l:
        i,j=ij[0],ij[1]
        if i not in dic1.keys():
          dic1[i]=1
        else:
          dic1[i]+=1
          if dic1[i]==3:
            return 'Yes'
        if j not in dic2.keys():
          dic2[j]=1
        else:
          dic2[j]+=1
          if dic2[j]==3:
            return 'Yes'
      return 'No'
print(judge(l))

Submission status: Accepted

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

for i in out: # 出た目を順番にiに入力
    for j in range(3):
        if i in bingo[j]: #iがbingoにあるかどうか
            bingo[j][bingo[j].index(i)] = 0

if bingo[0][0] == bingo[1][1] == bingo[2][2] == 0 or bingo[0][2] == bingo[1][1] == bingo[2][0] == 0:
    print("Yes")

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

Submission status: Accepted

Solution code:
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
for number in b:
    for i in range(3):
        if number in a[i]:
            a[i][a[i].index(number)] = 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')
else:
    for i in range(3):
        if a[i][0] == a[i][1] == a[i][2] == 0:
            print('Yes')
            break
        elif a[0][i] == a[1][i] == a[2][i] == 0:
            print('Yes')
            break
    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())
    if b in a1:
        a1[a1.index(b)] = 0
    elif b in a2:
        a2[a2.index(b)] = 0
    elif b in a3:
        a3[a3.index(b)] = 0

ans = "No"
bi = [0,0,0]
if a1 == bi or a2 == bi or a3 == bi:
    ans = "Yes"
elif a1[0] == 0 and a2[1] == 0 and a3[2] == 0:
    ans = "Yes"
elif a1[2] == 0 and a2[1] == 0 and a3[0] == 0:
    ans = "Yes"
else:
    for i in range(3):
        if a1[i] == 0 and a2[i] == 0 and a3[i] == 0:
            ans = "Yes"
            break
print(ans)

Submission status: Accepted

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

N = int(input())
B = [[0]*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 A[j][k] == b:
                B[j][k] = 1

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

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

Submission status: Accepted

Solution code:
def bingo(board):
    for i in range(3):
        if all(board[i][j] for j in range(3)):
            return True
    for j in range(3):
        if all(board[i][j] for i in range(3)):
            return True
    if all(board[i][i] for i in range(3)):
        return True
    if all(board[i][2-i] for i in range(3)):
        return True

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

seen = {}
for i in range(3):
    for j in range(3):
        seen[a[i][j]] = (i, j)

board = [[False] * 3 for _ in range(3)]

n = int(input())
for _ in range(n):
    b = int(input())
    if b in seen:
        board[seen[b][0]][seen[b][1]] = True

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

Submission status: Accepted

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

for i in range(n):
    b = int(input())
    for j, k in enumerate(horizontals):
        if b in k:
            horizontals[j][k.index(b)] = 0

verticals = [[horizontals[i][j] for i in range(3)] for j in range(3)]
diagonals = [[horizontals[i][i] for i in range(3)],
            [horizontals[j][2-j] for j in range(3)]]
card = horizontals + verticals + diagonals
bingo = [0, 0, 0]
if bingo in card:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

for r in range(3):
	if a[r]==[0, 0, 0]:
		print('Yes')
		exit()
	elif a[0][r]==a[1][r]==a[2][r]==0:
		print('Yes')
		exit()

if a[0][0]==a[1][1]==a[2][2]==0	or a[0][2]==a[1][1]==a[2][0]==0:	
		print('Yes')
		exit() 
print('No')

Submission status: Accepted

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

for x in range(n):
	for i in range(3):
		for j in range(3):
			if a[i][j] == b[x]:
				a[i][j] = 0
                
for r in range(3):
	if a[r]==[0, 0, 0]:
		print('Yes')
		exit()
	if a[0][r]==a[1][r]==a[2][r]==0:
		print('Yes')
		exit()

if a[0][0]==a[1][1]==a[2][2]==0	or a[0][2]==a[1][1]==a[2][0]==0:	
		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] = 0

bingo = [0, 0, 0]
for i in range(3):
    if a[i] == bingo:
        print("Yes")
        exit()
    tate = []
    for j in range(3):
        tate.append(a[j][i])
        if tate == bingo:
            print("Yes")
            exit()

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

Submission status: Accepted

Solution code:
import numpy as np
a = [[j for j in 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] = 0
a = np.array(a)
if sum(a[0,:]) == 0 or sum(a[1,:]) == 0 or sum(a[2,:]) == 0:
    print('Yes')
elif sum(a[:,0]) == 0 or sum(a[:,1]) == 0 or sum(a[:,2]) == 0:
    print('Yes')
elif (a[0][0] + a[1][1] + a[2][2]) == 0 or (a[0][2] + a[1][1] + a[2][0]) == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
A=[[int(i) for i in 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]=-1
flag=False
for h in range(3):
    cnt=0
    for w in range(3):
        if A[h][w]==-1:
            cnt+=1
    if cnt==3:
        flag=True
for w in range(3):
    cnt=0
    for h in range(3):
        if A[h][w]==-1:
            cnt+=1
    if cnt==3:
        flag=True
cnt=0
for d in range(3):
    if A[d][d]==-1:
        cnt+=1
if cnt==3:
    flag=True
cnt=0
for d in range(3):
    if A[d][2-d]==-1:
        cnt+=1
if cnt==3:
    flag=True
print('Yes' if flag else 'No')

Submission status: Accepted

Solution code:
a = [list(map(int, input().split())) for _ in range(3)]
s = [[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 b == a[i][j]: s[i][j] = True

for i in range(3):
    if all(s[i]) or (s[0][i] and s[1][i] and s[2][i]):
        print("Yes")
        break
else:
    if all([s[i][i] for i in range(3)]) or all([s[i][2-i] for i in range(3)]):
        print("Yes")
    else: print("No")

Submission status: Accepted

Solution code:
import itertools
l1=list(map(int,input().split(" ")))
l2=list(map(int,input().split(" ")))
l3=list(map(int,input().split(" ")))
b_st=[list(sorted(l1))]
b_st.append(list(sorted(l2)))
b_st.append(list(sorted(l3)))

b_st.append(list(sorted([l1[0],l2[0],l3[0]])))
b_st.append(list(sorted([l1[1],l2[1],l3[1]])))
b_st.append(list(sorted([l1[2],l2[2],l3[2]])))
b_st.append(list(sorted([l1[0],l2[1],l3[2]])))
b_st.append(list(sorted([l1[2],l2[1],l3[0]])))
con=int(input())
#print(b_st)
f=0

if con==1:
    a=int(input())
    l2=[[a,a,a]]
elif con==2:
    list1=[int(input())for n in range(0,con)]
    l2=list[list[itertools.combinations_with_replacement(list1, 3)]]
else:
    list1=[int(input())for n in range(0,con)]
    list1=list(sorted(list1))
    l2=[[a,b,c] for a,b,c in list(list(itertools.combinations(list1,3)))]
#print(l2)
#print(b_st)
for sw in b_st:
    for lw2 in l2:
        #print(sw)
        #print(lw2)
        if sw==lw2:
            print("Yes")
            f=1
            break
    if f==1:
        break
if f==0:
    print("No")

Submission status: Accepted

Solution code:
# 2020/03/09
# AtCoder Beginner Contest 157 - B

# Input
al = list()
for i in range(3):
    il = list(map(int,input().split()))
    al.append(il)

n = int(input())

# Init
wl = [[0] * 3 for i in range(3)]
ans = "No"

# Input N
for x in range(n):
    b = int(input())
    for y in range(3):
        for z in range(3):
            if al[y][z] == b:
                wl[y][z] = 1
                y = 3
                break

# Check -
for y in range(3):
    cnt = 0
    for z in range(3):
        cnt = cnt + wl[y][z]
    if cnt >= 3:
        ans = "Yes"
        break

# Check |
for y in range(3):
    cnt = 0
    for z in range(3):
        cnt = cnt + wl[z][y]
    if cnt >= 3:
        ans = "Yes"
        break

# Check / or \
bs = wl[0][0] + wl[1][1] + wl[2][2]
sl = wl[2][0] + wl[1][1] + wl[0][2]

if bs >= 3 or sl >= 3:
    ans = "Yes"

# Output
print(ans)

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 number in b:
    for i in range(3):
        if number in a[i]:
            a[i][a[i].index(number)] = 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')
else:
    for i in range(3):
        if a[i][0] == a[i][1] == a[i][2] == 0:
            print('Yes')
            break
        elif a[0][i] == a[1][i] == a[2][i] == 0:
            print('Yes')
            break
    else:
        print('No')

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    readline=stdin.readline
    bingo=[]
    for _ in range(3):
        A=list(map(int,readline().split()))
        bingo.append(A)
    N=int(readline())
    b=[0]*N
    c=[[False]*3 for _ in range(3)]
    for i in range(N):
        b[i]=int(readline())
        for j in range(3):
            for k in range(3):
                if bingo[j][k]==b[i]:
                    c[j][k]=True

    #縦
    flag=False
    for j in range(3):
        if c[0][j] and c[1][j] and c[2][j]:
            flag=True

    #横
    for i in range(3):
        if c[i][0] and c[i][1] and c[i][2]:
            flag=True
    
    #斜め
    if c[0][0] and c[1][1] and c[2][2]:
        flag=True

    if c[0][2] and c[1][1] and c[2][0]:
        flag=True

    if flag:
        print("Yes")
    else:
        print("No")
if __name__=="__main__":
    main()

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)]
for i in b:
  for j in range(3):
    for k in range(3):
      if i==a[j][k]:a[j][k]=0
ans="No"
for i in range(3):
  if a[i][0]==a[i][1]==a[i][2]:ans="Yes"
  if a[0][i]==a[1][i]==a[2][i]:ans="Yes"
if a[0][0]==a[1][1]==a[2][2]:ans="Yes"
if a[0][2]==a[1][1]==a[2][0]:ans="Yes"
print(ans)

Submission status: Accepted

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

for i in l:
    for p in range(3):
        for q in range(3):
            if bingo[p][q] == i:
                bingo[p][q] = -1

flag = False

for i in range(3):
    t = True
    for j in range(3):
        t &= bingo[i][j] == -1
    flag |= t

for i in range(3):
    t = True
    for j in range(3):
        t &= bingo[j][i] == -1
    flag |= t

flag |= bingo[0][0]==-1 and bingo[1][1]==-1 and bingo[2][2]==-1
flag |= bingo[0][2]==-1 and bingo[1][1]==-1 and bingo[2][0]==-1

if flag:
    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 a in A:
        if b in a:
            a[a.index(b)] = 0

if (any(A[0]) and any(A[1]) and any(A[2])
        and any((A[0][0], A[1][0], A[2][0]))
        and any((A[0][1], A[1][1], A[2][1]))
        and any((A[0][2], A[1][2], A[2][2]))
        and any((A[0][0], A[1][1], A[2][2]))
        and any((A[0][2], A[1][1], A[0][2]))):
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
row1 = input().split()
row2 = input().split()
row3 = input().split()

n = int(input())
nums = [input() for i in range(n)]

rows = [row1, row2, row3]

for i in range(0, 3):
    rows += [[row1[i], row2[i], row3[i]]]

rows += [[row1[0], row2[1], row3[2]]]
rows += [[row1[2], row2[1], row3[0]]]

for row in rows:
    j = 0
    for num in nums:
        if num in row:
            j += 1
        if j == 3:
            print('Yes')
            exit()

print('No')

Submission status: Accepted

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

lst_empty=[[0,0,0],[0,0,0],[0,0,0]]

for i in range(3):
    for j in range(3):
        for k in b:
            if lst[i][j]==k:
                lst_empty[i][j]="x"
ans="No"
for i in lst_empty:
    if i[0]==i[1]==i[2]=="x":
        ans="Yes"
for j in list(zip(*lst_empty)):
    if j[0]==j[1]==j[2]=="x":
        ans="Yes"
if lst_empty[0][0]==lst_empty[1][1]==lst_empty[2][2]=="x" or lst_empty[0][2]==lst_empty[1][1]==lst_empty[2][0]=="x":
    ans="Yes"
print(ans)

Submission status: Accepted

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

for i in range(N):
    b = int(input())
    for row in card:
        if b in row:
            row[row.index(b)] = 0

def f():
    for row in card:
        if sum(row) == 0:
            return True
    
    for x in range(3):
        if sum([card[0][x], card[1][x], card[2][x]]) == 0:
            return True
    
    if sum([card[0][0], card[1][1], card[2][2]]) == 0:
        return True
    
    if sum([card[2][0], card[1][1], card[0][2]]) == 0:
        return True

    return False

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

Submission status: Accepted

Solution code:
card=[list(map(int,input().split())) for i in range(3)]
N=int(input())
b=[int(input()) for i in range(N)]
for i in range(N):
    for j in range(3):
        for k in range(3):
            if card[j][k]==b[i]:
                card[j][k]=0
if (card[0][0]==card[0][1]==card[0][2]==0) or (card[1][0]==card[1][1]==card[1][2]==0) or (card[2][0]==card[2][1]==card[2][2]==0) or (card[0][0]==card[1][0]==card[2][0]==0) or (card[0][1]==card[1][1]==card[2][1]==0)  or (card[0][2]==card[1][2]==card[2][2]==0) or (card[0][0] == card[1][1] == card[2][2] == 0) or (card[2][0]==card[1][1]==card[0][2]==0):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a = [list(input().split()) for _ in range(3)]
check = [[0,0,0] for _ in range(3)]
n = int(input())
b = [] * n
for _ in range(n):
    c = input()
    b.append(c)
#
for i in range(n):
    for y in range(3):
        if b[i] in a[y]:
            check[y][a[y].index(b[i])] = 1
ans = 'No'
for k in range(3):
    if check[k][0] * check[k][1] * check[k][2] == 1:
        ans = 'Yes'
        break
    elif check[0][k] * check[1][k] * check [2][k] ==1:
        ans = 'Yes'
        break
if check[0][0] * check[1][1] * check[2][2] == 1 or check[0][2] * check[1][1] * check[2][0] == 1:
    ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
Bingo=[0]*9
correct=[]
A=list(map(int,input().split()))
for i in range(3):
    correct.append(A[i])
A=list(map(int,input().split()))
for i in range(3):
    correct.append(A[i])
A=list(map(int,input().split()))
for i in range(3):
    correct.append(A[i])
N=int(input())
for i in range(N):
    a=int(input())
    for j in range(9):
        if a==correct[j]:
            Bingo[j]=1
            break
if Bingo[0]==Bingo[1]==Bingo[2]==1:
    print("Yes")
elif Bingo[3]==Bingo[4]==Bingo[5]==1:
    print("Yes")
elif Bingo[6]==Bingo[7]==Bingo[8]==1:
    print("Yes")
elif Bingo[0]==Bingo[3]==Bingo[6]==1:
    print("Yes")
elif Bingo[1]==Bingo[4]==Bingo[7]==1:
    print("Yes")
elif Bingo[2]==Bingo[5]==Bingo[8]==1:
    print("Yes")
elif Bingo[0]==Bingo[4]==Bingo[8]==1:
    print("Yes")
elif Bingo[2]==Bingo[4]==Bingo[6]==1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import math
A = list(map(int,"\n".join([input() for i in range(3)]).strip().split()))
N = int(input())
B = [int(input()) for i in range(N)]
size = 3
punched = set()

corrects = []
# 縦の揃い方
corrects += [{i + size*j for i in range(size)} for j in range(size)]
# 横の揃い方
corrects += [{j + size*i for i in range(size)} for j in range(size)]
# 斜めの揃い方
corrects += [{i + size*i for i in range(size)}]
corrects += [{(size - 1 - i) + size*i for i in range(size)}]

def punch(b, A, punched):
    for i in range(len(A)):
        if b == A[i]: punched.add(i)
          
for b in B:
    punch(b, A, punched)
    
for correct in corrects:
    if correct.issubset(punched):
        print("Yes")
        break
else:
  	print("No")

Submission status: Accepted

Solution code:
import itertools as it
dic={}
bing=[[0 for i in range(3)] for j in range(3)]
for i in range(3):
    f=list(map(int,input().split()))
    for each in f:
        dic.update({each:(i,f.index(each))})
n=int(input())
for i in range(n):
    m=int(input())
    if m in dic.keys():
        place=dic[m]
        bing[place[0]][place[1]]=1
flag=False
code="000102101112202122"
code=code+code[::-1]
code=code+"001122021120"

for i in range(8):
    code_sep=code[6*i:6*i+6]
    p=1
    for j in range(3):
        cords=code_sep[2*j:2*j+2]
        p*=bing[int(cords[0])][int(cords[1])]
    if p==1:
        flag=True
        break
    
print("Yes")if flag else print("No")

Submission status: Accepted

Solution code:

def evalList(a, b):
    try:
        i = a.index(b)
        a[i] = 0
    except ValueError:
        pass


def evalBingo(i, j, k):
    return True if sum([i, j, k]) == 0 else False


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())
    evalList(a1, b)
    evalList(a2, b)
    evalList(a3, b)

isBingo = (
    evalBingo(a1[0], a1[1], a1[2]) or
    evalBingo(a2[0], a2[1], a2[2]) or
    evalBingo(a3[0], a3[1], a3[2]) or
    evalBingo(a1[0], a2[1], a3[2]) or
    evalBingo(a3[0], a2[1], a1[2]) or
    evalBingo(a1[0], a2[0], a3[0]) or
    evalBingo(a1[1], a2[1], a3[1]) or
    evalBingo(a1[2], a2[2], a3[2])
)

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