Harryxun/stf_run huggingface dataset:
H,W = map(int,input().split())
Ch,Cw = map(int,input().split())
Dh,Dw = map(int,input().split())
S = [input() for i in range(H)]

dist = [[10**9+7 for _ in range(W)] for _ in range(H)]
Ch = Ch-1
Cw = Cw-1
Dh = Dh-1
Dw = Dw-1

queue = []
queue.append([Ch,Cw])
queue2 = []
dist[Ch2][Cw2] = 0
    
while len(queue) > 0:
    while len(queue) > 0:
        x, y = queue.pop(0)
        d = dist[x][y]
        flag = 0
        for vx in range(-1,2):
            for vy in range(-1,2):
                if [vx,vy] in [[1,1],[1,-1],[-1,-1],[-1,1]]:
                    continue
                nx = x + vx
                ny = y + vy
                if 0 <= nx and nx < H and 0 <= ny and ny < W:
                    if S[nx][ny] == '.':
                        if dist[nx][ny] > d:
                            dist[nx][ny] = d
                            queue.append([nx,ny])
                    else:
                        flag += 1
        if flag:
            queue2.append([x,y])
            
    while len(queue2) > 0:
        x, y = queue2.pop(0)
        for vx in range(-2,3):
            for vy in range(-2,3):
                nx = x + vx
                ny = y + vy
                if 0 <= nx and nx < H and 0 <= ny and ny< W:
                    if S[nx][ny] == '.' and dist[nx][ny] == 10**9+7:
                        dist[nx][ny] = dist[x][y] + 1
                        queue.append([nx,ny])
                
print(dist[Dh][Dw])

### FIXED CODE ###

from collections import deque


H,W = map(int,input().split())
Ch,Cw = map(int,input().split())
Dh,Dw = map(int,input().split())
S = [input() for i in range(H)]

dist = [[10**9+7] * W for _ in range(H)]
Ch = Ch-1
Cw = Cw-1
Dh = Dh-1
Dw = Dw-1

queue = deque()
queue.append((Ch,Cw))
queue2 = deque()
dist[Ch][Cw] = 0

walk = [[0,1],[1,0],[0,-1],[-1,0]]
    
while len(queue) > 0:
    while len(queue) > 0:
        h, w = queue.popleft()
        d = dist[h][w]
        flag = 0
        for vh,vw in walk:
            nh = h + vh
            nw = w + vw
            if 0 <= nh and nh < H and 0 <= nw and nw < W:
                if S[nh][nw] == '.':
                    if dist[nh][nw] > d:
                        dist[nh][nw] = d
                        queue.append([nh,nw])
                else:
                        flag += 1
        if flag:
            queue2.append([h,w])
            
    while len(queue2) > 0:
        h, w = queue2.popleft()
        for vh in range(-2,3):
            for vw in range(-2,3):
                nh = h + vh
                nw = w + vw
                if 0 <= nh and nh < H and 0 <= nw and nw < W:
                    if S[nh][nw] == '.' and dist[nh][nw] == 10**9+7:
                        dist[nh][nw] = dist[h][w] + 1
                        queue.append([nh,nw])
                
if dist[Dh][Dw] != 10**9+7:
    print(dist[Dh][Dw])
else:
    print(-1)
A = int(input())
B = int(input())
p = 0
if A>8:
	p = 1
if B>8:
	p = 1
if p==0:
	print("Yay!")
else:
	print(":(")

### FIXED CODE ###

A,B = map(int,input().split())
p = 0
if A>8:
	p = 1
if B>8:
	p = 1
if p==0:
	print("Yay!")
else:
	print(":(")
a = x*x*x
return a

### FIXED CODE ###

x = input()
ans = x**3
print ans
N = input()
if N%2 == 0:
  ans = N/2
else:
  ans = N/2+1
  
print(ans)

### FIXED CODE ###

N = int(input())
if N%2 == 0:
  ans = int(N/2)
else:
  ans = int(N/2)+1
  
print(ans)
max = 0
i = 0
j = 0
k = 0
n_max = 19999

price = []
for k in range(n_max):
    price.attend(int(raw_input())
    
for i in range(n_max):
    for j in range(k, n_max):
        if max <= price[j] - price[i]:
            max = price[j] - price[i]
print max

### FIXED CODE ###

import sys

n = int(raw_input())

min_R = int(raw_input())
nums = map(int, sys.stdin.readlines())

ans = -10**9

for num in nums:
    if num - min_R > ans:
        ans = num - min_R
    if num < min_R:
        min_R = num
        
print ans
a, b, c, d = map(int, input().split())

if ads(a-c) <= d:
  print("Yes")
else:
  if a-b <= d and b-c <=d:
    print(Yes)
  else:
    print("No")

### FIXED CODE ###

a, b, c, d = map(int, input().split())
 
if abs(a-c) <= d:
  print("Yes")
else:
  if abs(a-b) <= d and abs(b-c) <=d:
    print("Yes")
  else:
    print("No")
# coding: utf-8
 
N  = int(input())
sum_pre = 0
sum = 1
 
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

for x in range(N):  
    for i in range (N):
        for j in range(N):
            for k in range(N):
                sum_pre += gcd([i, j, k])
     sum += sum_pre

print(sum)


### FIXED CODE ###

# coding: utf-8
 
N  = int(input())
sum = 0
 
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
for i in range (N):
    for j in range(N):
        for k in range(N):
            sum += gcd(*[i+1, j+1, k+1])
 
print(sum)
N, K = map(int,input().split())
H = list(map(int,input().split()))
H.sort()
result = 0
if len(H) <= K:
    print(result)
else:
    for i in range(1, K+1):
        H.remove(H[-i])
    for i in H:
        result += i
    print(result)

### FIXED CODE ###

N, K = map(int,input().split())
H = list(map(int,input().split()))
result = 0
if len(H) <= K:
    print(result)
else:
    H.sort()
    result = sum(H[0:N-K])
    print(result)
d=int(input())
a=[]
for x in range(d+1):
  b=list(map(int,input().split()))
  a.append(b)

for n in range(d):
  print(random.randint(1:27))

### FIXED CODE ###

d=int(input())
a=[]
for x in range(d+1):
  b=list(map(int,input().split()))
  a.append(b)

import random
for n in range(d):
  print(random.randint(1,26))
a, b, c = map(int,input().split())
if a+b=c or b+c=a or c+a=b:
  print(Yes)
else:
  print(No)

### FIXED CODE ###

a, b, c = map(int,input().split())
if a+b==c or b+c==a or c+a==b:
  print("Yes")
else:
  print("No")
A,B=map(int, input().split())
if A >= 13:
	print(B)
elif 6<=A<=12
	print(B//2)
else:
    print(0)
A,B=map(int, input().split())
if A >= 13:
	print(B)
elif 6<=A<=12:
	print(B//2)
else:
    print(0)

### FIXED CODE ###

A,B=map(int, input().split())
if A >= 13:
	print(B)
elif 6<=A<=12:
	print(B//2)
else:
    print(0)
o,e = [input() for i in range(2)]

print(*[o[i]+e[i] for i in range(len(o))], sep='')

### FIXED CODE ###


o = list(input())
e = list(input())+[""]

for x,y in zip(o,e):print(x+y,end='')
o = deque(input())
e = deque(input())

if len(o) > len(e):
    e.append('')
ans = ''

while len(o):
    ans += o.popleft()
    ans += e.popleft()
print(ans)

### FIXED CODE ###

from collections import deque

o = deque(input())
e = deque(input())

if len(o) > len(e):
    e.append('')
ans = ''

while len(o):
    ans += o.popleft()
    ans += e.popleft()
print(ans)
#9の倍数か判定する
x=0
N=int(input("整数を入力:"))
#Nを桁ごとに分解
while(1==1):
    Nn=str(N/10)
    a=Nn.split(".")
    x+=int(a[1])
    N=int(a[0])
    if N==0:
        break
if x%9==0:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

N=int(input())
if N%9==0:
  print('Yes')
else:
  print('No')
def dfs(i,f,ans):
  if i<3:
    return dfs(i+1,f+"+"+s[i+1],ans+int(s[i+1]),dfs(i+1,f+"-"+s[i+1],ans-int(s[i+1])
  elif ans==7:
    print(f+"=7")
a=input()
dfs(0,a[0],0)

### FIXED CODE ###

def dfs(i,f,ans):
  if i<3:
    dfs(i+1,f+"+"+s[i+1],ans+int(s[i+1]))
    dfs(i+1,f+"-"+s[i+1],ans-int(s[i+1]))
  elif ans==7:
    print(f+"=7")
    exit()
s=input()
dfs(0,s[0],int(s[0]))
N = int(input())
s = 0
for i in range(10):
  if s >= N:
    ans = s - N
    break
  else:
    s += 1000
print(ans)

### FIXED CODE ###

N = int(input())
s = 0
for i in range(11):
  if s >= N:
    ans = s - N
    break
  else:
    s += 1000
print(ans)
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
import numpy as np
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

h,w = MI()
a = [list(input()) for i in range(h)]
d = deque()
dx = [1,-1,0,0]
dy = [0,0,1,-1]
dist = [[-1]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            d.append([i,j])
            dist[i][j] = 0
while d:
    s = d.popleft()
    y= s[0]
    x= s[1]
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if nx < 0 or ny < 0 or nx >= w or ny >= h:
            continue
        else:
            if dist[ny][nx] == -1:
                dist[ny][nx] = dist[y][x] + 1
                d.append([nx,ny])
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans,dist[i][j])
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

h,w = MI()
a = [list(input()) for i in range(h)]
d = deque()
dx = [1,-1,0,0]
dy = [0,0,1,-1]
dist = [[-1]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            d.append([i,j])
            dist[i][j] = 0
while d:
    s = d.popleft()
    x= s[0]
    y= s[1]
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if nx < 0 or ny < 0 or nx >= h or ny >= w:
            continue
        else:
            if dist[nx][ny] == -1:
                dist[nx][ny] = dist[x][y] + 1
                d.append([nx,ny])
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans,dist[i][j])
print(ans)
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)
from collections import deque
import heapq
def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N = int(input())
    S = [int(a) for a in input().split()]
    S = sorted(S,key=lambda x:x)
    debug(S,'S')
    live = [S[-1]]
    S.pop()
    # iはステップ
    for i in range(N):
        # 各スライムに生んでもらう
        livenext = live.copy()
        for l in live:
            borned = False
            for j in range(len(S)-1, -1, -1):
                if l > S[j]:
                    # debug((l,S[j]),'parent, child')
                    livenext.append(S[j])
                    S.remove(S[j])
                    borned = True
                    break
            if not borned:
                print("No")
                exit()
        live = livenext
    if len(S) == 0:
        print("Yes")
    else:
        print("No")



if __name__ == "__main__":
    main()


### FIXED CODE ###

from sys import exit, stderr, stdin
input = stdin.readline
from collections import defaultdict
from sys import stderr
def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return
def main():
    N = int(input())
    S = [int(a) for a in input().split()]
    S = sorted(S)
    exist = [S.pop()]
    debug(S)
    debug(exist)
    for i in range(N):
        next_exist = []
        next_s = []
        for p in exist[::-1]:
            while S:
                x = S.pop()
                if x < p:
                    next_exist.append(x)
                    break
                else:
                    next_s.append(x)
        exist += next_exist
        exist.sort()
        S += next_s[::-1]

    if len(exist) == 2**N:
        print("Yes")
        exit()
    else:
        print("No")
        exit()

if __name__ == "__main__":
    main()
n = int(input())

import math
# 桁判定
keta_now = 0
res_num = []

MAP = {
    1:"a",
    2:"b",
    3:"c",
    4:"d",
    5:"e",
    6:"f",
    7:"g",
    8:"h",
    9:"i",
    10:"j",
    11:"k",
    12:"l",
    13:"m",
    14:"n",
    15:"o",
    16:"p",
    17:"q",
    18:"r",
    19:"s",
    20:"t",
    21:"u",
    22:"v",
    23:"w",
    24:"x",
    25:"y",
    26:"z",
}

while True:
    keta_now += 1
    # if n < (26**keta_now + 26**(keta_now-1)):
    if n < sum([26**k for k in range(keta_now+1)]):
        # 26より大きく702以下
        
        # 最大桁iのうち、i**1からi**26(a to z)でnより小さく最大のものを26_iとする
        # n - 26_i
        # (i-1)**1から(i-1)**26でn -26_iより小さく最大のもの
        # 繰り返してiが0の時に終了
        for i in range(keta_now, 0, -1):
            for al in range(26, 0, -1):
                if i == 1:
                    res_num.append(n)
                    break
                if n >= (26**(i-1) * al):
                    res_num.append(al)
                    n -= (26**(i-1) * al)
                    break
            
        break           
print("".join([MAP[n] for n in res_num]))
    

### FIXED CODE ###

"""
問題の解釈
長さがlであるような文字列の中で辞書順でk番目のものを求めよ

26進表記における位の値の求め方
1. 変数xをk-1で初期化し、xが0となるまで以下の操作を繰り返す
2. xを26で割った商がq、余りがrであるとする。この操作がi回目に実行された時のrがk-1の下からi番目の桁である。xをqで置き換える
"""
ALPHABET = "abcdefghijklmnopqrstuvwxyz"

n = int(input())

# 長さの判定
# 26 **11 > 10*15より
ll = 0
for l in range(1, 12):
    ll += 26**l
    if ll >= n:
        break

ans = []
for li in range(1, l+1):
    r = n % 26
    q = n // 26
    if r == 0:
        q -= 1
    ans.append(r)
    n = q

answer = ""
for s in ans[::-1]:
    answer += ALPHABET[s-1] 
print(answer)
from math import gcd
def lcm(x,y):
    return x*y//gcd(x,y)
n,m = map(int,input().split())
s=input()
t=input()
ss=''
tt=''

l=lcm(n,m)
x=['x']*l

for i in range(n):
    x[i*(l//n)]=s[i]

for i in range(m):
    x[i*(l//m)]=t[i]

for i in range(n):
    if x[i*(l//n)]!=s[i]:
        print(-1)
        exit()

for i in range(m):
    if x[i*(l//m)]!=t[i]:
        print(-1)
        exit()
print(l)


### FIXED CODE ###

from fractions import gcd
def lcm(x,y):
    return x*y//gcd(x,y)
n,m = map(int,input().split())
s=input()
t=input()

l=lcm(n,m)
x=dict()

for i in range(n):
    x[i*(l//n)]=s[i]

for i in range(m):
    j=i*(l//m)
    if j in x and x[j]!=t[i]:
        print(-1)
        exit()
print(l)
import math
N,K = map(int,input().split())
r = 0
for i in range(1,N+1):
    if i >= K:
        r += 1/N
    else:
        l = math.ceil(math.log2(K / i))
        r += ((1 / 2) ** l)/N
print(r)



### FIXED CODE ###

import math
N,K = map(int,input().split())
r = 0
for i in range(1,N+1):
    if i >= K:
        r += 1/N
    else:
        l = math.ceil(math.log2(K / i))
        r += ((1 / 2) ** l)/N
print(r)
A,B,H,M = map(int, input().split())

import math
print(math.pi)

degreeA = (H * 60 + M) / 2
degreeB = M * 6

if degreeA == degreeB:
    print(abs(A - B))
else: #degreeA > degreeB:
    degreeAB = abs(degreeA - degreeB)
    if degreeAB == 180:
        print(A + B)
    elif degreeAB > 180:
        degreeAB = 360 - degreeAB
    C = A ** 2 + B ** 2 - 2 * A * B * math.cos(degreeAB * math.pi / 180)
    print(math.sqrt(C))

### FIXED CODE ###

N = input()


if int(N[len(N)-1]) in [2 , 4 , 5 ,7 , 9]:
    print("hon")
elif int(N[len(N)-1]) in [0,1,6,8]:
    print("pon")
else:
    print("bon")
A,B = map(input(), int);

print(A*A-B)

### FIXED CODE ###

A = int(input())
B = int(input())


print(A*A-B)
a,b=map(int input().split())

print(a*b-(a+b-1))

### FIXED CODE ###

a,b=map(int,input().split())

m=a*b-a-b+1

print(int(m))
import sys
 
def main():
  a = sys.argv
  i1 = int(a[1])
  i2 = int(a[2])

  if i1 < 10 and i2 < 10:
    return i1 * i2
  else:
    return -1

main()

### FIXED CODE ###

a,b =map(int,input().split())
ai = int(a)
bi = int(b)
 
if ai < 10 and bi < 10:
  print(ai * bi)
else:
  print(-1)
A,B,C,K=map(int,input().strip().split())
K=K-A
if K>0:
  Sum=A
  K=K-B
  if K>0:
    if K>C:
      print(Sum-C)
   	else:
      print(Sum-K)
  else:
     print(Sum)
else:
      print(K)

### FIXED CODE ###

A,B,C,K=map(int,input().strip().split())
if K-A>0:
  K=K-A
  Sum=A
  K=K-B
  if K>0:
    if K>C:
      print(Sum-C)
    else:
      print(Sum-K)
    #if K>C:
  else:
    print(Sum)
else:
	print(K)
def main():
    s = input()
    t = input()
    sletters = set()
    for i in s:
        sletters.add(i)

    for i in t:
        if i not in sletters:
            print(-1)
            return

    s = s*len(t)
    i = 0
    j = 0
    while i < len(s) and j < len(t):
        if s[i] == t[j]:
            i += 1
            j += 1
        else:
            i += 1

    print(i)


main()


### FIXED CODE ###

import bisect

def main():
    s = input()
    t = input()
    sletters = [0]*26
    for i in range(len(s)):
        x = ord(s[i])-ord('a')
        if sletters[x] == 0:
            sletters[x] = [i]
        else:
            sletters[x].append(i)

    ans = 0
    curr_index = -1
    for i in t:
        x = ord(i)-ord('a')
        if sletters[x] == 0:
            print(-1)
            return
        index = bisect.bisect(sletters[x],curr_index)
        #print(sletters[x],i,curr_index,index)
        if index == len(sletters[x]):
            ans += len(s)-curr_index
            curr_index = sletters[x][0]
            ans += curr_index
        else:
            ans += sletters[x][index]-curr_index
            curr_index = sletters[x][index]
        

    print(ans)


main()
from collections import deque, defaultdict
# import sys
# sys.setrecursionlimit(1000000)
X, Y = map(int, input().split())

MOD = 1000000007

dp = defaultdict(int)
def search(r, c):
    if (r > X) or (c > Y):
        return 0

    # if dp[r][c] is not None:
    #     return dp[r][c]
    if (r, c) in dp:
        return dp[(r, c)]

    if (r == X) and (c == Y):
        return 1

    ret = search(r + 1, c + 2) + search(r + 2, c + 1)

    # dp[r][c] = ret
    dp[(r, c)] = ret
    return ret
  
print(search(0, 0) % MOD)

### FIXED CODE ###

import math
X, Y = map(int, input().split())

MOD = 1000000007


def combination(n, r):
    r = min(r, n - r)

    num = 1
    den = 1

    for i in range(1, r + 1):
        num = num * (n + 1 - i) % MOD
        den = den * i % MOD

    return num * pow(den, MOD - 2, MOD) % MOD


if (X + Y) % 3 != 0:
    print(0)
    exit()

m = (2 * Y - X) / 3
n = (2 * X - Y) / 3
m = int(m)
n = int(n)

if m < 0 or n < 0:
    print(0)
    exit()

print(int(combination(m + n, n)) % MOD)
import sys
input = sys.stdin.readline
n,q = map(int, input().split())
# print(n,q)
tree = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int, input().split())
    tree[a-1].append(b)
    tree[b-1].append(a)
px = [ list(map(int,input().split())) for _ in range(q) ]

print(tree)
print(px)

c = [0]*n

for i in range(len(px)):
    c[px[i][0]-1] += px[i][1]

print(c)

# for i in range(1,n):
#     c[i] += c[min(tree[i])-1]

visited = [False]*n
visited[0] = True
# print(visited)
check = visited.count(False)
# print(check)
while check!=0:
    for i in range(1,n):
        # mi = min(tree[i])-1
        for j in range(len(tree[i])):
            node_tmp = tree[i][j]
            if visited[node_tmp-1]:
                c[i] += c[node_tmp-1]
                visited[i] = True
                # print("OK")
            else:
                # print("NG")
    check = visited.count(False)

print(" ".join(map(str,c)))

### FIXED CODE ###

import sys
input = sys.stdin.readline
n,q = map(int, input().split())
tree = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int, input().split())
    tree[a-1].append(b)
    tree[b-1].append(a)
# px = [ list(map(int,input().split())) for _ in range(q) ]
c = [0]*n
# for i in range(len(px)):
for _ in range(q):
    p,x = map(int,input().split())
    c[p-1] += x  
visited = [0]*n
cnd = [1]   # current_node
while len(cnd)>0:
    nnd = []
    for j in cnd:
        visited[j-1]=1
        ko = tree[j-1]
        for k in ko:
            if visited[k-1]==0:
                c[k-1] += c[j-1]
                nnd.append(k)
    cnd = nnd
print(" ".join(map(str,c)))
import math
r=int(input())
area = r**2*math.pi
circle = 2*r*math.pi
print(area, circle)

### FIXED CODE ###

import math
r = float(input())
print(r**2*math.pi, 2*r*math.pi)
import math

N = int(input())

ans = 10**13


for i in range(1,10**6+1:
    if N % i == 0:
        j = N / i
        ans = min(ans,j + i - 2)
        
print(int(ans))

### FIXED CODE ###

import math

N = int(input())

ans = 10**13


for i in range(1,10**6+1):
    if N % i == 0:
        j = N / i
        ans = min(ans,j + i - 2)
        
print(int(ans))
a, b = int(input()),int(input())
 
ans = a * b
 
if ans % 2 == 1:
  print("Odd")
else:
  print("Even")

### FIXED CODE ###

a, b = map(int,input().split())
 
ans = a * b
 
if ans % 2 == 1:
  print("Odd")
else:
  print("Even")
#!/usr/bin/python3

def find(id, V, d, dist):
    i = id - 1
    dist[i] = d
    for v in V[i]:
        find(v, V, d + 1, dist)
    
n = int(input())
# [isFind, d, f]
A = [[False, 0, 0] for i in range(n)]
U = []
V = []
dist = [-1] * n
for i in range(n):
    l = list(map(int, input().split()))
    U.append(l[0])
    V.append(l[2:])

find(1, V, 0, dist)

for u in U:
    print(u, dist[u - 1])

### FIXED CODE ###

#!/usr/bin/python3

def find(id, V, d, dist):
    i = id - 1
    dist[i] = d
    for v in V[i]:
        if dist[v - 1] == -1 or dist[v - 1] > d + 1:
            find(v, V, d + 1, dist)
    
n = int(input())
# [isFind, d, f]
A = [[False, 0, 0] for i in range(n)]
U = []
V = []
dist = [-1] * n
for i in range(n):
    l = list(map(int, input().split()))
    U.append(l[0])
    V.append(l[2:])

find(1, V, 0, dist)

for u in U:
    print(u, dist[u - 1])
N = int(input())
H = list(map(int, input().split()))

if H[0]-H[1] <= -1:
    H[1] -= 1
elif H[0]-H[1] == 0:
    H[0] -= 1
    H[1] -= 1
elif H[0]-H[1] == 1:
    H[0] -= 1
else:
    print("No")

for i in range(1, N):
    if i == N-1:
        print("Yes")
        break
    elif H[i]-H[i+1] <= -1:
        H[i+1] -= 1
        continue
    elif H[i]-H[i+1] == 0:
        continue
    else:
        print("No")
        break


### FIXED CODE ###

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

if N == 1:
    print("Yes")

if N == 2:
    if H[0]-H[1] <= -1:
        print("Yes")
    else:
        print("No")

if N >= 3:
    for i in range(1, N):
        if H[0]-H[1] <= -1:
            H[1] -= 1
        elif H[0]-H[1] == 0:
            H[0] -= 1
            H[1] -= 1
        elif H[0]-H[1] == 1:
            H[0] -= 1

        if i == N-1:
            print("Yes")
            break
        elif H[i]-H[i+1] <= -1:
            H[i+1] -= 1
            continue
        elif H[i]-H[i+1] == 0:
            continue
        else:
            print("No")
            break
import math
def fact(n):
    ans = 1
    for i in range(2, n+1):
        ans*= i
    return ans
def comb(n, c):
    return fact(n)//(fact(n-c)*c)
n,m,q = map(int, input().split())
lis = [1 for i in range(n)]
ords = []
cost = []
dp = [-1 for i in range(200)]
ans = 0
for i in range(q):
    o = list(map(int, input().split()))
    ords.append(o[:n])
    cost.append(o[-1])
def checker(p, arr, ans):
    if(dp[p] == ans):
        return dp[p]
    for i in range(n-p-1, -1, -1):
        for c in range(1, m+1):
            arr[p] = c
            temp = 0
            ans = checker(p+1, arr, ans)
            for i in range(q):
                if(arr[ords[i][1]-1]-arr[ords[i][0]-1]==ords[i][2]):
                    temp+=cost[i]
            if(temp > ans):
                ans = temp
            dp[p] = ans
    return ans
print(checker(0, lis, 0))


### FIXED CODE ###

N,M,Q=map(int,input().split())
L = []
for i in range(Q):
  L.append(list(map(int, input().split())))
  L[i][0]-=1
  L[i][1]-=1
 
import itertools
l =list(range(1,M+1))
v=list(itertools.combinations_with_replacement(l,N))
ans=0
for arr in v:
  score=0
  for a,b,c,d in L:
    if (arr[b] - arr[a])==c:      
      score+=d
  ans=max(ans,score)
print(ans)
N = input();
M = input();

if N == M:
  print('Yes')
else:
  print('No')
  

### FIXED CODE ###

N,M = (int(x) for x in input().split())

if N == M:
  print("Yes")
else:
  print('No')