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

n = int(raw_input())

dishes_a = list()
dishes_b = list()
dishes_diff = list()
for i in range(0, n):
    a, b = raw_input().split()
    a = int(a)
    b = int(b)
    diff = b - a
    dishes_a.append(a)
    dishes_b.append(b)
    dishes_diff.append(diff)

takahashi = 0
aoki = 0
index = 0
diff_flag = True

if max(dishes_diff) == 0:
    diff_flag = False

for i in range(0, n):
    if i % 2 == 0:
        if diff_flag and max(dishes_diff) != 0:
            index = dishes_diff.index(max(dishes_diff))
        else:
            diff_flag = False
            index = dishes_a.index(max(dishes_a))

        takahashi = takahashi + dishes_a[index]
        dishes_a.pop(index)
        dishes_b.pop(index)
        dishes_diff.pop(index)
    else:
        index = dishes_b.index(max(dishes_b))
        aoki = aoki + dishes_b[index]
        dishes_a.pop(index)
        dishes_b.pop(index)
        dishes_diff.pop(index)

print(takahashi - aoki)


### FIXED CODE ###

#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
import sys
import math


n = int(input())

dishes = list()

for i in range(0, n):
    a, b = raw_input().split()
    a = int(a)
    b = int(b)
    sum = a + b
    dishes.append([a, b, sum])

takahashi = 0
aoki = 0
dishes.sort(key=lambda x: x[2], reverse=True)

for i in range(0, n):
    if i % 2 == 0:
        j = dishes[0]
        dishes.pop(0)
        takahashi = takahashi + j[0]
    else:
        j = dishes[0]
        dishes.pop(0)
        aoki = aoki + j[1]

print takahashi - aoki
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
CB = []
for _ in range(M):
    b, c = map(int, input().split())
    CB.append((c, b))

# ascend
A.sort()

# descend
CB.sort(reverse=True)

# fill convert ary
conv = []
for cb in CB:
    c, b = cb
    conv.extend([c] * b)

cl = len(conv)

sum = 0
for i in range(N):
    if i >= cl:
        sum += A[i]
    else:
        sum += max(A[i], conv[i])

print(sum)


### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
CB = []
for _ in range(M):
    b, c = map(int, input().split())
    CB.append((c, b))

# ascend
A.sort()

# descend
CB.sort(reverse=True)

# fill convert ary
conv = []
for cb in CB:
    c, b = cb
    conv.extend([c] * b)
    if len(conv) >= N:
        break

cl = len(conv)

sum = 0
for i in range(N):
    if i >= cl:
        sum += A[i]
    else:
        sum += max(A[i], conv[i])

print(sum)
### BUGGY CODE ###

a,b,k=map(int,input().split())
for i in range(a,b+1):
    if i<a+k or b-k<i:
        print(i)


### FIXED CODE ###

a,b,k=map(int,input().split())
al=list(range(a,min(b+1,a+k)))
bl=list(range(max(a,b-k+1),b+1))
l=sorted(set(al+bl))
for v in l:
    print(v)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
import numpy as np
N, K = map(int, raw_input().split())
R = np.array([])
for i in xrange(N):
    ia, ib = map(int, raw_input().split())
    R = np.append(R, np.ones(ib) * ia)

print int(np.sort(R)[K-1])

### FIXED CODE ###

# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N, K = map(int, raw_input().split())
R = [0] * (10**5+10) 

for i in xrange(N):
     ia, ib = map(int, raw_input().split())
     R[ia] += ib

k = 0
c = 0
while k < K:
    c += 1
    k += R[c]
print c
### BUGGY CODE ###

n = int(input())
i = 1
ret = ""
while True:
    x = i
    if  x % 3 == 0:
        ret = " " + str(i)
        i+=1
        if i > n:
            print(ret)
            break
    if x % 10 == 3:
        ret = " " + str(i)
        i+=1
        if i > n:
            print(ret)
            break
    else:
        x /= 10
        if x != 0:
            if x % 10 == 3:
                ret = " " + str(i)
                i+=1
                if i > n:
                    print(ret)
                    break


### FIXED CODE ###

#
# 5d
#

def main():
    n = int(input())
    s = ""
    for i in range(1, n+1):
        x = i
        if x % 3 == 0 or x % 10 == 3:
            s += " " + str(i)
        else:
            x //= 10
            while x:
                if x % 10 == 3:
                    s += " " + str(i)
                    break
                x //= 10
    print(s)


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

from sys import exit
n, m = map(int, input().split())
s = input()

one_sequence = 0
for i in range(1, n):
    if s[i] == "1":
        one_sequence += 1
        if one_sequence == m:
            print(-1)
            exit()
    else:
        one_sequence = 0

pos = n
ans = ""
while pos != 0:
    for i in range(1, m+1)[::-1]:
        if pos-i < 0:
            continue
        if s[pos-i] != "1":
            ans = str(i) + " " + ans
            pos -= i
            break
print(ans.strip())


### FIXED CODE ###

from sys import exit
n, m = map(int, input().split())
s = input()

one_sequence = 0
for i in range(1, n):
    if s[i] == "1":
        one_sequence += 1
        if one_sequence == m:
            print(-1)
            exit()
    else:
        one_sequence = 0

pos = n
ans = ""
while pos != 0:
    for i in range(1, m+1)[::-1]:
        if pos-i < 0:
            continue
        if s[pos-i] != "1":
            ans = str(i) + " " + ans
            pos -= i
            break
print(ans)
### BUGGY CODE ###

N = int(input())
A = [int(x) for x in input().split()]
INF = 10**18
ans = 1
for i in range(N):
    ans *= A[i]
if ans > INF:
    ans = -1
print(ans)

### FIXED CODE ###

N = int(input())
A = [int(x) for x in input().split()]
INF = 10**18
ans = 1
A.sort()
for i in range(N):
    ans *= A[i]
    if ans > INF:
        ans = -1
        break
print(ans)
### BUGGY CODE ###

s = input()
s = s[::-1]
n = len(s)

num = [0]*2019
num[0] = 1
number = 0
d = 1

for i in range(n):
    number += int(s[i])*d
    num[number%2019] += 1
    d *= 10

ans = 0

for i in num:
    ans += i*(i-1)//2

print(ans)

### FIXED CODE ###

s=input()
s=s[::-1]
n=len(s)

count=[0]*2019
count[0]=1
num,d=0,1

for i in s:
  num+=int(i)*d
  num%=2019
  d*=10
  d%=2019
  count[num]+=1

ans=0
for i in count:
  ans+=i*(i-1)//2
  
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n, q = map(int, input().split())
p = []
x = [0] * (n+1)
for _ in range(n-1):
    p.append(list(map(int, input().split())))

for _ in range(q):
    tmp1, tmp2 = map(int, input().split())
    x[tmp1] += tmp2

# 隣接リスト
l = [[] for _ in range(n+1)]
for pi in p:
    l[pi[0]].append(pi[1])
    l[pi[1]].append(pi[0])
p = [0] * (n+1)

import sys
sys.setrecursionlimit(100000)


def dfs(n, v, par):
    p[n] = v
    for chl in l[n]:
        if chl == par:
            continue  # parent
        dfs(chl, v+x[chl], n)
    return

dfs(1, x[1], 0)
print(*p[1:])

### FIXED CODE ###

import sys
input = sys.stdin.readline

n, q = map(int, input().split())
p = []
x = [0] * (n+1)
for _ in range(n-1):
    p.append(list(map(int, input().split())))

for _ in range(q):
    tmp1, tmp2 = map(int, input().split())
    x[tmp1] += tmp2

# 隣接リスト
l = [[] for _ in range(n+1)]
for pi in p:
    l[pi[0]].append(pi[1])
    l[pi[1]].append(pi[0])
p = [0] * (n+1)

import sys
sys.setrecursionlimit(10000000)


def dfs(n, v, par):
    p[n] = v
    for chl in l[n]:
        if chl == par:
            continue  # parent
        dfs(chl, v+x[chl], n)
    return

dfs(1, x[1], 0)
print(*p[1:])
### BUGGY CODE ###

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

sum_num = 0
for i in range(len(nums)):
    for j in range(i+1, len(nums)):
        sum_num += nums[i]*nums[j]
        if sum_num > 10**9 + 7:
            sum_num = sum_num%(10**9+7)
print(sum_num)

### FIXED CODE ###

N = input()
nums = list(map(int, input().split()))
rests = []
rest_sum = 0
for i in reversed(nums):
    rest_sum += i
    rests.append(rest_sum)

sum_num = 0
for i in range(len(nums)-1):
    sum_num += nums[i]*rests[-(i+2)]
    if sum_num > 10**9 + 7:
        sum_num = sum_num % (10**9 + 7)
    

print(sum_num)
### BUGGY CODE ###

from collections import Counter

n = int(input().strip())
L = list(map(int, input().strip().split()))
seen = Counter()
ans=0

for x in L:
    seen[x]+=1

for x in L:
    if seen[x]>1 or x!=1 and 1 in seen:
        continue

    tmp=2
    while tmp**2<=x:
        if x%tmp==0 and (tmp in seen or x/tmp in seen):
            break
        tmp+=1
    else:
        ans+=1

print(ans)

### FIXED CODE ###

def main():
    n = int(input().strip())
    L = list(map(int, input().strip().split()))
    L.sort()
    max_=L[-1]
    isDivisible = [False]*(max_) # 1-Lmax
    
    for i,x in enumerate(L):
        if i!=n-1 and x==L[i+1]:
            isDivisible[x-1]=True
            continue
        j=2*x
        while j<=max_:
            isDivisible[j-1]=True
            j+=x
    ans=0
    for x in L:
        if not isDivisible[x-1]:
            ans+=1
    print(ans)
# print(ans)
    
if '__main__' == __name__:
    main()
### BUGGY CODE ###

N,K = map(int,input().split())
S = []
for _ in range(K):
    l,r = map(int,input().split())
    S+=[i for i in range(l,r+1)]
    S.sort()

dp=[0]*(N+1)
dp[1]=1

for i in range(2,N+1):
    for j in S:
        if i<j:
            break
        else:
            dp[i]+=dp[i-j]
            dp[i]%998244353

#print(S)
#print(dp)
print(dp[-1]%998244353)

### FIXED CODE ###

N,K = map(int,input().split())
S = [tuple(map(int,input().split())) for _ in range(K)]
MOD=998244353
dp=[0]*N
dp[0]=1
for i in range(N-1):
    x = dp[i]
    dp[0]=0
    for k in range(K):
        l,r = S[k]
        if i+l < N:
            dp[i+l]+=x
            dp[i+l]%=MOD
        if i+r+1 < N:
            dp[i+r+1]-=x
            dp[i+r+1]%=MOD
    dp[i+1]+=dp[i]
    dp[i+1]%=MOD
print(dp[-1]%MOD)
### BUGGY CODE ###

# coding: utf-8
# Your code here!

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
 
def lcm(a,b):
    return a*b//gcd(a,b)
     

a,b,c,d=map(int,input().split())
e=lcm(c,d)
a_1=a%e
b_1=b%e
cnt=0
if b-a<=e:
    for i in range(a,b+1):
        if i%c!=0 and i%d!=0:
            cnt+=1
    print(cnt)
    exit()
a_2=a//e
b_2=b//e
if b_2-a_2==1:
    for i in range(a,b+1):
        if i%c!=0 and i%d!=0:
            cnt+=1
    print(cnt)
    exit()
for i in range(0,e):
    if i%c!=0 and i%d!=0:
        cnt+=1

cnt*=b_2-a_2-1

for i in range(a,(a_2+1)*e):
    if i%c!=0 and i%d!=0:
        cnt+=1
for i in range(b_2*e,b+1):
    if i%c!=0 and i%d!=0:
        cnt+=1
print(cnt)

### FIXED CODE ###

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

def lcm(a,b):
    return a*b//gcd(a,b)

a,b,c,d=map(int,input().split())
a-=1
b_1=b//c
b_1+=b//d
b_1-=b//lcm(c,d)
a_1=a//c
a_1+=a//d
a_1-=a//lcm(c,d)
print((b-b_1)-(a-a_1))
### BUGGY CODE ###

k = int(input())
count = 0
num = 1

while count!=k:
    N = str(num)
    check = 0
    for i in range(len(N)-1):
        if abs(int(N[i])-int(N[i+1]))>1:
            check = 1
    if check==0:
        count += 1
    num += 1

print(num-1)


### FIXED CODE ###

import queue
k = int(input())

q = queue.Queue()
num = 0
for i in range(1,10):
    q.put(i)

while num<k:
    i = q.get()
    l = i%10
    if l!=0:
        q.put(i*10+l-1)
    q.put(i*10+l)
    if l!=9:
        q.put(i*10+l+1)
    num += 1

print(i)
### BUGGY CODE ###

s = input()
count = 0
flag = True
while flag == True:
    flag = False
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            s = s[0:i]+s[i+2:]
            count += 2
            flag = True
            break

print(count)

### FIXED CODE ###

s = input()
print(2*min(s.count('0'), s.count('1')))
### BUGGY CODE ###

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
ARC103 D
"""

n = int(input())
xyli = [tuple(map(int,input().split())) for i in range(n)]

m = 20
dli = [1 for i in range(20)]

zli = list(map(lambda t:(t[0]+t[1])%2,xyli))

flag=True
if len(set(zli))>1:
    flag = False


oe = zli[0]



if flag:
    if oe==0:
        print(20)
        print(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
        for j in range(n):
            x,y=xyli.pop(0)
            ans = []
            if x>0:
                ans = ans + ['R' for i in range(abs(x))]
            elif x<0:
                ans = ans + ['L' for i in range(abs(x))]
            if y>0:
                ans = ans + ['U' for i in range(abs(y))]
            elif y<0:
                ans = ans + ['D' for i in range(abs(y))]
            nn = (20-len(ans))//2
            ans = ans+['L' for i in range(nn)]
            ans = ans+['R' for i in range(nn)]
            print(''.join(ans))
    if oe==1:
        print(19)
        print(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
        for j in range(n):
            x,y=xyli.pop(0)
            ans = []
            if x>0:
                ans = ans + ['R' for i in range(abs(x))]
            elif x<0:
                ans = ans + ['L' for i in range(abs(x))]
            if y>0:
                ans = ans + ['U' for i in range(abs(y))]
            elif y<0:
                ans = ans + ['D' for i in range(abs(y))]
            nn = (19-len(ans))//2
            ans = ans+['L' for i in range(nn)]
            ans = ans+['R' for i in range(nn)]
            print(''.join(ans))
else:
    print(-1)

    
            



### FIXED CODE ###

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
ARC103 D
"""

from collections import deque
n = int(input())
xyli = deque([tuple(map(int,input().split())) for i in range(n)])

m = 20
dli = [1 for i in range(20)]

zli = list(map(lambda t:(t[0]+t[1])%2,xyli))

flag=True
if len(set(zli))>1:
    print(-1)
    exit()


oe = zli[0]

ans = []
dli = []
flag =False
if oe == 0:
    xyli = list(map(lambda t:(t[0]+1,t[1]),xyli))
    flag = True

uvli = list(map(lambda t:(t[0]+t[1],t[0]-t[1]),xyli))

def mode(ubin,vbin):
    if ubin and vbin:
        return('R')
    elif (not ubin) and vbin:
        return('D')
    elif ubin and (not vbin):
        return('U')
    else:
        return('L')

if flag:
    print(32)
    print(" ".join(map(str,[1]+[2**(30-i) for i in range(31)])))
else:
    print(31)
    print(" ".join(map(str,[2**(30-i) for i in range(31)])))

for u,v in uvli:
    ubin = format(((2**31-1)+u)//2,'031b')
    vbin = format(((2**31-1)+v)//2,'031b')
    if flag:
        print('L',end='')
    for i in range(31):
        print(mode(int(ubin[i]),int(vbin[i])),end='')
    print()
### BUGGY CODE ###

n = int(input())
listx = [int(input()) for i in range(n)]

listx.sort()
listy=[]
ans=0

x=listx.pop(0)
listy.append(x)
x=listx.pop(-1)
listy.append(x)
ans=ans+int(listy[1])-int(listy[0])

while len(listx)>=1:
    abs1=abs(listx[0]-listy[-1])
    abs2=abs(listx[-1]-listy[0])

    if abs1 < abs2:
        x=listx.pop(-1)
        listy.insert(0,x)
        ans=ans+abs2
    else:
        x=listx.pop(0)
        listy.append(x)
        ans=ans+abs1
    
    if listy[0] > listy[-1]:
        listy.reverse()

print(ans)


### FIXED CODE ###

import itertools
import numpy as np
data_num = int(input()) 
data = [int(input()) for i in range(data_num)] 
#data_num=5
#data=[6,8,1,2,3]

data.sort()
npdata=np.array(data)

parts1=[1]
parts2=[2 for i in range(data_num-2)]
parts1.extend(parts2)
parts1.append(1)
npparts1=np.array(parts1)

parts0=[(-1)**(i+1) for i in range(data_num)]
npparts0=np.array(parts0)

y=npparts1*npparts0

y=y.tolist()
y.sort()

y=np.array(y)
z1=sum(data*y)

parts01=[(-1)**i for i in range(data_num)]
npparts0=np.array(parts01)

y=npparts1*npparts0

y=y.tolist()
y.sort()
y=np.array(y)
z2=sum(data*y)

print(max(z1,z2))
### BUGGY CODE ###

s = list(input())
q = int(input())
for i in range(q):
    query = list(input().split())
    # print(query)
    
    if query[0]=='1':
        s.reverse()
    elif query[0]=='2' and query[1]=='1':
        s.insert(0,query[2])
    elif query[0]=='2' and query[1]=='2':
        s.append(query[2])
[print(a, end='') for a in s]

### FIXED CODE ###

import sys
from collections import deque

s = input()
q = int(input())
ans = deque()
ans.append(s)
reverseFlg = False

for i in range(q):
    query = list(input().split())
    # print(query)

    if query[0]=='1':
        reverseFlg = not reverseFlg
    else:
        if reverseFlg:
            if query[1]=='1':
                ans.append(query[2])
            else:
                ans.appendleft(query[2])
        else:
            if query[1]=='1':
                ans.appendleft(query[2])
            else:
                ans.append(query[2])
    

out = ''.join(ans)

if reverseFlg:
    print(out[::-1])
else:
    print(out)
### BUGGY CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))

inf=float("inf")
dp=[inf]*N
dp[0]=0
 
for i in range(1,N):
	dp[i] = min(
		dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
	)

print(dp[N-1])

### FIXED CODE ###

def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))

	dp=[0]*N
 
	for i in range(1,N):
		dp[i] = min(
			dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
		)
	print(dp[N-1])
main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import collections
N=int(input())
s=['']*N
for i in range(N):
    s[i]=input()
c=list(map(collections.Counter,s))
count=0
for i in range(N):
    count += c[i+1:].count(c[i])
print(count)

### FIXED CODE ###

from collections import Counter
N = int(input())
S = [input() for i in range(N)]
ctr = Counter()
answer = 0
for s in S:
    a = ''.join(sorted(list(s)))
    #print(a)
    if a in ctr:
        answer += ctr[a]
    ctr[a] += 1
print(answer)
### BUGGY CODE ###

from sys import stdin
n,m,k = map(int, stdin.readline().rstrip().split())
a = list(map(int, stdin.readline().rstrip().split()))
b = list(map(int, stdin.readline().rstrip().split()))

A = [0]
B = [0]
ans,res = 0,0
for i in range(0, n):
    A.append(A[i]+a[i])
for i in range(0, m):
    B.append(B[i]+b[i])

def ans(A, B):
    ans= 0
    for i in range(0, n + 1):
        j = m
        if A[i] > k:
            break
        while A[i] + B[j] > k:
            j -= 1
        ans = max(ans, i + j)
    return ans

res = ans(A, B)
print(res)

### FIXED CODE ###

n,m,k=map(int,input().split())

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


a_pre,b_pre=[0],[0]

for i in range(n):
	a_pre.append(a_pre[i]+a[i])

for i in range(m):
	b_pre.append(b_pre[i]+b[i])

ans,j=0,m
for i in range(n+1):
	if a_pre[i]>k:
		break
	while b_pre[j]>k-a_pre[i]:
		j-=1

	ans=max(ans,i+j)

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

n = int(input())
li = [int(i) for i in input().split()]
times = 1

for k in range (0, n):
  times = times * li[k]

if times > 10**18:
  print(-1)
else:
  print(times)

### FIXED CODE ###

n = int(input())
li = [int(i) for i in input().split()]
times = 1

if 0 in li:
    times = 0
    print(0)
else:
    for k in range (0, n):
        times = times * li[k]
        if times > 10**18:
            print(-1)
            break
  
if times <= 10**18 and times != 0:
  print(times)
### BUGGY CODE ###

from sys import stdin
sin = stdin.readline().rstrip()
q = int(stdin.readline().rstrip())
li = [list(stdin.readline().rstrip().split()) for _ in range(q)]
for i in li:
    if i[0] == "1":
        sin = sin[::-1]
    elif i[0] == "2":
        if i[1] == "1":
            sin = i[2] + sin
        else:
            sin += i[2]
print(sin)

### FIXED CODE ###

from sys import stdin
sin = stdin.readline().rstrip()
q = int(stdin.readline().rstrip())
li = [list(stdin.readline().rstrip().split()) for _ in range(q)]
point = 0
omote = ""
ura = ""
for i in li:
    if i[0] == "1":
        point += 1
    elif i[0] == "2":
        if i[1] == "1":
            if point%2 == 0:
                omote += i[2]
            else:
                ura += i[2]
        else:
            if point%2 == 0:
                ura += i[2]
            else:
                omote += i[2]
if point%2 == 0:
    omote = omote[::-1]
    sin = omote + sin + ura
    print(sin)
else:
    sin = sin[::-1]
    ura = ura[::-1]
    sin = ura + sin + omote
    print(sin)
### BUGGY CODE ###

n,a=int(input()),list(map(int,input().split()))
c=[a.count(i+1)for i in range(3)]
x=[1/i for i in range(1,n+1)]
dp=[[[0]*(n+2) for i in range(n+2)]for i in range(n+2)]
for k in range(n+1):
  for j in range(n-k+1):
    for i in range(n-k-j+1):
      if n+1>i+j+k>0:
        dp[i][j][k]=(n+dp[i-1][j][k]*i+dp[i+1][j-1][k]*j+dp[i][j+1][k-1]*k)*x[i+j+k-1]
print(dp[c[0]][c[1]][c[2]])

### FIXED CODE ###

n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])
### BUGGY CODE ###

# 色の最大は辺が一番多い頂点
# 各頂点が現在持ってる色を覚える -> 2次元配列 : color_num = [[]*N]
# 答えを出力するための部分 -> 2次元配列 : ans = [[] * N for _ in range(N)]
# 答えの出し方はN-1ループでa[i], b[i]をansにいれる
def main():
    from collections import deque
    N = int(input())
    graph = {i:[] for i in range(N)}
    A = [0] * (N-1)
    B = [0] * (N-1)
    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append(b)
        graph[b].append(a)
        A[i] = a
        B[i] = b        
        if i == 0:
            start = a

    K = 0
    for some in graph.values():
        K = max(len(some), K)

    # BFSのためのデータ構造
    que = deque()
    dist = [False] * N

    # 初期条件
    que.append(start)
    color_num = {i:{} for i in range(N)}
    dist[start] = True

    # BFS開始
    while que:
        v = que[0]
        que.popleft()
        tmp = 0
        for new_v in graph[v]:
            if dist[new_v]:
                continue
            # 新たな頂点 new_vについて距離情報を更新してキューを追加する
            dist[new_v] = True
            que.append(new_v)
            # 色を塗る
            for k in range(tmp+1, K+1):
                if k in color_num[v].values():
                    continue
                else:
                    color_num[v][new_v] = k
                    color_num[new_v][v] = k
                    tmp = k
                    break
    # 答えの出力
    print(K)
    for i in range(N-1):
        print(color_num[A[i]][B[i]])

if __name__ == "__main__":
    main()

### FIXED CODE ###

#幅優先探索
from collections import deque
d=deque()
e=deque()
import sys
sys.setrecursionlimit(1000000000)
n=int(input())
start_node=0
querie=[]
edge={i:[]for i in range(1,n+1)}
for j in range(n-1):
    a,b=map(int,input().split())
    querie.append((a,b))
    edge[a].append(b)
    edge[b].append(a)
    if j==0:
        start_node=a  

d.append((start_node,0))

#はじめにdequeに入れておいて幅優先探索を行うものを決める。そして、塗り分けの結果はans_dictに保存する
#print(edge) 
ans_dict={i:{}for i in range(1,n+1)}
K=0
for some in edge.values():
    K=max(K,len(some))
    
#幅優先探索に使用する すでに訪れたか確認するためのリスト

visited=[False for i in range(n+1)]
visited[start_node]=True

#使う頂点の数を記録した
#nodeをリスト型にしたリストを返す
#start_nodeを記録しておく
def determine_edge_color(node,color):
    new_color=0
    for some in edge[node]:
        if visited[some]==False:
            visited[some]=True
            new_color+=1
            if new_color==color:
                new_color+=1
                ans_dict[node][some]=new_color
                ans_dict[some][node]=new_color
                e.append((some,new_color))
            else:
                ans_dict[node][some]=new_color
                ans_dict[some][node]=new_color
                e.append((some,new_color))
        else:
            pass
            
while d:
    for some in d:
        if visited[some[0]]==True:
            determine_edge_color(some[0],some[1])
        else:
            determine_edge_color(some[1],some[0])
    d=e
    e=deque()
    
#ans_dictの完成
print(K)
#答えの出力
for item in querie:
    a,b=item[0],item[1]
    print(ans_dict[a][b])