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

import sys
from collections import namedtuple

INF = sys.maxsize

Item = namedtuple('Item', 'w v')

N, W = map(int, input().split())

items = []

for _ in range(N):
  w, v = map(int, input().split())
  items.append(Item(w, v))
  
memo = [0] + [INF] * 100000
  
for item in items:
  for v in range(100000, item.v - 1, -1):
    memo[v] = min(memo[v], memo[v - item.v] + item.w)

print(max([v for v, w in enumerate(memo) if w <= W]))

### FIXED CODE ###

import sys
from collections import namedtuple

INF = sys.maxsize

Item = namedtuple('Item', 'w v')

N, W = map(int, input().split())

items = []

for _ in range(N):
  w, v = map(int, input().split())
  items.append(Item(w, v))
  
memo = [0] + [INF] * 100000
  
for item in items:
  for v in range(100000, item.v - 1, -1):
    memo[v] = min(memo[v], memo[v - item.v] + item.w)

print(max([v for v, w in enumerate(memo) if w <= W]))
### BUGGY CODE ###

from collections import deque

N = int(input())
T = [ [] for _ in range(N) ]
ans = []
for i in range(N-1):
    a,b = map(int,input().split())
    T[a-1].append(b-1)
    T[b-1].append(a-1)
    ans.append([a-1,b-1])


color = [ [0]*N for _ in range(N)]
total = 0
q = deque()
q.append(0)

while(len(q) > 0):
    k = 0
    c = 1
    r = q.popleft()
    m = min(T[r])
    if r > m:
        k = color[r][m]
        T[r].remove(m)
    for j in T[r]:
        if c != k:
            color[r][j] = c
            color[j][r] = c
        else:
            c += 1
            color[r][j] = c
            color[j][r] = c
        c += 1
        q.append(j)
    total = max(total,c-1)

print(total)
for pair in ans:
    print(color[pair[0]][pair[1]])

### FIXED CODE ###

from collections import deque

N = int(input())
T = [ [] for _ in range(N) ]
ans = []
for i in range(N-1):
    a,b = map(int,input().split())
    T[a-1].append(b-1)
    T[b-1].append(a-1)
    ans.append((a-1,b-1))


used = [0]*N
used[0] = 1
a = dict()
parent = [0]*N
total = 0
q = deque()
q.append(0)

while(len(q) > 0):
    c = 1
    r = q.popleft()
    for j in T[r]:
        if used[j] == 0:
            used[j] = 1
            if c == parent[r]:
                c += 1
            a[(r,j)] = c
            parent[j] = c
            c += 1
            q.append(j)
    total = max(total,c-1)


print(total)
for pair in ans:
    print(a[pair])
### BUGGY CODE ###

import numpy as np


def solve():
    H, W = map(int, input().split())
    maze = [[] for _ in range(H)]
    for i in range(H):
        maze[i] = list(input())

    u = [[0 for _ in range(W)] for _ in range(H)]
    r = [[0 for _ in range(W)] for _ in range(H)]
    d = [[0 for _ in range(W)] for _ in range(H)]
    l = [[0 for _ in range(W)] for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if maze[i][j] == '#':
                continue
            if i == 0:
                u[i][j] = 1
            else:
                u[i][j] = u[i-1][j] + 1
            if j == 0:
                l[i][j] = 1
            else:
                l[i][j] = l[i][j-1] + 1
    for i in range(H-1, -1, -1):
        for j in range(W-1, -1, -1):
            if maze[i][j] == '#':
                continue
            if i == H - 1:
                d[i][j] = 1
            else:
                d[i][j] = d[i+1][j] + 1
            if j == W - 1:
                r[i][j] = 1
            else:
                r[i][j] = r[i][j+1] + 1

    num_sum = np.zeros(H*W, int).reshape(H, W)
    for i in range(H):
        for j in range(W):
            num_sum[i][j] = u[i][j] + r[i][j] + d[i][j] + l[i][j] - 3
    print(num_sum.max())


if __name__ == '__main__':
    solve()


### FIXED CODE ###

def solve():
    H, W = map(int, input().split())
    maze = [[] for _ in range(H)]
    for i in range(H):
        maze[i] = list(input())

    u = [[0 for _ in range(W)] for _ in range(H)]
    r = [[0 for _ in range(W)] for _ in range(H)]
    d = [[0 for _ in range(W)] for _ in range(H)]
    l = [[0 for _ in range(W)] for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if maze[i][j] == '#':
                continue
            if i == 0:
                u[i][j] = 1
            else:
                u[i][j] = u[i-1][j] + 1
            if j == 0:
                l[i][j] = 1
            else:
                l[i][j] = l[i][j-1] + 1
    for i in range(H-1, -1, -1):
        for j in range(W-1, -1, -1):
            if maze[i][j] == '#':
                continue
            if i == H - 1:
                d[i][j] = 1
            else:
                d[i][j] = d[i+1][j] + 1
            if j == W - 1:
                r[i][j] = 1
            else:
                r[i][j] = r[i][j+1] + 1

    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, u[i][j] + r[i][j] + d[i][j] + l[i][j] - 3)
    print(ans)


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

N, K = map(int, input().split())
p = [(int(x)+1)/2 for x in input().split()]

result = []
for i in range(N-K+1):
    total = 0
    for j in range(K):
        total += p[i+j]
    result.append(total)
print(max(result))


### FIXED CODE ###

N, K = map(int, input().split())
p = [(int(x)+1)/2 for x in input().split()]

result = []
sub_total = sum(p[0:K])
result.append(sub_total)

for i in range(1, N-K+1):
    sub_total = sub_total - p[i-1] + p[i+K-1]
    result.append(sub_total)

print(max(result))
### BUGGY CODE ###

import numpy as np
 
N = int(input())
A = np.array(list(map(int, input().split())))
 
A = A % (1000000000+7)
_sum = 0
 
for n in range(N-1):
  for i in range(n+1):
    _sum = _sum + (A[n+1] * A[i])
    _sum = _sum % (1000000000+7)
    
print(_sum)

### FIXED CODE ###

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

#累積和
S = [0]*N
for n in range(N):
  S[n] = S[n-1] + A[n]

_sum = int(0)
for i in range(N-1):
  _sum = _sum + (A[i] * (S[-1] - S[i]))

#modulo
_sum = _sum % (1000000000+7)
  
print(_sum)
### BUGGY CODE ###

from bisect import bisect_left
def main():
    n, w = map(int, input().split())
    item = [list(map(int, input().split())) for _ in range(n)]
    dp = [0]*(w+1)
    item.sort()
    x = 0
    for i in range(n):
        for j in reversed(range(item[i][0], min(w+1, x+item[i][0]+1))):
            dp[j] = max(dp[j-item[i][0]]+item[i][1], dp[j])
        x += item[i][0]
    print(max(dp))

if __name__ == "__main__":
    main()


### FIXED CODE ###

from bisect import bisect_left
def main():
    n, w = map(int, input().split())
    item = [list(map(int, input().split())) for _ in range(n)]
    dp = [0]*(w+1)
    item.sort()
    x = 0
    for p, q in item:
        for j in reversed(range(p, min(w+1, x+p+1))):
            dp[j] = max(dp[j-p]+q, dp[j])
        x += p
    print(max(dp))

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

def equal(x,y,z):
    return x**2 + y**2 + z**2 +x*y+y*z+z*x

N = int(input())

for i in range(1,N+1):
    cnt = 0
    for x in range(1,N+1):
        for y in range(1,N+1):
            for z in range(1,N+1):
                if equal(x,y,z) == i:
                    #print(x,y,z)
                    cnt+=1
    print(cnt)


### FIXED CODE ###

import math
def equal(x,y,z):
    return x**2 + y**2 + z**2 +x*y+y*z+z*x

N = int(input())
ans = [0 for _ in range(10050)]
for x in range(1,105):
        for y in range(1,105):
            for z in range(1,105):
                v = equal(x,y,z)
                if v < 10050:
                    ans[v]+=1
for i in range(N):
    print(ans[i+1])
### BUGGY CODE ###

INF = 10**11
from bisect import bisect

A, B, Q = map(int, input().split())
s_array = [int(input()) if i != 0 else -INF for i in range(A + 1)]
s_array.append(INF)
t_array = [int(input()) if i != 0 else -INF for i in range(B + 1)]
t_array.append(INF)
q_array = [int(input()) for i in range(Q)]

# print(s_array, t_array, q_array)

ans_array = []
for q in q_array:
    s_index = bisect(s_array, q) - 1
    t_index = bisect(t_array, q) - 1
    # print(s_index,t_index)
    method_a = q - min(s_array[s_index], t_array[t_index])
    method_b = max(s_array[s_index + 1], t_array[t_index + 1]) - q
    method_c = (q - s_array[s_index]) + (t_array[t_index + 1] - q) + min(
        (q - s_array[s_index]), (t_array[t_index + 1] - q))
    method_d = (q - t_array[t_index]) + (s_array[s_index + 1] - q) + min(
        (q - t_array[t_index]), (s_array[s_index + 1] - q))
    # ans_array.append(min(method_a, method_b, method_c, method_d))
    print(min(method_a, method_b, method_c, method_d))

### FIXED CODE ###

INF = 10**11


def binary_search(array, value):
    start = 0
    end = len(array) - 1
    while end - start >= 2:
        tmp = (start + end) // 2
        # print(start, end, tmp)
        if array[tmp] <= value:
            start = tmp
        else:
            end = tmp
        # print(start, end, tmp)
    return start


A, B, Q = map(int, input().split())
s_array = [int(input()) if i != 0 else -INF for i in range(A + 1)]
s_array.append(INF)
t_array = [int(input()) if i != 0 else -INF for i in range(B + 1)]
t_array.append(INF)
q_array = [int(input()) for i in range(Q)]

# print(s_array, t_array, q_array)

ans_array = []
for q in q_array:
    s_index = binary_search(s_array, q)
    t_index = binary_search(t_array, q)
    method_a = q - min(s_array[s_index], t_array[t_index])
    method_b = max(s_array[s_index + 1], t_array[t_index + 1]) - q
    method_c = (q - s_array[s_index]) + (t_array[t_index + 1] - q) + min(
        (q - s_array[s_index]), (t_array[t_index + 1] - q))
    method_d = (q - t_array[t_index]) + (s_array[s_index + 1] - q) + min(
        (q - t_array[t_index]), (s_array[s_index + 1] - q))
    ans_array.append(min(method_a, method_b, method_c, method_d))

for ans in ans_array:
    print(ans)
### BUGGY CODE ###

# coding: utf-8
N,a,b=map(int,input().split())
def pow(x, n):
        ans = 1
        while(n > 0):
            if(bin(n & 1) == bin(1)):
                ans = ans*x
            x = x*x
            n = n >> 1 #ビットシフト
        return ans
        
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans=pow(2,N)-1
ans-=cmb(N,a,mod)
ans-=cmb(N,b,mod)

print(ans)

### FIXED CODE ###

# coding: utf-8
n,a_,b_=map(int,input().split())
l=[min(a_,n-a_),min(b_,n-b_)]
a,b=min(l),max(l)
mod=10**9+7
def pow_k(x,n):
    k=1
    #kは漏れたやつ
    while n>1:
        if n%2==1:
            k*=x
            n-=1
            k=k%mod
        x**=2
        x=x%mod
        n//=2
    
    return (k * x) % mod
    
#ans=pow_k(2,1000000000)
def modcomb(n,r,mod):
    X, Y =  1, 1
    r = min(r, n-r)
    for i in range(1,r+1):
        X = X * (n-i+1) % mod
        Y = Y * i % mod
    
    return (X * pow_k(Y, mod-2) % mod) % mod
ans=pow_k(2,n)-1-modcomb(n,a,mod)-modcomb(n,b,mod)
print(ans%mod)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(500000)

def input() -> str:
    return sys.stdin.readline().rstrip()

def f(i, j):
    if j <= 0:
        return 0
    if i < 0 and j > 0:
        return float("inf")
    if dp.get((i, j)) is None:
        dp[(i, j)] = min([f(i - 1, j - k * ab[i][0]) + k * ab[i][1] for k in range((h - 1) // ab[i][0] + 2)])
    return dp[(i, j)]

h, n = map(int, input().split())
ab = sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x: -x[0])
dp = dict()
print(f(n - 1, h))

### FIXED CODE ###

import sys

def input() -> str:
    return sys.stdin.readline().rstrip()

h, n = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
m = max(a for a, _ in ab)
dp = [0] * (h + m * 2 + 1)
for i in range(-m, h + m + 1):
    if i <= 0:
        dp[i] = 0
    else:
        dp[i] = min(dp[i - a] + b for a, b in ab)
print(min(dp[h:h + m + 1]))
### BUGGY CODE ###

S = input()
N = len(S)

cnt = 0
for i in range(N - 3):
    for j in range(i + 4, N + 1):
        if int(S[i:j]) % 2019 == 0:
            # print(i, j)
            cnt += 1
print(cnt)


### FIXED CODE ###

S = input()
N = len(S)

num = [0] * 2019
num[0] = 1
now, ans = 0, 0
_10 = 1

for i in range(N-1, -1, -1):
    now = (now + int(S[i]) * _10) % 2019
    _10 *= 10
    _10 %= 2019
    ans += num[now]
    num[now] += 1
 
print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    print(a.count(i+1))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(n-1):
    ans[a[i]-1] += 1
for i in range(n):
    print(ans[i])
### BUGGY CODE ###

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


n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

li = [0] * (10 ** 6 + 1)
for e in a:
    l = factorization(e)
    for le in l:
        num, times = le
        li[num] = max(li[num], times)

ans = 0
for e in a:
    l = factorization(e)
    l2 = [0] * (10 ** 6 + 1)
    for le in l:
        num, times = le
        l2[num] = times

    b = 1
    for i, (lie, l2e) in enumerate(zip(li, l2)):
        b *= i ** (lie - l2e)

    ans += b
    ans %= mod

print(ans)


### FIXED CODE ###

from fractions import gcd


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


n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

l = 1
for e in a:
    l = lcm(l, e)

l %= mod

ans = 0
for e in a:
    ans += l * pow(e, mod - 2, mod)
    ans %= mod

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

import queue

def solve():
    h, w = map(int, input().split())

    field = [input() for _ in range(h)]

    dist = [[h*w*100 for i in range(w)] for j in range(h)]
    dist[0][0] = 1

    q = queue.Queue()
    q.put((0,0))

    dx = [-1,1,0,0]
    dy = [0,0,1,-1]
    while not q.empty() :
        (x,y) = q.get()
        for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)] :
            nx = x + dx
            ny = y + dy
            if nx < 0 or nx >= h or ny < 0 or ny>= w :
                continue
            if field[nx][ny] == '#':
                continue
            if dist[nx][ny] > dist[x][y] :
                dist[nx][ny] = dist[x][y] + 1
                q.put((nx,ny))

    if dist[h-1][w-1] >= h*w :
        return -1

    # print(dist)

    ans = h*w - dist[h-1][w-1]
    for v in field:
        for c in v:
            if c == '#':
                ans -= 1

    return ans

print(solve())


### FIXED CODE ###

import queue

def solve():
    h, w = map(int, input().split())

    field = [input() for _ in range(h)]

    dist = [[h*w*100 for i in range(w)] for j in range(h)]
    dist[0][0] = 1

    q = queue.Queue()
    q.put((0,0))

    dx = [-1,1,0,0]
    dy = [0,0,1,-1]
    while not q.empty() :
        (x,y) = q.get()
        for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)] :
            nx = x + dx
            ny = y + dy
            if nx < 0 or nx >= h or ny < 0 or ny>= w :
                continue
            if field[nx][ny] == '#' :
                continue
            if dist[nx][ny] > dist[x][y] + 1 :
                dist[nx][ny] = dist[x][y] + 1
                q.put((nx,ny))

    if dist[h-1][w-1] >= h*w :
        return -1

    # print(dist)

    ans = h*w - dist[h-1][w-1]
    for v in field:
        for c in v:
            if c == '#':
                ans -= 1

    return ans

if __name__ == '__main__':
    print(solve())
### BUGGY CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


n, m = LI()
total = m * 3


fac = [1] * (total + n)
inv = [1] * (total + n)
i = 1
for j in range(1, total + n):
    i = i * j % mod
    fac[j] = i
    inv[j] = pow(i, mod - 2, mod)



def comb(n, r):
    if r > n:
        return 0
    return fac[n] * inv[n - r] * inv[r] % mod



ans = comb(total + n - 1, n - 1)
for i in range(m + 2, min(n + 1, total + 1), 2):
    ans -= comb(n, i) * comb(n + (total - i) // 2 - 1, n - 1) % mod
    ans %= mod


ret = 0
for i in range(m):
    ret = (ret + comb(i + n - 2, n - 2)) % mod


ans -= (ret * n) % mod
print(ans % mod)

### FIXED CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


n, m = LI()
total = m * 3

fac = [1] * (total+n+1)
inv = [1] * (total+n+1)
for i in range(total+n):
    fac[i+1] = fac[i]*(i+1)%mod

inv[total+n]=pow(fac[-1], mod-2, mod)
for j in range(total+n-1, -1, -1):
    inv[j]=inv[j+1]*(j+1)%mod



def comb(n, r):
    if r > n:
        return 0
    return fac[n] * inv[n - r] * inv[r] % mod


ans = comb(total+n-1, n-1)
for i in range(m + 2, min(n + 1, total + 1)):
    if (total - i) % 2 == 0:
        ans -= comb(n, i) * comb(n + (total - i) // 2 - 1, n - 1) % mod
        ans %= mod


ret = 0
for i in range(m):
    ret = (ret + comb(i + n - 2, n - 2)) % mod


ans -= (ret * n) % mod
print(ans % mod)
### BUGGY CODE ###

N = int(input())
L = list(map(int,input().split()))
L.sort()
sum = 0
for i in range(0,N):
  L_1st= L[i]
  for j in range(i+1,N):
    L_2nd = L[j]
    for _ in range(j+1,N):
      if L[i]-L[j]<L[_]<L[i]+L[j]:
        sum += 1
print(sum)

### FIXED CODE ###

import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()
sum = 0
for i in range(0,N):
  L_1st= L[i]
  for j in range(i+1,N):
    L_2nd = L[j]
    c_min = L_2nd-L_1st+1
    c_max = L_2nd+L_1st-1
    l = bisect.bisect_left(L,c_min,lo = j+1)
    if l!= N:
      r = bisect.bisect_right(L,c_max,lo = j+1)
      if r:
        r = r-1
        if r>= l:
          sum += r-l+1
print(sum)
### BUGGY CODE ###

import sys
import math
from functools import lru_cache

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


@lru_cache(maxsize=None)
def solve(x, y):
    return math.gcd(x, y)


def main():
    N = int(input())

    ans = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            for k in range(1, N + 1):
                x = [i, j, k]
                x.sort()
                xx = solve(x[0], x[1])
                if xx > x[2]:
                    ans += solve(x[2], xx)
                else:
                    ans += solve(xx, x[2])

    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import math
from functools import lru_cache

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


@lru_cache(maxsize=None)
def solve(x, y):
    return math.gcd(x, y)


def main():
    N = int(input())

    ans = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            x = math.gcd(i, j)
            for k in range(1, N + 1):
                ans += math.gcd(x, k)

    print(ans)


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


x = input().split()
n = int(x[0]) # n == 比較文字列の長さ
q = int(x[1]) # q == 検討する回数
s = input()
maxx = 0
count = 0
data = ["A","C","T","G"]

def sc():
    global s
    global n
    global q
    maxx = 0
    count = 0
    com = [int(s)-1 for s in input().split()]
    for i in range(com[0], com[1] ): # i == 先頭の文字
        if (s[i] == "A") and(s[i+1] == "C"):
            count += 1
        
            
    print(count)

for i in range(q):
    sc()


### FIXED CODE ###


x = input().split()
n = int(x[0]) # n == 比較文字列の長さ
q = int(x[1]) # q == 検討する回数
s = input()

        
t = [0] * n
if s[0] == "A":
    t[0] = 1
    
for i in range(0,n-1):
    if s[i:i+2] == "AC":
        
        if (i == 0) :
            t[i] =  + 1
        else:
            t[i] = t[i-1] + 1
    else :
        if i == 0:
            t[i] = 0
        else:
            t[i] = t[i-1]



def sc():
    global t
    global s
    global n
    global q
    global idbox
    maxx = 0
    count = 0
    com = [int(s)-1 for s in input().split()]
    
    
    print(t[com[1]-1] - t[com[0]-1])
        
    

    

for i in range(q):
    
    sc()
### BUGGY CODE ###

S = input()

ans = 0
pos = 0
while True:
    tmp = S.find('W', pos)
    if tmp == -1:
        break
    ans += S[:tmp].count('B')
    pos = tmp + 1

print(ans)

### FIXED CODE ###

S = input()

b_count = 0
ans = 0

for pos in range(len(S)):
    if S[pos] == 'B':
        b_count += 1
    else:
        ans += b_count

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

import math
k = int(input())
su = 0
for x in range(1, k+1):
  for y in range(1, k+1):
    for z in range(1, k+1):
      i = math.gcd(x, y)
      ans = math.gcd(i, z)
      su += ans
      
print(su)

### FIXED CODE ###

import math
k = int(input())
su = 0
lis = []
for x in range(1, k+1):
  for y in range(1, k+1):
    a = math.gcd(x, y)
    lis.append(a)

for z in range(1, k+1):
  for p in lis:
    ans = math.gcd(p, z)
    su += ans
  
print(su)
### BUGGY CODE ###

newlst = []
lst =[]
m = int(input())
while m > 0:
    a = str(input())
    lst.append(a)
    m = m -1
for j in lst:
    if j not in newlst:
        newlst.append(j)
print(len(newlst))


### FIXED CODE ###

newlst = []
lst =[]
m = int(input())
while m > 0:
    a = str(input())
    lst.append(a)
    m = m -1
newlst = list(dict.fromkeys(lst))
print(len(newlst))
### BUGGY CODE ###

n, m = map(int, input().split())
list_PY = [ list(map(int,input().split(" "))) for _ in range(m)]
list_K = [[] for _ in range(n + 1)]

for p, y in list_PY:
    list_K[p].append(y)

for l in list_K:
    l.sort()

for p, y in list_PY:
    u = str(p)
    u = "0" * (6 - len(u)) + u

    d = str(list_K[p].index(y) + 1)
    d = "0" * (6 - len(d)) + d

    print(u + d)

### FIXED CODE ###

n, m = map(int, input().split())
list_PY = [ list(map(int,input().split(" "))) for i in range(m)]

for i in range(m):
    l = list_PY[i]
    l.append(i)
list_PY.sort(key=lambda x:(x[0], x[1]))

cnt = 0
k = 0
for i in range(m):
    l = list_PY[i]
    if l[0] == k:
        cnt += 1
        a = len(list(str(l[0])))
        b = "0"*(6 - a) + str(l[0])
        c = len(list(str(cnt)))
        d = "0"*(6 - c) + str(cnt)
    else:
        k = l[0]
        cnt = 1
        a = len(list(str(l[0])))
        b = "0" * (6 - a) + str(l[0])
        c = len(list(str(cnt)))
        d = "0" * (6 - c) + str(cnt)
    l.append(b+d)


list_PY.sort(key=lambda x:x[2])

for i in range(m):
    print(list_PY[i][3])
### BUGGY CODE ###

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

### FIXED CODE ###

k,s = map(int,input().split())
c=0
for i in range(k+1):
	for j in range(k+1):
		if 0 <= s-i-j <= k:
			c+=1
print(c)