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 _ in range(3)]
C = [[0]*3 for _ in range(3)]
n = int(input())
for _ in range(n):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        C[i][j] = 1
def hoge():
  print("Yes")
  exit()
 
if C[0][0] & C[0][1] & C[0][2]:
  hoge()
if C[1][0] & C[1][1] & C[1][2]:
  hoge()
if C[2][0] & C[2][1] & C[2][2]:
  hoge()
if C[0][0] & C[1][0] & C[2][0]:
  hoge()
if C[0][1] & C[1][1] & C[2][1]:
  hoge()
if C[0][2] & C[1][2] & C[2][2]:
  hoge()
if C[0][0] & C[1][1] & C[2][2]:
  hoge()
if C[0][2] & C[1][1] & C[2][0]:
  hoge()
print("No")

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

for i in range(n):
  for x in range(3):
    for y in range(3):
      if A[x][y] == b[i]:
        A[x][y] = -1
        
flag = 0
for i in range(3):
  if A[i][0]==-1 and A[i][1]==-1 and A[i][2]==-1:
    flag = 1
  if A[0][i]==-1 and A[1][i]==-1 and A[2][i]==-1:
    flag = 1
    
if A[0][0]==-1 and A[1][1]==-1 and A[2][2]==-1:
  flag = 1
if A[2][0]==-1 and A[1][1]==-1 and A[0][2]==-1:
  flag = 1
  
if flag==1:
  print("Yes")
else:
  print("No")

Solution (Python):
import sys
input = sys.stdin.readline
a = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
l = []
for i in range(3):
  t = []
  for j in range(3):
    t.append(a[i][j])
  l.append(t)
for j in range(3):
  t = []
  for i in range(3):
    t.append(a[i][j])
  l.append(t)
l.append([a[0][0], a[1][1], a[2][2]])
l.append([a[0][2], a[1][1], a[2][0]])
for t in l:
  s = [0] * 3
  for x in b:
    for i in range(3):
      if x == t[i]: s[i] = 1
  if sum(s) == 3:
    print("Yes")
    exit(0)
print("No")

Solution (Python):
A = [list(map(int,input().split())) for i in range(3)]
N = int(input())
B = [int(input()) for n in range(N)]
C = [[0,0,0],[0,0,0],[0,0,0]]
F = "No"

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

for i in range(3):
  if C[i][0]+C[i][1]+C[i][2]==3:
    F = "Yes"

for i in range(3):
  if C[0][i]+C[1][i]+C[2][i]==3:
    F = "Yes"

for i in range(3):
  if C[0][0]+C[1][1]+C[2][2]==3 or C[0][2]+C[1][1]+C[2][0]==3:
    F = "Yes"

print(F)

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

P = [[0 for j in range(3)] for i in range(3)]

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

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

Solution (Python):
def main():
    A = [ list( map( int, input().split())) for _ in range(3)]
    N = int( input())
    B = [ int( input()) for _ in range(N)]
    T = [[0]*3 for _ in range(3)]
    for b in B:
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    T[i][j] = 1
    ans = 'No'
    for i in range(3):
        if T[i][0]*T[i][1]*T[i][2] > 0:
            ans = 'Yes'
    for i in range(3):
        if T[0][i]*T[1][i]*T[2][i] > 0:
            ans = 'Yes'
    if T[0][0]*T[1][1]*T[2][2] > 0:
        ans = 'Yes'
    if T[0][2]*T[1][1]*T[2][0] > 0:
        ans = 'Yes'
    print(ans)
if __name__ == '__main__':
    main()

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


S = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

for b in B:
    for i in range(3):
        for j in range(3):
            if S[i][j] == b:
                S[i][j] = -1

ok = False
for i in range(3):
    bi = True
    for j in range(3):
        if S[i][j] != -1:
            bi = False
    if bi: ok = True

for j in range(3):
    bi = True
    for i in range(3):
        if S[i][j] != -1:
            bi = False
    if bi: ok = True

if S[0][0] == -1 and S[1][1] == -1 and S[2][2] == -1:
    ok = True
if S[0][2] == -1 and S[1][1] == -1 and S[2][0] == -1:
    ok = True

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

Solution (Python):
def Bingo():
    for a in bingo:
        if sum(a) == 0:
            return True
    for b in range(len(bingo)):
        if sum([bingo[i][b] for i in range(3)]) == 0:
            return True
    if bingo[0][0] + bingo[1][1] + bingo[2][2] == 0:
        return True
    if bingo[1][1] + bingo[2][0] + bingo[0][2] == 0:
        return True
    return False

bingo = [[int(i) for i in input().split()] for i in range(3)]
valid = False
N = int(input())
for a in range(N):
    num = int(input())
    for b in range(len(bingo)):
        if num in bingo[b]:
            bingo[b][bingo[b].index(num)] = 0
    if Bingo():
        valid = True
        break
if valid:
    print("Yes")
else:
    print("No")

Solution (Python):
def main():
    a = [[int(x) for x in input().split()] for _ in range(3)]
    n = int(input())

    t = [[0] * 3 for _ in range(3)]

    for _ in range(n):
        b = int(input())
        for r in range(3):
            for c in range(3):
                if a[r][c] == b:
                    t[r][c] = 1

    for r in range(3):
        if t[r][0] == t[r][1] == t[r][2] == 1:
            print('Yes')
            return

    for c in range(3):
        if t[0][c] == t[1][c] == t[2][c] == 1:
            print('Yes')
            return

    if t[0][0] == t[1][1] == t[2][2] == 1:
        print('Yes')
        return

    if t[0][2] == t[1][1] == t[2][0] == 1:
        print('Yes')
        return

    print('No')


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import combinations
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
ans = []
for i in b:
  for x in range(3):
    for y in range(3):
      if i == a[x][y]:
        ans.append(3*x+y)
if len(ans) <= 2:
  print("No")
  exit()
ans.sort()
for i,j,k in combinations(ans,3):
  if (i,j,k) in ((0,1,2),(0,4,8),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(2,4,6)):
    print("Yes")
    break
else:
  print("No")

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

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

for i in range(3):
    count = 0
    for j in range(3):
        if A[i][j] != 0:
            break
        count += 1
    if count == 3:
        print("Yes")
        exit()

for i in range(3):
    count = 0
    for j in range(3):
        if A[j][i] != 0:
            break
        count += 1
    if count == 3:
        print("Yes")
        exit()

count = 0
for i in range(3):
    if A[i][i] != 0:
        break
    count += 1
if count == 3:
    print("Yes")
    exit()

count = 0
for i in range(3):
    if A[i][2-i] != 0:
        break
    count += 1
if count == 3:
    print("Yes")
    exit()

print("No")

Solution (Python):
import sys

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def input(): return sys.stdin.readline().strip()

mat = []
for i in range(3):
    mat.append(get_array())

n = int(input())
for i in range(n):
    x = int(input())
    for j in range(3):
        for k in range(3):
            if mat[j][k]==x:
                mat[j][k]=-1

flag = 0
if mat[0][0]==mat[0][1]==mat[0][2]==-1:
    flag = 1
elif mat[1][0]==mat[1][1]==mat[1][2]==-1:
    flag = 1
elif mat[2][0]==mat[2][1]==mat[2][2]==-1:
    flag = 1
elif mat[0][0]==mat[1][0]==mat[2][0]==-1:
    flag = 1
elif mat[0][1]==mat[1][1]==mat[2][1]==-1:
    flag = 1
elif mat[0][2]==mat[1][2]==mat[2][2]==-1:
    flag = 1
elif mat[0][0]==mat[1][1]==mat[2][2]==-1:
    flag = 1
elif mat[0][2]==mat[1][1]==mat[2][0]==-1:
    flag = 1
if flag==0:
    print('No')
else:
    print('Yes')

Solution (Python):
def main():
    aa = []
    for _ in xrange(3):
        aa.extend(map(int, raw_input().split()))
    n = input()
    for _ in xrange(n):
        b = input()
        try:
            aa[aa.index(b)] = 0
        except ValueError:
            continue
    for i in xrange(3):
        if sum(aa[i*3:i*3+3]) == 0:
            print 'Yes'
            return
        if sum(aa[i::3]) == 0:
            print 'Yes'
            return
    if sum(aa[::4]) == 0:
        print 'Yes'
        return
    if sum(aa[2:7:2]) == 0:
        print 'Yes'
        return
    print 'No'

main()

Solution (Python):
lst = []
atari = [0 for _ in range(9)]
for _ in range(3):
	a, b, c = map(int, input().split())
	lst.append(a)
	lst.append(b)
	lst.append(c)

N = int(input())

for _ in range(N):
	b = int(input())
	if b in lst:
		atari[lst.index(b)] = 1
	
if atari[0] * atari[1] * atari[2] == 1 or atari[3] * atari[4] * atari[5] == 1 or atari[6] * atari[7] * atari[8] == 1 or atari[0] * atari[3] * atari[6] == 1 or atari[1] * atari[4] * atari[7] == 1 or atari[2] * atari[5] * atari[8] == 1 or atari[0] * atari[4] * atari[8] == 1 or atari[2] * atari[4] * atari[6] == 1:
	print("Yes")
else:
	print("No")

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

flag = [[False] * 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:
                flag[j][k] = True

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

flag_t = [list(x) for x in zip(*flag)]
for i in range(3):
    if sum(flag_t[i]) == 3:
        ans = True

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

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

Solution (Python):
a=[[int(i) for i in 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]=1000
ans=False
for i in range(3):
    if a[i][0]==a[i][1]==a[i][2]==1000:
        ans=True
    elif a[0][i]==a[1][i]==a[2][i]==1000:
        ans=True
if a[0][0]==a[1][1]==a[2][2]==1000:
    ans=True
elif a[0][2]==a[1][1]==a[2][0]==1000:
    ans=True
print("Yes" if ans else "No")

Solution (Python):
a = []
for i in range(3):
    a.append(tuple(map(int, input().split( ))))
a2 = [[0]*3 for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

for i in range(n):
    for j in range(3):
        for k in range(3):
            if a[j][k]==b[i]:
                a2[j][k]=1
for i in range(3):
    flag = True
    for j in range(3):
        if a2[i][j]==0:
            flag = False
            break
    if flag:
        print("Yes")
        exit()
for j in range(3):
    flag = True
    for i in range(3):
        if a2[i][j]==0:
            flag = False
            break
    if flag:
        print("Yes")
        exit()
if a2[0][0]==1 and a2[1][1]==1 and a2[2][2]==1:
    print("Yes")
    exit()
if a2[0][2]==1 and a2[1][1]==1 and a2[2][0]==1:
    print("Yes")
    exit()
print("No")

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

for i in range(3):
  if sum(used[i]) == 3:
    print('Yes')
    exit()

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

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

  
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 range(3):
    for j in range(3):
        if a[i][j] in b:
            a[i][j] = 0




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

print('No')

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

hit = [[0] * 3 for _ in range(3)]

for e in b:
    for i in range(3):
        for j in range(3):
            if a[i][j] == e:
                hit[i][j] = 1

bl = False
for i in range(3):
    if hit[i][0] and hit[i][1] and hit[i][2]:
        bl = True

    if hit[0][i] and hit[1][i] and hit[2][i]:
        bl = True

if hit[0][0] and hit[1][1] and hit[2][2]:
    bl = True

if hit[0][2] and hit[1][1] and hit[2][0]:
    bl = True

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

Solution (Python):
from collections import defaultdict

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

for i in range(3):
    for j in range(3):
        d[A[i][j]] = (i, j)
        
N = int(input())
flag = [[False]*3 for _ in range(3)]

for _ in range(N):
    b = int(input())
    if b in d:
        x, y = d[b]
        flag[x][y] = True

ans = False

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

if flag[0][2] and flag[1][1] and flag[2][0]:
    ans = True
    
if ans:
    print('Yes')
else:
    print('No')

Solution (Python):
bingo = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
l = [int(input()) for _ in range(n)]
for i in range(3):
    if bingo[i][0] in l and bingo[i][1] in l and bingo[i][2] in l:
        print("Yes")
        exit()
for i in range(3):
    if bingo[0][i] in l and bingo[1][i] in l and bingo[2][i] in l:
        print("Yes")
        exit()
if bingo[0][0] in l and bingo[1][1] in l and bingo[2][2] in l:
    print("Yes")
    exit()
if bingo[0][2] in l and bingo[1][1] in l and bingo[2][0] in l:
    print("Yes")
    exit()
print("No")

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

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

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

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

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

flag = False
if L[0][0] & L[1][1] & L[2][2]:
  flag = True
if L[0][2] & L[1][1] & L[2][0]:
  flag = True
for i in range(3):
  if L[i][0] & L[i][1] & L[i][2]:
    flag = True
  if L[0][i] & L[1][i] & L[2][i]:
    flag = True

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    def bingo():
        for row in t:
            if sum(row)==3:return True
        for col in zip(*t):
            if sum(col)==3:return True
        if sum(t[i][i] for i in range(3)) == 3: return True
        if sum(t[i][2-i] for i in range(3)) == 3: return True
        return False

    atoij={}
    aa=LLI(3)
    for i in range(3):
        for j in range(3):
            a=aa[i][j]
            atoij[a]=(i,j)
    t=[[False]*3 for _ in range(3)]
    n=II()
    for _ in range(n):
        a=II()
        if a in atoij:
            i,j=atoij[a]
            t[i][j]=True
    if bingo():print("Yes")
    else:print("No")

main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A = [LIST() for _ in range(3)]
N = INT()
b = [INT() for _ in range(N)]

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

for i in range(3):
	if sum(check[i]) == 3:
		print("Yes")
		exit()
for i in range(3):
	if check[0][i] and check[1][i] and check[2][i]:
		print("Yes")
		exit()

if check[0][0] and check[1][1] and check[2][2]:
	print("Yes")
	exit()

if check[0][2] and check[1][1] and check[2][0]:
	print("Yes")
	exit()

print("No")

Solution (Python):
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

l = list()
for _ in range(3):
    l += nl()
n = ni()
b = set([ni() for _ in range(n)])
g = [(x in b) for x in l]
f = g[0]&g[1]&g[2]
f |= g[3]&g[4]&g[5]
f |= g[6]&g[7]&g[8]
f |= g[0]&g[3]&g[6]
f |= g[1]&g[4]&g[7]
f |= g[2]&g[5]&g[8]
f |= g[0]&g[4]&g[8]
f |= g[2]&g[4]&g[6]
print('YNeos'[1^f::2])

Solution (Python):
dat = []
isok = []
for _ in range(3):
    l = list(map(int, input().split()))
    dat.append(l)
    isok.append([False] * 3)
n = int(input())
for _ in range(n):
    c = int(input())
    for i in range(3):
        for j in range(3):
            if dat[j][i] == c:
                isok[i][j] = True
if isok[0][0] and isok[0][1] and isok[0][2]:
    print("Yes")
elif isok[1][0] and isok[1][1] and isok[1][2]:
    print("Yes")
elif isok[2][0] and isok[2][1] and isok[2][2]:
    print("Yes")
elif isok[0][0] and isok[1][0] and isok[2][0]:
    print("Yes")
elif isok[0][1] and isok[1][1] and isok[2][1]:
    print("Yes")
elif isok[0][2] and isok[1][2] and isok[2][2]:
    print("Yes")
elif isok[0][0] and isok[1][1] and isok[2][2]:
    print("Yes")
elif isok[2][0] and isok[1][1] and isok[0][2]:
    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 b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A[i][j] = 0
                
for i in range(3):
    if A[i][0] == A[i][1] == A[i][2] == 0:
        print("Yes")
        exit()
for j in range(3):
    if A[0][j] == A[1][j] == A[2][j] == 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")

Solution (Python):
def main():
    a = [list(map(int, input().split())) for i in range(3)]
    n = int(input())
    for i in range(n):
        x = int(input())
        for j in range(3):
            for k in range(3):
                if a[j][k] == x:
                    a[j][k] = 0
    f = False
    for i in range(3):
        s = True
        for j in range(3):
            if a[i][j] != 0:
                s = False
        if s:
            f = True
    for i in range(3):
        s = True
        for j in range(3):
            if a[j][i] != 0:
                s = False
        if s:
            f = True
    if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
        f = True
    if a[2][0] == 0 and a[1][1] == 0 and a[0][2] == 0:
        f = True
    if f:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Solution (Python):


import sys
sys.setrecursionlimit(300000)

YES = "Yes"  
NO = "No"  

def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    tmp = [[False] * 3 for _ in range(3)]
    for i, vals in enumerate(A):
        for j, v in enumerate(vals):
            if v in b:
                tmp[i][j] = True
    for i in range(3):
        found = True
        for j in range(3):
            if not tmp[i][j]:
                found = False
        if found:
            print(YES)
            return
    for i in range(3):
        found = True
        for j in range(3):
            if not tmp[j][i]:
                found = False
        if found:
            print(YES)
            return
    if tmp[0][0] and tmp[1][1] and tmp[2][2]:
        print(YES)
        return
    if tmp[0][2] and tmp[1][1] and tmp[2][0]:
        print(YES)
        return
    print(NO)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [[int(next(tokens)) for _ in range(3)] for _ in range(3)]  
    N = int(next(tokens))  
    b = [int(next(tokens)) for _ in range(N)]  
    solve(A, N, b)

if __name__ == '__main__':
    main()

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

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

ANS=[[0]*3 for i in range(3)]

B=set(B)

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

SCORE=0
for i in range(3):
    if sum(ANS[i])==3:
        SCORE=1

for i in range(3):
    X=0
    for j in range(3):
        X+=ANS[j][i]
    if X==3:
        SCORE=1

if ANS[0][0]==1 and ANS[1][1]==1 and ANS[2][2]==1:
    SCORE=1

if ANS[0][2]==1 and ANS[1][1]==1 and ANS[2][0]==1:
    SCORE=1

if SCORE==1:
    print("Yes")
else:
    print("No")

Solution (Python):
A=[]
B=[False]*9
for i in range(3):
  A+=[int(i) for i in input().split()]
n=int(input())
for _ in range(n):
  b=int(input())
  for i in range(9):
    if b==A[i]:
      B[i]=True
C=[[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]]
Chk=False
for a,b,c in C:
  if B[a-1] and B[b-1] and B[c-1]:
    Chk=True
print("Yes" if Chk else "No")

Solution (Python):
import sys

def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
import bisect
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**21

def main():
    bingo = []
    punched = [[0 for i in range(3)] for j in range(3)]
    for i in range(3):
        bingo.append(getlist())

    n = getN()
    for ball in range(n):
        num = getN()
        for i, row in enumerate(bingo):
            for j, cell in enumerate(row):
                if num == cell:
                    punched[i][j] = 1

    for row in punched:
        if sum(row) == 3:
            print("Yes")
            return

    for i in range(3):
        if punched[0][i] and punched[1][i] and punched[2][i]:
            print("Yes")
            return

    if punched[0][0] and punched[1][1] and punched[2][2]:
        print("Yes")
        return

    if punched[0][2] and punched[1][1] and punched[2][0]:
        print("Yes")
        return

    print("No")
    return

if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Solution (Python):
a11, a12, a13 = map(int, input().split())
a21, a22, a23 = map(int, input().split())
a31, a32, a33 = map(int, input().split())
pairs = [
    [a11, a12, a13],
    [a21, a22, a23],
    [a31, a32, a33],
    [a11, a21, a31],
    [a12, a22, a32],
    [a13, a23, a33],
    [a11, a22, a33],
    [a13, a22, a31],
]
n = int(input())
bList = []
for i in range(n):
    bList.append(int(input()))
flag = False
for pair in pairs:
    if (pair[0] in bList) and (pair[1] in bList) and (pair[2] in bList):
        flag = True
        break
print('Yes' if flag else 'No')

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A=LLIN(3)
    M=I()
    B=[[0]*3 for _ in range(3)]
    for _ in range(M):
        b = I()
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    B[i][j] = 1
    for i in range(3):
        if B[i]==[1]*3:
            print("Yes")
            return
        if [B[0][i],B[1][i],B[2][i]] == [1]*3:
            print("Yes")
            return
    if [B[0][0],B[1][1],B[2][2]] == [1]*3:
        print("Yes")
        return
    if [B[0][2],B[1][1],B[2][0]] == [1]*3:
        print("Yes")
        return
    print("No")
if __name__ == '__main__':
    main()

Solution (Python):
A = [list(map(int, input().split())) for i in range(3)]
X = [[0] * 3 for i in range(3)]
N = int(input())
for i in range(N):
    b = int(input())
    for row in range(3):
        for col in range(3):
            if A[row][col] == b:
                X[row][col] = 1


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

for j in range(3):
    if X[0][j] + X[1][j] + X[2][j] == 3:
        print('Yes')
        exit()

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

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

print('No')

Solution (Python):
card = [[0 for i in range(3)] for j in range(3)]

for i in range(3):
    a,b,c = map(int,input().split())
    card[i][0] = a
    card[i][1] = b
    card[i][2] = c

op = [[False for i in range(3)] for j in range(3)]

n = int(input())

for l in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if card[i][j] == b:
                op[i][j] = True

flag = False

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

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


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

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

Solution (Python):
def main():
    a = [list(map(int, input().split())) for _ in range(3)]
    n = int(input())
    b = [int(input()) for _ in range(n)]
    for i in range(3):
        for j in range(3):
            if a[i][j] in b:
                a[i][j] = -1
    answer = 0
    for i in range(3):
        if a[i] == [-1, -1, -1]:
            answer += 1
    for i in range(3):
        if a[0][i] == a[1][i] == a[2][i] == -1:
            answer += 1
    if a[0][0] == a[1][1] == a[2][2] == -1:
        answer += 1
    if a[0][2] == a[1][1] == a[2][0] == -1:
        answer += 1
    print("Yes" if answer > 0 else "No")


if __name__ == '__main__':
    main()

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

ok = False
for i in range(3):
    if A[i][0] == A[i][1] and A[i][1] == A[i][2]:
        ok = True
    if A[0][i] == A[1][i] and A[1][i] == A[2][i]:
        ok = True
if A[0][0] == A[1][1] and A[1][1] == A[2][2]:
    ok = True
if A[2][0] == A[1][1] and A[1][1] == A[0][2]:
    ok = True
print('Yes' if ok else 'No')

Solution (Python):
def main():
    A = []
    for _ in range(3):
        A.append(list(map(int, input().split())))
    N = int(input())
    B = []
    for _ in range(N):
        B.append(int(input()))
    for b in B:
        for a in A:
            if b in a:
                a[a.index(b)] = 0
    for a in A:
        if a == [0, 0, 0]:
            return True
    for i in range(3):
        if A[0][i] == A[1][i] == A[2][i] == 0:
            return True
    return (A[0][0] == A[1][1] == A[2][2] == 0) or (A[0][2] == A[1][1] == A[2][0] == 0)

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