Harryxun/stf_run huggingface dataset:
n=I()
op=[LI() for i in range(n)]
pro=[LI() for i in range(n)]
vals=[]
for j in range(1,2**10):
    ans=0
    common=[0 for i in range(n)]
    for k in range(n):
        for i in range(10):
            x=(j>>i) %2
            common[k]+=x*op[k][i]
        ans+=pro[k][common[k]]
    vals.append(ans)
print(max(vals))

### FIXED CODE ###

# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
op=[LI() for i in range(n)]
pro=[LI() for i in range(n)]
vals=[]
for j in range(1,2**10):
    ans=0
    common=[0 for i in range(n)]
    for k in range(n):
        for i in range(10):
            x=(j>>i) %2
            common[k]+=x*op[k][i]
        ans+=pro[k][common[k]]
    vals.append(ans)
print(max(vals))
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot,
                  log2, pi, radians, sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


def inlist():
    return(list(map(int, input().split())))


def instr():
    s = input()
    return(list(s[:len(s)]))


def invr():
    return(map(int, input().split()))


def def_value():
    return 0


n, m = invr()
res = []
if n == 1:
    res = [0]
elif n == 2:
    res = [1, 0]
elif n == 3:
    res = [1, 0, 0]

f = [0, 0, 0]
out = 1
for _ in range(m):
    si, ci = invr()
    if si == 1 and n > 1 and ci == 0:
        out = -1
        break
    if f[si-1] == 0 or res[si-1] == ci:
        res[si-1] = ci
        f[si-1] = 1
    else:
        out = -1
        break
if out == -1:
    print(-1)

elif res[0] == 0 and len(res) > 1:
    print(-1)
else:
    for i in res:
        print(i, end="")


### FIXED CODE ###

import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (
    acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians,
    sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


def inlist():
    return(list(map(int, input().split())))


def instr():
    s = input()
    return(list(s[:len(s)]))


def invr():
    return(map(int, input().split()))


n, m = invr()
res = []
if n == 1:
    res = [0]
elif n == 2:
    res = [1, 0]
elif n == 3:
    res = [1, 0, 0]

f = [0, 0, 0]
out = 1
for _ in range(m):
    si, ci = invr()
    if si == 1 and n > 1 and ci == 0:
        out = -1
        break
    if f[si-1] == 0 or res[si-1] == ci:
        res[si-1] = ci
        f[si-1] = 1
    else:
        out = -1
        break
if out == -1:
    print(-1)

elif res[0] == 0 and len(res) > 1:
    print(-1)
else:
    for i in res:
        print(i, end="")
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = np.array(A, dtype=np.int64)

lim = 10**18
if len(B[B==0]) >0:
    print(0)
elif N >59:
    print(-1)
else:
    ans = 1
    for i in A:
        ans *= i
        if ans > lim:
            print(-1)
            exit()
    else:
        if ans >10**18:
            print(-1)
        else:
            print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
if 0 in A:
    print(0)
    exit()
lim = 10**18

ans = 1
for i in A:
    ans *= i
    if ans > lim:
        print(-1)
        exit()

else:
    if ans >10**18:
        print(-1)
    else:
        print(ans)
import copy
N, T = map(int, input().split())
ct = {}
for _ in range(N):
  ci, ti = map(int, input().split())
  ct[ci] = ti
  
count = 0
ct2 = copy.deepcopy(ct)
for ci, ti in ct.items():
  if ti > T:
    count += 1
    del ct2[ci]

if count == N:
  print("TLE")
else:
  print(min(ct2.keys()))

### FIXED CODE ###

N, T = map(int, input().split())
c = []
for _ in range(N):
  ci, ti = map(int, input().split())
  if ti <= T:
      c.append(ci)

if len(c) == 0:
  print("TLE")
else:
  print(min(c))
def main():
  N, M = map(int,input().split())
  fromOne = set()
  toM = set()
  for i in range(N):
    a, b = map(int,input().split())
    if a == 1:
      fromOne.add(b)
    elif b == M:
      toM.add(a)
  return 'POSSIBLE' if fromOne & toM else 'IMPOSSIBLE'
print(main())

### FIXED CODE ###

def main():
  N, M = map(int,input().split())
  fromOne = set()
  toM = set()
  for i in range(M):
    a, b = map(int,input().split())
    if a == 1:
      fromOne.add(b)
    elif b == N:
      toM.add(a)
  return 'POSSIBLE' if fromOne & toM else 'IMPOSSIBLE'
print(main())
days, assi = map(int, input().split())
lst = []
for i in range(assi):
    i = int(input())
    lst.append(i)
    tot = sum(lst)
if (days > tot):
    print(days-tot)
elif (days == tot):
    print(days-tot)
else:
    print('-1')


### FIXED CODE ###

days , assi = map(int,input().split())
lst = []
lst = [int(i) for i in input().split()]
tot = sum(lst)
if (tot>days):
    print(-1)
else:
    print(days-tot)
n = int(input())
xl = sorted([list(map(int, input().split())) for i in range(n)])

prev_right = -float("inf")
ans = 0
for i in range(n):
    now_left = xl[i][0] - xl[i][1]
    if prev_right > now_left:
        ans += 1
    else:
        prev_right = xl[i][0] + xl[i][1]

xl = reversed(xl)

prev_right = -float("inf")
ans_ = 0
for i in range(n):
    now_left = xl[i][0] - xl[i][1]
    if prev_right > now_left:
        ans_ += 1
    else:
        prev_right = xl[i][0] + xl[i][1]

print(n - min(ans, ans_))

### FIXED CODE ###

from operator import itemgetter

n = int(input())
xl = []

for i in range(n):
    x, l = map(int, input().split())
    xl.append([x - l, x + l])

xl = sorted(xl, key=itemgetter(1))

ans = 0
m = -float("inf")
for left, right in xl:
    if left < m:
        ans += 1
    else:
        m = max(m, right)

print(n - ans)
import sys
sys.setrecursionlimit(10**6)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(99999)
B.append(99999)
Sum = 0
i = 0
j = 0
while True:
  if A[i] <= B[j] and Sum + A[i] <= K:
    Sum += A[i]
    i += 1
  elif A[i] > B[j] and Sum + B[j] <= K:
    Sum += B[j]
    j += 1
  else:
    break
print(i + j)

### FIXED CODE ###

a = int(input())
ans =(a + a ** 2 + a ** 3) // 1
print(ans)
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
gcd = math.gcd
n = ni()
x = input()
xr = x[::-1]
px = x.count("1")
def solve(t):
    ret = 1 #最初の一回
    while t>0:
        p = bin(t).count("1")
        t %=p
        ret +=1
    return ret
x_tp = 0
x_tm = 0

for i in range(n):
    x_tp = (x_tp + int(xr[i])*pow(2,i,px+1) ) %(px+1) ## 0->1
if px>1:
    for i in range(n):
        x_tm = (x_tm + int(xr[i])*pow(2,i,px-1) ) %(px-1) # 1->0
ans = []

for i in range(n):
    if xr[i] =="0":
        x_tmp = (x_tp + pow(2,i,px+1) ) %(px+1)
    else:#1->0
        x_tmp = (x_tm - pow(2,i,px-1)) %(px-1)
    t = solve(x_tmp)
    ans.append(t)
for i in range(n-1,-1,-1):
    print(ans[i])


### FIXED CODE ###

ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
gcd = math.gcd
n = ni()
x = input()
xr = x[::-1]
px = x.count("1")
def solve(t):
    ret = 1 #最初の一回
    while t>0:
        p = bin(t).count("1")
        t %=p
        ret +=1
    return ret
x_tp = 0
x_tm = 0

for i in range(n):
    x_tp = (x_tp + int(xr[i])*pow(2,i,px+1) ) %(px+1) ## 0->1
if px>1:
    for i in range(n):
        x_tm = (x_tm + int(xr[i])*pow(2,i,px-1) ) %(px-1) # 1->0
ans = []

for i in range(n):
    if xr[i] =="0":
        x_tmp = (x_tp + pow(2,i,px+1) ) %(px+1)
    else:#1->0
        if px==1:
            ans.append(0)
            continue
        x_tmp = (x_tm - pow(2,i,px-1)) %(px-1)
    t = solve(x_tmp)
    ans.append(t)
for i in range(n-1,-1,-1):
    print(ans[i])
import numpy as np
import itertools
H, W, K = map(int, input().split())
L = np.array([list(input()) for i in range(H)])
Ans = 0
for h in range(H):
    for w in range(W):
        if L[h,w] == '.':
            L[h,w] = '0'
        else:
            L[h,w] = '1'
L = L.astype("int64")

def del_w(w):#w列目
    if w != 0:
        for h1 in range(H):
            L1[h1,w-1] =  0   

def del_h(h):#h行目
    if h != 0:
        for w1 in range(W):
            L1[h-1,w1] =  0
            
H_list = []
for h in range(H+1):
    H_list += list(itertools.combinations(range(1,H+1),h))

W_list = []
for w in range(W+1):
    W_list += list(itertools.combinations(range(1,W+1),w))
    
for h_list in H_list:
    for w_list in W_list:
        
        L1 = L.copy()
        
        for w1 in w_list :
            for h in range(H):
                L1[h,w1-1] =  0
                
        for h1 in h_list :
            for w in range(W):
                L1[h1-1,w] =  0 
                
        if np.sum(L1) == K:
            #print(L1,h_list,w_list)
            Ans += 1
            
print(Ans)

### FIXED CODE ###

import numpy as np
import itertools
H, W, K = map(int, input().split())
L = np.array([list(input()) for i in range(H)])
Ans = 0
for h in range(H):
    for w in range(W):
        if L[h,w] == '.':
            L[h,w] = '0'
        else:
            L[h,w] = '1'
L = L.astype("int64")

def del_w(w):#w列目
    if w != 0:
        for h1 in range(H):
            L1[h1,w-1] =  0   

def del_h(h):#h行目
    if h != 0:
        for w1 in range(W):
            L1[h-1,w1] =  0
            
H_list = []
for h in range(H+1):
    H_list += list(itertools.combinations(range(1,H+1),h))

W_list = []
for w in range(W+1):
    W_list += list(itertools.combinations(range(1,W+1),w))
    
for h_list in H_list:
    for w_list in W_list:
        
        L1 = L.copy()
        
        for w1 in w_list :
            for h in range(H):
                L1[h,w1-1] =  0
                
        for h1 in h_list :
            for w in range(W):
                L1[h1-1,w] =  0 
                
        if np.sum(L1) == K:
            #print(L1,h_list,w_list)
            Ans += 1
            
print(Ans)
# 初期入力
N = int(input())
AB = [list(map(int, input().split())) for i in range(N-1)]

#　頂点をキー、つながり先をVALUEの辞書
tunagari ={}
for ab in AB:
    tunagari.setdefault(ab[0], []).append(ab[1])
    tunagari.setdefault(ab[1], []).append(ab[0])

# 　最小の色数（根の辺の数）
color_count = [len(i) for i in tunagari.values() ]
color_max =max(color_count)     
print(color_max) #答え

#
color_set =set("")
#頂点とつながり先をキー、色をValueの辞書
color_ten_ten = {}
from collections import defaultdict
col_sumi= {i:set() for i in tunagari.keys()} # 使った色を覚えておく辞書

for k,v in tunagari.items():
    color_set =set([i for i in range(1,color_max+1) ])
    for ii in v:
        if (col_sumi[k] & color_set) and (k<ii) :
            color_set = color_set - col_sumi[k] # 今の頂点に対して覚えていた色を消す
        if (col_sumi[ii] & color_set) and (k<ii):    
            color_set =color_set - col_sumi[ii] # 先の頂点に対して覚えていた色を消す
        if k<ii:
            xx = color_set.pop() # ポップだから速度のため末尾から消す  
            color_ten_ten.setdefault((k,ii) ,xx)  
        #else:
            #xx = color_set.pop() # ポップだから速度のため末尾から消す  
            #color_ten_ten.setdefault((ii,k) ,xx)  
        col_sumi[k].add(xx) # 元の頂点に対して使った色を覚えておく
        col_sumi[ii].add(xx) # 後の頂点に対して使った色を覚えておく

#AB＝color_ten_tenのキーが同じなら、値の色をprint
for i in AB:
    ab = tuple(i)
    if ab in color_ten_ten.keys() :
        print(color_ten_ten[ab])

### FIXED CODE ###

"""
参考    yy4さん 2019-11-24 21:24:43
516 ms          PyPy3 (2.4.0)
"""
#def solve():
from collections import deque
import sys

input = sys.stdin.readline

n = int(input())

g = tuple(set() for _ in range(n))
for idx in range(n - 1):
    a, b = (int(x) - 1 for x in input().split())
    g[a].add((b, idx))
    g[b].add((a, idx))

q = deque()
q.append((0, -1, -1))

e = [-1] * n  # e[-1]は使わない
used = [False] * n
used[0] = True
while q:
    v, v_idx, prev_color = q.popleft()
    curr = 1 if prev_color != 1 else 2
    for u, u_idx in g[v]:
        if used[u]:
            continue
        used[u] = True
        e[u_idx] = curr
        q.append((u, u_idx, curr))
        curr += 1
        if curr == prev_color:
            curr += 1

ret = e[:-1]
#return len(set(ret)), ret

    
#l, ret = solve()
l=len(set(ret))
print(l)
print(*ret, sep='\n')
L, R = map(int, input().split())

div_l = L//2019
div_r = R//2019
div_ll = L//673
div_rr = R//673

ans = 0
if div_l == div_r and div_ll == dir_rr:
  mod_l = L%2019
  mod_r = R%2019
  ans = mod_l * (mod_l+1)
print(ans)


### FIXED CODE ###

L, R = map(int, input().split())

if R - L >= 2019:
    print(0)
else:
    mod_l = L%2019
    mod_r = R%2019
    ans = 2019
    for i in range(mod_l, mod_r):
        for j in range(i+1, mod_r+1):
            if (i * j)%2019 == 0:
                ans = 0
                break
            ans = min(ans, (i * j)%2019)
        else:
            continue
        break
    print(ans)
s=raw_input()
s=s.split(' ')
maisuu = int(s[0])
maney  = int(s[1])

minn_man = int(maney/10000)+1
minn_sen = int(maney / 1000 )+1
minn_go  = int(maney / 5000) +1
flg=True

for man in range(0,minn_man):
	for go in range(0,minn_go):
		for sen in range(0,minn_sen):
			if man+go+sen == maisuu:
				if man*10000+ go*5000 + sen*1000 == maney:
					if flg:
						break
					print(str(man)+","+str(go)+","+str(sen))
					flg=False
if flg:
	print('-1,-1,-1')


### FIXED CODE ###

s=input()
s=s.split(' ')
maisuu = int(s[0])
maney  = int(s[1])
 
minn_man = int(maney/10000)+1
minn_go  = int(maney / 5000) +1
for man in range(0,minn_man):
	for go in range(0,minn_go):
		# for sen in range(0,minn_sen):
		sen = maisuu - go - man
		if sen>=0:
			if man*10000+ go*5000 + sen*1000 == maney:
				print(str(man)+" "+str(go)+" "+str(sen))
				exit()
print('-1 -1 -1')
n,A,B,C = map(int, input().split())

if n == 2:
  print("No)

### FIXED CODE ###

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    n,A,B,C = map(int, readline().split())
    N = A + B + C
    S = [readline().strip() for _ in range(n)]

    ans = []
    possible = True
    for i, s in enumerate(S):
        if s == "AB":
            if A + B == 0:
                print("No")
                possible = False
                break
            
            if i < n - 1 and N == 2 and A == B == 1:
                if S[i+1] == "AC":
                    A += 1
                    B -= 1
                    ans.append("A")
                elif S[i+1] == "BC":
                    A -= 1
                    B += 1
                    ans.append("B")
                else:
                    A += 1
                    B -= 1
                    ans.append("A")
            else:
                if A < B:
                    A += 1
                    B -= 1
                    ans.append("A")
                else:
                    A -= 1
                    B += 1
                    ans.append("B")

        elif s == "AC":
            if A + C == 0:
                print("No")
                possible = False
                break
            
            if i < n - 1 and N == 2 and A == C == 1:
                if S[i+1] == "AB":
                    A += 1
                    C -= 1
                    ans.append("A")
                elif S[i+1] == "BC":
                    A -= 1
                    C += 1
                    ans.append("C")
                else:
                    A += 1
                    C -= 1
                    ans.append("A")
            else:
                if A < C:
                    A += 1
                    C -= 1
                    ans.append("A")
                else:
                    A -= 1
                    C += 1
                    ans.append("C")

        else:
            if B + C == 0:
                print("No")
                possible = False
                break
            
            if i < n - 1 and N == 2 and B == C == 1:
                if S[i+1] == "AB":
                    B += 1
                    C -= 1
                    ans.append("B")
                elif S[i+1] == "AC":
                    B -= 1
                    C += 1
                    ans.append("C")
                else:
                    B += 1
                    C -= 1
                    ans.append("B")
            else:
                if B < C:
                    B += 1
                    C -= 1
                    ans.append("B")
                else:
                    B -= 1
                    C += 1
                    ans.append("C")

    if possible:
        print("Yes")
        print("\n".join(ans))


if __name__ == "__main__":
    main()
import numpy as np
N=list(map(int,input().split()))
A,B=max(N),min(N)
#ユーグリッド
GCD=1
while True:
    r=A%B
    if r==0:
        GCD=B
        break
    else:
        A=B
        B=r

num_list=np.arange(1,GCD+1)
count=0

#1から調べていき、逐一倍数をリストから消していく
while not list(num_list) == [] :
    num=num_list[0]
    if A%num==0 and B%num==0:
        count+=1
        if num==1:
            num_list=num_list[~(num_list==1)]
        else:
            num_list=num_list[~(num_list % num == 0)]
    else:
        num_list=num_list[~(num_list % num == 0)]
print(count)

### FIXED CODE ###

import numpy as np
N=list(map(int,input().split()))
A,B=max(N),min(N)
#ユーグリッド
GCD=1
while True:
    r=A%B
    if r==0:
        GCD=B
        break
    else:
        A=B
        B=r

if GCD==1:
    print(1)
else:
    def factorization(n):
        arr = []
        temp = n
        for i in range(2, int(-(-n**0.5//1))+1):
            if temp%i==0:
                cnt=0
                while temp%i==0:
                    cnt+=1
                    temp //= i
                arr.append([i, cnt])

        if temp!=1:
            arr.append([temp, 1])

        if arr==[]:
            arr.append([n, 1])

        return arr

    _GCD=factorization(GCD)
    num_list=[1]
    for num in _GCD:
        num_list+=[num[0]]
    #これで素因数分解の加工が完全に完了
    print(len(num_list))
#coding:utf-8
import math
n, k = map(int, input().split())

if n < k:
    print(min(n, k%n))
elif k == 1 or n == 0 or n%k == 0:
    print(0)
elif k % 2 == 0 and n % 2 == 0 and n%k != 0:
    print(n%k)
elif n%k != 0:
    print(min(abs(n%k-k), n%k))


### FIXED CODE ###

#coding:utf-8
import math
n, k = map(int, input().split())

if n < k:
    print(min(n, abs(n-k)))
elif k == 1 or n == 0 or n%k == 0:
    print(0)
elif n%k != 0:
    print(min(abs(n%k-k), n%k))
def count():
    N = int(input())
    A = list(map(int,input().split()))

    for i in range(N):
        print(A.count(i+1))
        A.remove(i+1)
count()

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
Ansbox = [0]*(N+1)

def count(N,A,Ansbox):

    for i in range(N- 1):
        Ansbox[A[i] - 1] += 1
        
    for i in range(N):
        print(Ansbox[i])
        
count(N,A,Ansbox)
n = int(input())

if n >= 1000:
    n = int(str(n[1:]))

if n > 0:
    ans = 1000 - n
else:
    ans = 0

print(ans)

### FIXED CODE ###

n = int(input())

if n >= 1000:
    n = int(str(n)[1:])

if n > 0:
    ans = 1000 - n
else:
    ans = 0

print(ans)
n,k = map(int,input().split())
s = input()
ls = list(s)
ls[k] = ls[k-1].lower()
print("".join(ls))


### FIXED CODE ###

n,k = map(int,input().split())
s = input()
ls = list(s)
ls[k-1] = ls[k-1].lower()
print("".join(ls))
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    def dfs(u, s=0):
        if route[u]:
            if s>score[u]:
                return True
            return False
        route[u]=True
        score[u]=max(score[u],s)
        for v,c in to[u]:
            if dfs(v,s+c):return True
        route[u]=False
        return False

    inf = 10 ** 14
    n, m = MI()
    to = defaultdict(list)
    for _ in range(m):
        a, b, c = MI()
        a, b = a - 1, b - 1
        to[a].append([b, c])
        ot[b].append([a, c])

    score = [-inf] * n
    route=[False]*n
    if dfs(0):
        print("inf")
    else:
        print(score[n-1])

main()


### FIXED CODE ###

import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    inf = 10 ** 14
    n, m = MI()
    ee = []
    # スコアの正負を逆にし、最小値を求める問題に置き換える
    for _ in range(m):
        a, b, c = MI()
        a, b = a - 1, b - 1
        ee.append([a, b, -c])
    # ベルマン・フォードで最小スコアを計算
    # n-1回やっても更新があるということは負の閉路があるということ
    # 負の閉路がなければ答えを出力して終了
    score = [inf] * n
    score[0] = 0
    for _ in range(n):
        change = False
        for a, b, c in ee:
            if score[a] + c < score[b]:
                score[b] = score[a] + c
                change = True
        if not change:
            print(-score[n - 1])
            exit()
    # 負の閉路がある場合は、その影響がゴールまで届くかをチェック
    reachable = [False] * n
    for _ in range(n):
        for a, b, c in ee:
            if reachable[a]:reachable[b]=True
            if score[a] + c < score[b]:
                score[b] = score[a] + c
                reachable[b] = True
        if reachable[n - 1]:
            print("inf")
            exit()
    print(-score[n-1])

main()
from collections import defaultdict

N = int(input())
ab = [tuple(map(int, input().split())) for _ in range(N - 1)]

G = defaultdict(list)

v = [-1 for _ in range(N - 1)]

for i, (a, b) in enumerate(ab):
    G[a].append((b, i))
    G[b].append((a, i))

def check(p, trg, pc):
    # print(p, trg, pc)
    c = 0
    for next_, vi in G[trg]:
        if next_ != p:
            if c == pc:
                c += 1
            check(trg, next_, c)
            v[vi] = c
            c += 1

check(0, 1, -1)
print(len(set(v)))
for c in v:
    print(c + 1)

### FIXED CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)

N = int(input())
ab = [tuple(map(int, input().split())) for _ in range(N - 1)]

G = defaultdict(list)

v = [-1 for _ in range(N - 1)]

for i, (a, b) in enumerate(ab):
    G[a].append((b, i))
    G[b].append((a, i))

def check(p, trg, pc):
    # print(p, trg, pc)
    c = 0
    for next_, vi in G[trg]:
        if next_ != p:
            if c == pc:
                c += 1
            check(trg, next_, c)
            v[vi] = c
            c += 1

check(0, 1, -1)
print(len(set(v)))
for c in v:
    print(c + 1)