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

import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from scipy.sparse.csgraph import floyd_warshall
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush, heapify
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n,k = inpm()
    a = inpl()
    ans = [0 for _ in range(n+1)]
    for _ in range(k):
        ans = [0 for _ in range(n+1)]
        for i in range(n):
            [l,r] = [max(0,i-a[i]),min(n-1,i+a[i])]
            ans[l] += 1
            ans[r+1] -= 1
        for i in range(n):
            ans[i+1] += ans[i]
        a = ans
        if sum(ans) >= n**2:
            print(*[n for _ in range(n)])
            return
    x = []
    for i in range(n):
        x.append(ans[i])
    print(*x)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    n,k = map(int,input().split())
    a = list(map(int, input().split()))
    ans = [0 for _ in range(n+1)]
    for _ in range(k):
        ans = [0 for _ in range(n+1)]
        for i in range(n):
            [l,r] = [max(0,i-a[i]),min(n-1,i+a[i])]
            ans[l] += 1
            ans[r+1] -= 1
        for i in range(n):
            ans[i+1] += ans[i]
        a = ans
        if ans[0] >= n and ans[n-1] >= n:
            print(*[n for _ in range(n)])
            return
    x = []
    for i in range(n):
        x.append(ans[i])
    print(*x)


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

import sys
input = sys.stdin.readline

def main():
    s = input()[:-1]
    q = int(input())
    tmp = [input().split() for _ in range(q)]

    for i in range(len(tmp)):
        if len(tmp[i]) == 1:
            s = s[::-1]
        else:
            if int(tmp[i][1]) == 1:
                s = '{}{}'.format(tmp[i][2], s)
            else:
                s = '{}{}'.format(s, tmp[i][2])
                
    print(s)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
from collections import deque

def main():
    input = sys.stdin.readline

    s = input()[:-1]
    q = int(input())
    tmp = [input().split() for _ in range(q)]

    flag = 0
    ans = deque([s])
    for t in tmp:
        if len(t) == 1:
            flag = ~flag 
        else:
            f = int(t[1])
            c = t[2]
            if (f == 1 and flag == 0) or (f ==2 and flag == -1):
                ans.appendleft(c)
            else:
                ans.append(c)
    if flag == 0:
        print(''.join(ans))
    else:
        print(''.join(ans)[::-1])

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

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

goukei = 1
for i in ls:
  goukei *= i

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

### FIXED CODE ###

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

if 0 in ls:
  print('0')
  exit()

goukei = 1
for i in ls:
  goukei *= i

  if goukei > 1000000000000000000:
    print('-1')
    exit()

print(int(goukei))
### BUGGY CODE ###

K = int(input())
ans = 1
tmp = 7
if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    x = (9/7) * K + 1
    ans = 0
    while x != 1:
        x /= 10
        ans += 1
    print(ans)

### FIXED CODE ###

k=int(input())
a=7
for i in range(10**6):
    if a%k==0:
        print(i+1)
        exit()
    a=(a*10+7)%k
print(-1)
### BUGGY CODE ###

def rolling_hash(s):
    l = len(s)
    h = [0]*(l + 1)
    v = 0
    for i in range(l):
        h[i+1] = v = (v * base + ord(s[i])) % mod
    return h
def setup_pw(l):
    pw = [1]*(l + 1)
    v = 1
    for i in range(l):
        pw[i+1] = v = v * base % mod
    return pw
def get(h, b, l, r):
    return (h[r] - h[l] * b[r-l]) % mod

def check_bisect(l,h,b):
    for j in range(N-2*l+1):
        for k in range(N-2*l-j+1):
            if get(h,b,j,l+j) == get(h,b,j+l+k,2*l+j+k):
                return True
    return False

N = int(input())
S = input()
mod = 1000000007
base = 401
h = rolling_hash(S)
b = setup_pw(N)
left = 1
right = N // 2
finish = False
if N <= 26:
    s = set(list(S))
    if N <= 3:
        if len(s) < N:
            print('1')
        else:
            print('0')
        finish = True
    else:
        if len(s) == N:
            print('0')
            finish = True
while finish == False:
    if left == right:
        print(left)
        finish = True
    elif right - left == 1:
        if check_bisect(right,h,b):
            print(right)
        else:
            print(left)
        finish = True
    else:
        mid = (left+right) // 2
        if check_bisect(mid,h,b):
            left = mid
        else:
            right = mid - 1

### FIXED CODE ###

def rolling_hash(s):
    l = len(s)
    h = [0]*(l + 1)
    v = 0
    for i in range(l):
        h[i+1] = v = (v * base + ord(s[i])) % mod
    return h
def setup_pw(l):
    pw = [1]*(l + 1)
    v = 1
    for i in range(l):
        pw[i+1] = v = v * base % mod
    return pw
def get(h, b, l, r):
    return (h[r] - h[l] * b[r-l]) % mod

def check_bisect(l,h1,b1,h2,b2):
    for j in range(N-2*l+1):
        a1 = get(h1,b1,j,l+j)
        a2 = get(h2,b2,j,l+j)
        for k in range(N-2*l-j+1):
            if a1 == get(h1,b1,j+l+k,2*l+j+k) and a2 == get(h2,b2,j+l+k,2*l+j+k):
                return True
    return False

N = int(input())
S = input()
mod = 1000000007
base = 37
h1 = rolling_hash(S)
b1 = setup_pw(N)
base = 401
h2 = rolling_hash(S)
b2 = setup_pw(N)
left = 1
right = N // 2
finish = False
if N <= 26:
    s = set(list(S))
    if N <= 3:
        if len(s) < N:
            print('1')
        else:
            print('0')
        finish = True
    else:
        if len(s) == N:
            print('0')
            finish = True
while finish == False:
    if left == right:
        print(left)
        finish = True
    elif right - left == 1:
        if check_bisect(right,h1,b1,h2,b2):
            print(right)
        else:
            print(left)
        finish = True
    else:
        mid = (left+right) // 2
        if check_bisect(mid,h1,b1,h2,b2):
            left = mid
        else:
            right = mid - 1
### BUGGY CODE ###

import sys, math, collections, heapq, itertools
from bisect import bisect_left
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    Q = int(single_input())
    n, a, b = map(int, line_input())
    left, right = [], []
    left.append(a)
    right.append(a)
    minans =  b
    for i in range(1, Q):
        queri = [int(i) for i in line_input()]
        if queri[0] == 1:
            a, b = queri[1:]
            minans += b
            if left[-1] <= a <= right[0]:
                left.append(a)
                right.insert(0, a)
            elif a < left[-1]:
                minans += left[-1] - a
                insertpos = bisect_left(left, a)
                left.insert(insertpos, a)
                left.insert(insertpos, a)
                right.insert(0, left.pop())
            else:
                minans += a - right[0]
                insertpos = bisect_left(right, a)
                right.insert(insertpos, a)
                right.insert(insertpos, a)
                left.append(right.pop(0))
        else: print(left[-1], minans)
    return 0
  
if __name__ == "__main__":
    solve()

### FIXED CODE ###

import sys, math, collections, heapq, itertools
from bisect import bisect_left
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    Q = int(single_input())
    n, a, b = map(int, line_input())
    left, right = [-a], [a]
    heapq.heapify(left)
    heapq.heapify(right)
    minans =  b
    for i in range(1, Q):
        queri = [int(i) for i in line_input()]
        if queri[0] == 1:
            a, b = queri[1:]
            minans += b
            left_upper = -1 * heapq.heappop(left)
            right_lower = heapq.heappop(right)
            if left_upper <= a <= right_lower:
                heapq.heappush(left, -a)
                heapq.heappush(left, -1 * left_upper)
                heapq.heappush(right, a)
                heapq.heappush(right, right_lower)
            elif a < left_upper:
                minans += left_upper - a
                heapq.heappush(left, -a)
                heapq.heappush(left, -a)
                heapq.heappush(right, left_upper)
                heapq.heappush(right, right_lower)
            else:
                minans += a - right_lower
                heapq.heappush(left, -1 * left_upper)
                heapq.heappush(left, -1 * right_lower)
                heapq.heappush(right, a)
                heapq.heappush(right, a)
        else:
            left_lower = -1 * heapq.heappop(left)
            print(left_lower, minans)
            heapq.heappush(left, -1 * left_lower)
    return 0
  
if __name__ == "__main__":
    solve()
### BUGGY CODE ###

# -*- coding: utf-8 -*-

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

mod = 2019

ans = 2018

for i in range(L, R+1):
    for j in range(i+1, R+1):
        if i==j:
            continue
        else:
            ans = min(ans, (i*j)%mod)

print(ans)



### FIXED CODE ###

# -*- coding: utf-8 -*-
L, R = map(int, input().split())
end = min(R, L + 637*2)

ans = 2018
for i in range(L, end+1):
    for j in range(i+1, end+1):
        x = i*j%2019
        ans = min(ans, x)
print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
G = [[] for i in range(N + 1)]
for i in range(M):
    l, r, d = map(int, input().split())
    l, r = l - 1, r - 1
    G[l].append((r, d))
    G[r].append((l, -d))
used = [False] * (N + 1)
dist = [0] * (N + 1)
flag = False


def dfs(v, d0):
    global flag
    if used[v]:
        if dist[v] != d0:
            flag = True
        return
    else:
        used[v] = True
        dist[v] = d0

    if v not in G:
        for w, d1 in G[v]:
            dfs(w, d0 + d1)


for i in range(1, N + 1):
    if not used[i]:
        dfs(i, 0)

if flag:
    print("No")
else:
    print("Yes")

### FIXED CODE ###

import sys
sys.setrecursionlimit(200002)
N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    l, r, q = map(int, input().split())
    G[l - 1].append((r - 1, q))
    G[r - 1].append((l - 1, -q))
X = [None] * N


def dfs(u):
    global X, G
    for w, d in G[u]:
        if X[w] is None:
            X[w] = X[u] + d
            if not dfs(w):
                return False
        else:
            if X[w] != X[u] + d:
                return False

    return True


flag = True
for i in range(N):
    if X[i] is None:
        X[i] = 0
        flag &= dfs(i)

if flag:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

# 入力
N = input()

A1 = input()

total = float('INF')
for i in range(int(N)):
    tmpW = A1[:i].count('W')
    tmpE = A1[i+1:].count('E')
    tmp = tmpW + tmpE
    if(total > tmp):
        total = tmp
print(total)

### FIXED CODE ###

# 入力
N = input()

A1 = [ n=='E' for n in input()]


minimum = sum(A1[1:])
count = minimum

for i in range(1,int(N)):
    if(not A1[i-1]):
        count += 1
    if(A1[i]):
        count -= 1
    if(count<minimum):
        minimum = count
print(minimum)
### BUGGY CODE ###


N = int(input())
S = input()

ans = 0
k = 'RGB'
for i in range(N):
	for j in range(i+1,N):
		if not S[i]==S[j]:
			tmp =k.replace(S[i],'')
			tmp = tmp.replace(S[j],'')
			ans += S[j+1:].count(tmp)
			if 2*j-i<N and S[2*j-i]==tmp:
				ans -= 1
print(ans)


### FIXED CODE ###

import sys
from collections import defaultdict
d = defaultdict(str)
N = int(sys.stdin.readline())
S = sys.stdin.readline()

ans = 0
k = 'RGB'
for i in range(N):
	for j in range(i+1,N):
		if not S[i]==S[j]:
			tmp =k.replace(S[i],'')
			tmp = tmp.replace(S[j],'')
			if d[str(j+1)+tmp]=='':
				p = S[j+1:].count(tmp)
				d[str(j+1)+tmp] = p
				ans += p
				if 2*j-i<N and S[2*j-i]==tmp:
					ans-= 1
					
			else:
				ans +=d[str(j+1)+tmp]
				if 2*j-i<N and S[2*j-i]==tmp:
					ans -=1
print(ans)
### BUGGY CODE ###

'''
dpt[r][c][taken]
への遷移は、
max(dpt[r-1][c]) -> dpt[r][c][0]
dpt[r][c-1][taken-1] -> dpt[r][c][taken] + field[r][c]
dpt[r][c-1][taken] -> dpt[r][c][taken]
'''

import numpy as np
from numba import njit
def main():
    R, C, K = map(int, input().split())
    field = np.full((R+1,C+1), 0)
    dpt = np.full((R+1,C+1,4), 0)
    for i in range(K):
        r, c, v = map(int, input().split())
        field[r][c] = v
    dp(R, C, field, dpt)
    print(max(dpt[-1][-1]))

def dp(R, C, field, dpt):
    for r in range(1, R+1):
        for c in range(1, C+1):
            for taken in range(4):
                max_v = 0
                if taken == 0:
                    max_v = max(dpt[r-1][c])
                    max_v = max(dpt[r][c-1][0], max_v)
                elif taken == 1:
                    max_v = max(dpt[r][c-1][taken-1] + field[r][c],
                                dpt[r][c-1][taken],
                                max(dpt[r-1][c]) + field[r][c])
                else:
                    max_v = max(dpt[r][c-1][taken-1] + field[r][c],
                                dpt[r][c-1][taken])
                dpt[r][c][taken] = max_v
    return True

if __name__ == '__main__':
    main()


### FIXED CODE ###

import numpy as np
from numba import njit
def main():
    R, C, K = map(int, input().split())
    field = np.full((R+1,C+1), 0, dtype='int64')
    dpt = np.full((R+1,C+1,4), 0, dtype='int64')
    for i in range(K):
        r, c, v = map(int, input().split())
        field[r][c] = v
    dp(R, C, field, dpt)
    print(max(dpt[-1][-1]))

@njit('i4(i4,i4,i8[:,:],i8[:,:,:])', cache=True)
def dp(R, C, field, dpt):
    for r in range(1, R+1):
        for c in range(1, C+1):
            for taken in range(4):
                max_v = 0
                if taken == 0:
                    max_v = max(dpt[r-1][c])
                    max_v = max(dpt[r][c-1][0], max_v)
                elif taken == 1:
                    max_v = max(dpt[r][c-1][taken-1] + field[r][c],
                                dpt[r][c-1][taken],
                                max(dpt[r-1][c]) + field[r][c])
                else:
                    max_v = max(dpt[r][c-1][taken-1] + field[r][c],
                                dpt[r][c-1][taken])
                dpt[r][c][taken] = max_v
    return 1

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

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

total_rain = sum(A) // 2

one = total_rain
for j in range(1, N-1, 2):
    one -= A[j]
rain = one*2
ans = str(rain)
prerain = rain

for m in range(1, N):
    rain = (A[m-1] - prerain//2)*2
    ans+=" "
    ans+=str(rain)
    prerain = rain

print(ans)

### FIXED CODE ###

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

total_rain = sum(A) // 2

one = total_rain
for j in range(1, N-1, 2):
    one -= A[j]
rain = one*2
ans = str(rain)
prerain = rain

for m in range(1, N):
    rain = (A[m-1] - prerain//2)*2
    ans+=" "
    ans+=str(rain)
    prerain = rain

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

from bisect import bisect_left, bisect_right

N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
for i, A in enumerate(L):
    for j, B in enumerate(L):
        if i == j:
            continue
        left = bisect_right(L, abs(A - B))
        right = bisect_left(L, A + B)

        ans += right - left

        if left <= i < right:
            ans -= 1
        if left <= j < right:
            ans -= 1

print(ans // 6)

### FIXED CODE ###

from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
for i, A in enumerate(L):
    for j, B in enumerate(L[i + 1:], start=i + 1):
        right = bisect_left(L, A + B)
        ans += right - j - 1

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

import collections
r, g, b, n = map(int, input().split())

sum_rg = collections.Counter()

for i in range(n + 1):
    if n < r*i:
        break
    for j in range(n + 1):
        if n < r*i + g*j:
            break
        sum_rg[r*i + g*j] += 1

ans = 0
for k in range(n + 1):
    if n < b*k:
        break
    ans += sum_rg[n - b*k]

#print(sum_rg)
print(ans)

### FIXED CODE ###

import collections
r, g, b, n = map(int, input().split())

#sum_rg = collections.Counter()
sum_rg = collections.defaultdict(int)

for i in range(n + 1):
    if n < r*i:
        break
    for j in range(n + 1):
        if n < r*i + g*j:
            break
        sum_rg[r*i + g*j] += 1

ans = 0
for k in range(n + 1):
    if n < b*k:
        break
    ans += sum_rg[n - b*k]

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

def dijkstra(s,n,w,cost):
    d = [float('inf')] * n
    used = [False] * n
    d[s] = 0

    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1):
                v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
            break
        used[v] = True

        for j in range(n):
            d[j] = min(d[j],d[v] + cost[v][j])
    return d

N = int(input())

cost = [[float('inf')] * N for _ in range(N)]

for i in range(N-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    cost[a][b] = c
    cost[b][a] = c


Q, K = map(int, input().split())
b = dijkstra(K-1,N,N-1,cost)
for _ in range(Q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    a = dijkstra(x,N,N-1,cost)
    print(a[K-1] + b[y])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
def dfs(v,p,d):
    for i, j in tree[v]:
        if i != p:
            depth[i] = d + j
            dfs(i,v,d+j)

N = int(input())

tree = [[] for _ in range(N)]

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

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

depth = [0 for i in range(N)]
depth[K-1] = 0

dfs(K-1,-1,0)

for _ in range(Q):
    x, y = map(int, input().split())
    print(depth[x-1] + depth[y-1])
### BUGGY CODE ###

N = int(input())
S = input()
num = [S[:n].count("W") + S[n + 1:].count("E") for n in range(N)]
print(min(num))

### FIXED CODE ###

N = int(input())
S = input()
result = S[1:].count("E")
cost = result
l0 = S[0]
for n in range(1, N):
    l1 = S[n]
    if l0 != l1:
        l0 = l1
        continue
    if l0 == "W":
        cost += 1
        continue
    cost -= 1
    if cost < result:
        result = cost

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

import sys


def solve():
    sys.setrecursionlimit(2000)
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    x = list(map(int, input().rstrip('\n').split()))
    if len(x) == 1:
        print(abs(sum(x)))
    else:
        mt = 10 ** 10
        for i in range(k, n+1):
            tx = x[i-k:i]
            if tx[0] * tx[-1] < 0:
                mt = min(mt, abs(tx[0]) + abs(tx[-1]) + min(abs(tx[0]), abs(tx[-1])))
            else:
                mt = min(mt, max(abs(tx[0]), abs(tx[-1])))
        print(mt)


if __name__ == '__main__':
    solve()


### FIXED CODE ###

n, k = map(int, input().split())
x = list(map(int, input().split()))
d = 10 ** 9
for i in range(k-1, n):
    if x[i] * x[i-k+1] < 0:
        d = min(d, min(abs(x[i]), abs(x[i-k+1])) + abs(x[i] - x[i-k+1]))
    else:
        d = min(d, max(abs(x[i]), abs(x[i-k+1])))
print(d)
### BUGGY CODE ###

n = int(input())
print(sum(range(1, n)))


### FIXED CODE ###

n = int(input())
ans = n * (n-1) // 2
print(ans)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
sorted(A)
result=1
for i in A:
    if 0 in A:
        result=0
        break
    result*=i
    if result>1000000000000000000:
        result=-1
        break
print(result)


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
sorted(A)
result=1
if 0 in A:
    result=0
for i in A:
    if result==0:
        break
    result*=i
    if result>1000000000000000000:
        result=-1
        break

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

n, q = map(int, input().split())
listS = list(input())
index=0
listA=[]
listI=[]
index2=0
while index2 < len(listS)-1:
    if listS[index2]=="A" and listS[index2+1]=="C":
        listI.append(index2)
    index2+=1

while index < q:
    l, r = map(int, input().split())
    count=0
    index3=0
    while index3 < len(listI):
        if listI[index3] >= l-1 and listI[index3]+1 <= r-1:
            count+=1
        index3+=1
    listA.append(count)
    index+=1
for ans in listA:
    print(ans)

### FIXED CODE ###

n, q = map(int, input().split())
listS = list(input())
index=0
listA=[]
listM=[0]*n
index2=1
countM=0
while index2 < len(listS):
    if listS[index2-1]=="A" and listS[index2]=="C":
        countM+=1
    listM[index2] = countM               
    index2+=1

while index < q:
    l, r = map(int, input().split())
    listA.append(listM[r-1]-listM[l-1])
    index+=1
for ans in listA:
    print(ans)
### BUGGY CODE ###

n, m = list(map(int, input().split()))
card = list(map(int, input().split()))
data = []
for i in range(m):
    data.append(list(map(int, input().split())))
data.sort(key=lambda x:x[1])
count = 0
cnt = 0
for i in range(m):
    cnt = 0
    while min(card) < data[m - i - 1][1] and cnt < data[m - i - 1][0]:
        card[card.index(min(card))] = data[m - i - 1][1]
        count += 1
        cnt += 1
    if count >= n:
        break
print(sum(card))

### FIXED CODE ###

import bisect
n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()

data = [None] * m
for i in range(m):
    data[i] = list(map(int, input().split()))
data.sort(key = lambda x : x[1])
data.reverse()


ans = 0
count = 0
pre_index = 0
#print(data)
#print(a)
#data[][1] = value, data[][0] = card_num
for i in range(m):
    insert_index = bisect.bisect_left(a, data[i][1])
    count = min(data[i][0], insert_index - pre_index)
    for j in range(pre_index, pre_index + count):
        if j >= n:
            break
        a[j] = 0
    ans += count * data[i][1]
    pre_index = pre_index + count
print(ans + sum(a))
### BUGGY CODE ###

S=list(input())
n=len(S)
ans=0

i=0
while i<n-1:
    if S[i]=='B' and S[i+1]=='W':
        S[i],S[i+1]='W','B'
        ans+=1
        if i: i-=1
        else: i=1
    else:
        i+=1
print(ans)


### FIXED CODE ###

S=list(input())
n=len(S)
ans=0
b=0

for s in S:
    if s=='B':b+=1
    else:ans+=b
    
print(ans)