Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = input()
j = 0
for i in range(len(s)):
    #print("i=",i)
    if s[i-(2*j)] == "B":
        #print(i-(2*j))
        #print(s)
        if s[0] == "B":
            s = 'x'+s[1:]
            #print(s)
            #print(s[0])
        else:
            #print(i-(2*j))
            s = s.replace(s[i-1-(2*j)]+s[i-(2*j)],'')
            j += 1
            s += 'xx'
            #print(s)
ans = s.replace('x','')
print(ans)

Fixed submission:
s = input()
j = 0
for i in range(len(s)):
    #print("i=",i)
    if s[i-(2*j)] == "B":
        #print(i-(2*j))
        #print(s)
        if s[0] == "B":
            s = 'x'+s[1:]
            #print(s)
            #print(s[0])
        else:
            #print(i-(2*j))
            s = s[:i-1-(2*j)]+s[i-(2*j)+1:]
            j += 1
            
            #print("s=",s)
            #print(s[:i-1-(2*j)-1])
ans = s.replace('x','')
print(ans)

Buggy python submission (verdict: Runtime Error):
s = input()
j = 0
for i in range(len(s)):
    if s[i-(2*j)] == "B":
        if s[0] == "B":
            s = s.replace(s[0],'')
            s += 'x'
        else:
            s = s.replace(s[i-1-(2*j)]+s[i-(2*j)],'')
            j += 1
            s += 'xx'
            #print(s, i-(2*j))
ans = s.replace('x','')
print(ans)

Fixed submission:
s = input()
j = 0
for i in range(len(s)):
    #print("i=",i)
    if s[i-(2*j)] == "B":
        #print(i-(2*j))
        #print(s)
        if s[0] == "B":
            s = 'x'+s[1:]
            #print(s)
            #print(s[0])
        else:
            #print(i-(2*j))
            s = s[:i-1-(2*j)]+s[i-(2*j)+1:]
            j += 1
            
            #print("s=",s)
            #print(s[:i-1-(2*j)-1])
ans = s.replace('x','')
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

A = input()
B = input()

if A = 1:
    if B = 2:
        print(3)
    else:
        print(2)
elif A = 2:
    if B = 1:
        print(3)
    else:
        print(1)
elif A = 3:
    if B = 1:
        print(2)
    else:
        print(1)


Fixed submission:
import sys

A = input()
B = input()

if A == '1':
    if B == '2':
        print('3')
    else:
        print('2')
elif A == '2':
    if B == '1':
        print('3')
    else:
        print('1')
elif A == '3':
    if B == '1':
        print('2')
    else:
        print('1')

Buggy python submission (verdict: Runtime Error):
A = input()
B = input()

if A = 1:
    if B = 2:
        print(3)
    else:
        print(2)
elif A = 2:
    if B = 1:
        print(3)
    else:
        print(1)
elif A = 3:
    if B = 1:
        print(2)
    else:
        print(1)


Fixed submission:
import sys

A = input()
B = input()

if A == '1':
    if B == '2':
        print('3')
    else:
        print('2')
elif A == '2':
    if B == '1':
        print('3')
    else:
        print('1')
elif A == '3':
    if B == '1':
        print('2')
    else:
        print('1')
Buggy python submission (verdict: Runtime Error):
import sys
a, b = input().split()

A = int(a)
B = int(b)

Adiv = A
Bdiv = B
k = 0




for i in reversed(range(min([A, B]))):
    j = i+1
    if Adiv % j == 0 and Bdiv % j == 0:
        k = j
    else:
        break

res = A * B / k
print(int(res))


Fixed submission:
import sys
a, b = input().split()

A = int(a)
B = int(b)

Adiv = A
Bdiv = B
k = 0




for i in reversed(range(min([A, B]))):
    j = i+1
    if Adiv % j == 0 and Bdiv % j == 0:
        k = j
        break


if k == 0:
    k = 1


res = A * B / k

print(int(res))

Buggy python submission (verdict: Runtime Error):
import sys
a, b = input().split()

A = int(a)
B = int(b)

Adiv = A
Bdiv = B
k = 0

n = int(10000)
primeN = []
for i in range(2, n):
    for j in range(2, i+1):
        if i % j == 0:
            if i == j:
                primeN.append(i)
            else:
                break



for i in range(min([A, B])):
    j = primeN[i]
    if Adiv % j == 0 and Bdiv % j == 0:
        k = j
    else:
        break

res = A * B / k
print(int(res))


Fixed submission:
import sys
a, b = input().split()

A = int(a)
B = int(b)

Adiv = A
Bdiv = B
k = 0




for i in reversed(range(min([A, B]))):
    j = i+1
    if Adiv % j == 0 and Bdiv % j == 0:
        k = j
        break


if k == 0:
    k = 1


res = A * B / k

print(int(res))
Buggy python submission (verdict: Runtime Error):
def main():
    N,K = map(int, input().split())
    S =	input()
    if K == 1:
	print(S[0].lower() + S[1:])
    elif K == N:
	print(S[:N-1] + S[N-1].lower())
    else:
      	print(S[0:K-1] + S[K-1].lower() + S[K:])

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    N,K = map(int, input().split())
    S = input()
    if K == 1:
        print(S[0].lower() + S[1:])
    elif K == N:
        print(S[:N-1] + S[N-1].lower())
    else:
        print(S[0:K-1] + S[K-1].lower() + S[K:])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

def main():
    N,M = list(map(int, input().split()))
    lst = []
    anslst = []
    for i in range(M):
        P,Y = list(map(int, input().split()))
        lst.append({'city_id':i, 'pref':P, 'year':Y})
    lst = sorted(lst, key = itemgetter('year'))
    for i in range(N):
        tmp = [ d for d in lst if d['pref'] == i+1]
        for j in range(len(tmp)):
            city_id = tmp[j]['city_id']
            pref = tmp[j]['pref']
            year = tmp[j]['year']
            id = '{0:06d}'.format(pref) + '{0:06d}'.format(j+1)
            anslst.append({'city_id':city_id, 'pref':pref, 'year':year, 'id':id})
    anslst = sorted(anslst, key = itemgetter('city_id'))
    for i in range(len(anslst)):
        print(anslst[i]['id'])

if __name__ == '__main__':
    main()


Fixed submission:
from operator import itemgetter

def main():
    N,M = list(map(int, input().split()))
    lst = [[] for i in range(N)]
    anslst = []

    for i in range(M):
        P,Y = list(map(int, input().split()))
        lst[P-1].append({'city_id':i, 'pref':P, 'year':Y})

    for i in range(N):
        tmp = lst[i]
        tmp = sorted(tmp, key = itemgetter('year'))
        for j in range(len(tmp)):
            city_id = tmp[j]['city_id']
            pref = tmp[j]['pref']
            year = tmp[j]['year']
            id = '{0:06d}'.format(pref) + '{0:06d}'.format(j+1)
            anslst.append({'city_id':city_id, 'pref':pref, 'year':year, 'id':id})

    anslst = sorted(anslst, key = itemgetter('city_id'))
    for i in range(len(anslst)):
        print(anslst[i]['id'])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import collections
 
def main():
    n = input()
    a = map(int, raw_input().split())
    odd = [a[2 * i] for i in range(n/2)]
    even = [a[2*i + 1] for i in range(n/2)]
    codd = collections.Counter(odd)
    ceven = collections.Counter(even)
    coddmostitem = codd.most_common()[0][0]
    coddmosttimes = codd.most_common()[0][1]
    cevenmostitem = ceven.most_common()[0][0]
    cevenmosttimes = ceven.most_common()[0][1]
    if coddmostitem == cevenmostitem:
        if coddmosttimes >= cevenmosttimes:
            if len(ceven) == 1:
                cevennoreplace = 0
            else:
                cevennoreplace = ceven.most_common()[1][1]
            coddnoreplace = codd.most_common()[0][1]
        if coddmosttimes < cevenmosttimes:
            if len(codd) == 1:
                coddnoreplace = 0
            else:
                coddnoreplace = codd.most_common()[1][1]
            cevennoreplace = ceven.most_common()[0][1]
    else:
        coddnoreplace = codd.most_common()[0][1]
        cevennoreplace = ceven.most_common()[0][1]
    coddreplace = n/2 - coddnoreplace
    cevenreplace = n/2 - cevennoreplace
    print(coddreplace+cevenreplace)
 
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    string = raw_input()
    A = string[0]
    B = string[1]
    C = string[2]
    if A == '1':
        A = '9'
    else:
        A = '1'
    if B == '1':
        B = '9'
    else:
        B = '1'
    if C == '1':
        C = '9'
    else:
        C = '1'        
    print(A+B+C)



if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    N = input()
    if N%10 != 0:
        print(digitSum(N))
    else:
        print(digitSum(N)*10)

def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = input()
    if N%10 != 0:
        print(digitSum(N))
    else:
        print(digitSum(N)*10)

def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
x = input()

while True:
    flg = True
    for i in range(2, x):
        if x % i == 0.0:
            flg = False
            break
    if flg:
        print(x)
        break
    x += 1

Fixed submission:
x = int(input())

while True:
    flg = True
    for i in range(2, x//2+1):
        if x % i == 0.0:
            flg = False
            break
    if flg:
        print(x)
        break
    x += 1
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]

minv = -1
count = 0
s = 0
for i in range(n):
    if a[i] < 0:
        s += -a[i]
        if minv > -a[i] or minv == -1:
            minv = -a[i]
        count += 1
    else:
        s += a[i]
        if minv > a[i] or minv == -1:
            minv = a[i]

print(s)
if count % 2 == 1:
    s += 2*(-minv)

print(s)


Fixed submission:
a,b,t = [int(i) for i in input().split()]

ans = (t + 0.5) // a * b
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    if a < b:
        return gcd(b, a)
    if b == 0:
        return a
    else:
        c = a % b
        return gcd(b, c)

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

g_max = -1
for i in range(n):
    g = -1
    for j in range(n):
        if j == i:
            continue
        if g == -1:
            g = a[j]
        else:
            g = gcd(g, a[j])
    if g > g_max:
        g_max = g

print(g_max)


Fixed submission:
def gcd(a, b):
    if a == 0:
        return b
    if b == 0:
        return a
    if a < b:
        return gcd(b, a)
    if b == 0:
        return a
    else:
        c = a % b
        return gcd(b, c)

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

g_max = -1
l = [0] * n
r = [0] * n
for i in range(n):
    if i == 0:
        l[0] = 0
    else:
        l[i] = gcd(l[i-1], a[i-1])

for i in range(n-1,-1,-1):
    if i == n-1:
        r[i] = 0
    else:
        r[i] = gcd(r[i+1], a[i+1])

g_max = -1
for i in range(n):
    g = gcd(l[i], r[i])
    if g > g_max:
        g_max = g

print(g_max)

Buggy python submission (verdict: Runtime Error):
from math import gcd

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

g_max = 0
for i in range(n-1):
    g = gcd(a[i], a[i+1])
    if g > g_max:
        g_max = g
if n == 3:
    g = gcd(a[0], a[2])
    if g > g_max:
        g_max = g

print(g_max)


Fixed submission:
def gcd(a, b):
    if a == 0:
        return b
    if b == 0:
        return a
    if a < b:
        return gcd(b, a)
    if b == 0:
        return a
    else:
        c = a % b
        return gcd(b, c)

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

g_max = -1
l = [0] * n
r = [0] * n
for i in range(n):
    if i == 0:
        l[0] = 0
    else:
        l[i] = gcd(l[i-1], a[i-1])

for i in range(n-1,-1,-1):
    if i == n-1:
        r[i] = 0
    else:
        r[i] = gcd(r[i+1], a[i+1])

g_max = -1
for i in range(n):
    g = gcd(l[i], r[i])
    if g > g_max:
        g_max = g

print(g_max)
Buggy python submission (verdict: Runtime Error):
def main():
    n = 10**18
    a = 10**18
    b = 10**18
    n, a, b = map(int, input().split())

    if (b-a) % 2 == 1:
        t = min(a-1, n-b)
        if a-1 == t:
            a = 1
            b = b-t
            print(t + 1 + ((b-1)-a)//2)
        else:
            a = a + t
            b = n
            print(t + 1 ((b-1)-a)//2)

    else:
        print((b-a)//2)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = 10**18
    a = 10**18
    b = 10**18
    n, a, b = map(int, input().split())

    if (b - a) % 2 == 1:
        print((b-a)//2 + (b-a) % 2 + min(a-1, n-b))
    else:
        print((b - a) // 2)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    n = 10**18
    a = 10**18
    b = 10**18
    print(n, a, b)
    n, a, b = map(int, input().split())

    if (b-a) % 2 == 1:
        t = min(a-1, n-b)
        if a-1 == t:
            a = 1
            b = b-t
            print(t + 1 + ((b-1)-a)//2)
        else:
            a = a + t
            b = n
            print(t + 1 ((b-1)-a)//2)

    else:
        print((b-a)//2)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = 10**18
    a = 10**18
    b = 10**18
    n, a, b = map(int, input().split())

    if (b - a) % 2 == 1:
        print((b-a)//2 + (b-a) % 2 + min(a-1, n-b))
    else:
        print((b - a) // 2)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    n, a, b = map(int, input().split())

    if (b-a) % 2 == 1:
        t = min(a-1, n-b)
        if a-1 == t:
            a = 1
            b = b-t
            print(t + 1 + ((b-1)-a)//2)
        else:
            a = a + t
            b = n
            print(t + 1 ((b-1)-a)//2)

    else:
        print((b-a)//2)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = 10**18
    a = 10**18
    b = 10**18
    n, a, b = map(int, input().split())

    if (b - a) % 2 == 1:
        print((b-a)//2 + (b-a) % 2 + min(a-1, n-b))
    else:
        print((b - a) // 2)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import math


def main():
    a, b = map(int, input().split())
    ans = round(a * b / math.gcd(a, b))
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def gcd(a, b):
    if a > b:
        a, b = (b, a)
    while b:
        a, b = b, a % b
    return a


def main():
    a, b = map(int, input().split())
    ans = round(a * b / gcd(a, b))
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import math


def main():
    a, b = map(int, input().split())
    ans = "{:.0f}".format(a * b / math.gcd(a, b))
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def gcd(a, b):
    if a > b:
        a, b = (b, a)
    while b:
        a, b = b, a % b
    return a


def main():
    a, b = map(int, input().split())
    ans = round(a * b / gcd(a, b))
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import math


def main():
    a, b = map(int, input().split())
    ans = "{:.0f}".format(a * b / math.gcd(a, b))
    print(ans)


if __name__ == '__main__':
    main()

Fixed submission:
def gcd(a, b):
    if a > b:
        a, b = (b, a)
    while b:
        a, b = b, a % b
    return a


def main():
    a, b = map(int, input().split())
    ans = round(a * b / gcd(a, b))
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    mod = 10 ** 9 + 7

    sum = 0

    for i in range(60):
        count_1 = 0
        for a in a_list:
            bin_a = format(a, "b").zfill(60)
            if bin_a[59-i] == "1":
                count_1 += 1

        sum += 2 ** i * count_1 * (N - count_1)

    print(sum % mod)


if __name__ == '__main__':
    main()

Fixed submission:
def main():
    A1, A2, A3 = map(int, input().split())

    if A1+A2+A3 >= 22:
        print("bust")
    else:
        print("win")


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    S = input()

    code_pattern = set()

    for i in range(0, N):
        for j in range(i + 1, N):
            for k in range(j + 1, N):
                code_pattern.add(S[i]+S[j]+S[k])

    print(len(code_pattern))


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = int(input())
    S = input()

    count = 0

    for i in range(10):
        a = S.find(str(i))
        if a == -1:
            continue

        for j in range(10):
            b = S[a+1:].find(str(j))
            if b == -1:
                continue

            for k in range(10):
                if str(k) in S[a+b+2:]:
                    # print(i*100+j*10+k)
                    count += 1

    print(count)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())
    a_list = list(map(int, input().split()))

    for _ in range(m):
        i = a_list.index(max(a_list))
        a_list[i] = int(a_list[i]/2)

    print(sum(a_list))


if __name__ == '__main__':
    main()


Fixed submission:
import heapq


def main():
    n, m = map(int, input().split())
    a_list = list(map(lambda x: -int(x), input().split()))

    heapq.heapify(a_list)
    for _ in range(m):
        a = heapq.heappop(a_list)
        heapq.heappush(a_list, -(-a // 2))

    print(-sum(a_list))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    n, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    sorted_a_list = sorted(a_list, reverse=True)

    for _ in range(m):
        sorted_a_list[0] = int(sorted_a_list[0]/2)
        if sorted_a_list[0] < sorted_a_list[1]:
            sorted_a_list = sorted(sorted_a_list, reverse=True)

    print(sum(sorted_a_list))


if __name__ == '__main__':
    main()


Fixed submission:
import heapq


def main():
    n, m = map(int, input().split())
    a_list = list(map(lambda x: -int(x), input().split()))

    heapq.heapify(a_list)
    for _ in range(m):
        a = heapq.heappop(a_list)
        heapq.heappush(a_list, -(-a // 2))

    print(-sum(a_list))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    sorted_a_list = sorted(a_list, reverse=True)

    for _ in range(m):
        sorted_a_list[0] = int(sorted_a_list[0]/2)
        sorted_a_list = sorted(sorted_a_list, reverse=True)

    print(sum(sorted_a_list))


if __name__ == '__main__':
    main()


Fixed submission:
import heapq


def main():
    n, m = map(int, input().split())
    a_list = list(map(lambda x: -int(x), input().split()))

    heapq.heapify(a_list)
    for _ in range(m):
        a = heapq.heappop(a_list)
        heapq.heappush(a_list, -(-a // 2))

    print(-sum(a_list))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):

def main():
    n = int(input())
    sum = 0
    for i in range(n):
        sum += i
    print(sum)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())
    print(n*(n-1)//2)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())

    s_list = []
    for i in range(n):
        s = sorted(input())
        s_list.append("".join(s))

    count = 0
    for s in list(set(s_list)):
        i = s_list.count(s)
        if i == 1:
            continue
        else:
            count += i * (i-1) // 2

    print(count)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())

    s_dict = {}
    count = 0
    
    for i in range(n):
        s = sorted(input())
        _s = "".join(s)
        
        if not _s in s_dict:
            s_dict[_s] = 1
        else:
            count += s_dict[_s]
            s_dict[_s] += 1
    print(count)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())

    s_list = []
    for i in range(n):
        s = sorted(input())
        s_list.append("".join(s))

    count = 0
    for i in range(n-1):
        for j in range(i+1, n):
            if s_list[i] == s_list[j]:
                count += 1

    print(count)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())

    s_dict = {}
    count = 0
    
    for i in range(n):
        s = sorted(input())
        _s = "".join(s)
        
        if not _s in s_dict:
            s_dict[_s] = 1
        else:
            count += s_dict[_s]
            s_dict[_s] += 1
    print(count)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from fractions import gcd

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

forward = []
backward = [0 for x in range(n)]

if n == 2:
    print(max(a[0], a[1]))
    exit(0)

for i in range(n):
    if i == 0:
        forward.append(a[i])
    else:
        forward.append(gcd(forward[i - 1], a[i]))


for i in range(n - 1, -1, -1):
    if i == n - 1:
        backward[i] = a[i]
    else:
        backward[i] = gcd(backward[i + 1], a[i])


ans = 1

for i in range(n):
    if i == 0:
        ans = max(ans, backward[1])
    elif i == n - 1:
        ans = max(ans, forward[n - 2])
    else:
        ans = max(ans, gcd(forward[i - 1], backward[i + 1]))

print(ans)

Fixed submission:
from fractions import gcd

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

forward = []
backward = [0 for x in range(n)]

if n == 2:
    print(max(a[0], a[1]))
    exit(0)

for i in range(n):
    if i == 0:
        forward.append(a[i])
    else:
        forward.append(gcd(forward[i - 1], a[i]))


for i in range(n - 1, -1, -1):
    if i == n - 1:
        backward[i] = a[i]
    else:
        backward[i] = gcd(backward[i + 1], a[i])


ans = 1

for i in range(n):
    if i == 0:
        ans = max(ans, backward[1])
    elif i == n - 1:
        ans = max(ans, forward[n - 2])
    else:
        ans = max(ans, gcd(forward[i - 1], backward[i + 1]))

print(ans)
Buggy python submission (verdict: Runtime Error):
from sys import stdin

input = stdin.buffer.readline

n = int(input())
v = [[] for _ in range(n+1)]
edge = [0] * -~n

ans = 0


def dfs(c,fa,x):
    global ans
    color = 1
    for to, eg in v[x]:
        if to == fa:
            continue
        if color == c:
            color += 1
        edge[eg] = color
        ans = max(ans, color)
        dfs(color, x, to)
        color += 1


for i in range(n - 1):
    a, b = map(int, input().split())
    v[a].append([b, i])
    v[b].append([a, i])

dfs(0,0,1)
print(ans)
for i in range(n-1):
    print(edge[i])






Fixed submission:
from sys import stdin

input = stdin.buffer.readline

n = int(input())
v = [[] for _ in range(n+1)]
edge = [0] * -~n

ans = 0


def dfs(c,fa,x):
    global ans
    color = 1
    for to, eg in v[x]:
        if to == fa:
            continue
        if color == c:
            color += 1
        edge[eg] = color
        ans = max(ans, color)
        dfs(color, x, to)
        color += 1


def bfs(x):
    q = [[0,0,x]]
    ans = 0
    while len(q):
        c, fa, now = q.pop()
        color = 1
        for to, eg in v[now]:
            if to == fa:
                continue
            if color == c:
                color += 1
            edge[eg] = color
            q.append([color, now, to])
            ans = max(ans, color)
            color += 1
    return ans


for i in range(n - 1):
    a, b = map(int, input().split())
    v[a].append([b, i])
    v[b].append([a, i])

print(bfs(1))
for i in range(n-1):
    print(edge[i])