Harryxun/stf_run huggingface dataset:
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

S = input()

count = 0
if len(S)%2==0:
	a = int(len(S)/2-1)
	for i in range(a+1):
		if S[a+1+i] != S[a-i]:
			count += 1
else:
	a = int(len(S)//2)
	for i in range(a+1):
		if S[a+1+i] != S[a-1-i]:
			count += 1

print(count)

### FIXED CODE ###

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

S = input()

count = 0
if len(S)%2==0:
	a = int(len(S)/2-1)
	for i in range(a+1):
		if S[a+1+i] != S[a-i]:
			count += 1
else:
	a = int(len(S)//2)
	for i in range(a):
		if S[a+1+i] != S[a-1-i]:
			count += 1

print(count)
n,k = map(int,input().split())
h = list(map(int,input().split()))
h.sort()
for i in range(k):
    h[n-i-1] = 0
print(sum(h))

### FIXED CODE ###

n,k = map(int,input().split())
h = list(map(int,input().split()))
h.sort()
if n <= k:
    print(0)
elif n > k:
    for i in range(k):
        h[n-i-1] = 0
    print(sum(h))
input()
if K <= A + B:
  print(K)
else:
  print(A * 2 + B - K)

### FIXED CODE ###

import math
A, B, C, K = list(map(int, input().split()))
if K <= A:
  print(K)
if A < K <= A + B:
  print(A)
if A + B < K <= A + B + C:
  print(A * 2 + B - K)
n = int(input())
v = sorted(list(map(int, input().split())))

ans = (v[0]+v[1])/2
for i in range(2,n):
    ans = (a+v[i])/2
print(ans)


### FIXED CODE ###

n = int(input())
v = sorted(list(map(int, input().split())))

while len(v) > 1:
    new_v = (v[0]+v[1]) / 2
    del v[0:2]
    v = [new_v]+v

print(v[0])
n = int(input())

maxv =  int(-20000000)
minv = int(input())

for i in range(n):
    r= int(input())
    maxv = max(maxv, r - minv)
    minv = min(minv, r)

print(maxv)



### FIXED CODE ###

n = int(input())

maxv = -10**18
minv = 10**18

for i in range(n):
    r= int(input())
    maxv = max(maxv, r - minv)
    minv = min(minv, r)

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

dp = np.zeros((N+1, 2), dtype=int)
dp[0, 1] = -10**9

for i in range(N):
    dp[i+1, 0] = max(dp[i, 0] + A[i], dp[i, 1] - A[i])
    dp[i+1, 1] = max(dp[i, 0] - A[i], dp[i, 1] + A[i])
print(dp[N, 0])

### FIXED CODE ###

import numpy as np
N = int(input())
A = list(map(int, input().split()))

dp = np.zeros((N+1, 2), dtype=int)
dp[0, 1] = -10**9

for i in range(N):
    dp[i+1, 0] = max(dp[i, 0] + A[i], dp[i, 1] - A[i])
    dp[i+1, 1] = max(dp[i, 0] - A[i], dp[i, 1] + A[i])
print(dp[N, 0])
from collections import defaultdict
from heapq import heappop, heappush

N, M = map(int, input().split())


class Graph(object):
    def __init__(self):
        self.edges = defaultdict(list)
        self.nodes = set()

    def add_edge(self, src, dst, weight=1):
        self.edges[src].append((dst, weight))
        self.nodes.add(src)
        self.nodes.add(dst)


def BellmanFord(graph, start):
    N = len(graph.nodes)
    dist = [float('-inf')] * N
    dist[start] = 0
    prev = [None] * N

    for _ in range(N):
        for u, l in graph.edges.items():
            for v, weight in l:
                if dist[v] < dist[u] + weight:
                    dist[v] = dist[u] + weight
                    prev[v] = u
    
    for u, l in graph.edges.items():
        for v, weight in l:
             if dist[u] + weight > dist[v]:
                 return False
    return dist


def topological_sort(graph):
    g = graph.edges
    N = len(graph.nodes)

    indeg = [0] * N
    for v in g:
        for u, _ in g[v]:
            indeg[u] += 1

    S = [i for i in range(N) if indeg[i] == 0]
    L = []

    while S:
        u = S.pop()
        L.append(u)
        for v, _ in g[u]:
            indeg[v] -= 1
            if indeg[v] == 0:
                S.append(v)
    return L


g = Graph()
for _ in range(M):
    a, b, c = map(int, input().split())
    g.add_edge(a - 1, b - 1, c)

if len(topological_sort(g)) == N:
    dist = BellmanFord(g, 0)
    if dist:
        print(dist[N - 1])
    else:
        print('inf')
else:
    print('inf')


### FIXED CODE ###

N, M = map(int, input().split())


class BellmanFord(object):
    def __init__(self, edges, n_nodes, start):
        self.edges = edges
        dist = [float('inf')] * n_nodes
        dist[start] = 0
        prev = [None] * n_nodes

        for _ in range(n_nodes - 1):
            for u, v, weight in edges:
                if dist[u] == float('inf'):
                    continue
                if dist[v] > dist[u] + weight:
                    dist[v] = dist[u] + weight
                    prev[v] = u
        self.dist = dist
        self.prev = prev

    def check(self, goal=None):
        if goal is None:
            for u, v, weight in self.edges:
                if self.dist[v] > self.dist[u] + weight:
                    return False
            return True
        else:
            negative = [False] * N
            for _ in range(N):
                for u, v, weight in self.edges:
                    if self.dist[u] == float('inf'):
                        continue
                    if negative[u] or self.dist[v] > self.dist[u] + weight:
                        negative[v] = True
            return not negative[goal]


edges = [None] * M
for i in range(M):
    a, b, c = map(int, input().split())
    edges[i] = (a - 1, b - 1, -c)

bf = BellmanFord(edges, N, 0)
if bf.check(N - 1):
    print(-bf.dist[N - 1])
else:
    print('inf')
N = int(input())
H = list(map(int, input().split()))
for i in range(N,-1,-1):
    if H[i]>H[i-1]:
        H[i] -= 1
        if H[i]>H[i-1]:
            print("No")
            break
print("Yes")


### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
for i in reversed(range(N-1)):
    if H[i]>H[i+1]:
        H[i] -= 1
        if H[i]>H[i+1]:
            print("No")
            exit()
print("Yes")
n = int(input())
A = [list(map(int, input().split())) for _ in range(n)]

ans = 0
cannot = 0
for i in range(n-1):
  for j in range(i+1,n):
    detour = min([A[i][k] + A[k][j] for k in range(n) if k!=i and k!=j])
    if detour<A[i][j]:
      cannot = 1
    elif detour>A[i][j]:
      ans += A[i][j]
if cannot:
  print(-1)
else:
  print(ans)


### FIXED CODE ###

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

ans = 0
cannot = 0
for i in range(n-1):
  for j in range(i+1,n):
    detour = min([A[i][k] + A[k][j] for k in range(n) if k!=i and k!=j]+[10**18])
    if detour<A[i][j]:
      cannot = 1
    elif detour>A[i][j]:
      ans += A[i][j]
if cannot:
  print(-1)
else:
  print(ans)
import sys
sys.setrecursionlimit(10**5)
m = 100005
visited = [False]*(m*2)
cnt = [0,0]
def dfs(i):
    visited[i] = True
    cnt[i//m] = cnt[i//m]+1
    for j in to[i]:
        if not visited[j]:
            dfs(j)
 
input = sys.stdin.readline
n = int(input())
to = [[] for _ in range(m*2)]
for _ in range(n):
    x,y = map(int,input().split())
    y = y+m
    to[x].append(y)
    to[y].append(x)
 
ans = 0
for i in range(m):
    if not visited[i]:
        cnt = [0,0]
        dfs(i)
        ans = ans + cnt[0]*cnt[1]
 
print(ans-n)

### FIXED CODE ###

s=input()
ans = 'Good'
last = s[0]
for i in s[1:]:
    if last==i:
        ans = 'Bad'
        break
    last = i
print(ans)
# B - K-th Common Divisor
# https://atcoder.jp/contests/abc120/tasks/abc120_b
# 1WA
import math

MAX = 100

def gcd(m, n):
    return m if n == 0 else gcd(n, m % n)

prime_table = [True]*MAX
prime_table[0] = prime_table[1] = False
for i in range(2, int(math.sqrt(MAX)) + 1):
    for j in range(i*2, MAX, i):
        prime_table[j] = False
primes = [i_idx for i_idx in range(len(prime_table)) if prime_table[i_idx] == True]

A, B, K = map(int, raw_input().split())
gcdAB = gcd(A, B)

factors = set()
factors.add(gcdAB)
factors.add(1)

for prime in primes:
    if prime > gcdAB:
        break
    if gcdAB % prime == 0:
        factors.add(prime)
        factors.add(gcdAB/prime)

factors = list(factors)
factors.sort(reverse=True)

print '{}'.format(factors[K - 1])


### FIXED CODE ###

# B - K-th Common Divisor
# https://atcoder.jp/contests/abc120/tasks/abc120_b
# 1WA
MAX = 100

def gcd(m, n):
    return m if n == 0 else gcd(n, m % n)

A, B, K = map(int, raw_input().split())
gcdAB = gcd(A, B)

cnt = 0
for n in range(gcdAB, 0, -1):
    if gcdAB % n == 0:
        cnt += 1
        if cnt == K:
            print '{}'.format(n)
            break
# -*- coding: utf-8 -*-
# リストの準備
list = [SUN,MON,TUE,WED,THU,FRI,SAT]
# 文字列の入力
s = input()
# indexの検索
a = list.index(s)
# 7-indexで出力
print(7 - b)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
# リストの準備
daylist = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
# 文字列の入力
s = input()
# indexの検索
if s in daylist:
    a = daylist.index(s)
    print(7 - a)
else:
    print("{} is not day of week".format(s))
from sys import stdin
N,P=[int(x) for x in stdin.readline().rstrip().split()]
for i in reversed(range(int(pow(P,(1/N))))):
    if P==1:
        ans=1
        break
    if N==1:
        ans=P
        break
    if P%i==0:
        ans=i
        break:
print(ans)

### FIXED CODE ###

import math
from sys import stdin
N,P=[int(x) for x in stdin.readline().rstrip().split()]
for i in reversed(range(round(math.pow(P,(1/N)))+1)):
    tmp=math.pow(i,N)
    if P==1:
        ans=1
        break
    if N==1:
        ans=P
        break
    if P%tmp==0:
        ans=i
        break
print(ans)
s = input()
l = []

while flag=False:
  if tmp in l:
    flag = True
  else:
    if s % 2 == 0:
      tmp = s / 2
      l.append(tmp)
      s = tmp
    else:
      tmp = 3*s +1
      l.append(tmp)
      s = tmp
      
l.sort()
print(l[-2])

### FIXED CODE ###

s = int(input())
l = []
flag = False
cnt = 0
tmp = 0
while flag==False:
  if tmp in l:
    cnt += 1
    flag = True
  else:
    if s % 2 == 0:
      tmp = s / 2
      l.append(s)
      s = tmp
      cnt += 1
    else:
      tmp = 3*s +1
      l.append(s)
      s = tmp
      cnt += 1
      
print(cnt)
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, groupby
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X, A = MAP()
print(0 if x <A else 10)

### FIXED CODE ###

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, groupby
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X, A = MAP()
print(0 if X <A else 10)
s=input()
a=0
A=[]
for i in range(len(s)):
    if s[i]=='A' or s[i]=='T' or s[i]=='G' or s[i]=='C':
        a+=1
        A.append(a)
    else:
        a=0
print(max(A))


### FIXED CODE ###

s=input()
a=0
A=[0]
for i in range(len(s)):
    if s[i]=='A' or s[i]=='T' or s[i]=='G' or s[i]=='C':
        a+=1
        A.append(a)
    else:
        a=0
print(max(A))
from collections import deque
n, m = map(int, input().split())
a = set(int(input()) for _ in range(m))
M = 1_000_000_007
dp = {}
dp[0] = 1
for i in range(1, n+1):
    if i in a:
        dp[i] = 0
        continue
    if i - 2 < 0:
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[n] % M)

### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
a = set(int(input()) for _ in range(m))
M = 1000000007
dp = {}
dp[0] = 1
for i in range(1, n+1):
    if i in a:
        dp[i] = 0
        continue
    if i - 2 < 0:
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[n] % M)
str = input()

str_length = len(str)

import randum

start_num = randum.randint(0,str_length-3)

print(str[start_num:start_num+2])

### FIXED CODE ###

str = input()
 
str_length = len(str)
 
import random
 
start_num = random.randint(0,str_length-3)
 
print(str[start_num:start_num+3])
import sys
input = sys.stdin.readline
s=list(input())
x,y = map(int, input().split())
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0


dpx=[[0 for i in range(sum(x1)*2+2)] for j in range(len(x1)+1)]
if len(x1)<=2:
    dpx.append(0)
dpx[1][0]=1
for i in range(1,len(x1)):
    for j in range(-(sum(x1))-1,sum(x1)+1):
        if j-x1[i]<-sum(x1)-1:
            dpx[i + 1][j] =  dpx[i][j+x1[i]]
        elif j+x1[i]>=sum(x1)+1:
            dpx[i + 1][j] = dpx[i][j-x1[i]]
        else:
            dpx[i + 1][j] = dpx[i][j + x1[i]] or dpx[i][j - x1[i]]

dpy=[[0 for i in range(sum(y1)*2+2)] for j in range(len(y1)+1)]
if len(y1)==0:
    dpy.append(0)
dpy[0][0]=1

for i in range(len(y1)):
    for j in range(-sum(y1)-1,sum(y1)+1):
        if j-y1[i]<-sum(y1)-1:
            dpy[i + 1][j] = dpy[i][j + y1[i]]
        elif j+y1[i]>=sum(y1)+1:
            dpy[i + 1][j] = dpy[i][j - y1[i]]
        else:
            dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j+y1[i]]

if dpy[len(y1)][y]==1 and dpx[len(x1)][x-x1[0]]==1:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

import sys
input = sys.stdin.readline
s=list(input())
x,y = map(int, input().split())
y=abs(y)
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0
v=sum(x1)
w=sum(y1)
v-=x1[0]
x-=x1[0]
x1.pop(0)
x=abs(x)
if v<x or w<y:
    print('No')
    exit()

dpx=[[0 for i in range(v+1)] for j in range(len(x1)+1)]
dpx[0][-1]=1

for i in range(len(x1)):
    for j in range(v+1):
        if dpx[i][j]==1:
            if j-2*x1[i]>=0:
                dpx[i+1][j-2*x1[i]]=1
            dpx[i+1][j]=1

if len(y1)==0:
    y1.append(0)
dpy=[[0 for i in range(w+1)] for j in range(len(y1)+1)]
dpy[0][-1]=1

for i in range(len(y1)):
    for j in range(w+1):
        if dpy[i][j]==1:
            if j-2*y1[i]>=0:
                dpy[i+1][j-2*y1[i]]=1
            dpy[i+1][j]=1

if dpy[-1][y]==1 and dpx[-1][x]==1:
    print('Yes')
else:
    print('No')
def gcd(a,b):
    if a<b:
     c=a
     a=b
     b=c
     
    c=a%b
    
    if c==0:
     return gcd(b,cs)
    else:
     return b
 
def lcm(a,b):
    c=gcd(a,b)
    return a/c*b
 
 
 
n=int(input())
t=[0]*n
 
for lop2 in range(n):
    t[lop2]=int(input())
 
ans=t[0]
 
for lop in range(1,n):
    ans=lcm(ans,t[lop])
print(int(ans))


### FIXED CODE ###

'''
def gcd(a,b):
    if a<b:
     c=a
     a=b
     b=c

    c=a%b

    if c==0:
     return b
    else:
     return gcd(b,c)
'''

def gcd(a,b):
    return a if b == 0 else gcd(b,a%b)

def lcm(e,f):
    c=gcd(e,f)
    g=e*f
    return g//c



n=int(input())
t=[0]*n

for lop2 in range(n):
    t[lop2]=int(input())

ans=t[0]

for lop in range(1,n):
    ans=lcm(ans,t[lop])
print(int(ans))
S = input()
st = 0
la = len(S) - 1
result = 0

while(st > la):
  if S[st]== 'x' and S[la]== 'x':
    st += 1
    la += 1
    continue
  if S[st] != 'x' and S[la]== 'x':
    result += 1
    la += 1
  elif S[st] == 'x' and S[la] != 'x':
    result += 1
    st += 1
  else
    result = -1
    break

 print(result)
  

### FIXED CODE ###

S = input()
N = len(S)
st = 0
la = N - 1
result = 0

while(st < la):
  if S[st] == 'x' and S[la] == 'x':
    st += 1
    la -= 1
    continue
  if S[st] != 'x' and S[la] == 'x':
    la -= 1
    result += 1
  elif S[st] == 'x' and S[la] != 'x':
    st += 1
    result += 1
  elif S[st] == S[la]:
    st += 1
    la -= 1
  else:
    result = -1
    break

print(result)
n = int(input())
s = input()

from collections import Counter
rgb = dict(Counter(s))
p = rgb['R'] * rgb['G'] * rgb['B']
for i in range(1, (len(s)-1)//2 + 1):
    for j in range(len(s) - 2*i):
        if {s[j], s[j + i], s[j + 2*i]} == {'R', 'G', 'B'}:
            p -= 1
print(p)

### FIXED CODE ###

n = int(input())
s = input()

from collections import Counter
rgb = dict(Counter(s))
if len(rgb) < 3:
    print('0')
else:
    p = rgb['R'] * rgb['G'] * rgb['B']
    for i in range(1, (len(s)-1)//2 + 1):
        for j in range(len(s) - 2*i):
            if {s[j], s[j + i], s[j + 2*i]} == {'R', 'G', 'B'}:
                p -= 1
    print(p)
N, K = map(int, input().split())
lst = []
for i in range(N):
    lst.append(int(input()))
lst.sort()
dif = 10**9
for i in range(N):
    if lst[i+K-1] - lst[i] < dif:
        dif = lst[i+K-1] - lst[i]
print(dif)

### FIXED CODE ###

N, K = map(int, input().split())
lst = []
for i in range(N):
    x = int(input())
    lst.append(x)
lst.sort()
L = []
for i in range(N - K + 1):
    L.append(lst[i + K -1] - lst[i])
L.sort()
print(L[0])
def wa(n,a,b):
  for i in range(1,n+1):
    s=str(i)
    for ii in s:
      ss+=int(ii)
    if a=<ss=<b:
      ans+=i
  return ans
n,a,b=map(int,input().split())
print(wa(n,a,b))  

### FIXED CODE ###

def wa(n,a,b):
  hoge=0
  ans=0
  for i in range(1,n+1):
    s=str(i)
    hoge=0
    for ii in s:
      hoge+=int(ii)
    if a<=hoge<=b:
      ans+=i
  return ans
n,a,b=map(int,input().split())
print(wa(n,a,b))
import itertools
import numpy as np
N,M,X=map(int,input().split())
CA=[]
for i in range(N):
  CA.append(list(map(int,input().split())))
#CA=sorted(CA, key=lambda x:sum(x[1:]))
money=100000000000000000000000000000
count=1
for i in range(1,N):
  test=itertools.combinations(CA,i)
  for j in test:#組み合わせごとに計算
    pre_ans=np.sum(j, axis=0)
    if pre_ans[0]<money and np.all(pre_ans[1:]>=X):
      money=pre_ans[0]
      count=0
if count==0:
  print(money)
else:
  print(-1)


### FIXED CODE ###

import itertools
import numpy as np
N,M,X=map(int,input().split())
CA=[]
for i in range(N):
  CA.append(list(map(int,input().split())))
money=9000000000
count=1
for i in range(1,N+1):
  test=itertools.combinations(CA,i)
  for j in test:#組み合わせごとに計算
    pre_ans=np.sum(j, axis=0)
    if pre_ans[0]<money and np.all(pre_ans[1:]>=X):
      money=pre_ans[0]
      count=0
if count==0:
  print(money)
else:
  print(-1)
import sys,math,collections,itertools
input = sys.stdin.readline

N,K,S=list(map(int,input().split()))
ans = [0]*N
ans[K]=10**9+1
ans[0]=S

print(*ans)

### FIXED CODE ###

import sys,math,collections,itertools
input = sys.stdin.readline

N,K,S=list(map(int,input().split()))
if S == 10**9:
    ans = [10**9-1]*N
else:
    ans = [10**9]*N
for i in range(K):
    ans[i]=S
print(*ans)
class node:
    def __init__(self, num):
        self.number     = num
        self.distance   = -1
        self.link_node  = []
        self.is_serched = False

def BFS(node):
    for item in node.link_node:
        if item.is_serched == False:
            item.distance = node.distance + 1
            item.is_serched = True
    for item in node.link_node:
        BFS(item)
n = input()
node_list = [None] * (n + 1)

for i in xrange(1, n + 1):
    node_list[i] = node(i)

for i in xrange(1, n + 1):
    line = raw_input().split()
    for node_num in line[2 : ]:
        node_list[i].link_node.append(node_list[int(node_num)])

node_list[1].is_serched = True
node_list[1].distance = 0
BFS(node_list[1])

for item in node_list[1 : ]:
    print '%s %s' % (str(item.number), str(item.distance))
    

### FIXED CODE ###

class node:
    def __init__(self, num):
        self.number     = num
        self.distance   = -1
        self.link_node  = []
        self.is_serched = False

class queue:
    def __init__(self):
        self.top = 0
        self.bottom = 0
        self.que = []
    
    def dequeue(self):
        self.top = self.top + 1
        return self.que[self.top - 1]
    
    def enqueue(self, item):
        self.que.append(item)
        self.bottom = self.bottom + 1
    
    def is_empty(self):
        if self.top == self.bottom:
            return True
        else:
            return False

n = input()
node_list = [None] * (n + 1)

for i in xrange(1, n + 1):
    node_list[i] = node(i)

for i in xrange(1, n + 1):
    line = raw_input().split()
    for node_num in line[2 : ]:
        node_list[i].link_node.append(node_list[int(node_num)])

node_que = queue()

node_list[1].distance = 0
node_que.enqueue(node_list[1])
while node_que.is_empty() == False:
    top_item = node_que.que[node_que.top]
    top_item.is_serched = True
    for item in top_item.link_node:
        if item.is_serched == False:
            node_que.enqueue(item)
            if item.distance == -1:
                item.distance = top_item.distance + 1
            elif item.distance > top_item.distance + 1:
                item.distance = top_item.distance + 1
    node_que.dequeue()

for item in node_list[1 : ]:
    print '%s %s' % (str(item.number), str(item.distance))
s = input().split('i')

h = s[:len(s)-1]
space = s[len(s)-1]

for j in h:
  if j =='h' and space == '':
    ans = 'Yes'
  else:
    ans = 'No'
    break
  
print(ans)

### FIXED CODE ###

h = input()

result = 'Yes'

if len(h)%2 != 0:
  result ='No'
  
for a in range(0,len(h)-1,2):  
  b = h[a:a+2]
  if b != 'hi':
    result = 'No'
    break
    
print(result)
N = int(input())
H = map(int,input().split())
m = 0
c = 0
for i in range(H-1):
  if H[i] >= H[i+1]:
    c+=1
  else:
    m = max(m,c)
    c = 0
print(m)

### FIXED CODE ###

N = int(input())
H = list(map(int,input().split()))
m = 0
c = 0
for i in range(N-1):
  if H[i] >= H[i+1]:
    c+=1
  else:
    m = max(m,c)
    c = 0
m = max(m,c)
print(m)