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: Wrong Answer

Solution code:
A = []
import sys
for i in range(3):
  A += [[int(c) for c in input().split()]]
N = int(input())
dic = [0]*101
for i in range(N):
  b = int(input())
  dic[b] = 1
for j in range(3):
  for i in range(3):
    if dic[A[j][i]]==0:
      break
  else:
    print('Yes')
    sys.exit()
for i in range(3):
  for j in range(3):
    if dic[A[j][i]]==0:
      break
  else:
    print('Yes')
    sys.exit()
for i in range(3):
  if dic[A[i][i]]==0:
    break
else:
  print('Yes')
  sys.exit()
for i in range(3):
  if dic[A[2-i][i]]==1:
    print('Yes')
    sys.exit()
print('No')

Submission status: Wrong Answer

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

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

flag = False
for i in range(3):
    for j in range(3):
        if B[i][j] == False:
            break
        if j == 2:
            flag = True


for j in range(3):
    for i in range(3):
        if B[i][j] == False:
            break
        if j == 2:
            flag = True

for i in range(3):
    if B[i][i] == False:
        break
    if i == 2:
        flag = True
for i in range(3):
    if B[2 - i][i] == False:
        break
    if i == 2:
        flag = True

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

Submission status: Wrong Answer

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

ans = 0
for i in range(3):
    if sum(A[i]) == 3:
        ans = 1

for i in range(3):
    s = 0
    for j in range(3):
        s += A[j][i]
    if s == 3:
        ans = 1

s = 0
for i in range(3):
    s += A[i][i]
if s == 3:
    ans = 1

for i in range(3):
    s += A[i][2 - i]
if s == 3:
    ans = 1

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

Submission status: Wrong Answer

Solution code:
A = [list(map(int,input().split())) for i in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]
for i in range(N):
    for h in range(3):
        for w in range(3):
            if b[i] == A[h][w]:
                A[h][w] = 0
if [0,0,0] in A:
    print('Yes')
else:
    ans = 'No'
    for i in zip(*A):
        if i == [0,0,0]:
            ans = 'Yes'
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline

lst1 = [list(map(int,readline().split())) for i in range(3)]

n = int(readline())

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

for i in range(n):
    b = int(readline())
    for i in range(3):
        for j in range(3):
            if lst1[i][j] == b:
                lstans[i][j] = 1
flag = 0
for i in range(3):
    if sum(lstans[i]) == 3:
        flag = 1
for i in range(3):
    res = 0
    for j in range(3):
        res += lstans[i][j]
    if res == 3:
        flag = 1

if lstans[0][0] + lstans[1][1] + lstans[2][2] == 3:
    flag = 1
if lstans[0][2] + lstans[1][1] + lstans[2][0] == 3:
    flag = 1

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

Submission status: Wrong Answer

Solution code:
A = [[0 for _ in range(3)] for _ in range(3)]

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

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


flag = [[False for _ in range(3)] for _ in range(3)]

f = False
for b in B:
    for row in range(3):
        for col in range(3):
            if A[row][col] == b:
                flag[row][col] = True
                f = True
if not f:
    print("No")
    exit(0)

# check (--)
for row in range(3):
    f = True
    for col in range(3):
        if not A[row][col]:
            f = False
            break
    if f:
        print("Yes")
        exit(0)

# check (|)
for row in range(3):
    f = True
    for col in range(3):
        if not A[col][row]:
            f = False
            break
    if f:
        print("Yes")
        exit(0)

# check (diag)
if A[0][0] and A[1][1] and A[2][2]:
    print("Yes")
elif A[0][2] and A[1][1] and A[2][0]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
A = [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] = -1

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

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

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

print("No")

Submission status: Wrong Answer

Solution code:
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
naname = False
if bingo[0][0] == bingo[1][1] == bingo[2][2] == None or bingo[0][2] == bingo[1][1] == bingo[0][2] == None:
    naname = True
if row or column or naname:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

for i in range(3):
    if l[i][0] in b and l[i][0] in b and l[i][0] in b :
        print("Yes")
        exit()
for j in range(3):
    if l[0][j] in b and l[0][j] in b and l[0][j] in b :
        print("Yes")
        exit()

if l[0][0] in b and l[1][1] in b and l[2][2] in b :
    print("Yes")
    exit()
if l[2][0] in b and l[1][1] in b and l[0][2] in b :
    print("Yes")
    exit()

print("No")

Submission status: Wrong Answer

Solution code:
def main():
    A = [list(map(int,input().split())) for _ in range(3)]
    N = int(input())
    b = [int(input()) for _ in range(N)]
    bng = [[False]*3 for _ in range(3)]
    ans = "No"
    for i in range(N):
        for j in range(3):
            for k in range(3):
                if b[i] == A[j][k]:
                    bng[j][k] = True
    if (bng[0] == [True]*3 or
        bng[1] == [True]*3 or
        bng[0] == [True]*3 or
        bng[0][0] == bng[1][0] == bng[2][0] == True or
        bng[0][1] == bng[1][1] == bng[2][1] == True or
        bng[0][2] == bng[1][2] == bng[2][2] == True or
        bng[0][0] == bng[1][1] == bng[2][2] == True):
        ans = "Yes"
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a = [[int(i) for i in input().split()] for _ in range(3)]
c=[[False]*3 for _ in range(3)]
n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                c[i][j] = True

ok = False
for i in range(3):
    d = True
    for j in range(3):
        if c[i][j] == False:
            d = False
    if d:
        ok = True

ok = False
for i in range(3):
    d = True
    for j in range(3):
        if c[j][i] == False:
            d = False
    if d:
        ok = True
d = True
for j in range(3):
    if c[j][j] == False:
        d = False
if d:
    ok = True

d = True
for j in range(3):
    if c[j][2-j] == False:
        d = False
if d:
    ok = True
print("Yes"if ok else"No")

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    a = inpll(3)
    n = inp()
    b = inplm(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):
        flag = True
        for j in range(3):
            if a[i][j] != 0:
                flag = False
        if flag:
            print('Yes')
            return
    for i in range(3):
        flag = True
        for j in range(3):
            if a[j][i] != 0:
                flag = False
        if flag:
            print('Yes')
            return
    for i in range(3):
        flag = True
        if a[i][i] != 0:
            flag = False
        if flag:
            print('Yes')
            return
    for i in range(3):
        flag = True
        if a[i][2-i] != 0:
            flag = False
        if flag:
            print('Yes')
            return
    print('No')
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a = [LI() for _ in range(3)]
n = I()
b = [I() for _ in range(n)]
for i in range(3):
    for j in range(3):
        if a[i][j] not in b:
            break
    else:
        print('Yes')
        quit()

for i in range(3):
    for j in range(3):
        if a[j][i] not in b:
            break
    else:
        print('Yes')
        quit()

for i in range(3):
    if a[i][i] not in b:
        break
else:
    print('Yes')
    quit()

for i in range(3)[::-1]:
    if a[i][i] not in b:
        break
else:
    print('Yes')
    quit()
print('No')

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    A1 = [int(x) for x in input().split()]
    A2 = [int(x) for x in input().split()]
    A3 = [int(x) for x in input().split()]
    N = int(input())
    A = set([int(input()) for _ in range(N)])
    f = False
    if A1[0] in A and A1[1] in A and A1[2]:
        print("Yes")
        return
    if A2[0] in A and A2[1] in A and A2[2]:
        print("Yes")
        return
    if A3[0] in A and A3[1] in A and A3[2]:
        print("Yes")
        return
    if A1[0] in A and A2[0] in A and A3[0]:
        print("Yes")
        return
    if A1[1] in A and A2[1] in A and A3[1]:
        print("Yes")
        return
    if A1[2] in A and A2[2] in A and A3[2]:
        print("Yes")
        return
    if A1[0] in A and A2[1] in A and A3[2]:
        print("Yes")
        return
    if A2[2] in A and A2[1] in A and A3[0]:
        print("Yes")
        return
    print("No")

    
    
    



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

A = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(3)]
N = int(sys.stdin.buffer.readline())
B = [int(sys.stdin.buffer.readline()) for _ in range(N)]

A = np.array(A, dtype=int)
board = np.zeros((3, 3), dtype=bool)
for b in B:
    board[A == b] = True

ok = False
for i in range(3):
    ok |=np.all(board[i])
    ok |=np.all(board[:, i])
a = True
for i in range(3):
    a &= board[i][i]
ok |= a
if ok:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
def check(a,b):
    if a==b:
        a=-1

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

i = 0
j = 0
while i<N:
    b = int(input())
    while j<3:
        check(A1[j],b)
    while j<3:
        check(A2[j],b)
    while j<3:
        check(A3[j],b)

if A1[0]==A1[1]==A1[2] or A2[0]==A2[1]==A2[2] or A3[0]==A3[1]==A3[2] or A1[0]==A2[0]==A3[0] or A1[1]==A2[1]==A3[1] or A1[2]==A2[2]==A3[2] or A1[0]==A2[1]==A3[2] or A1[2]==A2[1]==A3[0]:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
def check(a,b):
    if a==b:
        a=-1

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

i = 0
j = 0
while i<N:
    while j<3:
        check(A1[j],B[i])
while i<N:
    while j<3:
        check(A2[j],B[i])
while i<N:
    while j<3:
        check(A3[j],B[i])

if A1[0]==A1[1]==A1[2] or A2[0]==A2[1]==A2[2] or A3[0]==A3[1]==A3[2] or A1[0]==A2[0]==A3[0] or A1[1]==A2[1]==A3[1] or A1[2]==A2[2]==A3[2] or A1[0]==A2[1]==A3[2] or A1[2]==A2[1]==A3[0]:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
bingo = []

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

flat = [flatten for inner in bingo for flatten in inner]

n = int(input())

nums = []

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

for i in nums:
    if i in flat:
        flat[flat.index(i)] = 0

bingo = [flat[:3], flat[3:6], flat[6:]]
bingo_z = [x for x in zip(*bingo)]

count = 0
while count == 0:
    for i in range(3):
        if sum(bingo[i]) == 0:
            count += 1
            break

    for i in range(3):
        if sum(bingo_z[i]) == 0:
            count += 1
            break

    if (bingo[0][0] + bingo[1][1] + bingo[2][2] == 0) or (bingo[2][0] + bingo[1][1] + bingo[0][2] == 0):
        count += 1
        break

print("No" if count == 0 else "Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
A=[[0]*3 for i 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:
        A[j][k]=10**10
for i in range(3):
  if sum(A[i])==3*10**10:
    print("Yes")
    sys.exit()
a=0
for i in range(3):
  a=a+A[i][0]
if a==3**10**10:
  print("Yes")
  sys.exit()
a=0
for i in range(3):
  a=a+A[i][1]
if a==3*10**10:
  print("Yes")
  sys.exit()
a=0
for i in range(3):
  a=a+A[i][2]
if a==3*10**10:
  print("Yes")
  sys.exit()
if A[0][0]+A[1][1]+A[2][2]==3*10**10 or A[0][2]+A[1][1]+A[2][0]==3*10**10:
  print("Yes")
  sys.exit()
print("No")

Submission status: Accepted

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

for i in range(N):
  for j in range(3):
    for k in range(3):
      if B[i] == A[j][k]:
        sheet[j][k] = 1
if sheet[0][0] == 1 and sheet[0][1] == 1 and sheet[0][2] == 1:
  print('Yes')
elif sheet[1][0] == 1 and sheet[1][1] == 1 and sheet[1][2] == 1:
  print('Yes')
elif sheet[2][0] == 1 and sheet[2][1] == 1 and sheet[2][2] == 1:
  print('Yes')
elif sheet[0][0] == 1 and sheet[1][0] == 1 and sheet[2][0] == 1:
  print('Yes')
elif sheet[0][1] == 1 and sheet[1][1] == 1 and sheet[2][1] == 1:
  print('Yes')
elif sheet[0][2] == 1 and sheet[1][2] == 1 and sheet[2][2] == 1:
  print('Yes')
elif sheet[0][0] == 1 and sheet[1][1] == 1 and sheet[2][2] == 1:
  print('Yes')
elif sheet[2][0] == 1 and sheet[1][1] == 1 and sheet[0][2] == 1:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
def Judge(a):
  col=[]
  diag1=0
  diag2=0

  for i in range(3):
    if(a[i].count(0)==3):
      return 1
      break
    if(a[i][0]==0):
      col.append(0)
    if(a[i][1]==0):
      col.append(1)
    if(a[i][2]==0):
      col.append(2)
    if(a[i][i]==0):
      diag1+=1
    if(a[i][-(i+1)]==0):
      diag2+=1
  if(diag1==3 or diag2==3):
    return 1
  if(col.count(0)==3 or col.count(1)==3 or col.count(2)==3):
    return 1
  return 0


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(b==a[j][k]):
        a[j][k]=0
judge=Judge(a)
if(judge==1):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
c = [[0]*3 for _ in range(3)]
for x in b:
  for i in range(3):
    for j in range(3):
      if A[i][j] == x:
        c[i][j] = 1

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    for j in range(3):
        for k in range(3):
            if b[i] == A[j][k]:
                A[j][k] = 0
ans = 'No'
for i in range(3):
    if all(c == 0 for c in [A[i][0], A[i][1], A[i][2]]):
        ans = 'Yes'
for i in range(3):
    if all(c == 0 for c in [A[0][i], A[1][i], A[2][i]]):
        ans = 'Yes'
if all(c == 0 for c in [A[0][0], A[1][1], A[2][2]]):
    ans = 'Yes'
if all(c == 0 for c in [A[0][2], A[1][1], A[2][0]]):
    ans = 'Yes'
print(ans)

Submission status: Accepted

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

n = int(input())

for _ in range(n):
  x = int(input())
  for d in lst:
    if d[0] == x:
      d[0] = -1
    elif d[1] == x:
      d[1] = -1
    elif d[2] == x:
      d[2] = -1

for d in lst:
  if d[0] == d[1] == d[2] == -1:
    print('Yes')
    exit()
for i in range(3):
  if lst[0][i] == lst[1][i] == lst[2][i] == -1:
    print('Yes')
    exit()
for i in range(3):
  if lst[i][0] == lst[i][1] == lst[i][2] == -1:
    print('Yes')
    exit()
if lst[0][0] == lst[1][1] == lst[2][2] == -1:
  print('Yes')
  exit()
if lst[0][2] == lst[1][1] == lst[2][0] == -1:
  print('Yes')
  exit()
print('No')

Submission status: Accepted

Solution code:
def main():
    a = [list(map(int, input().split())) for _ in range(3)]
    n = int(input())
    b = [int(input()) for _ in range(n)]
    if a[0][0] in b and a[0][1] in b and a[0][2] in b or \
        a[1][0] in b and a[1][1] in b and a[1][2] in b or \
            a[2][0] in b and a[2][1] in b and a[2][2] in b or \
                a[0][0] in b and a[1][0] in b and a[2][0] in b or \
                    a[0][1] in b and a[1][1] in b and a[2][1] in b or \
                        a[0][2] in b and a[1][2] in b and a[2][2] in b or \
                            a[0][0] in b and a[1][1] in b and a[2][2] in b or \
                                a[0][2] in b and a[1][1] in b and a[2][0] in b:
                                    print('Yes')
    else:
        print('No')
        
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
A = [[]]*3
for row in range(3):
    A[row] = list(map(int, input().split()))
n = int(input())
B = [0]*n
for i in range(n):
    B[i] = int(input())
flag = False


def check_bingo(A, B):
    for row in range(3):
        if A[row][0] and A[row][1] and A[row][2]:
            return True

    for col in range(3):
        if A[0][col] and A[1][col] and A[2][col]:
            return True

    if A[0][0] and A[1][1] and A[2][2]:
        return True
    if A[0][2] and A[1][1] and A[2][0]:
        return True
    return False


for row in range(3):
    for col in range(3):
        if A[row][col] in B:
            A[row][col] = True
        else:
            A[row][col] = False

print("Yes" if check_bingo(A, B) else "No")

Submission status: Accepted

Solution code:
a = list(list(map(int,input().split())) for _ in range(3))
n = int(input())
b = list(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 a[i][0] == a[i][1] == a[i][2] or a[0][i] == a[1][i] == a[2][i] or a[0][0] == a[1][1] == a[2][2] or a[2][0] == a[1][1] == a[0][2]:
        print("Yes")
        break
else:
     print("No")

Submission status: Accepted

Solution code:
table=[[0]*3 for _ in range(3)]
A=[list(map(int,input().split())) for _ in range(3)]
A=sum(A,[])
N=int(input())
B=[int(input()) for _ in range(N)]

for b in B:
    tmp=[i for i,x in enumerate(A) if x==b]
    for t in tmp:
        table[t//3][t%3]=1

flag=False
n1,n2=0,0
for i in range(3):
    if sum(table[i])==3: flag=True
    if sum([table[j][i] for j in range(3)])==3: flag=True
    n1+=table[i][i]
    n2+=table[i][2-i]
if n1==3 or n2==3: flag=True
if flag: print('Yes')
else: print('No')

Submission status: Accepted

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

Submission status: Accepted

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

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

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

state = False
for i in range(3):
    num = 0
    for j in range(3):
        num += ans[i][j]
    
    if num == 3:
        state = True

for i in range(3):
    num = 0
    for j in range(3):
        num += ans[j][i]
    
    if num == 3:
        state = True

if ans[0][0] + ans[1][1] + ans[2][2] == 3:
    state = True

if ans[0][2] + ans[1][1] + ans[2][0] == 3:
    state = True

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

Submission status: Accepted

Solution code:
def main():
    A_checked = [ [False] * 3 for i in range(3) ]
    A_map = {}

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

    N = int(input())
    for i in range(N):
        b = int(input())
        if b in A_map:
            v = A_map[b]
            A_checked[v[0]][v[1]] = True

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

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

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

    print("No")

main()

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

a = LIR(3)
n = I()
b = IR(n)


def check(A, B):
   S = set(b)
 
   # check each row
   for r in range(3):
      cnt = 0
      for c in range(3):
         if A[r][c] in S:
            cnt += 1
      if cnt == 3:
         return True
 
   # check each colum
   for c in range(3):
      cnt = 0
      for r in range(3):
         if A[r][c] in S:
            cnt += 1
      if cnt == 3:
         return True
 
   # check back diagonal
   cnt = 0
   for i in range(3):
      if A[i][i] in S:
         cnt += 1
   if cnt == 3:
      return True
 
   # check forward diagonal
   cnt = 0
   for i in range(3):
      if A[i][2-i] in S:
         cnt += 1
   if cnt == 3:
      return True
 
   return False
 
 
print('Yes' if check(a, b) else 'No')

Submission status: Accepted

Solution code:
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())

ar=[]
for i in range(3):
    ar.append(lis())
mark=[[0]*3 for _ in range(3)]
n=int(input())
for _ in range(n):
    k=int(input())
    for i in range(3):
        for j  in range(3):
            if ar[i][j]==k:
                mark[i][j]=1

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

Submission status: Accepted

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

for i in range(3) :
    if l[i][0] + l[i][1] + l[i][2] == 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')

Submission status: Accepted

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

for i in range (3):
  if a[i] == a[i+3] and a[i+3]==a[i+6]:
    print('Yes')
    exit()
for i in range(3):
  if a[3*i]==a[3*i+1] and a[3*i]==a[3*i+2]:
    print('Yes')
    exit() 
if a[0]==a[4] and a[0]==a[8]:
  print('Yes')
  exit()

if a[2]==a[4] and a[2]==a[6]:
  print('Yes')
  exit()
print('No')