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:
a = []
for _ in range(3):
    a.append(list(map(int, input().split())))
n = int(input())
b = []
for _ in range(n):
    b.append(int(input()))
b = set(b)
row = []
col = []
diag = []
for i in range(3):
    tmp1 = []
    tmp2 = []
    for j in range(3):
        tmp1.append(a[i][j])
        tmp2.append(a[j][i])
    row.append(set(tmp1))
    col.append(set(tmp2))

tmp3 = []
tmp4 = []
for i in range(3):
    tmp3.append(a[i][i])
    tmp4.append(a[i][2-i])
diag.append(set(tmp3))
diag.append(set(tmp4))

bingo = False
for i in range(3):
    if row[i] <= b or col[i] <= b:
        bingo = True
for i in range(2):
    if diag[i] <= b:
        bingo = True

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

Submission status: Accepted

Solution code:
a1 = input().split()
a2 = input().split()
a3 = input().split()
A = [a1, a2, a3]
N = input()
N = int(N)

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

ans = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

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

flag = False
if sum(ans[0]) == 3 or sum(ans[1]) == 3 or sum(ans[2]) == 3:
	flag = True
if (ans[0][0] + ans[1][0] + ans[2][0]) == 3:
	flag = True
if (ans[0][1] + ans[1][1] + ans[2][1]) == 3:
	flag = True
if (ans[0][2] + ans[1][2] + ans[2][2]) == 3:
	flag = True
if (ans[0][0] + ans[1][1] + ans[2][2]) == 3:
	flag = True
if (ans[0][2] + ans[1][1] + ans[2][0]) == 3:
	flag = True

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

Submission status: Accepted

Solution code:
import sys
a0 = list(map(int,input().split()))
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
c = 0
n = int(input())
for i in range(n):
    b = int(input())
    if a0.count(b) == 1:
        c += 1
        a0[a0.index(b)] = "〇"
    elif a1.count(b) == 1:
        c += 1
        a1[a1.index(b)] = "〇"
    elif a2.count(b) == 1:
        c += 1
        a2[a2.index(b)] = "〇"
if c <= 2:
    print("No")
    sys.exit()
else:
    if a0[0] == "〇":
        if a1[0] == a2[0]:
            print("Yes")
            sys.exit()
        if a0[1] == a0[2]:
            print("Yes")
            sys.exit()
        if a1[1] == a2[2]:
            print("Yes")
            sys.exit()
    if a0[1] == "〇":
        if a1[1] == a2[1]:
            print("Yes")
            sys.exit()
    if a0[2] == "〇":
        if a1[2] == a2[2]:
            print("Yes")
            sys.exit()
        if a1[1] == a2[0]:
            print("Yes")
            sys.exit()
    if a1[0] == a1[1] == a1[2]:
        print("Yes")
        sys.exit()
    if a2[0] == a2[1] == a2[2]:
        print("Yes")
        sys.exit()
print("No")

Submission status: Accepted

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

N = int(input())
Flag = False
for k in range(N):
    temp = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == temp:
                A[i][j] = 0
            else:
                next

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


if Flag == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
A11, A12, A13 = map(int, input().split(' '))
A21, A22, A23 = map(int, input().split(' '))
A31, A32, A33 = map(int, input().split(' '))
N = int(input())


A = {"A11":A11,"A12":A12, "A13":A13,
     "A21":A21, "A22":A22, "A23":A23,
     "A31":A31, "A32":A32, "A33":A33}

for _ in range(N):
    b = int(input())
    for k, v in A.items():
        if v == b:
            A[k] = 0

        
bingoset = [["A11", "A12", "A13"],
            ["A21", "A22", "A23"],
            ["A31", "A32", "A33"],
            ["A11", "A21", "A31"],
            ["A12", "A22", "A32"],
            ["A13", "A23", "A33"],
            ["A11", "A22", "A33"],
            ["A13", "A22", "A31"]
           ]

no_flag = 1
for bingo in bingoset:
    if A[bingo[0]] == 0 and A[bingo[1]] == 0 and A[bingo[2]] == 0:
        print('Yes')
        no_flag = 0
        break

if no_flag:
    print('No')

Submission status: Accepted

Solution code:
bingo = [None]*3
for i in range(3):
    bingo[i] = list(map(int,input().split()))
N= int(input())
lis = [None]*N
for i in range(N):
    temp = int(input())
    for j in range(3):
        for k in range(3):
            if bingo[j][k] == temp:
                bingo[j][k] = 0
                break

if bingo[0][0] == bingo[1][1] == bingo[2][2] == 0:
    print('Yes')
elif bingo[0][2] == bingo[1][1] == bingo[2][0] == 0:
    print('Yes')

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

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
for i in range(2):
  a = a + list(map(int,input().split()))
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))
for i in range(len(a)):
  if a[i] in b:
    a[i] = 0

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

Submission status: Accepted

Solution code:
from sys import exit
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(3):
  for j in range(3):
    if j == 2 and A[i][j] in B:
      print("Yes")
      exit()
    if A[i][j] in B: pass
    else: break  
for i in range(3):
  for j in range(3):
    if j == 2 and A[j][i] in B:
      print("Yes")
      exit()
    if A[j][i] in B: pass
    else: break  
for i in range(3):
    if i == 2 and A[i][i] in B:
      print("Yes")
      exit()
    if A[i][i] in B: pass
    else: break  
for i in range(3):
    if i == 2 and A[i][2-i] in B:
      print("Yes")
      exit()
    if A[i][2-i] in B: pass
    else: break  
print("No")

Submission status: Accepted

Solution code:
gyo1 = list(map(int,input().split()))
gyo2 = list(map(int,input().split()))
gyo3 = list(map(int,input().split()))
 
n = int(input())
for i in range(n):
  detame = int(input())
  if detame in gyo1:
    gyo1[gyo1.index(detame)] = -1
  elif detame in gyo2:
    gyo2[gyo2.index(detame)] = -1
  elif detame in gyo3:
    gyo3[gyo3.index(detame)] = -1
    
if gyo1.count(-1) == 3 or gyo2.count(-1) == 3 or gyo3.count(-1) == 3:
  print('Yes')
  exit()
 
for i in range(3):
  if gyo1[i] == -1 and gyo2[i] == -1 and gyo3[i] == -1 :
    print('Yes')
    exit()
    
if gyo1[0] == -1 and gyo2[1] == -1 and gyo3[2] == -1 : 
  print('Yes')
elif gyo1[2] == -1 and gyo2[1] == -1 and gyo3[0] == -1 : 
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

for i, line in enumerate(card):
    for j, pt in enumerate(line):
        if pt in target_list:
            card[i][j] = 1 # マークあり
        else:
            card[i][j] = 0 #マークなし

result = False
# 横
for l in card:
    if l.count(1) == 3:
        result = True

# 縦
for l in list(zip(*card)):
    if l.count(1) == 3:
        result = True

# 斜め
if card[1][1] == 1: #真ん中にマークあり
    if card[0][0] == 1 and card[2][2] == 1:
        result = True
    if card[0][2] == 1 and card[2][0] == 1:
        result = True

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

Submission status: Accepted

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

G = [[False] * 3 for i in range(3)]
N = int(input())
for i in range(N):
    b = int(input())
    for r in range(3):
        for c in range(3):
            if A[r][c] == b:
                G[r][c] = True

def check():
    # xxx
    for r in range(3):
        if all(G[r][c] for c in range(3)):
            return "Yes"
    for c in range(3):
        if all(G[r][c] for r in range(3)):
            return "Yes"
    if all(G[c][c] for c in range(3)):
        return "Yes"
    if G[0][2] and G[1][1] and G[2][0]:
        return "Yes"
    return "No"

print(check())

Submission status: Accepted

Solution code:
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    lines = []
    a = list(map(int, sys.stdin.readline().split()))
    b = list(map(int, sys.stdin.readline().split()))
    c = list(map(int, sys.stdin.readline().split()))
    lines.append(a)
    lines.append(b)
    lines.append(c)
    N = int(sys.stdin.readline().rstrip())
    S = [line.rstrip() for line in sys.stdin.readlines()]

    ret = []
    for s in S:
        for i in range(3):
            for j in range(3):
                if int(s) == lines[i][j]:
                    ret.append(str(i) + str(j))

    if "00" in ret and "01" in ret and "02" in ret:
        print("Yes")
    elif "10" in ret and "11" in ret and "12" in ret:
        print("Yes")
    elif "20" in ret and "21" in ret and "22" in ret:
        print("Yes")
    elif "00" in ret and "10" in ret and "20" in ret:
        print("Yes")
    elif "01" in ret and "11" in ret and "21" in ret:
        print("Yes")
    elif "02" in ret and "12" in ret and "22" in ret:
        print("Yes")
    elif "00" in ret and "11" in ret and "22" in ret:
        print("Yes")
    elif "02" in ret and "11" in ret and "20" in ret:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A = [[0]*3]*3

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

N = int(input())
b = [0] * (N)
for i in range(N):
  b[i] = int(input())

for i in b:
  for k in range(0,3):
    for l in range(0,3):
      if A[k][l] == i:
        A[k][l] = 0

if sum(A[0]) == 0:
  print('Yes')
  exit()
if sum(A[1]) == 0:
  print('Yes')
  exit()
if sum(A[2]) == 0:
  print('Yes')
  exit()

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

sum = 0
for i in range(0,3):
    sum+= A[i][1]
if sum == 0:
  print('Yes')
  exit()

sum = 0
for i in range(0,3):
    sum+= A[i][2]
if sum == 0:
  print('Yes')
  exit()

if (A[0][0] + A[1][1] + A[2][2]) == 0:
  print('Yes')
  exit()
  
if (A[0][2] + A[1][1] + A[2][0]) == 0:
  print('Yes')
  exit()

print('No')

Submission status: Accepted

Solution code:
a=[]
b=[]
for i in range(3):
	a+=list(map(int,input().split()))
n=int(input())
for i in range(n):
	num=int(input())
	for j in range(9):
		if num==a[j]:
			b.append(j)
if 0 in b and 1 in b and 2 in b:
	print("Yes")
elif 3 in b and 4 in b and 5 in b:
	print("Yes")
elif 6 in b and 7 in b and 8 in b:
	print("Yes")
elif 0 in b and 3 in b and 6 in b:
	print("Yes")
elif 1 in b and 4 in b and 7 in b:
	print("Yes")
elif 2 in b and 5 in b and 8 in b:
	print("Yes")
elif 0 in b and 4 in b and 8 in b:
	print("Yes")
elif 2 in b and 4 in b and 6 in b:
	print("Yes")
else:
	print("No")

Submission status: Accepted

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

mask = [[0 for _ in range(3)] for _ in range(3)]
for row_idx, row in enumerate(A):
  for column_idx, element in enumerate(row):
    for val in b:
      if element == val:
        mask[row_idx][column_idx] = 1
        break

ans = "No"
for row in mask:
  if sum(row)==3: ans="Yes"
for column_idx in range(3):
  if mask[0][column_idx] + mask[1][column_idx] + mask[2][column_idx] == 3: ans="Yes"
if mask[0][0] + mask[1][1] + mask[2][2] == 3: ans="Yes"
if mask[0][2] + mask[1][1] + mask[2][0] == 3: ans="Yes"
print(ans)

Submission status: Accepted

Solution code:
s=[]
for i in range(3):
  a1,a2,a3=list(map(int,input().split()))
  s.append(a1)
  s.append(a2)
  s.append(a3)
n=int(input())

t=[]
for i in range(n):
  b=int(input())
  for j in range(9):
    if b==s[j]:
      t.append(b)
      
def f(blist):
  for i in blist:
    if s[i] not in t:
      return False
  return True

p=[
[0,1,2],[3,4,5],[6,7,8],
  [0,3,6],
  [1,4,7],
  [2,5,8],
  [0,4,8],
  [2,4,6],
]
ans="No"
for i in p:
  if f(i):
    ans="Yes"
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A = []
B = [[0,0,0], [0,0,0], [0,0,0]]
for i in range(3):
  A.append(input().split())
  
N = int(input())
b = []
for i in range(N):
  b.append(int(input()))
  
for i in range(3):
  for j in range(3):
    if int(A[i][j]) in b:
      B[i][j] = 1

bingo = False
if B[0][0] and B[0][1] and B[0][2]:
  bingo = True
if B[1][0] and B[1][1] and B[1][2]:
  bingo = True
if B[2][0] and B[2][1] and B[2][2]:
  bingo = True
if B[0][0] and B[1][0] and B[2][0]:
  bingo = True
if B[0][1] and B[1][1] and B[2][1]:
  bingo = True
if B[0][2] and B[1][2] and B[2][2]:
  bingo = True
if B[0][0] and B[1][1] and B[2][2]:
  bingo = True
if B[0][2] and B[1][1] and B[2][0]:
  bingo = True
  
if bingo:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
n = int(input())
for _ 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

msg='No'

if a1[0] == 0:
    if a1[1] == 0:
        if a1[2] == 0:
            msg='Yes'
    if a2[0] == 0:
        if a3[0] == 0:
            msg='Yes'
    if a2[1] == 0:
        if a3[2] == 0:
            msg='Yes'
if 0 == a1[1] == a2[1] == a3[1]:
    msg='Yes'
if 0 == a1[2] == a2[2] == a3[2]:
    msg='Yes'
if 0 == a2[0] == a2[1] == a2[2]:
    msg='Yes'
if 0 == a3[0] == a3[1] == a3[2]:
    msg='Yes'
if 0 == a1[2] == a2[1] == a3[0]:
    msg='Yes'
print(msg)

Submission status: Accepted

Solution code:
A = []
flag = False
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 j in range(3):
        for k in range(3):
            if b == A[j][k]:
                A[j][k] = 0
                
for i in range(3):
    if A[0][i]+A[1][i]+A[2][i]==0:
        flag = True
    

if sum(A[0])==0 or sum(A[1])==0 or sum(A[2])==0 or 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 == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
A = []

for i in range(3):
    temp = list(map(int, input().rstrip().split(' ')))
    A.append(temp)

N = int(input())

bingo = [[0] * 3 for i in range(3)]
for i in range(N):
    b = int(input())
    for y, row in enumerate(A):
        try:
            pos = (y, row.index(b))
            break
        except ValueError:
            pass

    try:
        bingo[pos[0]][pos[1]] = 1
    except:
        pass

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

Submission status: Accepted

Solution code:
import numpy as np

a=[]

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

a=np.array(a)

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:
                a[j][k]=-1
                break

bingo=False
for r in range(3):
    if np.all(a[r,:]==-1):
        bingo=True
        

for c in range(3):
    if np.all(a[:,c]==-1):
        bingo=True

if a[0][0]==-1 and a[1][1]==-1 and a[2][2]==-1:
    bingo=True

if a[0][2]==-1 and a[1][1]==-1 and a[2][0]==-1:
    bingo=True

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

Submission status: Accepted

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

tmp = []

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:
                tmp.append((j,k))

ans = [[(0,0),(1,1),(2,2)],[(0,2),(1,1),(2,0)],[(0,0),(0,1),(0,2)],[(1,0),(1,1),(1,2)],[(2,0),(2,1),(2,2)],[(0,0),(1,0),(2,0)],[(0,1),(1,1),(2,1)],[(0,2),(1,2),(2,2)]]

for i in ans:
    count = 0
    for j in tmp:
        if j in i:
            count += 1
    if count == 3:
        print('Yes')
        exit()
print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left
INF = float('inf')

card=[list(map(int, input().split())) for i in range(3)]
N=int(input())
num=[int(input()) for i in range(N)]
for i in range(3):
    for j in range(3):
        if card[i][j] in num:
            card[i][j] = True
        else:
            card[i][j] = False

res = 'No'
for i in range(3):
    if all(card[i]):
        res = 'Yes'
    if card[0][i] == card[1][i] == card[2][i] == True:
        res = 'Yes'

if card[0][0] == card[1][1] == card[2][2] == True:
    res = 'Yes'
elif card[0][2] == card[1][1] == card[2][0] == True:
    res = 'Yes'
print(res)

Submission status: Accepted

Solution code:
# ABC157b


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと
    bing = [list(map(int, input().split())) for _ in range(3)]
    n = int(input())
    b = [int(input()) for _ in range(n)]
    for num in b:
        for i in bing:
            try:
                while True:
                    t = i.index(num)
                    i[t] = -1
            except:
                continue
    # print(bing)

    naname = [((0, 0), (1, 1), (2, 2)), (2, 0), (1, 1), (0, 2)]
    if sum(bing[0]) == -3 or sum(bing[1]) == -3 or sum(bing[2]) == -3 or bing[0][0]+bing[1][0]+bing[2][0] == -3 or bing[0][1]+bing[1][1]+bing[2][1] == -3 or bing[0][2]+bing[1][2]+bing[2][2] == -3 or bing[0][0]+bing[1][1]+bing[2][2] == -3 or bing[0][2]+bing[1][1]+bing[2][0] == -3:
        print('Yes')
        exit(0)

    print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
list3 = list(map(int, input().split()))
bingo = [list1, list2, list3]
n = int(input())
b_list = []

for i in range(n):
    b_list.append(int(input()))

for i in range(3):
    for j in range(3):
        if bingo[i][j] in b_list:
            bingo[i][j] = 'X'

pattern_list =[]
pattern_list.append(bingo[0])
pattern_list.append(bingo[1])
pattern_list.append(bingo[2])
pattern_list.append([bingo[0][0], bingo[1][0], bingo[2][0]])
pattern_list.append([bingo[0][1], bingo[1][1], bingo[2][1]])
pattern_list.append([bingo[0][2], bingo[1][2], bingo[2][2]])
pattern_list.append([bingo[0][0], bingo[1][1], bingo[2][2]])
pattern_list.append([bingo[0][2], bingo[1][1], bingo[2][0]])

if ['X', 'X', 'X'] in pattern_list:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/python3.7
# -*- coding: utf-8 -*-

#ABC157B

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

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

ans = False
for i in range(3):
	c = 0
	for j in range(3):
		if a[i][j] in b:
			a[i][j] = 0
			c += 1
	if c == 3:
		ans = True
		break

if ans :
	print('Yes')
elif a[0][0] + a[1][0] + a[2][0] == 0:
	print('Yes')
elif a[0][1] + a[1][1] + a[2][1] == 0:
	print('Yes')
elif a[0][2] + a[1][2] + a[2][2] == 0:
	print('Yes')
elif a[0][0] + a[1][1] + a[2][2] == 0:
	print('Yes')
elif a[0][2] + a[1][1] + a[2][0] == 0:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
bng = []
for i1 in range(3):
    row = list(map(int,input().rstrip().split()))
    bng.append(row)

#print(bng)

N = int(input())

for l1 in range(N):
    tmp = int(input())
    for l2 in range(3):
        for l3 in range(3):
            if tmp == bng[l2][l3]:
                bng[l2][l3] = 0

if bng[0][0] + bng[0][1] + bng[0][2] == 0:
    print('Yes')
elif bng[1][0] + bng[1][1] + bng[1][2] == 0:
    print('Yes')
elif bng[2][0] + bng[2][1] + bng[2][2] == 0:
    print('Yes')
elif bng[0][0] + bng[1][0] + bng[2][0] == 0:
    print('Yes')
elif bng[0][1] + bng[1][1] + bng[2][1] == 0:
    print('Yes')
elif bng[0][2] + bng[1][2] + bng[2][2] == 0:
    print('Yes')
elif bng[0][2] + bng[1][1] + bng[2][0] == 0:
    print('Yes')
elif bng[0][0] + bng[1][1] + bng[2][2] == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Mar  1 20:52:24 2020

@author: H_Hoshigi
"""

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

N = int(input())

b_list = []
for i in range(N):
    b_list.append(int(input()))

bingo_line_list =[
    [0,1,2],
    [3,4,5],
    [6,7,8],
    [0,3,6],
    [1,4,7],
    [2,5,8],
    [0,4,8],
    [2,4,6]
    ]
at_least_one_bingo = False
for i in bingo_line_list:
    get_bingo = True
    for j in i:
        if A_list[j] not in b_list:
            get_bingo = False
            break
    if get_bingo:
        at_least_one_bingo = True
        break
if at_least_one_bingo:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:


# 入力でビンゴが成立しているかを確かめる
def isBingo(bingocard, calledlist):
    # # まずヨコを確かめる
    # for eachline in bingocard:
    #     # 最初はフラグが立っている
    #     # ビンゴが成立しなかったらフラグを下ろす
    #     flg = True
    #     for eachcell in eachline:
    #         print(eachcell)
    #         if eachcell in calledlist:
    #             continue
    #         else:
    #             flg = False
    #             break
    #     if flg:
    #         return 'Yes1'

    # # つぎにタテを確かめる
    # for eachline in [list(x) for x in zip(*bingocard)]:
    #     # 最初はフラグが立っている
    #     # ビンゴが成立しなかったらフラグを下ろす
    #     flg = True
    #     for eachcell in eachline:
    #         if eachcell in calledlist:
    #             continue
    #         else:
    #             flg = False
    #             break
    #     if flg:
    #         return 'Yes2'

    # まずヨコを確かめる
    if bingocard[0][0] in calledlist and bingocard[0][1] in calledlist and bingocard[0][2] in calledlist:
        return 'Yes'
    if bingocard[1][0] in calledlist and bingocard[1][1] in calledlist and bingocard[1][2] in calledlist:
        return 'Yes'
    if bingocard[2][0] in calledlist and bingocard[2][1] in calledlist and bingocard[2][2] in calledlist:
        return 'Yes'
    # つぎにタテを確かめる
    if bingocard[0][0] in calledlist and bingocard[1][0] in calledlist and bingocard[2][0] in calledlist:
        return 'Yes'
    if bingocard[0][1] in calledlist and bingocard[1][1] in calledlist and bingocard[2][1] in calledlist:
        return 'Yes'
    if bingocard[0][2] in calledlist and bingocard[1][2] in calledlist and bingocard[2][2] in calledlist:
        return 'Yes'

    # 最後に斜めを確かめる
    if bingocard[0][0] in calledlist and bingocard[1][1] in calledlist and bingocard[2][2] in calledlist:
        return 'Yes'
    if bingocard[0][2] in calledlist and bingocard[1][1] in calledlist and bingocard[2][0] in calledlist:
        return 'Yes'
    else:
        return 'No'

# 入力を変数に入れる
l1 = [int(each) for each in input().split(' ')]
l2 = [int(each) for each in input().split(' ')]
l3 = [int(each) for each in input().split(' ')]
bingocard = [l1, l2, l3]

calledlist = []
for called in range(int(input())):
    calledlist.append(int(input()))

print(isBingo(bingocard, calledlist))

Submission status: Accepted

Solution code:
arr = []
ptr = [
    [0, 1, 2],
    [3, 4, 5],
    [6, 7, 8],
    [0, 3, 6],
    [1, 4, 7],
    [2, 5, 8],
    [0, 4, 8],
    [2, 4, 6]]
for i in range(3):
    row = list(map(int, input().split()))
    arr.extend(row)
bingo = [False] * 9
N = int(input())
for i in range(N):
    n = int(input())
    if n in arr:
        idx = arr.index(n)
        bingo[idx] = True
for p in ptr:
    if all([bingo[idx] for idx in p]):
        print("Yes")
        exit(0)
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()))
A = []
for a in a1:
  A.append([a, False])
for a in a2:
  A.append([a, False])
for a in a3:
  A.append([a, False])

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

for i, a in enumerate(A):
  if (a[0] in B):
    A[i][1] = True

result = "No"
if (A[0][1] == True and A[1][1] == True and A[2][1] == True):
  result = "Yes"
elif (A[3][1] == True and A[4][1] == True and A[5][1] == True):
  result = "Yes"
elif (A[6][1] == True and A[7][1] == True and A[8][1] == True):
  result = "Yes"
elif (A[0][1] == True and A[3][1] == True and A[6][1] == True):
  result = "Yes"
elif (A[1][1] == True and A[4][1] == True and A[7][1] == True):
  result = "Yes"
elif (A[2][1] == True and A[5][1] == True and A[8][1] == True):
  result = "Yes"
elif (A[0][1] == True and A[4][1] == True and A[8][1] == True):
  result = "Yes"
elif (A[2][1] == True and A[4][1] == True and A[6][1] == True):
  result = "Yes"
else:
  result = "No"

print(result)

Submission status: Accepted

Solution code:
A11, A12, A13 = map(int, input().split())
A21, A22, A23 = map(int, input().split())
A31, A32, A33 = map(int, input().split())
N = int(input())
B = [int(input()) for _ in range(N)]

flag = False
if A11 in B and A12 in B and A13 in B:
    flag = True
elif A21 in B and A22 in B and A23 in B:
    flag = True
elif A31 in B and A32 in B and A33 in B:
    flag = True
elif A11 in B and A21 in B and A31 in B:
    flag = True
elif A12 in B and A22 in B and A32 in B:
    flag = True
elif A13 in B and A23 in B and A33 in B:
    flag = True
elif A11 in B and A22 in B and A33 in B:
    flag = True
elif A13 in B and A22 in B and A31 in B:
    flag = True

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

Submission status: Accepted

Solution code:
one = list(map(int, input().split()))
two = list(map(int, input().split()))
thr = list(map(int, input().split()))

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

ans = False

#斜め
if one[0] in b and two[1] in b and thr[2] in b:
    ans = True
if one[2] in b and two[1] in b and thr[0] in b:
    ans = True
#縦
if one[0] in b and two[0] in b and thr[0] in b:
    ans = True
if one[1] in b and two[1] in b and thr[1] in b:
    ans = True
if one[2] in b and two[2] in b and thr[2] in b:
    ans = True
#横
if one[0] in b and one[1] in b and one[2] in b:
    ans = True
if two[0] in b and two[1] in b and two[2] in b:
    ans = True
if thr[0] in b and thr[1] in b and thr[2] in b:
    ans = True

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

Submission status: Accepted

Solution code:
A1 = [int(a) for a in input().split()]
A2 = [int(a) for a in input().split()]
A3 = [int(a) for a in input().split()]
N = int(input())
b = []
for _ in range(N):
    b.append(int(input()))
b_set = set(b)

set_list = [set(A1),
            set(A2),
            set(A3),
            set([A1[0], A2[0], A3[0]]),
            set([A1[1], A2[1], A3[1]]),
            set([A1[2], A2[2], A3[2]]),
            set([A1[0], A2[1], A3[2]]),
            set([A1[2], A2[1], A3[0]])]

f = False
for s in set_list:
    if len(s - b_set)==0:
        f = True
        print('Yes')
        break
if not f:
    print('No')