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()))
a4 = set()
a5 = set()
a6 = set()
a7 = set()
a8 = set()
a4.update({a1[0],a2[1],a3[2]})
a5.update({a1[2],a2[1],a3[0]})
a6.update({a1[0],a2[0],a3[0]})
a7.update({a1[1],a2[1],a3[1]})
a8.update({a1[2],a2[2],a3[2]})
n = int(input())
B =set()
for i in range(n):
    b = int(input())
    B.add(b)
if set(a1) <= B or set(a2) <= B or set(a3) <= B or a4 <= B or a5 <= B or a6 <= B or a7 <= B or a8 <= B:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

cnt1 = 0
for i in A1:
    if i in b:
        cnt1 += 1
    if cnt1 == 3:
        flag1 = 1
    else:
        flag1 = 0

cnt2 = 0
for i in A2:
    if i in b:
        cnt2 += 1
    if cnt2 == 3:
        flag2 = 1
    else:
        flag2 = 0

cnt3 = 0
for i in A3:
    if i in b:
        cnt3 += 1
    if cnt3 == 3:
        flag3 = 1
    else:
        flag3 = 0

cnt4 = 0
for i in [A1[0], A2[1], A3[2]]:
    if i in b:
        cnt4 += 1
    if cnt4 == 3:
        flag4 = 1
    else:
        flag4 = 0

cnt5 = 0
for i in [A1[2], A2[1], A3[0]]:
    if i in b:
        cnt5 += 1
    if cnt5 == 3:
        flag5 = 1
    else:
        flag5 = 0

cnt6 = 0
for i in [A1[0], A2[0], A3[0]]:
    if i in b:
        cnt6 += 1
    if cnt6 == 3:
        flag6 = 1
    else:
        flag6 = 0

cnt7 = 0
for i in [A1[1], A2[1], A3[1]]:
    if i in b:
        cnt7 += 1
    if cnt7 == 3:
        flag7 = 1
    else:
        flag7 = 0

cnt8 = 0
for i in [A1[2], A2[2], A3[2]]:
    if i in b:
        cnt8 += 1
    if cnt8 == 3:
        flag8 = 1
    else:
        flag8 = 0

if flag1 == 1 or flag2 == 1 or flag3 == 1 or flag4 == 1 or flag5 == 1 or flag6 == 1 or flag7 == 1 or flag8 == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a = [input().split() for l in range(3)]
n = int(input())
b = [input() for i in range(n)]
c = [a[0][0],a[1][1],a[2][2]]
d = [a[0][2],a[1][1],a[2][0]]
tate1 = len(set(a[0]) & set(b))
tate2 = len(set(a[1]) & set(b))
tate3 = len(set(a[2]) & set(b))
yoko1 = len(set([x[0] for x in a]) & set(b))
yoko2 = len(set([x[1] for x in a]) & set(b))
yoko3 = len(set([x[2] for x in a]) & set(b))
naname1 = len(set(c) & set(b))
naname2 = len(set(d) & set(b))
bingo = [tate1,tate2,tate3,yoko1,yoko2,yoko3,naname1,naname2]
if 3 in bingo:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import numpy as np
A = []
marubatsu = np.zeros((3,3),dtype=int)

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

for i in lott:
    for j in range(3):
        for k in range(3):
            if A[j][k] == i:
                marubatsu[j,k] = 1
                break
            else:
                continue
            break
        
def bingo_tate_yoko(marubatsu):
    for i in range(3):
        if np.sum(marubatsu, axis=0)[i] == 3 or np.sum(marubatsu, axis=1)[i] == 3:
            return(1)
            break
        elif i == 2:
            return(0)

def bingo_naname(marubatsu):
    if marubatsu[0,0]+marubatsu[1,1]+marubatsu[2,2] == 3 or marubatsu[0,2]+marubatsu[1,1]+marubatsu[2,0] == 3:
        return(1)
    else:
        return(0)

if bingo_tate_yoko(marubatsu) == 1:
    print('Yes')
elif bingo_naname(marubatsu) == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
bingo_card =list(map(int, input().split()))
for _ in range(2):
    bingo_card+=list(map(int, input().split()))

n = int(input())

for _ in range(n):
    num = int(input())
    if num in bingo_card:
        bingo_card[bingo_card.index(num)] = 'o'

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

Submission status: Accepted

Solution code:
A=[[int(i) for i in input().split()]for j in range(3)]
N=int(input())
b=[int(input()) for i in range(N)]
C=[[0 for i in range(3)] for j in range(3)]
for i in range(N):
    for j in range(3):
        for k in range(3):
            if b[i]==A[j][k]:
                C[j][k]=1
for i in range(3):
    if C[i][0]*C[i][1]*C[i][2]==1:
        print("Yes")
        exit()
    if C[0][i]*C[1][i]*C[2][i]==1:
        print("Yes")
        exit()
if C[0][0]*C[1][1]*C[2][2]==1:
    print("Yes")
    exit()
if C[2][0]*C[1][1]*C[0][2]==1:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def solve():
  a = [list(int(i) for i in input().split()) for _ in range(3)]
  n = int(input())
  b = [int(input()) for _ in range(n)]
  query = [[False]*3 for _ in range(3)]
  for number in b:
    for i in range(3):
      for j in range(3):
        if a[i][j] == number:
          query[i][j] = True
  ans = "No"
  for i in range(3):
    if query[i][0] and query[i][1] and query[i][2]:
      ans = "Yes"
  for i in range(3):
    if query[0][i] and query[1][i] and query[2][i]:
      ans = "Yes"
  if query[0][0] and query[1][1] and query[2][2]:
    ans = "Yes"
  if query[0][2] and query[1][1] and query[2][0]:
    ans = "Yes"
  print(ans)
                                                
  
solve()

Submission status: Accepted

Solution code:
#abc157b
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):
  if a[i][j] in b:
   a[i][j]=0
if (a[0][0]==0 and a[0][1]==0 and a[0][2]==0) or (a[1][0]==0 and a[1][1]==0 and a[1][2]==0) or (a[2][0]==0 and a[2][1]==0 and a[2][2]==0) or (a[0][0]==0 and a[1][0]==0 and a[2][0]==0) or (a[0][1]==0 and a[1][1]==0 and a[2][1]==0) or (a[0][2]==0 and a[1][2]==0 and a[2][2]==0) or (a[0][0]==0 and a[1][1]==0 and a[2][2]==0) or (a[0][2]==0 and a[1][1]==0 and a[2][0]==0):
 print('Yes')
else:
 print('No')

Submission status: Accepted

Solution code:
al = input().split()
bl = input().split()
cl = input().split()
al = [int(i) for i in al]
bl = [int(i) for i in bl]
cl = [int(i) for i in cl]
h1 = [0,0,0]
h2 = [0,0,0]
h3 = [0,0,0]
n = int(input())
for h in range(n):
  m = int(input())
  ac = 0
  bc = 0
  cc = 0
  for i in al:
    if i == m:
      h1[ac] = 1
    ac += 1
  for i in bl:
    if i == m:
      h2[bc] = 1
    bc += 1
  for i in cl:
    if i == m:
      h3[cc] = 1
    cc += 1
if h1 == [1,1,1]:
  print("Yes")
elif h2 == [1,1,1]:
  print("Yes")
elif h3 == [1,1,1]:
  print("Yes")
elif h1[0]==1 and h2[0]==1 and h3[0]==1:
  print("Yes")
elif h1[1]==1 and h2[1]==1 and h3[1]==1:
  print("Yes")
elif h1[2]==1 and h2[2]==1 and h3[2]==1:
  print("Yes")
elif h1[0]==1 and h2[1]==1 and h3[2]==1:
  print("Yes")
elif h1[2]==1 and h2[1]==1 and h3[0]==1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
A = [[], [], []]
A[0] = [int(x) for x in input().split()]
A[1] = [int(x) for x in input().split()]
A[2] = [int(x) for x in input().split()]
N = int(input())

bingo = [[False] * 3 for _ in range(3)]
for _ in range(N):
    b = int(input())
    for tate in range(3):
        for yoko in range(3):
            if A[tate][yoko] == b:
                bingo[tate][yoko] = True

def check(bingo):
    for tate in range(3):
        if all(bingo[tate]):
            return True
    for yoko in range(3):
        if bingo[0][yoko] and bingo[1][yoko] and bingo[2][yoko]:
            return True
    if bingo[0][0] and bingo[1][1] and bingo[2][2]:
        return True
    if bingo[0][2] and bingo[1][1] and bingo[2][0]:
        return True
    return False

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

Submission status: Accepted

Solution code:
a = [input().split() for l in range(3)]
n = int(input())
b = [input() for i in range(n)]
c = [a[0][0],a[1][1],a[2][2]]
d = [a[0][2],a[1][1],a[2][0]]
tate1 = len(set(a[0]) & set(b))
tate2 = len(set(a[1]) & set(b))
tate3 = len(set(a[2]) & set(b))
yoko1 = len(set([x[0] for x in a]) & set(b))
yoko2 = len(set([x[1] for x in a]) & set(b))
yoko3 = len(set([x[2] for x in a]) & set(b))
naname1 = len(set(c) & set(b))
naname2 = len(set(d) & set(b))
bingo = [tate1,tate2,tate3,yoko1,yoko2,yoko3,naname1,naname2]
if 3 in bingo:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import numpy as np
def getLine():
    return list(map(int, input().split()))
a = np.zeros((3,3))
r = np.full((3,3),False)
for i in range(3):
    a[i] = getLine()
n = int(input())
for i in range(n):
    b = int(input())
    r[np.where(a == b)] = bool(b in a)
for i in range(3):
    if (r[i][0] and r[i][1] and r[i][2]) or (r[0][i] and r[1][i] and r[2][i]):
        print('Yes')
        break
else:
    if (r[0][0] and r[1][1] and r[2][2]) or (r[0][2] and r[1][1] and r[2][0]):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

cr1 = {A[0][0], A[1][1], A[2][2]}
cr2 = {A[2][0], A[1][1], A[0][2]}
main_list= [cr1, cr2]

R = [set([A[i][j] for j in range(3)]) for i in range(3)]
C = [set([A[i][j] for i in range(3)]) for j in range(3)]
main_list.extend(R)
main_list.extend(C)

for D in main_list:
  if D.issubset(B):
    print('Yes')
    quit()

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)]
maze=[["*" for i in range(3)] for _ in range(3)]
for i in range(n):
    for j in range(3):
        for k in range(3):
            if b[i]==a[j][k]:
                maze[j][k]="#"
for i in range(3):
    f=1
    for j in range(3):
        if maze[i][j]!="#":
            f=0
            break
    if f:
        print("Yes")
        exit()
for i in range(3):
    fc=1
    for j in range(3):
        if maze[j][i]!="#":
            fc=0
            break
    if fc:
        print("Yes")
        exit()
for i in range(3):
    fa=1
    if maze[i][i]!="#":
        fa=0
        break
if fa:
    print("Yes")
    exit()
for i in range(3):
    fe=1
    if maze[i][2-i]!="#":
        fe=0
        break
if fe:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
import sys
a = []
judge = [None,None,None]
for i in range(3):
    a.append(input().split())

n = int(input())

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

for i in a:
    if i == judge:
        print('Yes')
        sys.exit()

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

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

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

print('No')

Submission status: Accepted

Solution code:
# ビンゴは8通りあるためすべてをチェック
# a多次元配列でビンゴカードを表す
a = [list(map(int, input().split())) for _ in range(3)]
d = [[0] * 3 for _ in range(3)]
n = int(input())
# カードにbリストの数があれば、その数を１に変換
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                d[j][k] = 1
# 縦3通り、横3通り、斜め2通りについてチェック
for i in range(3):
    if sum(d[i]) == 3:
        print('Yes')
        exit(0)
for i in range(3):
    res = 0
    for j in range(3):
        res += d[j][i]
    if res == 3:
        print('Yes')
        exit(0)
res = 0
for i in range(3):
    res += d[i][i]
if res == 3:
    print('Yes')
    exit(0)
res = 0
for i in range(3):
    res += d[i][2 - i]
if res == 3:
    print('Yes')
    exit(0)
print('No')

Submission status: Accepted

Solution code:
Z=[]
b=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[6,4,2]]
for i in range(3):
    Z+=[int(x) for x in input().split()]
        
N=int(input())
bingo=0
for i in range(N):
    x=int(input())
    if x in Z:
        Z[Z.index(x)] = 0
    if i>1:
        for j in range(8):
            if Z[b[j][0]]+Z[b[j][1]]+Z[b[j][2]] == 0:
                      bingo = 1
                      break
    if bingo == 1: break
                      
if bingo == 1:print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
a = [[int(i) for i in input().split()] for _ in range(3)]
for i in range(int(input())):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                a[j][k] = 0
 
ans = "No"
for i in range(3):
    if a[i][0] == a[i][1] == a[i][2] == 0:
        ans = "Yes"
    if a[0][i] == a[1][i] == a[2][i] == 0:
        ans = "Yes"
if a[0][0] == a[1][1] == a[2][2] == 0:
    ans = "Yes"
if a[2][0] == a[1][1] == a[0][2] == 0:
    ans = "Yes"
print(ans)

Submission status: Accepted

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

ans = "No"
for i in range(3):
    if a[i][0] == a[i][1] == a[i][2] == 0:
        ans = "Yes"
    if a[0][i] == a[1][i] == a[2][i] == 0:
        ans = "Yes"
if a[0][0] == a[1][1] == a[2][2] == 0:
    ans = "Yes"
if a[2][0] == a[1][1] == a[0][2] == 0:
    ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
def get(A, ar, ac):
    if ar > 2 or ar < 0 or ac > 2 or ac < 0:
        return 0
    if A[ar][ac] == 0:
        return 1
    return 0

def check(A, ar, ac):
    # print( get(A, ar-1, ac-1) + get(A, ar-2, ac-2) + get(A, ar+1, ac+1) + get(A, ar+2, ac+2))
    if 2 == get(A, ar-1, ac-1) + get(A, ar-2, ac-2) + get(A, ar+1, ac+1) + get(A, ar+2, ac+2):
        return True
    if 2 == get(A, ar+1, ac-1) + get(A, ar+2, ac-2) + get(A, ar-1, ac+1) + get(A, ar-2, ac+2):
        return True
    if 2 == get(A, ar+1, ac) + get(A, ar+2, ac) + get(A, ar-1, ac) + get(A, ar-2, ac):
        return True
    if 2 == get(A, ar, ac+1) + get(A, ar, ac+2) + get(A, ar, ac-1) + get(A, ar, ac-2):
        return True
    return False

A = [[0 for i in range(3)] for i in range(3)]
for i in range(3):
    A[i] = list(map(int, input().split()))
N = int(input())
for n in range(N):
    b = int(input())
    for ar in range(3):
        for ac in range(3):
            if A[ar][ac] == b:
                A[ar][ac] = 0
                if check(A, ar, ac):
                    print("Yes")
                    # print(A)
                    import sys
                    sys.exit(0)
                continue
print("No")
# print(A)

Submission status: Accepted

Solution code:
a=[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):
        if int(a[i][j]) in b:
            a[i][j]=999
#印をつける
c=0
for i in range(3):
    if a[i][0]==999 and a[i][1]==999 and a[i][2]==999:
        c+=1
        break
    elif a[0][i]==999 and a[1][i]==999 and a[2][i]==999:
        c+=10
        break
    elif a[0][0]==999 and a[1][1]==999 and a[2][2]==999:
        c+=100
        break
    elif a[0][2]==999 and a[1][1]==999 and a[2][0]==999:
        c+=1000
        break
if c==0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A=[0]*9
for i in range(3):
    A[i*3:i*3+3]=input().split()
for i in range(int(input())):
    b=input()
    for j in range(9):
        if A[j]==b:
            A[j]="0"
s="012345678036147258048246"
a=f=0
for i in range(24):
    a+=int(A[int(s[i])])
    if i%3==2:
        if a==0:
            f+=1
        a=0
if f>0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a=open(0).read().split();print('YNeos'[all(t-set(map(a.index,a[10:]))for t in({0,3,6},{0,4,8},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2])

Submission status: Accepted

Solution code:
ansList = [[0] * 3 for i in range(3)]
a_i = []
for x in range(3):
    a_i.append(list(map(int, input().split())))
n = int(input())
for x in range(n):
    val = int(input())
    for id in range(3):
        if(val in a_i[id]): 
            ansList[id][a_i[id].index(val)] = 1
            break
#横
if(ansList[0][0] == 1 and ansList[0][1] == 1 and ansList[0][2] == 1): print("Yes")
elif(ansList[1][0] == 1 and ansList[1][1] == 1 and ansList[1][2] == 1): print("Yes")
elif(ansList[2][0] == 1 and ansList[2][1] == 1 and ansList[2][2] == 1): print("Yes")
#縦
elif(ansList[0][0] == 1 and ansList[1][0] == 1 and ansList[2][0] == 1): print("Yes")
elif(ansList[0][1] == 1 and ansList[1][1] == 1 and ansList[2][1] == 1): print("Yes")
elif(ansList[0][2] == 1 and ansList[1][2] == 1 and ansList[2][2] == 1): print("Yes")
#ななめ
elif(ansList[0][0] == 1 and ansList[1][1] == 1 and ansList[2][2] == 1): print("Yes")
elif(ansList[0][2] == 1 and ansList[1][1] == 1 and ansList[2][0] == 1): print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
a=open(0).read().split();print('YNeos'[all(t-set(map(a.index,a[10:]))for t in({0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2])

Submission status: Accepted

Solution code:
a=open(0).read().split();print('YNeos'[all(t-set(map(a.index,a[10:]))for t in({0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2])

Submission status: Accepted

Solution code:
*a,=map(int,open(0).read().split());print('YNeos'[all(t-set(map(a.index,a[10:]))for t in({0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2])

Submission status: Accepted

Solution code:
*a,=map(int,open(0).read().split());print('YNeos'[all(t-set(a.index(b)for b in a[10:])for t in({0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2])

Submission status: Accepted

Solution code:
*a,=map(int,open(0).read().split());print('NYoe s'[any(t<=set(a.index(b)for b in a[10:])for t in({0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2])

Submission status: Accepted

Solution code:
*t,=map(int,open(0).read().split())
a=t[:9]
s={10}
for b in t[10:]:
  if b in a:s|={a.index(b)}
print('NYoe s'[any(s>={i*3,i*3+1,i*3+2}or s>={i,i+3,i+6}for i in(0,1,2))or s>={0,4,8}or s>={2,4,6}::2])

Submission status: Accepted

Solution code:
f=lambda a:any(all(b)for b in a)|all(a[i][i]for i in(0,1,2))
*t,=map(int,open(0).read().split())
a=t[:9]
s=eval('[0]*3,'*3)
for b in t[10:]:
  if b in a:
    i=a.index(b)
    s[i//3][i%3]=1
print('NYoe s'[f(s)|f([t[::-1]for t in zip(*s)])::2])

Submission status: Accepted

Solution code:
l = []
for _ in range(3):
  A = list(map(int, input().split()))
  l.append(A)
N = int(input())
R = []
for _ in range(N):
  b = int(input())
  for i in range(3):
    if b in l[i]:
      for j in range(3):
        if b == l[i][j]:
          R.append((i, j))
if ({(0, 0), (1, 0), (2, 0)} <= set(R)) or ({(0, 1), (1, 1), (2, 1)} <= set(R)) or ({(0, 2), (1, 2), (2, 2)} <= set(R)) or ({(0, 0), (0, 1), (0, 2)} <= set(R)) or ({(1, 0), (1, 1), (1, 2)} <= set(R)) or ({(2, 0), (2, 1), (2, 2)} <= set(R)) or ({(0, 0), (1, 1), (2, 2)} <= set(R)) or ({(0, 2), (1, 1), (2, 0)} <= set(R)):
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

# a = [[66, 85, 92], [56, 37, 86], [7, 52, 23]]
# n = 9
# B = [30, 85, 52, 48,89, 92, 26, 5, 67]

d = [[0] * 3 for i in range(3)]
for i  in range(n):
    b = int(input())
    # b = B[i]
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                d[j][k] = 1

flag = False

# horizontal
for i in range(3):
    cnt = 0
    for j in range(3):
        cnt += d[i][j]
    if cnt == 3:
        flag = True

# vertical
for i in range(3):
    cnt = 0
    for j in range(3):
        cnt += d[j][i]
    if cnt == 3:
        flag = True

# diagonal 1
cnt = 0
for i in range(3):
    cnt += d[i][i]
    if cnt == 3:
        flag = True

# diagonal 2
cnt = 0
for i in range(3):
    cnt += d[i][2-i]
    if cnt == 3:
        flag = True
print("Yes") if flag == True else print('No')

Submission status: Accepted

Solution code:
f=lambda a:any(all(b)for b in a)|all(a[i][i]for i in(0,1,2))   
a=eval('list(map(int,input().split())),'*3)
exec('b=int(input());a=[[u*(u!=b)for u in t]for t in a];'*int(input()))
a=[[not u for u in t]for t in a]
print('NYoe s'[f(a)|f([t[::-1]for t in zip(*a)])::2])

Submission status: Accepted

Solution code:
# d = [[0]*3] * 3

a = [[i for i in map(int, input().split())] for j in range(3)]
n = int(input())

# a = [[66, 85, 92], [56, 37, 86], [7, 52, 23]]
# n = 9
# B = [30, 85, 52, 48,89, 92, 26, 5, 67]

d = [[0] * 3 for i in range(3)]
for i  in range(n):
    b = int(input())
    # b = B[i]
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                d[j][k] = 1
if d[0][0] + d[0][1] + d[0][2] == 3 or d[1][0] + d[1][1] + d[1][2] == 3 or d[2][0] + d[2][1] + d[2][2] == 3 or d[0][0] + d[1][0] + d[2][0] == 3 or d[0][1] + d[1][1] + d[2][1] == 3 or d[0][2] + d[1][2] + d[2][2] == 3 or d[0][0] + d[1][1] + d[2][2] == 3 or d[0][2] + d[1][1] + d[2][0] == 3:
    print('Yes')
else:
    print('No')

# flag = False
# for i in range(3):
#     cnt = 0
#     for j in range(3):
#         cnt += d[i][j]
#     if cnt == 3:
#         flag = True
#
# for i in range(3):
#     cnt = 0
#     for j in range(3):
#         cnt += d[j][i]
#     if cnt == 3:
#         flag = True
#
# cnt = 0
# for i in range(3):
#     cnt += d[i][i]
#     if cnt == 3:
#         flag = True
#
# cnt = 0
# for i in range(3):
#     cnt += d[i][2-i]
#     if cnt == 3:
#         flag = True
# print("Yes") if flag == True else print('No')

Submission status: Accepted

Solution code:
# d = [[0]*3] * 3

a = [[i for i in map(int, input().split())] for j in range(3)]
n = int(input())

# a = [[66, 85, 92], [56, 37, 86], [7, 52, 23]]
# n = 9
# B = [30, 85, 52, 48,89, 92, 26, 5, 67]

d = [[0] * 3 for i in range(3)]
for i  in range(n):
    b = int(input())
    # b = B[i]
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                d[j][k] = 1
# if ans[0][0] + ans[0][1] + ans[0][2] == 3 or ans[1][0] + ans[1][1] + ans[1][2] == 3 or ans[2][0] + ans[2][1] + ans[2][2] == 3 or ans[0][0] + ans[1][0] + ans[2][0] == 3 or ans[0][1] + ans[1][1] + ans[2][1] == 3 or ans[0][2] + ans[1][2] + ans[2][2] == 3 or ans[0][0] + ans[1][1] + ans[2][2] == 3 or ans[0][2] + ans[1][1] + ans[2][0] == 3:
flag = False
for i in range(3):
    cnt = 0
    for j in range(3):
        cnt += d[i][j]
    if cnt == 3:
        flag = True

for i in range(3):
    cnt = 0
    for j in range(3):
        cnt += d[j][i]
    if cnt == 3:
        flag = True

cnt = 0
for i in range(3):
    cnt += d[i][i]
    if cnt == 3:
        flag = True

cnt = 0
for i in range(3):
    cnt += d[i][2-i]
    if cnt == 3:
        flag = True
print("Yes") if flag == True 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 i in range(3):
    c,d=0,0
    for j in range(3):
        if a[i][j] in b:
            c+=1
        if a[j][i] in b:
            d+=1
    if c==3 or d==3:
        print("Yes")
        break
else:
    if a[0][0]in b and a[1][1]in b and a[2][2]in b:
        print("Yes")
    elif a[0][2]in b and a[1][1]in b and a[2][0]in b:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B - Bingo
def is_winnable(player: int) -> bool:
    winnable_conditions = \
        {0b111000000, 0b000111000, 0b000000111, 0b100100100, 0b010010010, 0b001001001, 0b100010001, 0b001010100}
    return any(player & condition == condition for condition in winnable_conditions)


def main():
    *ANB, = map(int, open(0).read().split())
    A, B = ANB[:9], set(ANB[10:])
    player = 0b000000000
    for i, a in enumerate(A):
        if a in B:
            player |= 1 << i
    print("Yes" if is_winnable(player) else "No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(3)]
lin = []
for i in range(3):
    for j in range(3):
        lin.append(li[i][j])
n = int(stdin.readline().rstrip())
lis = [int(stdin.readline().rstrip()) for _ in range(n)]
liv = []
for i in lin:
    if i in lis:
        liv.append(0)
    else:
        liv.append(1)
if liv[0:3] == [0,0,0] or liv[3:6] == [0,0,0] or liv[6:9] == [0,0,0]:
    print("Yes")
    exit()

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


if liv[0] == 0 and liv[4] == 0 and liv[8] == 0:
    print("Yes")
    exit()
if liv[2] == 0 and liv[4] == 0 and liv[6] == 0:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python

from sys import stdin, stderr

def check(A, B):
   S = set(B)

   # check each row
   for r in xrange(3):
      cnt = 0
      for c in xrange(3):
         if A[r][c] in S:
            cnt += 1
      if cnt == 3:
         return True

   # check each colum
   for c in xrange(3):
      cnt = 0
      for r in xrange(3):
         if A[r][c] in S:
            cnt += 1
      if cnt == 3:
         return True

   # check back diagonal
   cnt = 0
   for i in xrange(3):
      if A[i][i] in S:
         cnt += 1
   if cnt == 3:
      return True

   # check forward diagonal
   cnt = 0
   for i in xrange(3):
      if A[i][2-i] in S:
         cnt += 1
   if cnt == 3:
      return True

   return False

def main():
   A = []
   A.append( map(int, stdin.readline().split()) )
   A.append( map(int, stdin.readline().split()) )
   A.append( map(int, stdin.readline().split()) )

   N = int(stdin.readline())
   B = []
   for i in xrange(N):
      B.append( int(stdin.readline()) )

   print 'Yes' if check(A, B) else 'No'

   return 0

if __name__ == '__main__': main()

Submission status: Accepted

Solution code:
import numpy as np
a = np.zeros([3,3])
a[0] = list(map(int, input().split()))
a[1] = list(map(int, input().split()))
a[2] = list(map(int, input().split()))

ans = (np.zeros([3,3]) ==1)

n = int(input())
for i in range(n):
  num = int(input())
  ans += (a == num)
if(any([any(ans.all(axis=1, dtype=bool)),
          any(ans.all(axis=0, dtype=bool)),
          all([ans[0,0],ans[1,1],ans[2,2]]),
          all([ans[0,2],ans[1,1],ans[2,0]])])):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
array_1 = []
for i in range(3):
    line = input().rstrip().split(' ')
    array_1.append(line)

bool_array = []
for i in range(3):
    tmp = []
    for j in range(3):
        tmp.append(False)
    bool_array.append(tmp)
num = int(input().rstrip())
for i in range(num):
    input_line = input().rstrip()
    for j in range(3):
        for k in range(3):
            if array_1[j][k] == input_line:
                bool_array[j][k] = True

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

    if bool_array[0][i] and bool_array[1][i] and bool_array[2][i]:
        ans = 'Yes'

if bool_array[0][0] and bool_array[1][1] and bool_array[2][2]:
    ans = 'Yes'

if bool_array[0][2] and bool_array[1][1] and bool_array[2][0]:
    ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
d = {}
for i in range(3):
    Ai = list(input().split())
    # print(Ai)
    for j,a in enumerate(Ai):
        d[a] = 3*i+j
N = int(input())
A = [False]*9
for n in range(N):
    b = input()
    if b in d.keys():
        A[d[b]] = True

def check_bingo(li):
    bingo_list = [(0,3,6),(1,4,7),(2,5,8),(0,1,2),(3,4,5),(6,7,8),(0,4,8),(2,4,6)]
    for l in bingo_list:
        if li[l[0]] and li[l[1]] and li[l[2]]:
            return 'Yes'

    return 'No'

print(check_bingo(A))