Harryxun/stf_run huggingface dataset:
n, k = map(int, input().split())
a = list(map(int, input().split()))

history = []
is_visited = [False] * n

index = 0
cnt = 0
loop_start_city_index = 0
for i in range(k+1):
    if i == k:
        print(index+1)
        exit()

    is_visited[index] = True

    if is_visited[index]:    # すでに訪れた街にきた
        loop_start_city_index = index
        break
    history.append(index)
    index = a[index] - 1
    cnt += 1

from_start_to_loop_start = history.index(loop_start_city_index)
loop_length = len(history) - from_start_to_loop_start

print(history[from_start_to_loop_start + (k-from_start_to_loop_start)%loop_length] + 1)

### FIXED CODE ###

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

history = []
is_visited = [False] * n

index = 0
cnt = 0
loop_start_city_index = 0
for i in range(k+1):
    if i == k:
        print(index+1)
        exit()

    if is_visited[index]:    # すでに訪れた街にきた
        loop_start_city_index = index
        break
    
    is_visited[index] = True
    history.append(index)
    index = a[index] - 1
    cnt += 1

from_start_to_loop_start = history.index(loop_start_city_index)
loop_length = len(history) - from_start_to_loop_start

print(history[from_start_to_loop_start + (k-from_start_to_loop_start)%loop_length] + 1)
A, B = map(int, input().split())

if A*B%2=0:
  print("No")
else:
  print("Yes")

### FIXED CODE ###

A, B = map(int, input().split())

if A*B%2==0:
  print("No")
else:
  print("Yes")
N, M = (int(i) for i in input().split(' '))
py=[]
p =[]

# 全都市を配列に代入
for i in range(M):
    p = [i]
    p.extend([int(j) for j in input().split(' ')])
    py.append(p)

# 設立年で一度ソートする
py.sort(key = lambda x: x[2])
pcid = [1] * M # 各県の都市ID

for i in range(M):
    p = py[i][1] # 県ID
    py[i][2] = pcid[p-1]
    pcid[p-1] += 1

py.sort(key=lambda x:x[0])
for t in py:
    print('{0:0>6}{1:0>6}'.format(t[1],t[2]))
    

### FIXED CODE ###

N, M = (int(i) for i in input().split(' '))
py=[]
p =[]

# 全都市を配列に代入
for i in range(M):
    p = [i]
    p.extend([int(j) for j in input().split(' ')])
    py.append(p)

# 設立年で一度ソートする
py.sort(key = lambda x: x[2])
pcid = [1] * N # 各県の都市ID

for i in range(M):
    p = py[i][1] # 県ID
    py[i][2] = pcid[p-1]
    pcid[p-1] += 1

py.sort(key=lambda x:x[0])
for t in py:
    print('{0:0>6}{1:0>6}'.format(t[1],t[2]))
n,k=map(int,input().split())
X=list(map(int,input().split()))
ans=[]
for i in range(n-k+1):
  ans.append(X[i+k-1]-X[i]+min(abs(X[i+k+1]),abs(X[i])))
print(min(ans))

### FIXED CODE ###

n,k=map(int,input().split())
X=list(map(int,input().split()))
ans=[]
for i in range(n-k+1):
  ans.append(X[i+k-1]-X[i]+min(abs(X[i+k-1]),abs(X[i])))
print(min(ans))
s=input()
ans="AC"
if s[0]!="A":
    ans="WA"
c=0
idx=0
for i in range(2,len(s)-2):
    if s[i]=="C":
        c+=1
        idx=i
if c!=1:
    ans="WA"
small={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}
for i in range(1,len(s)+1):
    if i!=idx:
        if s[i] not in small:
            ans="WA"
            break
print(ans)


### FIXED CODE ###

s=input()
ans="AC"
if s[0]!="A":
    ans="WA"
c=0
idx=0
for i in range(2,len(s)-1):
    if s[i]=="C":
        c+=1
        idx=i
if c!=1:
    ans="WA"
small={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}
for i in range(1,len(s)):
    if i!=idx:
        if s[i] not in small:
            ans="WA"
            break
print(ans)
import numpy as np
n=[]
line=''
while line != [0,0]:
    line=list(map(int,input().split()))
    n.append(line)

### FIXED CODE ###

n=[]
line=''
while line != [0,0]:
    line=list(map(int,input().split()))
    n.append(line)
for i in range(len(n)-1):
    print('%d %d'%(n[i][0] if n[i][0]<=n[i][1] else n[i][1],n[i][0] if n[i][0]>=n[i][1] else n[i][1]))
num = int(input())
words = input()

words_count = {}
for key in words:
    if words_count[key] in words_count:
        words_count[key] += 1
    else:
        words_count[key] = 1

ans = 1
for key, val in words_count:
    ans *= (val + 1)

print(ans - 1)

### FIXED CODE ###

num = int(input())
words = input()
mod = 10**9+7

words_count = {}
for key in words:
    if key in words_count:
        words_count[key] += 1
    else:
        words_count[key] = 1

ans = 1
for key, val in words_count.items():
    ans *= (val + 1)

print((ans - 1) % mod)
a,b,c,d = [int(i) for i in input()]

print(min(a,b)+min(c,d))

### FIXED CODE ###

a, b, c, d = [int(input()) for i in range(4)]

print(min(a, b) + min(c, d))
N = int(input())

array = []

for i in range(N):
    array.append(list(map(int,input().split())))

test = []

for x in range(101):
    for y in range(101):
        H=[]
        for i in array:
            H_i = max(abs(i[0]-x)+abs(i[1]-y)+i[2],0)
            H.append(H_i)
        Hset = set(H)
        H = list(Hset)[0]
        if(len(Hset)==1 and H>=0):
            test.append(H)
            # print(x,y,H)
            
if(len(test)==0):
    print(5/0)
else:
    print(x,y,H)

### FIXED CODE ###

N = int(input())

array = []

for i in range(N):
    array.append(list(map(int,input().split())))

test = []

t = []

for x in range(101):
    for y in range(101):
        H = []
        for i in array:
            if i[2] > 0:
                H_i = max(abs(i[0]-x)+abs(i[1]-y)+i[2],0)
                H.append(H_i)
        Hset = set(H)
        H = list(Hset)[0]
        if(len(Hset)==1 and H>=0):
            t.append([x,y,H])

if len(t) >= 2:
    t = []
    for x in range(101):
        for y in range(101):
            H = []
            for i in array:
                if True:
                    H_i = max(abs(i[0]-x)+abs(i[1]-y)+i[2],0)
                    H.append(H_i)
            Hset = set(H)
            H = list(Hset)[0]
            if(len(Hset)==1 and H>=0):
                t.append([x,y,H])
            
print("{0[0]} {0[1]} {0[2]}".format(t[0]))
N = int(input())
A = list(map(int,input().split()))

nCr = {}
def cmb(n,r):
    if r > n:
        return 0
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n,r) in nCr.keys():
        return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

mem_cnt = {}
set_a = set(A)
for c in list(set_a):
    if str(c) not in mem_cnt.keys():
        mem_cnt[str(c)] = A.count(c)

for k in A:
    ret = 0
    for key,v in mem_cnt.items():
        x = v
        if str(key) == str(k):
            x = v-1
        ret += cmb(x,2)
    print(ret)


### FIXED CODE ###

from collections import Counter

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

cnt = Counter(A)
s = 0
for v in cnt.values():
    s += v*(v-1)//2

for a in A:
    print(s - (cnt[a]-1))
# C - Typical Stairs

MOD = 10 ** 9 + 7
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
dp = [None] * (N + 1)

def f(i):
    if dp[i] != None:
        return dp[i]
    else:
        if i in A:
            dp[i] = 0
        elif i == 1 or i == 0:
            dp[i] = 1
        else:
            dp[i] = (f(i - 1) + f(i - 2)) % MOD
        return dp[i]

print(f(N))


### FIXED CODE ###

# C - Typical Stairs

MOD = (10 ** 9) + 7
N, M = map(int, input().split())
A = [False] * (N + 1)
for _ in range(M):
    A[int(input())] = True
dp = [0] * (N + 1)
dp[0] = 1
if A[1] == False:
    dp[1] = 1

for i in range(2, N + 1):
    if A[i] == True:
        dp[i] = 0
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % MOD

print(dp[N])
s = input()
k = int(s)
n = 3
ans={}
for i in reversed(range(1, k+1)):
    ans[i]=math.floor(k/i)**n
    l=2
    j=i*l
    while j<=k:
        ans[i]=ans[i]-ans[j]
        l +=1
        j = i*l
res=0
for i in ans:
    res+=i*ans[i]
print(res)

### FIXED CODE ###

import math
s = input()
k = int(s)
n = 3
ans={}
for i in reversed(range(1, k+1)):
    ans[i]=math.floor(k/i)**n
    l=2
    j=i*l
    while j<=k:
        ans[i]=ans[i]-ans[j]
        l +=1
        j = i*l
res=0
for i in ans:
    res+=i*ans[i]
print(res)
x = input()
print x * x * x

### FIXED CODE ###

x = (int)(input())
print(x**3)
k, s = map(int, input().split())
ans = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if k >= z >= 0:
            ans += 1
print(ans))

### FIXED CODE ###

k, s = map(int, input().split())
arr = [1 for x in range(k+1) for y in range(k+1) if k >= s-x-y >= 0]
print(sum(arr))
N = int(input())
K = int(input())

if(N==1):
  	print(K)
else:
	answer = K*(N-1)*(K-1)
	print(answer)

### FIXED CODE ###

N,K= map(int,input().split())
if(N==1):
      print(K)
else:
    answer = K*((K-1)**(N-1))
    print(answer)
s=list(input())
t=list(input())
sl=len(s)
tl=len(t)
for i in range(sl-tl,-1,-1):
    j=0
    while j<tl:
        if s[j+1]==t[j] or s[j+i]=="?":
            j+=1
        else:
            break
    if j==tl:
        for i in range(tl):
            s[i+k]=t[k]
        for j in range(sl):
            if s[j]=="?":
                s[j]="a"
        print("".join(s))
        exit()
print("UNRESTORABLE")


### FIXED CODE ###

s=list(input())
t=list(input())
sl=len(s)
tl=len(t)
for k in range(sl-tl,-1,-1):
    judge=True
    for i in range(tl):
        if s[i+k]==t[i] or s[i+k]=="?":
            pass
        else:
            judge=False
            break
    if judge:
        for i in range(tl):
            s[i+k]=t[i]
        for i in range(sl):
            if s[i]=="?":
                s[i]="a"
        print("".join(s))
        exit()
print("UNRESTORABLE")
i = list(map(int, input().split()))
N = i[0]
R = i[1]
 
result = R if N >= 10 : else 100 * (10 - R)
 
print(result)

### FIXED CODE ###

i = list(map(int, input().split()))
N = i[0]
R = i[1]
 
result = R if N >= 10 else R + 100 * (10 - N)
 
print(result)
A,B = map(int, int().split())
C = A + B
if(C >= 10):
    print("error")
else:
    print(C)


### FIXED CODE ###

A,B = map(int, input().split())
C = A + B
if(C >= 10):
    print("error")
else:
    print(C)
import copy
import collections

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

nCr = {}
def cmb(n,r):
    if (n,r) in nCr:
        return nCr[(n,r)]
    if r > n:
        return 0
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

col = collections.Counter(A)
for a in A:
    c = col.copy()
    c[a] = c[a] - 1
    s = 0
    for i in c:
        s += cmb(c[i],2)
    print(s)


### FIXED CODE ###

from collections import Counter

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

cnt = Counter(A)
s = 0
for v in cnt.values():
    s += v*(v-1)//2

for a in A:
    print(s - (cnt[a]-1))
from scipy.misc import comb
 
N = int(input())
s = {}
for _ in range(N):
    b = sorted(input())
    #b.sort()
    #c = ''.join(b)
    if not b in s:
        s[b] = 1
    else:
        s[b] += 1
 
a = [comb(v, 2, exact=True) for v in s.values()]
print(sum(a))

### FIXED CODE ###

import itertools
from math import factorial
from scipy.misc import comb

N = int(input())
s = {}
for _ in range(N):
    b = list(input())
    b.sort()
    c = ''.join(b)
    if not c in s:
        s[c] = 1
    else:
        s[c] += 1

a = [comb(v, 2, exact=True) for v in s.values()]
print(sum(a))
N = int(input())

dic = {}
order = []
for i in range(1,N+1):
    s, p = map(str, input().split())
    p = int(p)
    order.append((s, p))
    if dic.get(s) is None:
        dic[s] = [(i, p)]
    else:
        dic[s].append((i, p))

for k in dic:
    tmp = dic[k][:]
    tmp2 = sorted(tmp, key=lambda x: -x[1])
    dic[k] = tmp2

inds = []
ind = 1
for k in sorted(dic.keys(), key=lambda x: x[1]):
    for t in dic[k]:
        inds.append((t[0], ind))
        ind += 1

for ind in sorted(inds, key=lambda x: x[1]):
    print(ind[0])

### FIXED CODE ###

N = int(input())

dic = {}
for i in range(1, N+1):
    s, p = map(str, input().split())
    p = int(p)
    if dic.get(s) is None:
        dic[s] = [(i, p)]
    else:
        dic[s].append((i, p))

for k in dic:
    tmp = sorted(dic[k][:], key=lambda x: -x[1])
    dic[k] = tmp

inds = []
ind = 1
for k in sorted(dic.keys()):
    for t in dic[k]:
        inds.append((t[0], ind))
        ind += 1

for ind in sorted(inds, key=lambda x: x[1]):
    print(ind[0])
n = int(input())
a = []
for i in range(n):
  x,y,z = map(int,input().split())
  a.append([x+y,x,y,z])
dp = [-1] * 2001
a.sort()
dp[0] = 0
for i in range(n):
  for j in range(2000,-1,-1):
    if dp[j] != -1 and a[i][2]>= j:
      dp[j+a[i][1]] = max(dp[j+a[i][1]],dp[j]+a[i][3])
print(max(dp)) 

### FIXED CODE ###

n = int(input())
a = []
for i in range(n):
  x,y,z = map(int,input().split())
  a.append([x+y,x,y,z])
dp = [-1] * 20001
a.sort()
dp[0] = 0
for i in range(n):
  for j in range(20000,-1,-1):
    if dp[j] != -1 and a[i][2]>= j:
      dp[j+a[i][1]] = max(dp[j+a[i][1]],dp[j]+a[i][3])
print(max(dp))
n = int(input())
import sys
sys.setrecursionlimit(100000)
def fa(n, memo=dict()):
	if n==0 or n == 1:
		return 1
	elif n in memo.keys():
		return memo[n]
	else:
		temp = fa(n-1)*n %int(10**9+7)
		memo[n] = temp
		return temp

print(fa(n))

### FIXED CODE ###

import math
n = int(input())
print(math.factorial(n)%int(10**9+7))
int(input(x))
print(x**3)

### FIXED CODE ###

x=int(input())
print(x*x*x)
l=[[]]*3
for k in range(3):
  l[k]=list(map(int,input().split()))
n=int(input())
ll=[[0,0,0]]*3
for k in range(n):
  i=int(input())
  for j in range(3):
    if i in l[j]:
      ll[j][l.index(i)]=1
a=0
if ll[0][0]==1:
  if ll[0][1]==1 and ll[0][2]==1:
    print("Yes")
    a=1
  elif ll[1][1]==1 and ll[2][2]==1:
    print("Yes")
    a=1
  elif ll[1][0]==1 and ll[2][0]==1:
    print("Yes")
    a=1
elif ll[0][1]==1 and ll[1][1]==1 and ll[2][1]==1:
  print("Yes")
  a=1
elif ll[0][2]==1:
  if ll[1][1]==1 and ll[2][0]==1:
    print("Yes")
    a=1
  elif ll[1][2]==1 and ll[2][2]==1:
    print("Yes")
    a=1
elif ll[1][0]==1:
  if ll[1][1]==1 and ll[1][2]==1:
    print("Yes")
    a=1
elif ll[2][0]==1:
  if ll[2][1]==1 and ll[2][2]==1:
    print("Yes")
    a=1
if a==0:
  print("No")

### FIXED CODE ###

l=[[]]*3
for k in range(3):
  l[k]=list(map(int,input().split()))
n=int(input())
ll=[[0]*3 for i in range(3)]
for k in range(n):
  i=int(input())
  for j in range(3):
    if i in l[j]:
      ll[j][l[j].index(i)]=1
a=0
if ll[0][0]==1:
  if ll[0][1]==1 and ll[0][2]==1:
    a=1
  if ll[1][1]==1 and ll[2][2]==1:
    a=1
  if ll[1][0]==1 and ll[2][0]==1:
    a=1
if ll[0][1]==1 and ll[1][1]==1 and ll[2][1]==1:
  a=1
if ll[0][2]==1:
  if ll[1][1]==1 and ll[2][0]==1:
    a=1
  if ll[1][2]==1 and ll[2][2]==1:
    a=1
if ll[1][0]==1:
  if ll[1][1]==1 and ll[1][2]==1:
    a=1
if ll[2][0]==1:
  if ll[2][1]==1 and ll[2][2]==1:
    a=1
if a==0:
  print("No")
else:
  print("Yes")
n = int(input())
s = [input() for i in range(n)]
ans = ''
for i in range(97,97+26):
    count=float("inf")
    for j in range(n):
        count=min(count,a[j].count(chr(i)))
    ans += chr(i)*count

print(ans)

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]
ans = ''
for i in range(97,97+26):
    count=float("inf")
    for j in range(n):
        count=min(count,s[j].count(chr(i)))
    ans += chr(i)*count

print(ans)
from fractions import gcd
import math
import numpy as np
N = list(map(int, input().split()))
g = gcd(N[0], N[1])
primes = np.ones(g+1)
#print(g+1, primes.shape)
primes[0] = 0
#print(primes)
for i in range(2, int(np.sqrt(g))+1):
  if primes[i] and i * 2 < g + 2:
    primes[i*2::i] = 0
    #print(i, primes)
    
primes = np.arange(g+1)[primes == 1]
#print(primes)

factor = []
for i in primes:
  if g % i == 0:
    g //= i
    factor.append(i)

if g == 1:
  print(len(factor) + 1)
else:
  print(len(factor))


### FIXED CODE ###

from fractions import gcd
import math
import numpy as np
N = list(map(int, input().split()))
g = gcd(N[0], N[1])

def factorize(g):
  factor = []
  for i in range(2, int(np.sqrt(g))+2):
    if g % i != 0:
      continue
    while g % i == 0:
      g //= i
    factor.append(i)
  if g != 1:
    factor.append(g)
  return factor
print(len(factorize(g))+1)
import NumPy
n, m = map(int, raw_input().split())
a = np.array(map(int, raw_input().split()))
for i in xrange(n-1):
	a = np.c_[a, (map(int, raw_input().split()))]
b = np.array(map(int, raw_input().split()))
for i in xrange(m-1):
	b = np.r_[b, (map(int, raw_input().split()))]
for i in xrange(n):
	print b.dot(a)[i]

### FIXED CODE ###

n, m = map(int, raw_input().split())
 
a = [[0]*m for i in xrange(n)]
 
b = [0]*m
 
for i in xrange(n):
    tmp = map(int, raw_input().split())
    for j in xrange(m):
        a[i][j] = tmp[j]
for i in xrange(m):
    b[i] = input()
for i in xrange(n):
    tmp = 0
    for j in xrange(m):
        tmp += a[i][j] * b[j]
    print tmp
a=input()
print(["No", "Yes"][a.count("5"==2 and a.count("7")==1)])

### FIXED CODE ###

abc =input()
five = abc.count("5")
seven = abc.count("7")
 
if five==2 and seven==1:
  print("YES")
else:
  print("NO")
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

t = []
temp = 10 ** 5
for i in range(N):
    t.append(int(T - H[i] * 0.006))
    if abs(t[i] - A) <= temp:
        temp = abs(t[i] - A)

if A < 0:
    print(t.index((temp-A) * -1)+1)
else:
    print(t.index(temp+A)+1)


### FIXED CODE ###

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

ans = []
for i in range(N):
    ans.append(abs(A - (T - H[i] * 0.006)))

print(ans.index(min(ans))+1)
list = []
while True:
    if(int(input()) == 0): break
    else: list.append(int(input()))
    

for i in len(list):
    print("Case %d:%d" %(i,list[i]))


### FIXED CODE ###

list = []
while True:
    a = int(input())
    if(a == 0): break
    else: list.append(a)
    

for i in range(len(list)):
    print("Case %d: %d" %(i+1,list[i]))
a, b = list(map(int, input().split()))
if a == 'H':
  print(b)
elif b == 'H':
  print('D')
else:
  print('H')

### FIXED CODE ###

a, b = input().split()
if a == 'H':
  print(b)
elif b == 'H':
  print('D')
else:
  print('H')
a,b,c =[input(i) for i in input().split()]


total = 0
for d in range(a,b + 1):
    if c % d == 0:
        tptal += 1

print(total)

### FIXED CODE ###

a,b,c = [int(i) for i in input().split()]


total = 0
for d in range(a,b + 1):
    if c % d == 0:
        total += 1

print(total)
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

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
nn = [a, b, c, d, e]
s = False
for i in nn:
    if s == False and i%10 != 0:
        chk = i%10
        last = i
        s = True
    elif s == True and i%10 != 0:
        if chk > i%10:
            chk = i%10
            last = i
#print(last)
s = False
for i in nn:
    if s == False and i == last:
        ans += i
        s = True
    else:
        if i%10 == 0:
            ans += i
        else:
            ans += i + (10 - i%10)
    #print(ans)
print(ans)

### FIXED CODE ###

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

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
nn = [a, b, c, d, e]
s = False
for i in nn:
    if s == False and i%10 != 0:
        chk = i%10
        last = i
        s = True
    elif s == False and i%10 == 0:
        pass
    elif s == True and i%10 != 0:
        if chk > i%10:
            chk = i%10
            last = i
if s == False:
    last = a
#print(last)
s = False
for i in nn:
    if s == False and i == last:
        ans += i
        s = True
    else:
        if i%10 == 0:
            ans += i
        else:
            ans += i + (10 - i%10)
    #print(ans)
print(ans)
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
adj = [set() for _ in range(N)]
colors = dict()
ed = []
for i in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    adj[a].add(b)
    adj[b].add(a)
    colors[a*N + b] = 0
    ed.append([a, b])

col = max(len(v) for v in adj)
cand = set([v for v in range(1, col+1)])

s = -1
for i, a in enumerate(adj):
    if len(a) == col:
        s = i
        break

Q = [[s, -1]]
cnt = 0
while Q and cnt < N-1:
    cur, prev, NG = Q.pop()
    for nex, c in zip(adj[cur]-{prev}, cand-{NG}):
        colors[min(cur, nex)*N + max(cur, nex)] = c
        Q.append([nex, cur, c])
        cnt += 1
print(col)
for a, b in ed:
    print(colors[a*N + b])


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
adj = [set() for _ in range(N)]
colors = dict()
ed = []
for i in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    adj[a].add(b)
    adj[b].add(a)
    ed.append([a, b])

col = max(len(v) for v in adj)

s = -1
for i, a in enumerate(adj):
    if len(a) == col:
        s = i
        break

Q = [[s, -1, -1]]
while Q:
    cur, prev, NG = Q.pop()
    c = 0
    for nex in adj[cur]:
        if nex == prev:
            continue
        else:
            c += 1
        if c == NG:
            c += 1
        colors[min(cur, nex)*N + max(cur, nex)] = c
        Q.append([nex, cur, c])
print(col)
for a, b in ed:
    print(colors[a*N + b])
c = input()
print("A" if c == "T" else "T" if c == "A" else "C" if c == "G" else "G" if c == "G")

### FIXED CODE ###

c = input()
print("A" if c == "T" else "T" if c == "A" else "C" if c == "G" else "G")
n = int(input())
c = [int(input()) for i in range(n)]
num,x = 1,[0]*(n+1)
c.append(0)
x[c[0]]+=1
for i in range(1,n):
    x[c[i]]+=num
    if c[i]-c[i+1]: num = x[c[i]]
    else: num = 0
print(num)

### FIXED CODE ###

n = int(input())
c = [int(input()) for i in range(n)]
num,x = 1,[0]*(200001)
c.append(0)
x[c[0]]+=1
for i in range(1,n):
    if c[i]-c[i-1]: x[c[i]] = (x[c[i]]+num)%(10**9+7)
    if c[i]-c[i+1]: num = x[c[i]]
    else: num = 0
print(num)
N = int(input())
 print((N-1) * N // 2)

### FIXED CODE ###

N = int(input())
print(((N-1)*N)//2)
N, A, B = [int(i) for i in input().split()]

ans = []
for i in range(1,10**18+1):
    ans.append("b"*A)
    ans.append("r"*B)
    if (A+B) * i >= N:
        break
    
ans = "".join(ans)
print(ans[:N].count("b"))

### FIXED CODE ###

N, A, B = [int(i) for i in input().split()]
ans = N // (A + B) * A
r = N % (A + B)
print(ans+min(r, A))
num = int(input())
if num == 2:
	print(2)
    exit()

flag = False
while True:
    for i in range(2, int(num**0.5)+1):
        if num % i ==0:
            flag = False
            break
        else:
            flag = True
    if flag:
        print(num)
        exit()
    else:
        num+=1

### FIXED CODE ###

num = int(input())

flag = False
while True:
    if num == 2:
        print(2)
        exit()
    for i in range(2, int(num**0.5)+1):
        if num % i ==0:
            flag = False
            break
        else:
            flag = True
    if flag:
        print(num)
        exit()
    else:
        num+=1
N = int(input())
ans = 1
for _ in range(N):
	ans *= int(input())
    if ans > 1e18:
    	ans = -1
        break
print(ans)

### FIXED CODE ###

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

if 0 in A:
    print(0)
    exit()

ans = 1
for i in range(N):
    ans *= A[i]
    if ans > 1e18:
        ans = -1
        break
print(ans)
N = input()
 
rN = N[::-1]
if N = rN:
  r = 'Yes'
else:
  r = 'No'

print(r)

### FIXED CODE ###

N = input()

rN = N[::-1]
if N == rN:
  r = 'Yes'
else:
  r = 'No'
 
print(r)