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.

Solution (Python):
a = [list(map(int,input().split())) for i in range(3)]
c = [[0,0,0] for _ in range(3)]
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))
for i in b:
  for j in range(3):
    for k in range(3):
      if a[j][k] == i:
        c[j][k] = 1
if sum(c[0]) == 3 or sum(c[1])==3 or sum(c[2])==3:
  print("Yes")
else:
  for i in range(3):
    s = c[0][i]+c[1][i]+c[2][i]
    if s == 3:
      print("Yes")
      quit()
  if c[0][0]+c[1][1]+c[2][2]==3 or c[2][0]+c[1][1]+c[0][2]==3:
    print("Yes")
    quit()
  print("No")

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

chk = [[0]*3 for _ in range(3)]
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            chk[i][j] = 1

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

print(ans)

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

for i in range(3):
    if B[i][0] == 1 and B[i][1] == 1 and B[i][2] == 1:
        print('Yes')
        exit()

for i in range(3):
    if B[0][i] == 1 and B[1][i] == 1 and B[2][i] == 1:
        print('Yes')
        exit()

if B[0][0] == 1 and B[1][1] == 1 and B[2][2] == 1:
    print('Yes')
    exit()

if B[0][2] == 1 and B[1][1] == 1 and B[2][0] == 1:
    print('Yes')
    exit()

print('No')

Solution (Python):
import itertools

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

hit = []
for i in range(3):
    hit.append((A[i][0], A[i][1], A[i][2]))
    hit.append((A[0][i], A[1][i], A[2][i]))
hit.append((A[0][0], A[1][1], A[2][2]))
hit.append((A[0][2], A[1][1], A[2][0]))

yes = False
for p in itertools.permutations(B, 3):
    if p in hit:
        print("Yes")
        yes = True
        exit()

if not yes:
    print("No")

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

N = int(input())

for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if (A[j][k] == b):
                c[j][k] = True

f = False
for i in range(3):
    f |= c[0][i] & c[1][i] & c[2][i]
    f |= c[i][0] & c[i][1] & c[i][2]

f |= c[0][0] & c[1][1] & c[2][2]
f |= c[0][2] & c[1][1] & c[2][0]

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

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

X = [0] * 101

for k in range(N):
    t = int(input())
    X[t] = 1

if X[a]*X[e]*X[i] == 1 or X[a]*X[b]*X[c] == 1 or X[d]*X[e]*X[f] == 1 or X[g]*X[h]*X[i] == 1 or X[a]*X[d]*X[g] == 1 or X[b]*X[e]*X[h] == 1 or X[c]*X[f]*X[i] == 1 or X[c]*X[e]*X[g] == 1:
    print("Yes")
else:
    print("No")

Solution (Python):
import sys







def main():

    A1 = list(map(int, input().split()))
    A2 = list(map(int, input().split()))
    A3 = list(map(int, input().split()))

    As = [A1, A2, A3]

    N = int(input())
    idxs = list()

    for i in range(N):
        b = int(input())
        for j, A in enumerate(As):
            if b in A:
                idx = A.index(b)
                idxs.append((j, idx))

    answer = 'No'

    
    for i in range(3):
        if (i, 0) in idxs and (i, 1) in idxs and (i, 2) in idxs:
            answer = 'Yes'

    
    for i in range(3):
        if (0, i) in idxs and (1, i) in idxs and (2, i) in idxs:
            answer = 'Yes'

    if (0, 0) in idxs and (1, 1) in idxs and (2, 2) in idxs:
        answer = 'Yes'

    if (0, 2) in idxs and (1, 1) in idxs and (2, 0) in idxs:
        answer = 'Yes'

    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
A = []
A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))
N = int(input())

B = [[0]*3 for _ in range(3)]
for _ in range(N):
    b = int(input())
    for j in range(3):
        for i in range(3):
            if A[j][i]==b:
                B[j][i]=1

if (B[0][0]+B[0][1]+B[0][2]==3) or (B[1][0]+B[1][1]+B[1][2]==3) or (B[2][0]+B[2][1]+B[2][2]==3) or (B[0][0]+B[1][0]+B[2][0]==3) or (B[0][1]+B[1][1]+B[2][1]==3) or (B[0][2]+B[1][2]+B[2][2]==3) or (B[0][0]+B[1][1]+B[2][2]==3) or (B[2][0]+B[1][1]+B[0][2]==3):
    print('Yes')
else:
    print('No')

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

for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k]==b:
                A[j][k] = -1

aa = False

while(1):
    
    for i in range(3):
        for j in range(3):
            if A[i][j] != -1:
                break
        else:
            print("Yes")
            aa = True
            break
    if aa:
        break

    
    for i in range(3):
        for j in range(3):
            if A[j][i] != -1:
                break
        else:
            print("Yes")
            aa = True
            break
    if aa:
        break
    
    
    if A[0][0]==-1 and A[1][1]==-1 and A[2][2]==-1:
        print("Yes")
        break
    if A[2][0]==-1 and A[1][1]==-1 and A[0][2]==-1:
        print("Yes")
        break

    print("No")
    break

Solution (Python):
import sys
input = sys.stdin.readline

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

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

flag = 0

for k in A:
    if k[0] == 0 and k[1] == 0 and k[2] == 0:
        flag = 1

for k in range(3):
    flag_2 = 1
    for j in range(3):
        if A[j][k] != 0:
            flag_2 = 0
    if flag_2:
        flag = 1

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

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

Solution (Python):
a=[ list(map(int,input().split())) for j in range(3)]
n=int(input())
kk=101
for i in range(n):
  s=int(input())
  for j in range(3):
    for k in range(3):
      if s==a[j][k]:
        a[j][k]=kk
count=0
ans=0
for j in range(3):
  count=0
  for k in range(3):
    if a[j][k]==kk:
      count+=1
  if count==3:
    ans=1
    break
    
for j in range(3):
  count=0
  for k in range(3):
    if a[k][j]==kk:
      count+=1
  if count==3:
    ans=1
    break
if a[0][0]==kk and a[1][1]==kk and a[2][2]==kk:
  ans=1
if a[0][2]==kk and a[1][1]==kk and a[2][0]==kk:
  ans=1
if ans==1:
  print("Yes")
else:
  print("No")

Solution (Python):
bingo = []
for i in range(3):
    bingo.append(list(map(int, input().split())))
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if bingo[j][k] == b:
                bingo[j][k] = None
for i in range(3):
    row = True
    column = True
    for j in range(3):
        if bingo[i][j] != None:
            column = False
        if bingo[j][i] != None:
            row = False
    if column or row:
        print("Yes")
        exit()
naname = False
if bingo[0][0] == bingo[1][1] == bingo[2][2] == None or bingo[0][2] == bingo[1][1] == bingo[2][0] == None:
    naname = True
if row or column or naname:
    print("Yes")
else:
    print("No")

Solution (Python):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a1=LIST()
    a2=LIST()
    a3=LIST()
    a=[]
    a.append(a1)
    a.append(a2)
    a.append(a3)
    n=INT()
    num=[]
    for i in range(n):
        num.append(INT())
    for i in num:
        for k in a:
            if i in k:
                temp=k.index(i)
                k[temp]=0
    flg=0
    for i in a:
        if i==[0,0,0]:
            flg=1
    for i in range(3):
        if a[0][i]==0 and a[1][i]==0 and a[2][i]==0:
            flg=1
    if a[0][0]==0 and a[1][1]==0 and a[2][2]==0:
        flg=1
    if a[2][0]==0 and a[1][1]==0 and a[0][2]==0:
        flg=1
    if flg==1:
        print('Yes')
    else:
        print('No')
    
if __name__ == '__main__':
    do()

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

def is_bingo(A, B):
    if A[0][0] in B and A[0][1] in B and A[0][2] in B:
        return True
    if A[1][0] in B and A[1][1] in B and A[1][2] in B:
        return True
    if A[2][0] in B and A[2][1] in B and A[2][2] in B:
        return True

    if A[0][0] in B and A[1][0] in B and A[2][0] in B:
        return True
    if A[0][1] in B and A[1][1] in B and A[2][1] in B:
        return True
    if A[0][2] in B and A[1][2] in B and A[2][2] in B:
        return True

    if A[0][0] in B and A[1][1] in B and A[2][2] in B:
        return True
    if A[0][2] in B and A[1][1] in B and A[2][0] in B:
        return True

    return False

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

Solution (Python):
import numpy as np
sheet = np.zeros((3,3))
for i in range(3):
    sheet[i] = list(map(int, input().split()))

N = int(input())

for _ in range(N):
    b = int(input())
    for r in range(3):
        for c in range(3):
            if sheet[r,c] == b:
                sheet[r,c] = 0

rows = np.sum(sheet, axis=0)
if 0 in list(rows):
    print("Yes")
    exit()
cols = np.sum(sheet, axis=1)
if 0 in list(cols):
    print("Yes")
    exit()
if (sheet[0,0] + sheet[1,1] + sheet[2,2]) == 0:
    print("Yes")
    exit()
if (sheet[0,2] + sheet[1,1] + sheet[2,0]) == 0:
    print("Yes")
    exit()
print("No")

Solution (Python):

bingo = [[int(x) for x in input().split()] for _ in range(3)]

N = int(input())


for _ in range(N):
    push = int(input())
    for i in range(3):
        if push in bingo[i]:
            bingo[i][bingo[i].index(push)] = -1

is_bingo = False

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



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

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

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

Solution (Python):
A = [list(map(int,input().split())) for i in range(3)]
N = int(input())
for _ in range(N):
    a = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k] == a:
                A[j][k] = 0
result = "No"
for i in range(3):
    if sum(A[i]) == 0:
        result = "Yes"
    elif A[0][i] + A[1][i] + A[2][i] == 0:
        result = "Yes"
    elif A[0][0] + A[1][1] + A[2][2] == 0 or A[0][2] + A[1][1] + A[2][0] == 0:
        result = "Yes"
    else:
        None
print(result)

Solution (Python):
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a = [a1,a2,a3]
n = int(input())
b = []
c = [0]*9
for i in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                c[i*3+j] = 1
ans = 'No'
if c[0]==c[3]==c[6]==1 or c[1]==c[4]==c[7]==1 or c[2]==c[5]==c[8]==1:
    ans = 'Yes'
elif c[0]==c[1]==c[2]==1 or c[3]==c[4]==c[5]==1 or c[6]==c[7]==c[8]==1:
    ans = 'Yes'
elif c[0]==c[4]==c[8]==1 or c[2]==c[4]==c[6]==1:
    ans = 'Yes'

print(ans)

Solution (Python):





import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    a = [[0] * 3 for _ in range(3)]
    b = [[0] * 3 for _ in range(3)]

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

    n = int(input())

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

    flag = False

    for i in range(3):
        for j in range(3):
            if b[i][j] != 1:
                break
        else:
            flag = True

    for i in range(3):
        for j in range(3):
            if b[j][i] != 1:
                break
        else:
            flag = True

    if b[1][1] == 1:
        if b[0][0] == 1:
            if b[2][2] ==1:
                flag = True
        if b[2][0] == 1:
            if b[0][2] ==1:
                flag = True

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



if __name__ == '__main__':
    main()

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

for i in range(3):
    flag = True
    for j in range(3):
        if not a[i][j] in b:
            flag = False
            break
    if flag:
        print("Yes")
        exit()

for i in range(3):
    flag = True
    for j in range(3):
        if not a[j][i] in b:
            flag = False
            break
    if flag:
        print("Yes")
        exit()

flag = True
for i in range(3):
    if not a[i][i] in b:
        flag = False
if flag:
    print("Yes")
    exit()

flag = True
if a[0][2] in b and a[1][1] in b and a[2][0] in b:
    print("Yes")
else:
    print("No")

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

Solution (Python):
import sys
import math
import fractions
import itertools
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

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 l in A:
        for c in range(3):
            if l[c] == i:
                l[c] = -1
for i in A:
    if set(i) == {-1}:
        print('Yes')
        sys.exit()
for i in range(3):
    if A[0][i] == A[1][i] == A[2][i] == -1:
        print("Yes")
        sys.exit()
if A[0][0] == A[1][1] == A[2][2]:
    print("Yes")
    sys.exit()
if A[2][0] == A[1][1] == A[0][2] == -1:
    print("Yes")
    sys.exit()
print("No")

Solution (Python):
a = [[0 for i in range(3)] for j in range(3)]
f = [[False for i in range(3)] for j in range(3)]

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

n = int(input())
for i in range(n):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k] == b:
        f[j][k] = True

ans = (f[0][0] and f[1][1] and f[2][2]) or (f[0][2] and f[1][1] and f[2][0])
for i in range(3):
  ans = ans or (f[i][0] and f[i][1] and f[i][2])
  ans = ans or (f[0][i] and f[1][i] and f[2][i])

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

Solution (Python):
def main():
    bingo=[list(map(int,input().split())) for i in range(3)]
    n=int(input())
    b={int(input()) for i in range(n)}
    
    X=[[0]*3 for _ in range(3)]
    for i in range(3):
        for j in range(3):
            if bingo[i][j] in b:
                X[i][j]=1
    
    flag=False
    for i in range(3):
        if (X[i][0]&X[i][1]&X[i][2])==1:
            flag=True
            print('Yes')
            exit()
        if (X[0][i]&X[1][i]&X[2][i])==1:
            flag=True
            print('Yes')
            exit()
    if (X[0][0]&X[1][1]&X[2][2])==1:
        flag=True
        print('Yes')
        exit()
    
    if (X[0][2]&X[1][1]&X[2][0])==1:
        flag=True
        print('Yes')
        exit()
    print('No')

if __name__=='__main__':
    main()

Solution (Python):
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
a3=list(map(int,input().split()))
a=[a1,a2,a3]
n=int(input())
b=[0 for _ in range(n)]
for i in range(n):
  b[i]=int(input())
bingo=[[0,0,0],[0,0,0],[0,0,0]]
for i in range(3):
  for j in range(3):
    if a[i][j] in b:
      bingo[i][j]=1
for i in range(3):
  if bingo[i]==[1,1,1]:
    print('Yes')
    exit()
for j in range(3):
  if bingo[0][j]==1 and bingo[1][j]==1 and bingo[2][j]==1:
    print('Yes')
    exit()
if bingo[0][0]==1 and bingo[1][1]==1 and bingo[2][2]==1:
  print('Yes')
  exit()
if bingo[0][2]==1 and bingo[1][1]==1 and bingo[2][0]==1:
  print('Yes')
  exit()


print('No')

Solution (Python):
def main():

    A = []
    for i in range(3):
        A.append(list(map(int, input().split())))
    cand = []
    for j in range(3):
        cand += [sorted(A[j])]
        cand += [sorted([A[i][j] for i in range(3)])]
    cand += [sorted([A[i][i] for i in range(3)])]
    cand += [sorted([A[i][2-i] for i in range(3)])]
    

    b = []
    N = int(input())
    for i in range(N):
        b.append(int(input()))
    b = set(sorted(b))
    
    for i in range(len(cand)):
        if cand[i][0] in b and cand[i][1] in b and cand[i][2] in b:
            return "Yes"

    return "No"

if __name__ == '__main__':
    print(main())

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
l = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
L = [None]*N
for i in range(N):
    L[i] = int(input())

for i in range(N):
    elm = L[i]
    for j in range(3):
        for k in range(3):
            if l[j][k]==elm:
                l[j][k] = 0
for i in range(3):
    if sum(l[i])==0:
        print('Yes')
        exit()
    if (l[0][i]+l[1][i]+l[2][i])==0:
        print('Yes')
        exit()
if l[0][0]+l[1][1]+l[2][2]==0:
    print('Yes')
    exit()
if l[0][2]+l[1][1]+l[2][0]==0:
    print('Yes')
    exit()
print('No')

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False



def main():
    A = []
    B = []
    for i in range(3):
        A.append(LI())
        B.append([False] * 3)


    N = I()

    b = []
    for i in range(N):
        b.append(I())

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

    for i in range(3):
        if B[i][0] is True and B[i][1] is True and B[i][2] is True:
            print('Yes')
            return

    for i in range(3):
        if B[0][i] is True and B[1][i] is True and B[2][i] is True:
            print('Yes')
            return

    if B[0][0] is True and B[1][1] is True and B[2][2] is True:
        print('Yes')
        return

    if B[0][2] is True and B[1][1] is True and B[0][2] is True:
        print('Yes')
        return

    print('No')


if __name__ == '__main__':
    main()

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

Solution (Python):
A = [[int(i) for i in input().split()] for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]
f = [[False]*3 for _ in range(3)]
for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                f[i][j] = True
for i in range(3):
    if all(f[i]):
        break
    if f[0][i] and f[1][i] and f[2][i]:
        break
    if f[0][0] and f[1][1] and f[2][2]:
        break
    if f[0][2] and f[1][1] and f[2][0]:
        break
else:
    print('No')
    exit()
print("Yes")

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

n = int(input())
B = [int(input()) for _ in range(n)]

y = []
for i in range(3):
    tmp = []
    for j in range(3):
        tmp.append(lst[i][j])
    y.append(tmp)
for i in range(3):
    tmp = []
    for j in range(3):
        tmp.append(lst[j][i])
    y.append(tmp)

y.append([lst[0][0], lst[1][1], lst[2][2]])
y.append([lst[0][2], lst[1][1], lst[2][0]])

res = False
for i in range(len(y)):
    a,b,c = y[i][0], y[i][1], y[i][2]
    if (a in B) and (b in B) and (c in B):
        res = True
print('Yes' if res else 'No')

Solution (Python):
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())
    for j in range(3):
        if a1[j]==b:
            a1[j]='o'
        if a2[j]==b:
            a2[j]='o'
        if a3[j]==b:
            a3[j]='o'

if a1.count('o')==3 or a2.count('o')==3 or a3.count('o')==3:
    print('Yes')
elif a1[0]==a2[0]==a3[0]=='o':
    print('Yes')
elif a1[1]==a2[1]==a3[1]=='o':
    print('Yes')
elif a1[2]==a2[2]==a3[2]=='o':
    print('Yes')
elif a1[0]==a2[1]==a3[2]=='o':
    print('Yes')
elif a1[2]==a2[1]==a3[0]=='o':
    print('Yes')
else:
    print('No')

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

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

Check = [[0 for _ in range(3)] for _ in range(3)]

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

ans = 'No'
for i in range(3):
    if sum(Check[i]) == 3:
        ans = 'Yes'
for i in range(3):
    now = 0
    for j in range(3):
        now += Check[j][i]
    if now == 3:
        ans = 'Yes'
now = 0
for i in range(3):
    now += Check[i][i]
if now == 3:
    ans = 'Yes'

if Check[2][0] + Check[1][1] + Check[0][2] == 3:
    ans = 'Yes'

print(ans)

Solution (Python):
A = input().split()
a1 = [int(a) for a in A]
A = input().split()
a2 = [int(a) for a in A]
A = input().split()
a3 = [int(a) for a in A]
ass = set(a1+a2+a3)

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

bs = set(Bs)

c = list(ass & bs)

if len(c) < 3:
  print('No')
else:
  if a1[0] in bs and a1[1] in bs and a1[2] in bs:
    print('Yes')
  elif a2[0] in bs and a2[1] in bs and a2[2] in bs:
    print('Yes')
  elif a3[0] in bs and a3[1] in bs and a3[2] in bs:
    print('Yes')
  elif a1[0] in bs and a2[0] in bs and a3[0] in bs:
    print('Yes')
  elif a1[1] in bs and a2[1] in bs and a3[1] in bs:
    print('Yes')
  elif a1[2] in bs and a2[2] in bs and a3[2] in bs:
    print('Yes')
  elif a1[0] in bs and a2[1] in bs and a3[2] in bs:
    print('Yes')
  elif a1[2] in bs and a2[1] in bs and a3[0] in bs:
    print('Yes')
  else:
    print('No')

Solution (Python):
a = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
bingo = [[False,False,False] 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] = True

ans = False
for i in range(3):
    q = True
    for j in range(3):
        if  not bingo[i][j]:
            q = False
            break
    if q:
        print("Yes")
        exit()
for i in range(3):
    q = True
    for j in range(3):
        if  not bingo[j][i]:
            q = False
            break
    if q:
        print("Yes")
        exit()
q = True
for i in range(3):
    if not bingo[i][i]:
        q = False
        break
if q:
    print("Yes")
    exit()

q = True
for i in range(3):
    if not bingo[i][2-i]:
        q = False
        break
if q:
    print("Yes")
    exit()

print("No")

Solution (Python):
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())

get_list1 = []
get_list2 = []
get_list3 = []
for n in range(N):
  _ = int(input())
  for idx,a1 in enumerate(A1):
    if a1 == _:
      get_list1.append(idx)

  for idx,a2 in enumerate(A2):
    if a2 == _:
      get_list2.append(idx)
      
  for idx,a3 in enumerate(A3):
    if a3 == _:
      get_list3.append(idx)
    

ans = 'No'


if 0 in get_list1:
  if 0 in get_list2:
    if 0 in get_list3:
      ans = 'Yes'
if 1 in get_list1:
  if 1 in get_list2:
    if 1 in get_list3:
      ans = 'Yes'      
if 2 in get_list1:
  if 2 in get_list2:
    if 2 in get_list3:
      ans = 'Yes'      


if len(get_list1) == 3:
  ans = 'Yes'
if len(get_list2) == 3:
  ans = 'Yes'
if len(get_list3) == 3:
  ans = 'Yes'


if 0 in get_list1:
  if 1 in get_list2:
    if 2 in get_list3:
      ans = 'Yes'
if 2 in get_list1:
  if 1 in get_list2:
    if 0 in get_list3:
      ans = 'Yes'
print(ans)

Solution (Python):
A = []
for _ in range(3):
    A.append(list(map(int, input().split())))
N = int(input())
B = [int(input()) for _ in range(N)]
bingo = [[False for _ in range(3)] for _ in range(3)]
for b in B:
    for h in range(3):
        for w in range(3):
            if A[h][w] == b:
                bingo[h][w] = True

for w in range(3):
    flag = True
    for h in range(3):
        if not bingo[h][w]:
            flag = False
            break
    if flag:
        print("Yes")
        exit()

for h in range(3):
    flag = True
    for w in range(3):
        if not bingo[h][w]:
            flag = False
            break
    if flag:
        print("Yes")
        exit()

flag = True
for i in range(3):
    if not bingo[i][i]:
        flag = False
        break

if flag:
    print("Yes")
    exit()

flag = True
for i in range(3):
    if not bingo[i][2-i]:
        flag = False
        break
if flag:
    print("Yes")
    exit()
print("No")

Solution (Python):
a=[]
for i in range(3):
    a.append(list(map(int,input().split())))
b=[[0 for i in range(3)] for j in range(3)]
n=int(input())
for i in range(n):
    p=int(input())
    for j in range(3):
        for k in range(3):
            if p==a[j][k]:
                b[j][k]=1
for i in range(3):
    x=0
    y=0
    for j in range(3):
        if b[i][j]==1:
            x+=1
        if b[j][i]==1:
            y+=1
    if x==3 or y==3:
        print('Yes')
        exit()
if b[0][0]==b[1][1]==b[2][2]==1:
    print('Yes')
    exit()
if b[2][0]==b[1][1]==b[0][2]==1:
    print('Yes')
    exit()
print('No')

Solution (Python):
bingo = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
bingo_tf = [[False]*3 for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == b:
                bingo_tf[i][j] = True

def c(a, b, c):
    return bingo_tf[a[0]][a[1]] and bingo_tf[b[0]][b[1]] and bingo_tf[c[0]][c[1]]

if c((0, 0), (0, 1), (0, 2)) or c((1, 0), (1, 1), (1, 2)) or c((2, 0), (2, 1), (2, 2)) or c((0, 0), (1, 0), (2, 0)) or c((0, 1), (1, 1), (2, 1)) or c((0, 2), (1, 2), (2, 2)) or c((0, 0), (1, 1), (2, 2)) or c((0, 2), (1, 1), (2, 0)):
    print("Yes")
else:
    print("No")

Solution (Python):
bingo = [[int(i) for i in input().split()] for _ in range(3)]
N= [int(i) for i in input().split()][0]
bn =[int(input()) for _ in range(N)]

array = [[0 for _ in range(3)] for _ in range(3)]

for i in range(3):
  for j in range(3):
    a = bingo[i][j]
    for b in bn:
      if a == b:
        array[i][j] = 1
bing = False
cor1 = 0
cor2 = 0
for i in range(3):
  cor1 += array[i][i]
  cor2 += array[i][2-i] 
  sum1 = 0
  sum2 = 0
  for j in range(3):
    sum1 += array[i][j]
    sum2 += array[j][i]
  if sum1 == 3 or sum2 == 3:
    bing = True
if cor1 == 3 or cor2 == 3:
  bing = True
    
print("Yes" if bing else "No")