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

K, S = map(int, input().split())

ans = 0
for x in range(0, K+1):
    for y in range(x, K+1):
        for z in range(y, K+1):
            if x + y + z == S:
                if len(set([x, y, z])) == 1:
                    ans += 1
                elif len(set([x, y, z])) == 2:
                    ans += 3
                else:
                    ans += 6

print(ans)




### FIXED CODE ###

K, S = map(int, input().split())

ans = 0
for i in range(K+1):
    for j in range(K+1):
        if S - i - j >= 0 and S - i - j <= K:
            ans += 1

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

import sys
import heapq
import copy


def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)


def _heappop_max(heap):
    """Maxheap version of a heappop."""
    lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt


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

sum_h1 = [0] * (N+1)
sum_h2 = [0] * (N+1)

'''
N=2
0 1 2 3 4 5 6
3 1 4 1 5 9
'''

h1 = A[0:N]
h2 = A[N*2:N*3]

heapq.heapify(h1)
heapq._heapify_max(h2)

#print("h1", h1)
#print("h2", h2)
sum_h1[0] = sum(h1)
sum_h2[N] = sum(h2)

for k in range(N):
    #print("A[N+k]", A[N+k])
    #print("k+1", k+1)
    heapq.heappushpop(h1, A[N+k])
    sum_h1[k+1] = sum(h1)

    #print("A[2*N-k-1]", A[2*N-k-1])
    #print("N-k-1", N-k-1)
    _heappush_max(h2, A[2*N-k-1])
    _heappop_max(h2)
    sum_h2[N-k-1] = sum(h2)


mx = None

#print("sum_h1", sum_h1)
#print("sum_h2", sum_h2)

for i in range(N+1):
    a = sum_h1[i] - sum_h2[i]

    if(mx == None or a > mx):
        mx = a

print(mx)

'''
for i in range(N+1):
    h1 = A[0:N+i]
    h2 = A[N+i:N*3]

    heapq.heapify(h1)
    heapq._heapify_max(h2)

    for k in range(N):
        if i <= k:
            _heappop_max(h2)
        else:
            heapq.heappop(h1)

    s = sum(h1) - sum(h2)

    if (mx == None or s > mx):
        mx = s
'''


### FIXED CODE ###

import sys
import heapq
import copy


def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)


def _heappop_max(heap):
    """Maxheap version of a heappop."""
    lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt


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

sum_h1 = [0] * (N+1)
sum_h2 = [0] * (N+1)

'''
N=2
0 1 2 3 4 5 6
3 1 4 1 5 9
'''

h1 = A[0:N]
h2 = A[N*2:N*3]

heapq.heapify(h1)
heapq._heapify_max(h2)

#print("h1", h1)
#print("h2", h2)
sum_h1[0] = sum(h1)
sum_h2[N] = sum(h2)

for k in range(N):
    #print("A[N+k]", A[N+k])
    #print("k+1", k+1)

    sum_h1[k+1] = sum_h1[k]
    sum_h1[k+1] += A[N+k]
    a = heapq.heappushpop(h1, A[N+k])
    sum_h1[k+1] -= a

    #sum_h1[k+1] = sum(h1)

    #print("A[2*N-k-1]", A[2*N-k-1])
    #print("N-k-1", N-k-1)

    sum_h2[N-k-1] = sum_h2[N-k]
    sum_h2[N-k-1] += A[2*N-k-1]
    _heappush_max(h2, A[2*N-k-1])
    sum_h2[N-k-1] -= _heappop_max(h2)

    #sum_h2[N-k-1] = sum(h2)


mx = None

#print("sum_h1", sum_h1)
#print("sum_h2", sum_h2)

for i in range(N+1):
    a = sum_h1[i] - sum_h2[i]

    if(mx == None or a > mx):
        mx = a

print(mx)

'''
for i in range(N+1):
    h1 = A[0:N+i]
    h2 = A[N+i:N*3]

    heapq.heapify(h1)
    heapq._heapify_max(h2)

    for k in range(N):
        if i <= k:
            _heappop_max(h2)
        else:
            heapq.heappop(h1)

    s = sum(h1) - sum(h2)

    if (mx == None or s > mx):
        mx = s
'''
### BUGGY CODE ###

# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array(lr())
A -= np.arange(1, N+1)
answer = 10 ** 15
for i in range(N):
    temp = np.abs(A - A[i]).sum()
    if temp < answer:
        answer = temp

print(answer)


### FIXED CODE ###

import numpy as np
import statistics

N = int(input())
A = np.array(list(map(int, input().split())))
R = np.array([x+1 for x in range(N)])

med = int(np.median((A-R)))
print(abs(A-R-med).sum())
### BUGGY CODE ###

n,m=[int(i) for i in input().split()]
c={}
for _ in range(n):
  a,b=[int(i) for i in input().split()]
  if a in c:
    c[a].append(b)
  else:
    c[a]=[b]
k=0
l=[]
for i in range(m+1):
  if i in c:
    j=sorted(c[i],reverse=True)
    if l:
      if max(j)>max(l):
        k+=max(j)
        if len(j)>1:
          l=l+j[1:]
      else:
        k+=max(l)
        del l[l.index(max(l))]
        l=l+j
    else:
      k+=j[0]
      l=j[1:]
  else:
    if l:
      k+=max(l)
      del l[l.index(max(l))]
  if len(l)>m:
    l=l[:m]
print(k)


### FIXED CODE ###

import heapq
n, m = [int(i) for i in input().split()]
ab = []
for _ in range(n):
    a, b = [int(i) for i in input().split()]
    ab.append([a, -b])
ab.sort()
j = 0
ans=0
h = []
for i in range(1, m + 1):
    while j<n and ab[j][0] <= i:
        heapq.heappush(h, ab[j][1])
        j += 1
    if h:
        ans += heapq.heappop(h)
print(-ans)
### BUGGY CODE ###

#!/usr/bin/env python3

def main():
    n, m = map(int, input().split())
    ab = sorted([list(map(int, input().split())) for i in range(m)])
    ans = "IMPOSSIBLE"
    for i in range(m):
        if ab[i][0] == 1:
            if [ab[i][1], n] in ab[i + 1:]:
                ans = "POSSIBLE"
        else:
            break
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3

def main():
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(m)]
    ans = "IMPOSSIBLE"
    list_1 = []
    list_n = []
    for i in range(m):
        if ab[i][0] == 1:
            list_1.append(ab[i][1])
        elif ab[i][1] == n:
            list_n.append(ab[i][0])
    if len(set(list_1) & set(list_n)) > 0:
        ans = "POSSIBLE"
    print(ans)


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

import sys
def main():
    s=sys.stdin.readline().strip()
    d,c={0:1},0
    for i in range(len(s)):
        k=int(s[-1-i:])%2019
        d[k]=d.get(k,0)+1
    for v in d.values():c+=v*(v-1)//2
    print(c)
if __name__=='__main__':main()

### FIXED CODE ###

import sys
def main():
    s=sys.stdin.readline().strip()
    x=[0 for _ in [0]*2020]
    x[0],c=1,0
    m,d=0,1
    for i in reversed(s):
        m+=(int(i)*d)
        x[m%2019]+=1
        d=(d*10)%2019
    for v in x:c+=v*(v-1)//2
    print(c)
if __name__=='__main__':main()
### BUGGY CODE ###

from itertools import*;input();i=input();l=[]
for r in range(1,len(i)+1):l.extend(combinations(i,r))
print(sum(len(s)==len(set(s))for s in l))

### FIXED CODE ###

from collections import*
n=int(input())
ans=1
for i in Counter(input()).values():
    ans*=(i+1)
print((ans-1)%(10**9+7))
### BUGGY CODE ###

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

b=list()
x=1

for i in range(k):
    x*=a[i]
b.append(x)
for i in range(k, n):
    x/=a[i-k]
    x*=a[i]
    b.append(x)
x=0
for i in b:
    if x==0:
        x=i
    else:
        if x<i:
            x=i
            print("Yes")
        else:
            x=i
            print("No")


### FIXED CODE ###

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

for i in range(k,n):
    if (a[i]/a[i-k])>1:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

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


### FIXED CODE ###

k,s = map(int,input().split())
ans = 0
i = list(range(k+1))

for x in i:
    for y in i:
        z = s-x-y
        if 0 <= z <= k:
            ans += 1
print(ans)
### BUGGY CODE ###

def main():
    import sys 
    input = sys.stdin.readline
    from heapq import heappop,heappush
    from operator import itemgetter
    
    def prim():
        used = [True]*n
        edgelist = []
        for e in edge[0]:
            heappush(edgelist,e)
        used[0] = False
        res = 0
        while len(edgelist) != 0:
            short_edge = heappop(edgelist)
            if not used[short_edge[1]]:
                continue
            v = short_edge[1]
            used[v] = False
            for e in edge[v]:
                if used[e[1]]:
                    heappush(edgelist,e)
            res += short_edge[0]
        return res

    n = int(input())
    A = []
    Aapp = A.append
    for i in range(n):
        x = list(map(int,input().split()))+[i]
        Aapp(x)
    Aapp([-10**12,-10**12,-1])
    Aapp([10**12,10**12,-1])
    X = sorted(A)
    Y = sorted(A,key = itemgetter(1))
    d = []
    dapp = d.append
    for i in range(1,n+1):
        sx = X[i-1][0]
        sy = Y[i-1][1]
        mx = X[i][0]
        my = Y[i][1]
        lx = X[i+1][0]
        ly = Y[i+1][1]
        nsx = X[i-1][2]
        nsy = Y[i-1][2]
        nmx = X[i][2]
        nmy = Y[i][2]
        nlx = X[i+1][2]
        nly = Y[i+1][2]
        i -= 1
        dapp((nsx,nmx,mx-sx))
        dapp((nmx,nlx,lx-mx))
        dapp((nsy,nmy,my-sy))
        dapp((nmy,nly,ly-my))

    edge = [[] for i in range(n)]
    for x,y,z in d:
        if x==-1 or y==-1:
            continue
        edge[x].append([z,y])
        edge[y].append([z,x])

    print(prim()) 

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys 
    input = sys.stdin.readline
    from heapq import heappop,heappush
    from operator import itemgetter
    
    def prim():
        used = [True]*n
        edgelist = []
        for e in edge[0]:
            heappush(edgelist,e)
        used[0] = False
        res = 0
        while len(edgelist) != 0:
            short_edge = heappop(edgelist)
            if not used[short_edge[1]]:
                continue
            v = short_edge[1]
            used[v] = False
            for e in edge[v]:
                if used[e[1]]:
                    heappush(edgelist,e)
            res += short_edge[0]
        return res

    n = int(input())
    A = [list(map(int,input().split()))+[i] for i in range(n)]
    A.append([-10**12,-10**12,-1])
    A.append([10**12,10**12,-1])
    X = sorted(A)
    Y = sorted(A,key = itemgetter(1))
    edge = [[] for i in range(n)]
    for i in range(1,n+1):
        sx = X[i-1][0]
        sy = Y[i-1][1]
        mx = X[i][0]
        my = Y[i][1]
        lx = X[i+1][0]
        ly = Y[i+1][1]
        nsx = X[i-1][2]
        nsy = Y[i-1][2]
        nmx = X[i][2]
        nmy = Y[i][2]
        nlx = X[i+1][2]
        nly = Y[i+1][2]
        edge[nsx].append((mx-sx,nmx))
        edge[nmx].append((mx-sx,nsx))
        edge[nlx].append((lx-mx,nmx))
        edge[nmx].append((lx-mx,nlx))
        edge[nsy].append((my-sy,nmy))
        edge[nmy].append((my-sy,nsy))
        edge[nly].append((ly-my,nmy))
        edge[nmy].append((ly-my,nly))

    print(prim()) 

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

from collections import Counter
def divisor(n):
    i = 1
    l = []
    while i * i <= n:
        if n%i == 0:
            l.append(i)
            l.append(n//i)
        i += 1
    l = list(set(l))
    return l   

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

arr_1=[]
for i in a:
    arr_1.append(divisor(i))

arr_2=sum(arr_1,[])
arr_3=Counter(arr_2)
ans=0
for d,c in arr_3.items():
    if c>=n-1 and d>=ans:
        ans=d
print(ans)

### FIXED CODE ###

from fractions import gcd

n=int(input())
a_1=list(map(int,input().split()))
a_2=list(reversed(a_1))
l=[0]
r=[0]

for i in range(n):
    l.append(gcd(l[i],a_1[i]))  

for i in range(n):    
    r.append(gcd(r[i],a_2[i]))
    
r=list(reversed(r))

m=[]
for i in range(n):
   m.append(gcd(l[i],r[i+1])) 

print(max(m))
### BUGGY CODE ###

M = 10**9+7
N = int(input())
A = list(map(int,input().split()))

maxA = max(A)
K = len(str(bin(maxA)))-2
ans = 0
for k in range(K):
    N1 = 0
    for a in A:
        N1 += int( (a >> k) & 1)
    N0 = N-N1
    ans += (((1<<k)%M) *N0 *N1) % M

ans %= M    
print(int(ans))

### FIXED CODE ###

M = 10**9+7
N = int(input())
A = list(map(int,input().split()))

ans = 0
for k in range(61):
    N1 = 0
    N1 = sum([1 for a in A if ( (a >> k) & 1)])
    ans += (((1<<k)) *(N-N1) *N1)
    ans %= M    

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

n, m = map(int, input().split())
ships = [[int(x) for x in input().split()] for x in range(m)]

judge = False
relay = []
for ship in ships:
    if n in ship:
        judge = True
        relay.append(ship[0])

res = False
if judge is False:
    print("IMPOSSIBLE")
else:
    for i in relay:
        if [1, i] in ships:
            res = True
    print("POSSIBLE" if res else "IMPOSSIBLE")

### FIXED CODE ###

n, m = map(int, input().split())
ships = [[int(x) for x in input().split()] for x in range(m)]

judge = False
relay = []
goal = []

for ship in ships:
    if n in ship:
        goal.append(ship[0])
    elif 1 in ship:
        relay.append(ship[1])

res = False
if len(goal) == 0 or len(relay) == 0:
    print("IMPOSSIBLE")

else:
    print("IMPOSSIBLE" if not set(relay) & set(goal) else "POSSIBLE")
### BUGGY CODE ###

import numpy as np

#input = raw_input
N, M = map(int, input().split(" "))
prices = sorted(map(int, input().split(" ")), reverse=True)


count = 0
cur_prices = []
for i in range(M):
    if i <= N-1:
        cur_prices = cur_prices + [prices[i]]

    max_i = np.argmax(cur_prices)
    cur_prices[max_i] /= 2 
    count += 1

out = int(np.floor(cur_prices).sum()) + sum(prices[i+1:])
print(out)

### FIXED CODE ###

from heapq import heappush, heappop

input = raw_input
N, M = map(int, input().split(" "))

prices = []
for price in map(int, input().split(" ")):
    heappush(prices, -price)


for i in range(M):
    max_p = - (heappop(prices))
    half_p = max_p // 2
    heappush(prices, - half_p)

out = - sum(prices)
print(out)
### BUGGY CODE ###

n = int(input())
a = []
for i in range(n):
    x,m = map(str,input().split())
    if x[0] =='i':a.append(m)
    elif x[0] =='f':
        if m in a:
            print('yes')
        else:
            print('no')
    
    


### FIXED CODE ###

n = int(input())
a = {}
for i in range(n):
    x,m = input().split()
    if x[0] =='i':a[m] = 0
    else:
        if m in a:
            print('yes')
        else:
            print('no')
### BUGGY CODE ###

n = int(input())
Robo = []
for i in range(n):
  x, leng = map(int, input().split())
  Robo.append([x - leng + 1, x + leng - 1])
Robo.sort(key=lambda x: x[1])
#print(Robo)

Robo_r = []
for robo_cand in Robo:
  l, r = robo_cand
  for robo_r in Robo_r:
    if l <= robo_r[1]:
      break
  else:
    Robo_r.append(robo_cand)
print(len(Robo_r))

### FIXED CODE ###

n = int(input())

Robo = []
for i in range(n):
    x, l = map(int, input().split())
    Robo.append([x-l, x+l])
Robo.sort(key=lambda x: x[1])

#print(Robo)
biggest_right = 2 * -10**9 - 1
counter = 0
for left, right in Robo:
    if biggest_right <= left:
        counter += 1
        biggest_right = max(right, biggest_right)
print(counter)
### BUGGY CODE ###

import sys
# sys.stdin = open('input.txt')

from math import gcd


def triple_gcd(x, y, z):
    return gcd(gcd(x, y), z)


k = int(input())
ans = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for k in range(1, k+1):
            ans += triple_gcd(i, j, k)

print(ans)

### FIXED CODE ###

import sys
# sys.stdin = open('input.txt')

from math import gcd


k = int(input())
ans = 0
memory = {}

for i in range(1, k+1):
    for j in range(1, k+1):
        temp = gcd(i, j)
        for k in range(1, k+1):
            ans += gcd(temp, k)

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

N=int(input())
s_list = []
S_list = []
for i in range(N):
  s = str(input())
  if len(s)<=5:
    if not (s in s_list):
      s_list.append(s)
  else:
    if not (s in S_list):
      S_list.append(s)
print(len(s_list)+len(S_list))

### FIXED CODE ###

import numpy as np
N=int(input())
S_list = np.zeros(N)
#S_list = np.zeros(N,dtype=str)
e_list = "abcdefghijklmnopqrstuvwxyz"

for i in range(N):
  s = input()
  n = 0
  for k in range(len(s)):
    n = n + (e_list.index(s[k])+1)*(100**k)
  S_list[i] = n
print(len(np.unique(S_list)))
### BUGGY CODE ###

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

uf=[i for i in range(n+1)]

def uff(x):
    while x!=uf[x]:
        x=uf[x]
    return x

for i in range(m):
    a,b=map(int,input().split())
    ua=uff(a)
    ub=uff(b)
    if ua<ub:
        uf[ub]=ua
    else:
        uf[ua]=ub

cnt=[0 for i in range(n+1)]
for i in range(1,n+1):
    cnt[uff(i)]+=1
print(max(cnt))

### FIXED CODE ###

import sys
class UnionFind:
    def __init__(self, n):
        # 負  : 根であることを示す。絶対値はランクを示す
        # 非負: 根でないことを示す。値は親を示す
        self.table = [-1] * n
 
    def _root(self, x):
        stack = []
        tbl = self.table
        while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x
 
    def find(self, x, y):
        return self._root(x) == self._root(y)
 
    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        # ランクの取得
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2
 
 
if __name__ == '__main__':
    sys.setrecursionlimit(1000000)
    n,m=map(int,sys.stdin.readline().split())
    ins = UnionFind(n+1)
    for i in range(m):
        a,b= map(int, sys.stdin.readline().split())
        ins.union(a,b)
    """
    ins.union(0, 1)
    ins.union(2, 3)
    print(ins.find(0, 3))  # False
    ins.union(1, 2)
    print(ins.find(0, 3))  # True
    """
    cnt=[0 for i in range(n+1)]
    for i in range(1,n+1):
        cnt[ins._root(i)]+=1
    print(max(cnt))
### BUGGY CODE ###

n, k, q = map(int,input().split())
grid = []
for i in range(q):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)

winner = [grid[i][0]-1 for i in range(q)]

point = [k - (q - winner.count(i)) for i in range(n)]

for i in range(n):
    if point[i] > 0:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

from collections import Counter

n, k, q = map(int,input().split())
winner = [int(input()) -1 for i in range(q)]
mycount = Counter(winner)
point = [k - (q - mycount[i])for i in range(n)]

for i in range(n):
    if point[i] > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

def main():
    import sys
    from collections import Counter
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N = int(input())
    A = [int(x) for x in input().strip().split()]
    j_Aj = [j-Aj for j, Aj in enumerate(A, start=1)]
    ans = 0
    for i, a in enumerate(A[:-1], start=1):
        if a > N:
            continue
        api = a + i
        temp = Counter(j_Aj[i:])
        ans += temp[api]

    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    from collections import Counter
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N = int(input())
    A = [int(x) for x in input().strip().split()]
    j_Aj = Counter([j-Aj for j, Aj in enumerate(A, start=1)])
    ans = 0
    for i, a in enumerate(A[:-1], start=1):
        if a > N:
            continue
        ans += j_Aj[a+i]

    print(ans)

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

from operator import mul
from functools import reduce
n = int(input())
a = list(map(int,input().split()))

if 0 in a:
	print(0)
else:
	M = 10**18
	ans = reduce(mul, a)
	if ans > M:
		print(-1)
	else:
		print(ans)


### FIXED CODE ###

n = int(input())
s = sorted(map(int,input().split()))
M = 10 ** 18
ans = 1
for ss in s:
	ans *= ss
	if ans > M:
		ans = -1
		break
	elif ans == 0:
		break
print(ans)
### BUGGY CODE ###

n,k=map(int,input().split())
A=list(map(int,input().split()))
cnt=0
s=1
M=[0]
while cnt<n:
    s=A[s-1]
    if s-1 in M:
        imp=s-1
        break
    M.append(s-1)
    cnt+=1
x=M.index(imp)
y=len(M)-x

if k<=x:
    print(M[k]+1)
else:
    N=M[x:]
    print(N[(k-x)%y]+1)

### FIXED CODE ###

n,k=map(int,input().split())
A=list(map(int,input().split()))
cnt=0
s=1
M=[0]
B=[0]*(n+1)
while cnt<n:
    s=A[s-1]
    if B[s-1]==0:
        B[s-1]+=1
    else:
        imp=s-1
        break
    M.append(s-1)
    cnt+=1
x=M.index(imp)
y=len(M)-x

if k<=x:
    print(M[k]+1)
else:
    N=M[x:]
    print(N[(k-x)%y]+1)
### BUGGY CODE ###

S = str(input())

count = 0
end = False
while not end:
    S2 = S.replace('BW', 'WB', 1)
    count += 1
    if S2 == S:
        count -= 1
        end = True
    S = S2
print(count)

### FIXED CODE ###

S = str(input())

count = 0

now = 0

for s in S:
    if s == 'B':
        now += 1
    else:
        count += now

print(count)
### BUGGY CODE ###

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

cum = [[0]*(N) for i in range(N)]
for i in range(N):
  c = 0
  for j in range(i, N):
    c += A[j]
    cum[i][j] = c

dp = [[0]*N for i in range(N)]

def get_min_cost(i, j):
  global dp
  if dp[i][j] > 0:
    return dp[i][j]
  else:
    min_cost = 0
    for k in range(i, j):
      if min_cost == 0:
        min_cost = get_min_cost(i, k) + get_min_cost(k+1, j) + cum[i][j]
      else:
        cost = get_min_cost(i, k) + get_min_cost(k+1, j) + cum[i][j]
        min_cost = min(min_cost, cost)
    
    dp[i][j] = min_cost
    return dp[i][j]

print(get_min_cost(0, N-1))

### FIXED CODE ###

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

cum = [[0]*(N) for i in range(N)]
for i in range(N):
  c = 0
  for j in range(i, N):
    c += A[j]
    cum[i][j] = c

dp = [[0]*N for i in range(N)]

def get_min_cost(i, j):
  global dp
  if dp[i][j] > 0:
    return dp[i][j]
  else:
    min_cost = 0
    for k in range(i, j):
      if min_cost == 0:
        min_cost = get_min_cost(i, k) + get_min_cost(k+1, j) + cum[i][j]
      else:
        cost = get_min_cost(i, k) + get_min_cost(k+1, j) + cum[i][j]
        min_cost = min(min_cost, cost)
    
    dp[i][j] = min_cost
    return dp[i][j]

print(get_min_cost(0, N-1))
### BUGGY CODE ###

from collections import deque

def bfs(idx,k):
  q = deque()
  visited[idx] = True
  q.append(idx)
  color = 0
  while q:
    r = q.pop()
    ver = graph[r].keys()
    col = graph[r].values()
    for n in set(ver):
      if not visited[n]:
        if color not in set(col):
          graph[r][n] = color
          graph[n][r] = color
          color = (color+1)%k
        else:
          color = (color+1)%k
          graph[r][n] = color
          graph[n][r] = color
          color = (color+1)%k
        visited[n] = True
        q.append(n)

        
N = int(input())
graph = {}
visited = [False]*(N+1)
for i in range(N+1):
  graph[i] = {}
ab = []
for i in range(N-1):
  a,b = map(int,input().split())
  ab.append((a,b))
  graph[a][b] = -1
  graph[b][a] = -1
  
k = max([len(graph[i]) for i in range(1,N+1)])

bfs(1,k)
print(k)
for a,b in ab:
  print(graph[a][b]+1)

  


  


### FIXED CODE ###

from collections import deque

def bfs(idx,k,colored):
  q = deque()
  visited[idx] = True
  q.append(idx)
  while q:
    r = q.pop()
    color = 0
    for n in graph[r].keys():
      if not visited[n]:
        if color == colored[r]: color+=1
        colored[n] = color
        graph[r][n] = color
        graph[n][r] = color
        color += 1

        visited[n] = True
        q.append(n)

        
N = int(input())
graph = {}
colored = [-1]*(N+1)
visited = [False]*(N+1)
for i in range(N+1):
  graph[i] = {}
ab = []
for i in range(N-1):
  a,b = map(int,input().split())
  ab.append((a,b))
  graph[a][b] = -1
  graph[b][a] = -1
  
k = max([len(graph[i]) for i in range(1,N+1)])

bfs(1,k,colored)
print(k)
for a,b in ab:
  print(graph[a][b]+1)