Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n,limit=[int(i) for i in input().split()]
baitolist=[[int(i) for i in input().split()] for j in range(n)]
baitodict={}
for i in range(1,limit+1):
    baitodict[str(i)]=[]
for baito in baitolist:
    day=str(baito[0])
    money=baito[1]
    if int(day)<=limit:
        baitodict[day].append(money)
        baitodict[day].sort()
# print(baitodict)

sumnum=0
for i in range(1,limit+1):
    maxindex=""
    maxmoney=0
    for j in range(1,i+1):
        if baitodict[str(j)]!=[]:
            a=baitodict[str(j)][-1]
            if maxmoney<a:
                maxmoney=a
                maxindex=str(j)
    if maxindex!="":
        baitodict[maxindex].pop()
    sumnum+=maxmoney
#     print(sumnum)
print(sumnum)            

### FIXED CODE ###

class Work:
    count=0
    def __init__(self,payday,money):
        Work.count+=1
        self.count=Work.count
        self.payday=payday
        self.money=money
 #moneyが大きい方、同じなら早くもらえる方、それも同じなら最初に書いてある方が強い方
    def __ft__(self,other):
        if self.money>other.money:
            return True
        if self.money==other.money:
            if self.payday<other.payday:
                return True
            if self.payday==other.payday:
                if self.count<other.count:
                    return True
        return False

    def __gt__(self,other):
        if self.money<other.money:
            return True
        if self.money==other.money:
            if self.payday>other.payday:
                return True
            if self.payday==other.payday:
                if self.count>other.count:
                    return True
        return False

#バイトの数、いつまでに稼ぐのか 
n,limit=[int(i) for i in input().split()]

#バイトのリストを作り、クラスを入れる O(n)
baitolist=[]
for i in range(n):
    payday,money=[int(i) for i in input().split()]
    work=Work(payday,money)
    baitolist.append(work)

#日数でランク付け　O(n)
summoney=0    
rank=[[] for i in range(limit+1)]
for baito in baitolist:
    if baito.payday<=limit:
        rank[baito.payday].append(baito)

        
import heapq
accessible=[]
count=1


for i in range(limit):
    for baito in rank[count]:
        heapq.heappush(accessible,baito)
    if accessible!=[]:
        dowork=heapq.heappop(accessible)
        summoney+=dowork.money
    count+=1
    
    
print(summoney)
### BUGGY CODE ###

#At coder 2020/2/9 B

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

ans='YES'
for ii in range(N-1):
    for jj in range(ii+1,N):
        if A[ii]==A[jj]:
            ans='NO'
            break


print(ans)

### FIXED CODE ###

#At coder 2020/2/9 B

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

if len(A)-len(set(A))==0:
    ans='YES'
else:
    ans='NO'
#ans='YES'
#for ii in range(N-1):
#    for jj in range(ii+1,N):
#        if A[ii]==A[jj]:
#            ans='NO'
#            break
#    if ans=='NO':
#        break


print(ans)
### BUGGY CODE ###

import sys
from math import sqrt


def rec(state, v):
    if state == (1 << N) - 1:
        return cakes[v]
    if dp[state][v] != -1:
        return dp[state][v]

    ret = INF
    for i in range(N):
        if not (state >> i & 1):
            ret = min(ret, rec(state | 1 << i, i) + sqrt(pow(cakes[i] + cakes[v], 2) - pow(cakes[i] - cakes[v], 2)))
    dp[state][v] = ret
    return ret


testcases = [[int(x) for x in line.split()] for line in sys.stdin.readlines()]

for testcase in testcases:
    box, *cakes = testcase
    N = len(cakes)
    INF = box + 1
    ans = INF
    for i in range(N):
        dp = [[-1] * N for _ in range(1 << N)]
        ans = min(ans, rec(1 << i, i) + cakes[i])
    print('OK' if ans <= box else 'NA')

### FIXED CODE ###

import sys
from math import sqrt


def rec(state, v):
    if state == (1 << N) - 1:
        return cakes[v]
    if dp[state][v] != -1:
        return dp[state][v]

    ret = INF
    for u in range(N):
        if state == 0:
            ret = min(ret, rec(1 << u, u) + cakes[u])
        elif not (state >> u & 1):
            ret = min(ret, rec(state | 1 << u, u) + sqrt(pow(cakes[u] + cakes[v], 2) - pow(cakes[u] - cakes[v], 2)))
    dp[state][v] = ret
    return ret


testcases = [[int(x) for x in line.split()] for line in sys.stdin.readlines()]

for testcase in testcases:
    box, *cakes = testcase
    N = len(cakes)
    INF = box + 1
    dp = [[-1] * N for _ in range(1 << N)]
    print('OK' if rec(0, 0) <= box else 'NA')
### BUGGY CODE ###

from itertools import combinations
N, K = map(int, input().split())
P = [list(map(int, input().split())) for _ in range(N)]
ans = 1<<62
for t in combinations(P, min(4, K)):
    xs, ys = zip(*t)
    xmin = min(xs)
    xmax = max(xs)
    ymin = min(ys)
    ymax = max(ys)
    area = (xmax-xmin) * (ymax-ymin)
    if ans < area:
        continue
    k = 0
    for x, y in P:
        if xmin <= x <= xmax and ymin <= y <= ymax:
            k += 1
    if k >= K:
        ans = area
print(ans)


### FIXED CODE ###

from itertools import combinations
def main():
    N, K = map(int, input().split())
    P = [list(map(int, input().split())) for _ in range(N)]
    ans = 1<<62
    for t in combinations(P, min(4, K)):
        xs, ys = zip(*t)
        xmin = min(xs)
        xmax = max(xs)
        ymin = min(ys)
        ymax = max(ys)
        area = (xmax-xmin) * (ymax-ymin)
        if ans < area:
            continue
        k = 0
        for x, y in P:
            if xmin <= x <= xmax and ymin <= y <= ymax:
                k += 1
        if k >= K:
            ans = area
    print(ans)

main()
### BUGGY CODE ###

s = input()
tmp = [0]
tmpsc = 1
tmpsum = 0
for i in range(len(s)):
    #print(tmp)
    if s[i] == '<':
        tmp.append(tmp[i] + 1)
        tmpsc = 0
    else:
        tmpsc += 1
        if tmp[i] - 1 < 0:
            # print(tmp)
            tmp.append(0)
            for j in range(tmpsc):
                if tmp[i - j] == tmp[i - j + 1]:
                    tmp[i - j] += 1
                    # print(i-j)
        else:
            tmp.append(0)
            #tmpsc += 1
#print(tmp)
print(sum(tmp))

### FIXED CODE ###

s = input()
arr = [0]
for i in range(len(s)):
  if s[i] == '<':
    arr.append(arr[i]+1)
  else:
    arr.append(0)
#print(len(arr))
for i in reversed(range(len(s))):
  if s[i] == '>':
    arr[i] = max(arr[i],arr[i+1]+1)
print(sum(arr))
### BUGGY CODE ###

N = int(input())
graph = [[] for i in range(N+1)] #graph[0]は使わない
edges = [list(map(int, input().split())) for _ in range(N-1)]

for i in range(N-1):
    a, b = edges[i]
    graph[a].append(b)
    graph[b].append(a)

colors = 1
for g in graph:
    colors = max(colors, len(g))
#colorsの数は決定
print(colors)

used = [set() for i in range(N+1)]
cur = 1

for a, b in edges:
    while cur in used[a] or cur in used[b]:
        cur += 1
        if cur > colors:
            cur = 1
    print(cur)
    used[a].add(cur)
    used[b].add(cur)


### FIXED CODE ###

import sys

stdin = sys.stdin
 
ni = lambda:int(ns())
na = lambda:list(map(int,stdin.readline().split()))
ns = lambda:stdin.readline().rstrip()  # ignore trailing spaces

N = ni()
AB = [na() for _ in range(N-1)]
graph = [[] for _ in range(N+1)]

for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)

root = 1
parent = [0] * (N+1)
order = []
stack = [root]

while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

color = [-1] * (N+1)
for o in order:
    ng = color[o]
    c = 1
    for y in graph[o]:
        if y == parent[o]:
            continue
        if c == ng:
            c += 1
        color[y] = c
        c += 1
answer = []
append = answer.append
for a, b in AB:
    if parent[a] == b:
        append(color[a])
    else:
        append(color[b])
print(max(answer))
print('\n'.join(map(str,answer)))
### BUGGY CODE ###

N=int(input())
A=[int(x) for x in input().split()]
bit= [bin(x ^ y) for x in A for y in A]
B=sorted(set(bit))
AA=[]
for a in A:
  AA.append(bin(a))
if all(a in B for a in AA):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
answer="No"

#文字が全部0
if all(a==0 for a in A):
  answer="Yes"

#0aa0aaという並びに出来る
#0がN/3個,aが2N/3個で数字は二種類
elif len(c)==2 and N%3==0:
  if all(a==0 for a in AA[:third]):
    answer="Yes"
     
#abc,abc...,abcという並びに出来る
#aがN/3個,bがN/3個,cがN/3個で数字は三種類
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if bin(AA[0]^AA[third])==bin(AA[2*third]) and \
    bin(AA[third]^AA[2*third])==bin(AA[0]) and \
    bin(AA[2*third]^AA[0])==bin(AA[third]):
      answer="Yes"
    
print(answer)
### BUGGY CODE ###

def main():
    n, m = map(int, input().split())

    card_list = [0] * n

    for _ in range(m):
        l, r = map(int, input().split())
        for i in range(l-1,r):
            card_list[i] += 1

    print(card_list.count(m))

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n, m = map(int, input().split())

    card_list = [0] * n

    l_list = []
    r_list = []

    for _ in range(m):
        l, r = map(int, input().split())
        l_list.append(l)
        r_list.append(r)

    max_l = max(l_list)
    min_r = min(r_list)

    print(min_r-max_l+1 if min_r >= max_l else 0)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
I = [i for i in range(1,N)]
print(sum(I))


### FIXED CODE ###

N = int(input())

print(N * (N - 1) // 2)
### BUGGY CODE ###

N = int(input())
S = input()
Rindexes = [i for i, x in enumerate(S) if x == 'R']
Gindexes = [i for i, x in enumerate(S) if x == 'G']
Bindexes = [i for i, x in enumerate(S) if x == 'B']
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    if S[i] != S[j]:
      diff_ji = j - i
      if S[i] != 'R' and S[j] != 'R':
        count += len(list(filter(lambda k: j < k and j - i != k - j, Rindexes)))
      elif S[i] != 'G' and S[j] != 'G':
        count += len(list(filter(lambda k: j < k and j - i != k - j, Gindexes)))
      elif S[i] != 'B' and S[j] != 'B':
        count += len(list(filter(lambda k: j < k and j - i != k - j, Bindexes)))
print(count)


### FIXED CODE ###

N = int(input())
S = input()
rcount = 0
gcount = 0
bcount = 0
for i in range(N):
  if S[i] == 'R':
    rcount += 1
  elif S[i] == 'G':
    gcount += 1
  elif S[i] == 'B':
    bcount += 1

total = rcount * gcount * bcount
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j - i
    if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
      count += 1
print(total - count)
### BUGGY CODE ###

from bisect import bisect_right
from math import ceil
N,K=map(int, input().split())
A=list(map(int, input().split()))
if K==0:
    print(max(A))
    exit()

A=sorted(A)
# 最小値で二分探索 してまだ行けるかどうか
# 回数で二分探索
left=0
right=max(A)

ans=float("INF")
pre=ans
flag=False
count=0
while True:
    now=0
    mid=(left+right)/2
    idx=bisect_right(A, mid)
    for i in range(idx, N):
        now+=ceil(A[i]/mid)-1
    if now==K:
        if ans!=float("INF"):
            if ans==ceil(mid):
                flag=True
        ans=min(ans, ceil(mid))
        right=mid
        
        #if flag:
        #    break
        pre=ans
    if now>K:
        left=mid
        pre=mid
    if now<K:
        ans=min(ans, ceil(mid))
        right=mid
        pre=mid
    count+=1
    if count>=10**3:
        break
    


if ans==float("INF"):
    ans=max(A)
print(ceil(ans))


### FIXED CODE ###

from bisect import bisect_right
from math import ceil
N,K=map(int, input().split())
A=list(map(int, input().split()))
if K==0:
    print(max(A))
    exit()

A=sorted(A)
# 最小値で二分探索 してまだ行けるかどうか
# 回数で二分探索
left=0
right=max(A)

ans=float("INF")
pre=ans
flag=False
count=0
while True:
    now=0
    mid=(left+right)/2
    idx=bisect_right(A, mid)
    for i in range(idx, N):
        now+=ceil(A[i]/mid)-1
    if now==K:
        if ans!=float("INF"):
            if ans==ceil(mid):
                flag=True
        ans=min(ans, ceil(mid))
        right=mid
        
        #if flag:
        #    break
        pre=ans
    if now>K:
        left=mid
        pre=mid
    if now<K:
        ans=min(ans, ceil(mid))
        right=mid
        pre=mid
    count+=1
    if count>=10**2:
        break
    


if ans==float("INF"):
    ans=max(A)
print(ceil(ans))
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
wa = 1
ka = 0
for i in range(n):
  wa = wa*a[i]
if(wa>10**18):
  print("-1")
else:
  print(wa)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
wa = 1
ka = 0
if(a.count(0)>=1):
  print(0)
  ka +=1
else:
  for i in range(n):
    wa = wa*a[i]
    if(wa>10**18):
      print("-1")
      ka +=1
      break
if(ka==0):
  print(wa)
### BUGGY CODE ###

N = int(input())
S = []
for i in range(N):
  new = input()
  if not(new in S):
  	S.append(new)
print(len(S))

### FIXED CODE ###

N = int(input())
S = {}
for i in range(N):
  new = input()
  if not(new in S):
    S[new]=1

print(len(S))
### BUGGY CODE ###

import sys
import itertools
input = sys.stdin.readline

def func(l, r):
    num_list = [num for num in range(l, r+1)]
    mod = []
    for i, j in itertools.combinations(num_list, 2):
        mod.append(i*j % 2019)
    print(str(min(mod)))


def main():
    l, r = [int(i) for i in input().split()] 
    func(l, r)
    
# main関数呼び出し
if __name__ == "__main__":
    main() 

### FIXED CODE ###

import sys
import itertools

input = sys.stdin.readline

def func(l, r):
    mod_min = float('inf')

    for i in range(l, r):
        for j in range(i+1, r+1):
            mod = (i*j % 2019)

            if mod == 0:
                print(mod)
                exit()     

            elif mod < mod_min:
                mod_min = mod

    print(mod_min)

def main():
    l, r = [int(i) for i in input().split()] 
    func(l, r)
    
# main関数呼び出し
if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

ans = 0
for x in range(n+1):
    tmp = a*x//b - a*(x//b)
    if tmp > ans:
        ans = tmp

print(ans)


### FIXED CODE ###

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

x = n
if n >= b-1:
    x = b-1

ans = (a*(x%b))//b
print(ans)
### BUGGY CODE ###

N = int(input())
h = [int(x) for x in input().split()]
for i in range(1,N+1):
  print(h.index(i)+1,"",end="")


### FIXED CODE ###

N = int(input())
h = [int(x) for x in input().split()]
t= [0]*N
for i in range(1,N+1):
  t[h[i-1]-1]=i
print(*t)
### BUGGY CODE ###

a, b, q = [int(i) for i in input().split()]
s = [-float('inf')] + [int(input()) for _ in range(a)] + [float('inf')]
t = [-float('inf')] + [int(input()) for _ in range(b)] + [float('inf')]
x = [int(input()) for _ in range(q)]

for xx in x:
  
  low = 0
  high = len(s)-1
  mid = (low+high)//2
  while low<=high:
    tmp = [i-xx for i in s[mid:mid+2]]
    if tmp[0] <= 0 and 0 <= tmp[1]:
      s_l = abs(tmp[0])
      s_r = abs(tmp[1])
      break
    elif tmp[0] > 0:
      high = mid
      mid = (low+high)//2
    else:
      low = mid
      mid = (low+high)//2
      
  low = 0
  high = len(t)-1
  mid = (low+high)//2
  while low<=high:
    tmp = [i-xx for i in t[mid:mid+2]]
    if tmp[0] <= 0 and 0 <= tmp[1]:
      t_l = abs(tmp[0])
      t_r = abs(tmp[1])
      break
    elif tmp[0] > 0:
      high = mid
      mid = (low+high)//2
    else:
      low = mid
      mid = (low+high)//2
  
  #print(s_l,s_r,t_l,t_r)
  
  #l = max(s_l,t_l)
  #r = max(s_r,t_r)
  if s_l <= t_l:
    l = t_l
    lr = s_l*2 + t_r
  else:
    l = s_l
    lr = t_l*2 + s_r
  if s_r <= t_r:
    r = t_r
    rl = s_r*2 + t_l
  else:
    r = s_r
    rl = t_r*2 + s_l
 
  ans = min(l,r,lr,rl)
  print(ans)
  


### FIXED CODE ###

from bisect import bisect

a, b, q = [int(i) for i in input().split()]
s = []
for i in range(a):
	s.append(int(input()))
s = [-float('inf')] + s + [float('inf')]
t = []
for i in range(b):
	t.append(int(input()))
t = [-float('inf')] + t + [float('inf')]
x = []
for i in range(q):
	x.append(int(input()))

for xx in x:
  
  s_i = bisect(s,xx)
  s_r = abs(xx - s[s_i])
  s_l = abs(xx - s[s_i-1])
  t_i = bisect(t,xx)
  t_r = abs(xx - t[t_i])
  t_l = abs(xx - t[t_i-1])

  
  #print(s_l,s_r,t_l,t_r)
  
  #l = max(s_l,t_l)
  #r = max(s_r,t_r)
  if s_l <= t_l:
    l = t_l
    lr = s_l*2 + t_r
  else:
    l = s_l
    lr = t_l*2 + s_r
  if s_r <= t_r:
    r = t_r
    rl = s_r*2 + t_l
  else:
    r = s_r
    rl = t_r*2 + s_l
 
  ans = min(l,r,lr,rl)
  print(ans)
### BUGGY CODE ###

import copy

N = int(input())
a = [int(input()) for i in range(N)]
for i in range(N):
  b = copy.deepcopy(a)
  del b[i]
  print(sorted(b, reverse=True)[0])


### FIXED CODE ###

from heapq import *

N=int(input())
A=[int(input()) for i in range(N)]
h=[]
for i in A:
    heappush(h, -i)
maxh = -heappop(h)
secondh = -heappop(h)
for i in A:
    print(maxh if i != maxh else secondh)
### BUGGY CODE ###

from functools import lru_cache
N,W=map(int,input().split())
weights0,profits0 = [0]*N, [0]*N
for i in range(N):
    weights0[i],profits0[i] = map(int,input().split())
weights0 = tuple(weights0)
profits0 = tuple(profits0)

@lru_cache(None)
def knapsack_recursive(weights, profits, capacity, currentIndex):
    if capacity <= 0 or currentIndex >= len(profits): return 0
    profit = 0
    if weights[currentIndex] <= capacity:
        profit = profits[currentIndex] + knapsack_recursive(weights, profits, capacity - weights[currentIndex], currentIndex + 1)
    tmp = knapsack_recursive(weights, profits, capacity, currentIndex + 1)
    if tmp > profit:
        profit = tmp  
    return profit
  
def main():
    res = knapsack_recursive(weights0, profits0, W, 0)
    print(res)
if __name__ == "__main__":
	main()

### FIXED CODE ###

def main():
  n, w = [int(e) for e in input().split()]
  t = [-1 for i in range(w + 1)]
  t[w] = 0
  for _ in range(n):
    nw, nv = [int(e) for e in input().split()]
    for i in range(nw, w + 1):
      if t[i] == -1:
        continue
      if t[i - nw] < t[i] + nv:
        t[i - nw] = t[i] + nv
  print(max(t))
main()
### BUGGY CODE ###

s = input()
q = int(input())

flg = True

def add(s , query , flg):
    if flg:
        if query[2] == '1':
            s = query[4] + s
        else:
            s = s + query[4]
    else:
        if query[2] == '1':
            s = s + query[4]
        else:
            s = query[4] + s
    return s

for i in range(q):
    query = input()
    if query[0] == '1':
        flg = not flg
    else:
        s = add(s ,query,flg)

if not flg:
    ans = s[::-1]
    print(ans)
else:
    print(s)

### FIXED CODE ###

s = input()
q = int(input())

flg = True

mae = ''
ato = ''

for i in range(q):
    query = input()
    if query[0] == '1':
        flg = not flg
    else:
        if query[2] == '1':
            if flg:
                mae += query[4]
            else:
                ato += query[4]
        else:
            if flg:
                ato += query[4]
            else:
                mae += query[4]

mae = mae[::-1]
ans = mae + s + ato
if not flg:
    ans = ans[::-1]

print(ans)
### BUGGY CODE ###

n = int(input())
nums = list(map(int, input().split()))

kaisu = 0

while True:
  for i in range(n):
    if nums[i] %2 == 0:
      nums[i] = nums[i]/2
      kaisu += 1
    else:
      break

print(kaisu)


### FIXED CODE ###

n = int(input())
nums = [int(i) for i in input().split()]

kaisu = 0

while True:
  if [i for i in nums if i % 2 == 1]:
    break
  nums = [i//2 for i in nums]
  kaisu += 1
print(kaisu)
### BUGGY CODE ###

from collections import deque
import sys
input=sys.stdin.buffer.readline
n,m,k=map(int,input().split())
link=[[] for _ in range(n)]
block=[[]  for _ in range(n)]
ans=[-1]*n
s=[]
for i in range(m):
    a,b=map(int,input().split())
    link[a-1].append(b-1)
    link[b-1].append(a-1)
for i in range(k):
  a,b=map(int,input().split())
  block[a-1].append(b-1)
  block[b-1].append(a-1)
for i in range(n):#スタートの選び方
    u=[0]*n
    q=deque([i])
    while len(q)>0:
        x=q.pop()
        u[x]=1
        ans[i]+=1
        for j in link[x]:
            if u[j]==1:
              continue
            elif j in q:
              continue
            else:
              q.append(j)
    s.append(u)
for i in range(n):
  for j in link[i]:
    if s[i][j]==1:
      ans[i]-=1
  for k in block[i]:
    if s[i][k]==1:
      ans[k]-=1
print(*ans)

### FIXED CODE ###

class UnionFind():
    def __init__(self,n):
      self.n=n
      self.root=[-1]*(n+1)
      self.rank=[0]*(n+1)
      
    def find(self,x):
      if self.root[x]<0:
        return x
      else:
        self.root[x]=self.find(self.root[x])
        return self.root[x]
    
    def unite(self,x,y):
      x=self.find(x)
      y=self.find(y)
      if x==y:
        return 0
      elif self.rank[x]>self.rank[y]:
        self.root[x]+=self.root[y]
        self.root[y]=x
      else:
        self.root[y]+=self.root[x]
        self.root[x]=y
        if self.rank[x]==self.rank[y]:
          self.rank[y]+=1
          
    def Same(self,x,y):
      return self.find(x)==self.find(y)
    
    def size(self,x):
      return -self.root[self.find(x)]
import sys
input=sys.stdin.buffer.readline
n,m,k=map(int,input().split())
link=UnionFind(n)
f=[0]*n
block=[[] for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    link.unite(a,b)
    f[a]+=1
    f[b]+=1
for _ in range(k):
    a,b=map(int,input().split())
    block[a-1].append(b-1)
    block[b-1].append(a-1)
ans=[]
for i in range(n):
  ret=link.size(i)-f[i]-1
  for j in block[i]:
    if link.Same(i,j):
      ret-=1
  ans.append(ret)
print(*ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

K = int(input())

N = 50
As = [N-1 for _ in range(N)]
ind = 0

for k in range(K):
    for i in range(N):
        As[i] -= 1
    As[ind] += N + 1
    ind += 1
    ind = ind % N
print(N)
print(*As)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import math
K = int(input())

N = 50
As = [N-1 for _ in range(N)]
ind = 0

modk = K % 50
L = K // 50
base = 49 + L - modk

ans = []

if modk != 0:
    for i in range(N):
        if i >= N - modk:
            ans.append(base + N + 1)
        else:
            ans.append(base)
    # for i in range(0,modk,1):
    #     ans.append(base + N + 1)
    # for i in range(modk,N,1):
    #     ans.append(base)
else:
    for i in range(N):
        ans.append(49 + L)
# for k in range(K):
#     for i in range(N):
#         As[i] -= 1
#     As[ind] += N + 1
#     ind += 1
#     ind = ind % N
# print(N)
# print(*As)
print(N)
print(*ans)
### BUGGY CODE ###

N=int(input())
G=[[] for i in range(N)]
a=[]
b=[]

for i in range(N-1):
    ai,bi=map(int,input().split())
    a.append(ai-1)
    b.append(bi-1)
    G[ai-1].append(bi-1)
    G[bi-1].append(ai-1)

k=[0]*N

from collections import deque

q=deque([0])
C=[[-1]*N for i in range(N)]
p=[-1]*N

kmx=0
while q:
    x=q.popleft()
    for i in G[x]:
        if C[x][i]!=-1:continue
        if p[x]==k[x]:
            k[x]+=1

        C[x][i] = k[x]
        C[i][x] = k[x]
        p[i] = k[x]
        k[x] += 1
        kmx=max(kmx,k[x])
        q.append(i)

print(kmx)
for i in range(N-1):
    print(C[a[i]][b[i]]+1)




### FIXED CODE ###

N=int(input())
G=[[] for i in range(N)]
a=[]
b=[]

for i in range(N-1):
    ai,bi=map(int,input().split())
    a.append(ai-1)
    b.append(bi-1)
    G[ai-1].append(bi-1)
    G[bi-1].append(ai-1)

k=[0]*N

from collections import deque

q=deque([0])
visited=[0]*N
ans={}
p=[-1]*N

kmx=0
while q:
    x=q.popleft()
    visited[x]=1
    cnt=1
    for i in G[x]:
        if visited[i]!=0:continue
        if p[x]==cnt:
            cnt+=1
        ans[(x,i)]=cnt
        ans[(i,x)]=cnt

        p[i] = cnt
        cnt += 1
        kmx=max(kmx,cnt-1)
        q.append(i)

print(kmx)
for i in range(N-1):
    print(ans[(a[i],b[i])])