Harryxun/stf_run huggingface dataset:
N, K = map(int, input().split())
A = [-1] + list(map(int, input().split()))

visited = set([1])
loop = [1]
now = 1

for _ in range(N):
    now = A[now]
    if now in visited:
        break
    else:
        loop.append(now)
        visited.add(now)

x = loop.index(now)

if K <= x:
    print(loop[x+1])
else:
    K -= x
    loop = loop[x:]
    K %= len(loop)
    print(loop[K])

### FIXED CODE ###

N, K = map(int, input().split())
A = [-1] + list(map(int, input().split()))

visited = set([1])
loop = [1]
now = 1

for _ in range(N):
    now = A[now]
    if now in visited:
        break
    else:
        loop.append(now)
        visited.add(now)

x = loop.index(now)

if K < x:
    print(loop[K])
else:
    K -= x
    loop = loop[x:]
    K %= len(loop)
    print(loop[K])
import math
         
def koch(n, h, i, j, k):
 if n == 0:
  return
          
 s.x = (h*2+j)/3
 s.y = (i*2+k)/3
 t.x = (h+j*2)/3
 t.y = (i+k*2)/3
 u.x = (t.x-s.x)*math.cos(math.pi/3) - (t.y-s.y)*math.sin(math.pi/3) + s.x
 u.y = (t.x-s.x)*math.sin(math.pi/3) + (t.y-s.y)*math.cos(math.pi/3) + s.y
         
 koch(n-1, h, i, s.x, s.y)
 print s.x, s.y
 koch(n-1, s.x, s.y, u.x, u.y)
 print u.x, u.y
 koch(n-1, u.x, u.y, t.x, t.y)
 print t.x, t.y
 koch(n-1, t.x, t.y, j, k)
  
n = input()
         
px = float(0)
py = float(0)
qx = float(100)
qy = float(0)
         
print px, py
koch(n, px, py, qx, qy)
print qx, qy

### FIXED CODE ###

import math
          
def koch(n, h, i, j, k):
 if n == 0:
  return
           
 sx = (h*2+j)/3
 sy = (i*2+k)/3
 tx = (h+j*2)/3
 ty = (i+k*2)/3
 ux = (tx-sx)*math.cos(math.pi/3) - (ty-sy)*math.sin(math.pi/3) + sx
 uy = (tx-sx)*math.sin(math.pi/3) + (ty-sy)*math.cos(math.pi/3) + sy
          
 koch(n-1, h, i, sx, sy)
 print sx, sy
 koch(n-1, sx, sy, ux, uy)
 print ux, uy
 koch(n-1, ux, uy, tx, ty)
 print tx, ty
 koch(n-1, tx, ty, j, k)
   
n = input()
          
px = float(0)
py = float(0)
qx = float(100)
qy = float(0)
          
print px, py
koch(n, px, py, qx, qy)
print qx, qy
a = input()
if (a[:2] >0 and a[:2]<13) and (a[2:] >0 and a[2:]<13):
  print("both")
if (a[:2] >0 and a[:2]<13) and (a[2:] ==0 or a[2:]>13):
  print("MMYY")
if (a[:2] ==0 or  a[:2]>13) and (a[2:]>0 or a[2:]<13):
  print("YYMM")
if (a[:2] ==0 or  a[:2]>13) and (a[2:] ==0 or a[2:]>13):
  print("YYMM")


### FIXED CODE ###

a = input()
mm = int(a[:2])
yy = int(a[2:])

can1 = True
can2 = True

if mm>12:
  can1 = False
if mm<1:
  can1= False

if yy>12:
  can2 = False
if yy<1:
  can2 = False

if can1 and can2:
  print("AMBIGUOUS")
elif can2:
  print("YYMM")
elif can1:
  print("MMYY")
else:
  print("NA")
import numpy as np

n,m = input().split(" ")
n = int(n)
m = int(m)

H = input().split(" ")
H = np.array([int(h) for h in H])

M = np.zeros((n,n))
for i in range(m):
    a, b = input().split(" ")
    M[int(a)-1, int(b)-1] = 1
    M[int(b)-1, int(a)-1] = 1

G = []
for i in range(n):
    # no path
    if sum(M[i,:])==0:
        G += [i]
    else:
        connected = np.where(M[i, :]==1)[0]
        flag = 0
        for c in connected:
            if (H[c] >= H[i]):
                flag  = 1
                break
        if flag == 1:
            G+= [i]

print(len(G))



### FIXED CODE ###

import numpy as np
 
n,m = input().split(" ")
n = int(n)
m = int(m)
 
H = input().split(" ")
H = np.array([int(h) for h in H])
Hs = np.zeros(n)

for i in range(m):
    a, b = input().split(" ")
    a = int(a) - 1
    b = int(b) - 1
    Hs[a] = np.max([Hs[a], H[b]])
    Hs[b] = np.max([Hs[b], H[a]])
 
G = []
for i in range(n):
    if Hs[i] < H[i]:
        G += [i]
 
print(len(G))
from operator import mul
from functools import reduce

n = int(input().rstrip())
nums = map(int,input().rstrip().split(' '))

ans = reduce(mul, nums)

if ans > 1000000000000000000:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

list = input().rstrip().split(' ')
a = int(list[0])
b = int(list[1])
print(a*b)
from collections import deque
from itertools import product


def bfs(x, y):
    dist = [[10 ** 9] * w for _ in range(h)]
    dist[y][x] = 0
    for i, si in enumerate(s):
        for j, sij in enumerate(si):
            if sij=='#':
                dist[j][i] = -1
    que = deque([(x, y)])

    while len(que) > 0:
        x, y = que.popleft()
        near_a = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
        num = product([-2, -1, 0, 1, 2], repeat=2)
        near_b = [(x + dx, y + dy) for dx, dy in num]

        for cnt, l in enumerate((near_a, near_b)):
            for i, j in l:
                if (0 <= i < w and 0 <= j < h and
                        dist[j][i] > dist[y][x] + cnt and s[j][i] == '.'):
                    dist[j][i] = dist[y][x] + cnt
                    if cnt == 0:
                        que.appendleft((i, j))
                    elif cnt == 1:
                        que.append((i, j))
    return dist


h, w = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
s = [input() for _ in range(h)]

ans = bfs(Cw - 1, Ch - 1)[Dh - 1][Dw - 1]
print(-1 if ans == 10 ** 9 else ans)


### FIXED CODE ###

from collections import deque
from itertools import product


def bfs(S):
    x, y = S
    dist = [[10 ** 9] * w for _ in range(h)]
    dist[y][x] = 0
    que = deque([S])

    while len(que) > 0:
        x, y = que.popleft()
        near_a = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
        num = product([-2, -1, 0, 1, 2], repeat=2)
        near_b = [(x + dx, y + dy) for dx, dy in num]

        for i, j in near_a:
            if (0 <= i < w and 0 <= j < h and
                    dist[j][i] > dist[y][x] and s[j][i] == '.'):
                dist[j][i] = dist[y][x]
                que.appendleft((i, j))
        for i, j in near_b:
            if (0 <= i < w and 0 <= j < h and
                    dist[j][i] > dist[y][x] + 1 and s[j][i] == '.'):
                dist[j][i] = dist[y][x] + 1
                que.append((i, j))
    return dist


h, w = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
s = [input() for _ in range(h)]

ans = bfs((Cw - 1, Ch - 1))[Dh - 1][Dw - 1]
print(-1 if ans == 10 ** 9 else ans)
N = int(input())
K = int(input())
Q = int(input())

A = [0] * Q

for i in range(Q):
	A[i] = int(input())

point = [K] * N

for i in range(Q):
	point = [point[i] - 1 for j in range(N)]
	point[A[i]] = point[A[i]] + 1

for i in range(N):
	if point[i] > 0:
		print("Yes")
	else:
		print("No")

### FIXED CODE ###

I = input()
I = I.split(" ")
N = int(I[0])
K = int(I[1])
Q = int(I[2])

A = [0] * Q

for i in range(Q):
	A[i] = int(input())

point = [0] * N

for i in range(Q):
	point[A[i]-1] = point[A[i]-1] + 1

for i in range(N):
	if Q - point[i] < K:
		print("Yes")
	else:
		print("No")
s = map(int, input().split())
l=[s]
i=1
def func(a):
  if a%2==0:
    return(a/2)
  else:
    return(3*a+1)

def Collatz(s):
  i+=1
  l.append(func(s))
  if not len(l) == len(set(l)):
    print(i)
    break
  else:
    continue

Collatz(s)

### FIXED CODE ###

s = int(input())
l=[s]
i=1
def func(a):
  if a%2==0:
    return(a/2)
  else:
    return(3*a+1)

while (len(l)==len(set(l))):
  i+=1
  s = func(s)
  l.append(s)
print(i)
import sys
sys.setrecursionlimit(10 ** 9)

h,w = map(int,input().split())
maze = [list(input().rstrip()) for _ in range(h)]
#print(maze)

from collections import deque
b = 0
INF = float("inf")
checked = [[INF]*w for i in range(h)]

q = deque([])
q.append((0,0))
checked[0][0] = 1
while len(q)>0:
    pos = q.popleft()
    if pos == (w-1,h-1):
        b = (checked[w-1][h-1])
        break
    if pos[0] > 0:
        if not maze[pos[0] - 1][pos[1]] == '#' and checked[pos[0] - 1][pos[1]] == INF:
            checked[pos[0] - 1][pos[1]] = checked[pos[0]][pos[1]] + 1
            q.append((pos[0] - 1, pos[1]))

    if pos[0] < w - 1:
        if not maze[pos[0] + 1][pos[1]] == '#' and checked[pos[0] + 1][pos[1]] == INF:
            checked[pos[0] + 1][pos[1]] = checked[pos[0]][pos[1]] + 1
            q.append((pos[0] + 1, pos[1]))

    if pos[1] > 0:
        if not maze[pos[0]][pos[1] - 1] == '#' and checked[pos[0]][pos[1] - 1] == INF:
            checked[pos[0]][pos[1] - 1] = checked[pos[0]][pos[1]] + 1
            q.append((pos[0], pos[1] - 1))

    if pos[1] < h - 1:
        if not maze[pos[0]][pos[1] + 1] == '#' and checked[pos[0]][pos[1] + 1] == INF:
            checked[pos[0]][pos[1] + 1] = checked[pos[0]][pos[1]] + 1
            q.append((pos[0], pos[1] + 1))
a = []
for i in range(h):
    a.append(maze[i].count("."))
if not b == 0:
    print(sum(a)-b)
else:
    print(-1)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 9)

h,w = map(int,input().split())
maze = [list(input().rstrip()) for _ in range(h)]
#print(maze)

from collections import deque
b = 0
INF = float("inf")
checked = [[INF]*w for i in range(h)]

q = deque([])
q.append((0,0))
checked[0][0] = 1
while len(q)>0:
    pos = q.popleft()
    if pos == (h-1,w-1):
        b = (checked[h-1][w-1])
        break
    if pos[0] > 0:
        if not maze[pos[0] - 1][pos[1]] == '#' and checked[pos[0] - 1][pos[1]] == INF:
            checked[pos[0] - 1][pos[1]] = checked[pos[0]][pos[1]] + 1
            q.append((pos[0] - 1, pos[1]))

    if pos[0] < h - 1:
        if not maze[pos[0] + 1][pos[1]] == '#' and checked[pos[0] + 1][pos[1]] == INF:
            checked[pos[0] + 1][pos[1]] = checked[pos[0]][pos[1]] + 1
            q.append((pos[0] + 1, pos[1]))

    if pos[1] > 0:
        if not maze[pos[0]][pos[1] - 1] == '#' and checked[pos[0]][pos[1] - 1] == INF:
            checked[pos[0]][pos[1] - 1] = checked[pos[0]][pos[1]] + 1
            q.append((pos[0], pos[1] - 1))

    if pos[1] < w - 1:
        if not maze[pos[0]][pos[1] + 1] == '#' and checked[pos[0]][pos[1] + 1] == INF:
            checked[pos[0]][pos[1] + 1] = checked[pos[0]][pos[1]] + 1
            q.append((pos[0], pos[1] + 1))
a = []
for i in range(h):
    a.append(maze[i].count("."))
if not b == 0:
    print(sum(a)-b)
else:
    print(-1)
import numpy as np
a = int(input())
b = a % 100
print(b)
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]
if b in hon:
    print("hon")
elif b in pon:
    print("pon")
else:
    print("bon")


### FIXED CODE ###

import numpy as np
a = int(input())
b = a % 10
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]
if b in hon:
    print("hon")
elif b in pon:
    print("pon")
else:
    print("bon")
str = input()
N = int(str.split()[0])
X = int(str.split()[1])

str = input()
L = []
for i in range(N) :
	L.append(int(str.split()[i]))

D = 0
i = 0
while(D <= X) :
	D = D + L[i]
	i = i + 1


print(i)


### FIXED CODE ###

str = input()
N = int(str.split()[0])
X = int(str.split()[1])

str = input()
L = []
for i in range(N) :
	L.append(int(str.split()[i]))

D = 0
i = 0
while(D <= X) :
	if (i == len(L)) :
		if (D <= X):
			i = N + 1
		break
	D = D + L[i]
	i = i + 1


print(i)
n = int(input())
c = list(map(int, input().split()))
k = 1
count = 0
while True:
  for i in range(n):
    k *= c[i]
  l = (k % (2**n))
  if (l == 0):
    for j in range(n):
      c[j] = c[j] / 2
    count += 1
  else:
    break
print(count)
  

### FIXED CODE ###

n = int(input())
c = list(map(int, input().split()))
k = 1
count = 0
while True:
  q = 0
  for i in range(n):
    if (c[i]%2 ==1):
      q += 1
  if (q > 0):
    break
  else:
    for j in range(n):
      c[j] = c[j] / 2
    count += 1
print(count)
N = input()
K = input()
for i in N
    if input() >= K :
       counter++
print(counter)


### FIXED CODE ###

N,K = map(int,input().split())
height_list = list(map(int,input().split()))
print(sum([1 for i in height_list if i >= K]))
import sys
input = sys.stdin.readline
import math

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

INF = 10 ** 9 + 7
N, K = map(int, input().split())
for i in range(1, K + 1):
    if N - K + 1 < i:
        print(0)
        complex
    ans = (combnations(N - K + 1, i) % INF) * (combnations(K - 1, i - 1) % INF)
    print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
import math

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

INF = 10 ** 9 + 7
N, K = map(int, input().split())
for i in range(1, K + 1):
    if N - K + 1 < i:
        print(0)
        continue
    ans = combnations(N - K + 1, i) * combnations(K - 1, i - 1)
    ans %= INF
    print(ans)
"""
A - Frog 1
"""
class DP():
    def __init__(self):
        pass
    
    def chmin(self, a, b):
        if a>b:
            return b
        else:
            return a
        
    def chmax(self):
        if a<b:
            return b
        else:
            return a
        
N = int(input())
# K = int(input())
cost_list = list(map(int, input().split()))
# cost_list = [2, 9, 4, 5, 1, 6, 10]
# N = len(cost_list)
# K = 2

dpfun = DP()
# dp = np.ones(N) * np.inf
INF = 2**60
dp = [INF]*N
" 初期条件 "
dp[0] = 0

for i in range(1, N, 1):
    if i==1:    
        dp[i] = dpfun.chmin(dp[i], dp[i-1] + abs(cost_list[i] - cost_list[i-1]))
    else:
        for j in range(1, K+1, 1):
            dp[i] = dpfun.chmin(dp[i], dp[i-j] + abs(cost_list[i] - cost_list[i-j]))
print(int(dp[-1]))

### FIXED CODE ###

"""
A - Frog 1
"""
class DP():
    def __init__(self):
        pass
    
    def chmin(self, a, b):
        if a>b:
            return b
        else:
            return a
        
    def chmax(self):
        if a<b:
            return b
        else:
            return a
        
N = int(input())
# K = int(input())
cost_list = list(map(int, input().split()))
# cost_list = [2, 9, 4, 5, 1, 6, 10]
# N = len(cost_list)
K = 2

dpfun = DP()
# dp = np.ones(N) * np.inf
INF = 2**60
dp = [INF]*N
" 初期条件 "
dp[0] = 0

for i in range(1, N, 1):
    if i==1:    
        dp[i] = dpfun.chmin(dp[i], dp[i-1] + abs(cost_list[i] - cost_list[i-1]))
    else:
        for j in range(1, K+1, 1):
            dp[i] = dpfun.chmin(dp[i], dp[i-j] + abs(cost_list[i] - cost_list[i-j]))
print(int(dp[-1]))
n, m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
total = sum(a)
if total/(4*m) > a[m]:
  print("No")
else:
  print("Yes")

### FIXED CODE ###

n, m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
total = sum(a)
if total/(4*m) > a[-m]:
  print("No")
else:
  print("Yes")
def calc_max_total_jewels_value():
  jewels = int(input())
  jewel_value = [int(x) for x in input().split()]
  jewel_cost = [int(x) for x in input().split()]
  
  max_total_jewels_value = 0
  for jewel_no in range(jewels):
    max_total_jewels_value += max([0, jewel_value[jewel_no] - jewel_cost[jewel_no]])
    
  return max_total_jewels_value

if __name__ == '__main__':
  print(calc_max_total_jewels_value())

### FIXED CODE ###

def count_sum_generated_biscuit():
  generation_interval_sec,\
  biscuit_per_generation,\
  initial_target_sec = [int(x) for x in input().split()]
  
  target_sec = initial_target_sec + 0.5
  sum_generated_biscuit\
  = (target_sec // generation_interval_sec) * biscuit_per_generation
  
  return int(sum_generated_biscuit)
  
if __name__ == '__main__':
  print(count_sum_generated_biscuit())
t = 0
list = []
for i in range(N):
    list.append(int(P[i]))
    m = min(list)
    if m == int(P[i]):
        t = t + 1

print(t)

### FIXED CODE ###

N = int(input())
P = input().split(" ")

t = 1
list = []
for i in range(N):
    list.append(int(P[i]))
    if i == 0:
        m = int(P[0])
    elif int(P[i]) < m:
        m = int(P[i])
        t = t + 1
        
print(t)
from sympy import nextprime
x = int(input())
if x==2:
	print(int(2))
elif x==3:
	print(int(3))
else:
	print(nextprime(x))

### FIXED CODE ###

x=int(input())

import math

def trial_division(target):
    dest = int(math.sqrt(target))
 
    for i in range(2,dest):
        if target % i == 0:
            #print("False")
            return
    print(x)
    exit()

while 1:
    trial_division(x)
    x+=1
import sys
sys.setrecursionlimit(2147483647) 
S=str(input())
s=list(S)
x1=0
x2=1
y=0
len=len(s)-1
for i in range(len):
  if s[i+1]==s[i]:
    x2=x2+1
  else:
    if i==0:
      x2=0
    if s[i]=='>':
      if x2<x1:
        x2=x2-1
      else:
          x1=x1-1
    y+=x1*(x1+1)/2
    x1=x2
    x2=1
if s[i+1]=='>':
      if x2<x1:
        x2=x2-1
      else:
          x1=x1-1
y+=x1*(x1+1)/2
y+=x2*(x2+1)/2
print(int(y))

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647) 
S=str(input())
s=list(S)
x1=0
x2=1
y=0
len=len(s)-1
for i in range(len):
  if s[i+1]==s[i]:
    x2=x2+1
  else:
    if i==0:
      x2=0
    if s[i]=='>':
      if x2<x1:
        x2=x2-1
      else:
          x1=x1-1
    y+=x1*(x1+1)/2
    x1=x2
    x2=1
if s[len]=='>':
  if x2<x1:
    x2=x2-1
  else:
    x1=x1-1
y+=x1*(x1+1)/2
y+=x2*(x2+1)/2
print(int(y))
import sys
input = sys.stdin.readline

x, k, d = map(int, input().split())
p_lst = list(range(0, k*d + 1, d))
n_lst = list(map(lambda x: -x, p_lst[1:]))
potential_pos = n_lst + p_lst
potential = [x + y for y in potential_pos]
potential.sort()
print(min(map(lambda x: max(x, -x), potential[0::2])))

### FIXED CODE ###

x, k, d = map(int, input().split())

x = abs(x)
kk = k - int(x/d)
if kk <= 0:
    print(x - k * d)
    exit()

a = x - int(x/d)*d
if kk % 2 == 0:
    ans = a
else:
    ans = abs(a - d)

print(ans)
a = input()
b = input()
print a*b,2 * (a+b)

### FIXED CODE ###

(a,b) = map(int,raw_input().split())
print a*b,2*(a+b)
N,K=map(int,input().split())
mod=7+10**9
ans=0
l=range(0,N+1)
for i range(k,n+2):
    ans+=(sum(l[(-k%(n+1)9:])-sum(l[:k])+1)%mod
print(ans%mod)



### FIXED CODE ###

N,K=map(int,input().split())
mod=7+10**9
ans=0
l=list(range(0,N+1))
for i in range(1,N+1):
    l[i]+=l[i-1]
for i in range(K,N+2):
    ans+=(l[-1]-l[-((1+i)%(N+2))]-l[i-1]+1)%mod
print(ans%mod)
n, q = map(int, input().split())
S = list(input())

lr = []
for _ in range(q):
    l, r = map(int, input().split())
    lr.append([l, r])

t = [0] * (n+1)
for i in range(n):
    if S[i] == "A" and S[i+1] == "C":
        t[i+1] = t[i] + 1
    else:
        t[i+1] = t[i]

for temp in lr:
    l, r = temp
    print(t[r-1] - t[l-1])

### FIXED CODE ###

n, q = map(int, input().split())
S = list(input())

lr = []
for _ in range(q):
    l, r = map(int, input().split())
    lr.append([l, r])

t = [0] * (n+1)
for i in range(n-1):
    if S[i] == "A" and S[i+1] == "C":
        t[i+1] = t[i] + 1
    else:
        t[i+1] = t[i]

for temp in lr:
    l, r = temp
    print(t[r-1] - t[l-1])
import collections

def insert_card(card_number, card_list):
    i = 0
    while i < card_number:
        card_list.append(input())
        i += 1


blue_card_number = int(input())
blue_card_list = []
insert_card(blue_card_number, blue_card_list)

red_card_number = int(input())
red_card_list = []
insert_card(red_card_number, red_card_list)

blue_card_collection = collections.Counter(blue_card_list)
red_card_collection = collections.Counter(red_card_list)

result_card_collection = blue_card_collection - red_card_collection

answer_collection = sorted(result_card_collection.items(), key=lambda x:x[1], reverse=True)
print(answer_collection[0][0])

### FIXED CODE ###

import collections

def insert_card(card_number, card_list):
    i = 0
    while i < card_number:
        card_list.append(input())
        i += 1


blue_card_number = int(input())
blue_card_list = []
insert_card(blue_card_number, blue_card_list)

red_card_number = int(input())
red_card_list = []
insert_card(red_card_number, red_card_list)

blue_card_collection = collections.Counter(blue_card_list)
red_card_collection = collections.Counter(red_card_list)

result_card_collection = blue_card_collection - red_card_collection

answer_collection = sorted(result_card_collection.items(), key=lambda x:x[1], reverse=True)
if answer_collection == []:
    print(0)
else:
    print(answer_collection[0][1])
N = int(input())
E = [[] for _ in range(N)]
for n in range(N-1):
    a,b = map(int, input().split())
    a -= 1; b -= 1
    E[a].append((b,n))
    E[b].append((a,n))

K = max(len(e) for e in E)
print(K)

res = [-1]*(N-1)
def dps(v=0, p=-1, p_col=-1):
    col = 1
    for child, idx in E[v]:
        if(child != p):
            if(col == p_col):
                col += 1
            res[idx] = col
            dps(child,v,col)
            col += 1
dps()
print("\n".join(map(str, res)))


### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)
N = int(input())
E = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    E[a].append((b, i))
    E[b].append((a, i))
K = max(len(e) for e in E)
print(K)
Ans = [-1] * (N-1)
def dfs(v=1, p=0, p_col=-1):
    col = 1
    for u, idx in E[v]:
        if u!=p:
            if col == p_col:
                col += 1
            Ans[idx] = col
            dfs(u, v, col)
            col += 1
dfs()
print("\n".join(map(str, Ans)))
a, b, c = map(int, input().split())
while a != 0:
    a, b = b%a, a
if c % b = 0:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

a, b, c = map(int, input().split())
while a != 0:
    a, b = b%a, a
if c % b == 0:
    print("YES")
else:
    print("NO")
A,B,C=map(int,input().split())
if B>=C:
  ans=B+C
else C>B:
  ans+=2*B
  if A>C:
    ans+=C
  else:
    ans+=A
print(ans)


### FIXED CODE ###

A,B,C=map(int,input().split())
if B>=C:
    print(B+C)
else:
    ans=2*B
    C-=B
    if A>=C:
        print(ans+C)
    else:
        print(ans+A+1)
from collections import defaultdict

N, Q = map(int, input().split())
e = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, input().split())
    e[a].append(b)

q = defaultdict(int)
for i in range(Q):
    p, x = map(int, input().split())
    q[p] += x

seen = [False] * (N + 1)
ans = [0] * (N + 1)


def dfs(e, v, x):
    seen[v] = True
    ans[v] += x
    for next_v in e[v]:
        if seen[next_v]:
            continue
        else:
            dfs(e, next_v, x + q[next_v])


dfs(e, 1, q[1])
ans = ans[1:]

for i in ans:
    print(i, end=" ")

print()


### FIXED CODE ###

from collections import defaultdict
import sys
input = sys.stdin.readline

sys.setrecursionlimit(10**6)

N, Q = map(int, input().split())
e = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, input().split())
    e[a].append(b)

q = defaultdict(int)
for i in range(Q):
    p, x = map(int, input().split())
    q[p] += x

seen = [False] * (N + 1)
ans = [0] * (N + 1)


def dfs(e, v, x):
    seen[v] = True
    ans[v] += x
    for next_v in e[v]:
        if seen[next_v]:
            continue
        else:
            dfs(e, next_v, x + q[next_v])


dfs(e, 1, q[1])
print(*ans[1:])
j = {
    "-":-1,
    "+":1
    }
l =input()
n = input()
s = 0
for i in range(len(l)):
  s += j[l[i]]
print(s)


### FIXED CODE ###

j = {
    "-":-1,
    "+":1
    }
l =input()
s = 0
for i in range(len(l)):
  s += j[l[i]]
print(s)
N,M = map(int, input().split())
x = []
for i in range(M):
  a,b = map(int, input().split())
  x[a-1] += 1
  x[b-1] += 1
for i in range(N):
  print(x[i])


### FIXED CODE ###

N,M = map(int, input().split())
x = [0]*N
for i in range(M):
  a,b = map(int, input().split())
  x[a-1] += 1
  x[b-1] += 1
for i in range(N):
  print(x[i])
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        count=0
        while n % b == 0:
            n //= b
            count+=1
            if(count==1):
                fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

import math
A,B=map(int,input().split())
g=math.gcd(A,B)
if(g==1):
    print("1")
else:
    print(len(factorize(g))+1)

### FIXED CODE ###

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        count=0
        while n % b == 0:
            n //= b
            count+=1
            if(count==1):
                fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

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

A,B=map(int,input().split())
g=gcd(A,B)
if(g==1):
    print("1")
else:
    print(len(factorize(g))+1)
A = int(input())
B,C = map(int,input().split())

for i in range(B, C+1):
  if i % A =0:
    print("OK")
    break

print("NG")

### FIXED CODE ###

A = int(input())
B, C = map(int,input().split())
flag = 1

for i in range(B, C+1):
  if i % A == 0:
    flag = 0
    print("OK")
    break

if flag==1:
  print("NG")