Harryxun/stf_run huggingface dataset:
N,M=map(int,input().split())
res = 0
#任意の数Kに対してたどり着く通り数
INF = 100000000000
stepList = [INF]*(N+1)
stepList[0] = 1
stepList[1] = 1
stepList[2] = 2
def stepF(K):
  if K == 0:
    return stepList[0]
  else:
    for i in range(1,K+1):
      if i == 1 or i == 2:
        pass
      else:
        if stepList[i]==INF:
          stepList[i]= stepList[i-2] + stepList[i-1]
    return stepList[K]
  
if M == 0:
  res = stepF(N)
  
else:
  List = []
  for i in range (M):
    List.append(int(input()))
  flag = True
  #任意の数aが壊れている場合
  
  for i in range(M):
    if i == 0:
      res = stepF(List[i]-1)
    else:
      if List[i] - List[i-1] == 1:
        flag = False
        break
      res = res * stepF(List[i]-List[i-1]-2)
  res = res * stepF(N-List[M-1]-1)

if flag:
  print(res%1000000007)
else:
  print(0)

### FIXED CODE ###

N,M=map(int,input().split())
res = 0
flag = True
#任意の数Kに対してたどり着く通り数
INF = 100000000000
stepList = [INF]*(N+1)
stepList[0] = 1
stepList[1] = 1
def stepF(K):
  if K == 0:
    return stepList[0]
  else:
    for i in range(1,K+1):
      if i == 1:
        pass
      else:
        if stepList[i]==INF:
          stepList[i]= stepList[i-2] + stepList[i-1]
    return stepList[K]
  
if M == 0:
  res = stepF(N)
  
else:
  List = []
  for i in range (M):
    List.append(int(input()))
  #任意の数aが壊れている場合
  
  for i in range(M):
    if i == 0:
      res = stepF(List[i]-1)
    else:
      if List[i] - List[i-1] == 1:
        flag = False
        break
      res = res * stepF(List[i]-List[i-1]-2)
  res = res * stepF(N-List[M-1]-1)
if flag:
  print(res%1000000007)
else:
  print(0)
s=input()
c=0
while n>0:
  n=s.count('01')
  s.replace('01','')
  c=c+n
  n=s.count('10')
  s.replace('10','')
  c=c+n
print(c)

### FIXED CODE ###

s=input()
print(2*min(s.count('0'),s.count('1')))
n,a,b,ax,bx=int(input()),list(map(int,input().split()))+[0],list(map(int,input().split()))+[0],0,0
for i in range(n):
	a[n]^=a[i]
	b[n]^=b[i]
na,nb=a,b
a,b=sorted(a),sorted(b)
if sum([a[i]!=b[i] for i in range(n+1)]):
	print("-1")
	exit()
f=dict()
def find(x):
	if f[x]==x:
		return x
	else:
		f[x]=find(f[x])
		return f[x]
ans=0
for i in range(n):
	if na[i]!=nb[i]:
		f[na[i]]=na[i]
f[na[n]]=na[n]
for i in range(n):
	if na[i]!=nb[i]:
		ans+=1
		f[find(nb[i])]=find(na[i])
for i,j in f:
	if i==j:
		ans+=1
print(ans-1)

### FIXED CODE ###

n,a,b=int(input()),list(map(int,input().split()))+[0],list(map(int,input().split()))+[0]
for i in range(n):
	a[n]^=a[i]
	b[n]^=b[i]
na,nb=sorted(a),sorted(b)
if na!=nb:
	print("-1")
	exit()
f=dict()
def find(x):
	if f[x]==x:
		return x
	else:
		f[x]=find(f[x])
		return f[x]
ans=0
for i in range(n):
	if a[i]!=b[i]:
		f[a[i]]=a[i]
f[a[n]]=a[n]
for i in range(n):
	if a[i]!=b[i]:
		ans+=1
		f[find(b[i])]=find(a[i])
for i in f:
	if i==f[i]:
		ans+=1
print(ans-1)
s = list(input())
def search(a, b, c, d):
  if a+b+c+d == 7:
    print(a '+' b '+'c '+' d '=' 7)
    
search(1, 2, 2, 2)

### FIXED CODE ###

s = list(input())
num = [0]*4
num[0] = int(s[0])
for i in range(1,4):
  num[i] = [0]*2
  num[i][0] = int(s[i])
  num[i][1] = -(int(s[i]))
  
patern = [0] * 8

p = ['+', '-']

count = 0
for i in range(2):
  for j in range(2):
    for k in range(2):
      temp = num[0] + num[1][i] + num[2][j] + num[3][k]
      patern[count] = [p[i], p[j], p[k]]
      if temp == 7:
        ans_count = count
      count += 1

print(s[0] + patern[ans_count][0] + s[1] + patern[ans_count][1] + s[2] + patern[ans_count][2] + s[3] + '=7')
s = input()
d = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRY', 'SAT']
print(7 - d.index(s))

### FIXED CODE ###

s = input()
d = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7 - d.index(s))
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():
    n=INT()
    ts=LIST()
    m=INT()
    xs=[0]*m
    for i in range(m):
        p,x=INTM()
        xs[i]=ts[p-1]-x
    tst=sum(ts)
    for i in range(m):
        #print(xs[i])
        print(tst-xs[i])
    #print(ts)
if __name__ == '__main__':
    do()

### FIXED CODE ###

#input
K,S = map(int,input().split()) 

#count
counter = 0
for x in range(0,K+1):
    for y in range(0,K+1):
        z = S - x - y
        if 0 <= z <= K:
            counter = counter + 1

#print
print(counter)
while True:
    x,y = map(int, input().split())
    if x == 0 and y == 0:
        continue
    elif x => y:
        print (y,x)
    else:
        print (x,y)

### FIXED CODE ###

while True:
    x,y = map(int, input().split())
    if x == 0 and y == 0 :
        break
    elif x <= y :
        print (x,y)
    else :
        print (y,x)
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,K=map(int,readline().split())
A=list(map(lambda x: int(x)-1,readline().split()))

visited=[True]*N
visitednum=[]
now=0
for i in range(K):
    if not visited[now]:
        break
    else:
        visited[now]=False
        visitednum.append(now)
        now=A[now]
d=visitednum.index(now)
ans=(K-d)%(len(visitednum)-d)+d
print(visitednum[ans]+1)

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))

num = 1
li = [1]
flag = [True] * n
flag[0] = False

for i in range(k):
    num = a[num-1]
    if flag[num-1]:
        li.append(num)
        flag[num-1] = False
    else:
        break

d = li.index(num)
ans = (k-d)%(len(li)-d)+d

print(li[ans])
import sys
from heapq import *

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))

countA = [0] * (N + 1)
countB = [0] * (N + 1)
for x in A:
    countA[x] += 1
for x in B:
    countB[x] += 1

q = []
only_A = []
only_B = []
for i in range(N + 1):
    if countA[i] and countB[i]:
        q.append((-countA[i] - countB[i], i))
        continue
    if countA[i]:
        only_A.append(i)
    elif countB[i]:
        only_B.append(i)
heapify(q)

if -q[0][0] > N:
    print('No')
    exit()
print('Yes')

ans = []
while q:
    _, x = heappop(q)
    if q:
        _, y = heappop(q)
        flag = True
    else:
        y = only_B.pop()
        flag = False
    countA[x] -= 1
    countB[y] -= 1
    ans.append((x, y))
    if countA[x]:
        heappush(q, (-countA[x] - countB[x], x))
    else:
        for _ in range(countB[x]):
            only_B.append(x)
    if countB[y]:
        heappush(q, (-countA[y] - countB[y], y))
    if flag and not countB[y]:
        for _ in range(countA[y]):
            only_A.append(y)
while only_A:
    x, y = only_A.pop(), only_B.pop()
    ans.append((x, y))

X, Y = zip(*ans)
print(*Y)

### FIXED CODE ###

import sys
from heapq import *

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))

countA = [0] * (N + 1)
countB = [0] * (N + 1)
for x in A:
    countA[x] += 1
for x in B:
    countB[x] += 1

q = []
only_A = []
only_B = []
for i in range(N + 1):
    if countA[i] and countB[i]:
        q.append((-countA[i] - countB[i], i))
        continue
    for _ in range(countA[i]):
        only_A.append(i)
    for _ in range(countB[i]):
        only_B.append(i)
heapify(q)

if q and -q[0][0] > N:
    print('No')
    exit()
print('Yes')

ans = []
while q:
    _, x = heappop(q)
    if q:
        _, y = heappop(q)
        flag = True
    else:
        y = only_B.pop()
        flag = False
    countA[x] -= 1
    countB[y] -= 1
    ans.append((x, y))
    if countA[x]:
        heappush(q, (-countA[x] - countB[x], x))
    else:
        for _ in range(countB[x]):
            only_B.append(x)
    if flag and countB[y]:
        heappush(q, (-countA[y] - countB[y], y))
    if flag and not countB[y]:
        for _ in range(countA[y]):
            only_A.append(y)
while only_A:
    x, y = only_A.pop(), only_B.pop()
    assert countA[x] > 0
    assert countB[y] > 0
    countA[x] -= 1
    countB[y] -= 1
    ans.append((x, y))

ans.sort()
X, Y = zip(*ans)
print(*Y)
import math

def main():
    N=int(input())
    ary = list(map(int,input().split()))
    ans = ary[0]
    for elem in ary:
        ans = math.gcd(ans,elem)
    print(ans)
    
if __name__=='__main__':
    main()

### FIXED CODE ###

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def main():
    N=int(input())
    ary = list(map(int,input().split()))
    ans = ary[0]
    for elem in ary:
        ans = gcd(ans,elem)
    print(ans)

if __name__=='__main__':
    main()
from sys
sys.setrecursionlimit(10**8)

N, M = map(int, input().split(" "))
AB = [list(map(int, input().split(" "))) for _ in range(M)]


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.per = list(range(n))
        self.point = n*(n-1) // 2
        self.counts = [1]*n

    def root(self, x):
        if self.per[x] == x:
            return x
        return self.root(self.per[x])

    def union(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return False
        self.per[rx] = ry
        self.point -= self.counts[ry] * self.counts[rx]
        self.counts[ry] += self.counts[rx]
        self.counts[rx] = 0

    def is_same(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        return rx == ry


u = UnionFind(N)
results = []
for a, b in AB[::-1]:
    results.append(u.point)
    x, y = a-1, b-1
    u.union(x, y)

# print(*results[::-1])
for r in results[::-1]:
    print(r)


### FIXED CODE ###

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]


class UnionFind:
    def __init__(self, n):
        self.par = [-1]*n
        self.size = [1]*n
        self.point = n*(n-1) // 2

    def root(self, x):
        if self.par[x] < 0:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return False
        if self.size[rx] < self.size[ry]:
            rx, ry = ry, rx
        self.point -= self.size[rx]*self.size[ry]
        self.size[rx] += self.size[ry]
        self.par[ry] = rx
        return True

    def is_same(self, x, y):
        rx, ry = self.root(x), self.root(y)
        return rx == ry

    def get_size(self, x):
        return self.size[self.root(x)]


uf = UnionFind(N)
results = []
for a, b in AB[::-1]:
    results.append(uf.point)
    x, y = a-1, b-1
    uf.unite(x, y)

print(*results[::-1], sep="\n")
N,M = map(int,input().split())
a=[]
for i in range(N):
  x = input().split()
  y = int(x[0])
  z = x[1:y]
  w = list(map(int(z)))
  w.append(a)
b = []
for l in range(1:M+1):
  for j in range(N-1):
    if l in a[j] and l in a[j+1]:
      l.append(b)
    else:
      b = b
cnt=0
k=1
for k in range(M+1):
  n = b.count(k)
  if n==M:
    cnt +=1
print(cnt)
    
  
    
    
       
    

### FIXED CODE ###

N,M = map(int,input().split())
a=[]
for i in range(N):
  x = input().split()
  z = x[1:]
  a += list(map(int,z))
cnt=0
for k in range(1,M+1):
  n = a.count(k)
  if n==N:
    cnt +=1
  else:
    cnt = cnt
print(cnt)
# -*- coding: utf-8 -*-
#ABC070C
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))

t=[]
for i in range(0,n):
	t.append(int(input()))
#print(t)

ans = t[0]
for i in range(1,n):
	ans = lcm(ans,t[i])

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
#ABC070C
import math

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

n = int(input())

t=[]
for i in range(0,n):
	t.append(0)
for i in range(0,n):
    t[i] = int(input())

ans = t[0]
for i in range(1,n):
	j = gcd(ans,t[i])
	ans *= t[i]
	ans = ans//j

print(ans)
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
L=list(map(int,input().split()))
A = L.count(1)
B = L.count(2)
C = L.count(3)
dp=[[[-1] * (301) for i in range(301)] for i in range(301)]

for a in range(n):
  for b in range(n):
    for c in range(n):
      result = n
      result += (dp[a-1][b][c] if a-1 >= 0 else 0)
      result += (dp[a+1][b-1][c] if b-1 >= 0 else 0)
      result += (dp[a][b+1][c-1] if c-1 >= 0 else 0)
      dp[a][b][c]=result / (a+b+c)

print(dp[A][B][C])



### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))

S = [0] * 3
for a in A:
  S[a-1] += 1
I, J, K = S

dp = [[[0.0] * (N+1) for j in range(N+1)] for i in range(N+1)]

for k in range(S[2] + 1):
  for j in range(S[1] + S[2] - k + 1):
    for i in range(S[0] + S[1] + S[2] - j - k + 1):
      if i == j == k == 0: continue
      dp[i][j][k] = (i * (dp[i-1][j][k] if i > 0 else 0) + j * (dp[i+1][j-1][k] if j > 0 else 0) + k * (dp[i][j+1][k-1] if k > 0 else 0) + N) / (i + j + k)

print(dp[I][J][K])
n,l = map(int,input().split())
li = []
for i in range(1,n+1):
  li.append(abs(l+i-1))
m = min(li)
if l+i-1 >= 0:
  print(int((n*(l-1)+(n*(n+1)/2)-l-i+1)))
else:
  print(int((n*(l-1)+(n*(n+1)/2)+l+i-1)))

### FIXED CODE ###

s = input()
for i in range(3):
  if s[i] == s[i+1]:
    print('Bad')
    exit()
    
print('Good')
def main():
    """
    N,M:10^6より N^2->NG
    矛盾する情報を見つける
    距離情報の保持

    1-2:1, 2-3:1, 1-3:2 <-OK
    1-2:1, 2-3:1, 1-3:5 <-NG(over)
    1-2:1, 2-3:1, 1-3:1 <-NG(less)
    1-2:1, 2-4:3, 1-3:3 <-OK(2-3:2, 3-4:1)
    1-2:1, 2-4:3, 1-3:5 <-NG

    (Li,Ri,Di)
    人Ri は人Li よりも距離 Di だけ右にいる
    すなわち、xRi − xLi = Di
    Ri > Li のとき(人7の右に人8がいる)処理上問題なし
    Ri < Li のとき(人8の右に人7がいる)場合、
    xLi - xRi = -Di
    """
    N, M = map(int, input().split())
    lrd = [
        tuple(map(int, input().split()))
        for _ in range(M)
    ]

    editorial(N, M, lrd)


def editorial(N, M, lrd):
    xs = [None] * N
    graph = [[] for _ in range(N)]
    for l, r, d in lrd:
        graph[l - 1].append((r - 1, d))
        graph[r - 1].append((l - 1, -d))

    def dfs(i):
        # 辺情報がなければ独立
        for j, d in graph[i]:
            if xs[j] is None:
                xs[j] = xs[i] + d
                f = dfs(j)
                if not f:
                    return False
            elif xs[j] - xs[i] != d:
                # 距離が誤情報
                return False

        return True

    for i, x in enumerate(xs):
        if x is None:
            # root以外は、dfsで木を探索するときに座標確定
            # １回で確定しないときは、独立した木が存在する
            # 他の木とは別で考えて良いので、初期座標は0固定で問題ない
            xs[i] = 0
            f = dfs(i)
            if not f:
                print("No")
                return

    print("Yes")

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    """
    N,M:10^6より N^2->NG
    矛盾する情報を見つける
    距離情報の保持

    1-2:1, 2-3:1, 1-3:2 <-OK
    1-2:1, 2-3:1, 1-3:5 <-NG(over)
    1-2:1, 2-3:1, 1-3:1 <-NG(less)
    1-2:1, 2-4:3, 1-3:3 <-OK(2-3:2, 3-4:1)
    1-2:1, 2-4:3, 1-3:5 <-NG

    (Li,Ri,Di)
    人Ri は人Li よりも距離 Di だけ右にいる
    すなわち、xRi − xLi = Di
    Ri > Li のとき(人7の右に人8がいる)処理上問題なし
    Ri < Li のとき(人8の右に人7がいる)場合、
    xLi - xRi = -Di
    """
    N, M = map(int, input().split())
    lrd = [
        tuple(map(int, input().split()))
        for _ in range(M)
    ]

    editorial(N, M, lrd)


def editorial(N, M, lrd):
    import sys
    sys.setrecursionlimit(10 ** 7)

    xs = [None] * N
    graph = [[] for _ in range(N)]
    for l, r, d in lrd:
        graph[l - 1].append((r - 1, d))
        graph[r - 1].append((l - 1, -d))

    def dfs(i):
        # 辺情報がなければ独立
        for j, d in graph[i]:
            if xs[j] is None:
                xs[j] = xs[i] + d
                f = dfs(j)
                if not f:
                    return False
            elif xs[j] - xs[i] != d:
                # 距離が誤情報
                return False

        return True

    for i, x in enumerate(xs):
        if x is None:
            # root以外は、dfsで木を探索するときに座標確定
            # １回で確定しないときは、独立した木が存在する
            # 他の木とは別で考えて良いので、初期座標は0固定で問題ない
            xs[i] = 0
            f = dfs(i)
            if not f:
                print("No")
                return

    print("Yes")

if __name__ == '__main__':
    main()
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


m = int(input)
print(24+(24-m)s)


### FIXED CODE ###

import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


m = int(input())
print(24+(24-m))
gcd = lambda x, y: x if (y==0) else gcd(y, x%y)
lcm = lambda x, y: int(x*y/gcd(x, y))

N = int(input())
A = list(map(int, input().split()))

gcd_all = 0
lcm_all = 1

for ai in A :
    gcd_all = gcd(gcd_all, ai)
    lcm_all = lcm(lcm_all, ai)

m = lcm_all - 1
print(sum(list(map(lambda ai: m%ai, A))))


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))

print(sum(list(map(lambda ai: ai-1, A))))
N = int(input())
words = []
l = []
for i in range(N):
    a = input()
    if i == 0:
        l.append(a)
        b = list(a)
        words.append(b[len(b)-1])
    elif i > 0:
        b = list(a)
        if i == N-1:
            words.append(b[0])
        else:
            words.append(b[0])
            words.append(b[len(b)-1])
        l.append(a)

if len(set(l)) != len(l):
    print("No")
    exit(1)

for h in range(0,len(words),2):
    if words[h] != words[h+1]:
        print("No")
        exit(1)
print("Yes")

    

    


### FIXED CODE ###

N = int(input())
words = []
l = []
for i in range(N):
    a = input()
    if i == 0:
        l.append(a)
        b = list(a)
        words.append(b[len(b)-1])
    elif i > 0:
        b = list(a)
        if i == N-1:
            words.append(b[0])
        else:
            words.append(b[0])
            words.append(b[len(b)-1])
        l.append(a)

if len(set(l)) != len(l):
    print("No")
    exit()

for h in range(0,len(words),2):
    if words[h] != words[h+1]:
        print("No")
        exit()
print("Yes")
from collections import deque

def cndP(l,n,p1,p2):
    d = set()
    length = len(l)
    for i in range(length-n+1):
        s = sum(l[i:i+n])
        if p2 == None:
            if p1 < s:
                d.add(s)
        else:
            if p1 < s < p2:
                d.add(s)
    return sorted(d)

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
#w = [int(x) for x in input().split()]
for i in range(n):
    e = int(input())
    w.append(e)
    
n=2
p = max(w)
p1 = p
p2 = None

if(pIsAccptbl(w,k,p)):
    print(p)
else:
    while(1):
        s = cndP(w,n,p1,p2)
        if s==[]:
            print(p2)
            break;
        for i in s:
            if(pIsAccptbl(w,k,i)):
                p2 = i
                break
            if(p2==None):
                p1 = i
        n+=1

### FIXED CODE ###

from collections import deque

def isPa(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp

n,k = [int(x) for x in input().split()]
w = deque()
for i in range(n):
    w.append(int(input()))
    
mean = int(sum(w)/k)
maxinp = MaxInP(w,k,mean)

if k == 1:
    print(mean)
else:
    minP = mean
    maxP = maxinp
    while(True):
        m = int ((minP + maxP)/2)
        if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
        if (minP+1 == maxP or minP == maxP):
            print(maxP)
            break
# -*- coding: utf-8 -*-
h, w = map(int, input().split())
a = []
a = [[True] * (w + 2)]
for i in range(h):
    a.extend([True] + [x == '#' for x in input()] + [True])
a.append([True] * (w + 2))
q = []


for i in range(1, w + 1):
    for j in range(1, h + 1):
        if a[i][j]:
            q.append((i, j))

count = 0
while True:
    qq = []
    for i, j in q:
        if not a[i-1][j]:
            a[i-1][j] = True
            qq.append((i - 1, j))
        if not a[i+1][j]:
            a[i+1][j] = True
            qq.append((i + 1, j))
        if not a[i][j-1]:
            a[i][j-1] = True
            qq.append((i, j - 1))
        if not a[i][j+1]:
            a[i][j+1] = True
            qq.append((i, j + 1))
    q = qq
    if len(q) <= 0:
        break
    count += 1

print(count)


### FIXED CODE ###

# -*- coding: utf-8 -*-
h, w = map(int, input().split())
a = []
a = [[True] * (w + 2)]
for i in range(h):
    a.append([True] + [x == '#' for x in input()] + [True])
a.append([True] * (w + 2))
q = []

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if a[i][j]:
            q.append((i, j))

count = 0
while True:
    qq = []
    for i, j in q:
        if not a[i-1][j]:
            a[i-1][j] = True
            qq.append((i - 1, j))
        if not a[i+1][j]:
            a[i+1][j] = True
            qq.append((i + 1, j))
        if not a[i][j-1]:
            a[i][j-1] = True
            qq.append((i, j - 1))
        if not a[i][j+1]:
            a[i][j+1] = True
            qq.append((i, j + 1))
    q = qq
    if len(q) <= 0:
        break
    count += 1

print(count)
A = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
B = [int(input()) for _ in range(n)]

F = [0]*100
for b in B:
  F[b]=1

ans = 'No'  
for i in range(3):
  c = 0
  d = 0
  for j in range(3):    
    c += F[A[i][j]]
    c += F[A[j][i]]
  if c==3 or d==3:
    ans ='Yes'
if F[A[0][0]]+F[A[1][1]]+F[A[2][2]] == 3 or F[A[0][2]]+F[A[1][1]]+F[A[2][0]] == 3:
  ans ='Yes'
  
print(ans)

### FIXED CODE ###

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

F = [0]*101
for b in B:
  F[b]=1

ans = 'No'  
for i in range(3):
  c = 0
  d = 0
  for j in range(3):    
    c += F[A[i][j]]
    d += F[A[j][i]]
  if c==3 or d==3:
    ans ='Yes'
if F[A[0][0]]+F[A[1][1]]+F[A[2][2]] == 3 or F[A[0][2]]+F[A[1][1]]+F[A[2][0]] == 3:
  ans ='Yes'
  
print(ans)