Problem:
 Score : 300 points    Problem Statement There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.)
The state of each piece is represented by a string S of length N .
If S_i= B , the i -th piece from the left is showing black;
If S_i= W , the i -th piece from the left is showing white.  Consider performing the following operation:   Choose i ( 1 \leq i < N ) such that the i -th piece from the left is showing black and the (i+1) -th piece from the left is showing white, then flip both of those pieces. That is, the i -th piece from the left is now showing white and the (i+1) -th piece from the left is now showing black.   Find the maximum possible number of times this operation can be performed.      Constraints  1 \leq |S| \leq 2\times 10^5  S_i= B or W         Input Input is given from Standard Input in the following format:  S       Output Print the maximum possible number of times the operation can be performed.        Sample Input 1 BBW      Sample Output 1 2  The operation can be performed twice, as follows:   Flip the second and third pieces from the left.  Flip the first and second pieces from the left.        Sample Input 2 BWBWBW      Sample Output 2 6

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
    def sum(self, i):  
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    def add(self, i, x):  
        while i <= self.size:
            self.tree[i] += x
            i += i & -i  
    def pos(self, idx):  
        return self.sum(idx) - self.sum(idx-1)
    def lower_bound(self, w):  
        if w <= 0:
            return 0
        idx = 0
        k = 1
        while k*2 <= self.size:
            k *= 2
        while k > 0:
            if idx+k <= self.size and self.tree[idx+k] < w:
                w -= self.tree[idx+k]
                idx += k
            k //= 2
        return idx+1

S = input()
N = len(S)
b = Bit(N)
x = [1 if s == "W" else 2 for s in S]
ans = 0
for i in range(N):
	ans += i-b.sum(x[i])
	b.add(x[i], 1)
print(ans)

Solution (Python):
S = input()
Sum = 0
b_num = 0
for s in S:
    if s=="W":
        Sum+=b_num
    else:
        b_num+=1
print(Sum)

Solution (Python):
S=list(input())
N=len(S)
sumB=0
ans=0

for i in range(N):
  if S[i]=="B":
    sumB +=1
  else:
    ans +=sumB
    
print(ans)

Solution (Python):
S = list(input())
f_list = [k for k in range(len(S)) if S[k] == "W"]    
S.sort(reverse=True)
s_list = [k for k in range(len(S)) if S[k] == "W"]
ans = 0
for i in range(len(f_list)):
    ans += f_list[i]-s_list[i]
print(ans)

Solution (Python):
S = input()
l1 = list(S)
l2 = sorted(l1,reverse=True)
m1 = [i for i, x in enumerate(l1) if x == 'W']
m2 = [i for i, x in enumerate(l2) if x == 'W']
count = 0
for i in range(len(m1)):
    count += m1[i] - m2[i]
print(count)

Solution (Python):
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') 
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(sys.stdin.readline()) 
def ifn(): return float(sys.stdin.readline()) 
def isn(): return sys.stdin.readline().split() 
def imn(): return map(int, sys.stdin.readline().split()) 
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) 
def fmn(): return map(float, sys.stdin.readline().split()) 
def iln(): return list(map(int, sys.stdin.readline().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def fln(): return list(map(float, sys.stdin.readline().split())) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

S = input()
S_length = len(S)
black_indices = []
for i in range(S_length):
    if S[i] == 'B': black_indices.append(i)

total_blacks_indices = sum(black_indices)

black_count = len(black_indices)
index = S_length-1
result_black_indices = 0
for _ in range(black_count):
    result_black_indices += index
    index -= 1

print(result_black_indices - total_blacks_indices)

Solution (Python):

def inputlist(): return [int(j) for j in input().split()]
from collections import Counter


S = input()
ans = 0
count = 0
for i in range(len(S)):
    if S[i] == 'W':
        ans += i - count
        count += 1
print(ans)

Solution (Python):
s = input()
b = 0
res = 0
for i in range(len(s)):
    if s[i]=='B':
        b += 1
    else:
        res += b
print(res)

Solution (Python):
S = input()
ans = 0
count = 0
for i in range(len(S)):
    if S[i] == 'W':
        ans += i - count
        count += 1
print(ans)

Solution (Python):
s  = (input())
dist = 0
count = 0
for i in range(len(s)):
         if s[i] == "W":
                  count += 1
                  dist += i
print(dist-((count * (count - 1))//2))

Solution (Python):
S = list(input())

b = S.count("B")


ans = 0
n = len(S)
for i, s in enumerate(S):
    
    if s == "B":
        ans += n - b - i
        b -= 1
        
print(ans)

Solution (Python):

b_count = 0
ret = 0
S = input()

for s in S:
    if s == 'B':
        b_count += 1
    else:
        ret += b_count

print(ret)

Solution (Python):
s = input()

ans = 0
b_count = 0
for i, c in enumerate(s):
    if c == "W":
        ans += b_count
    else:
        b_count += 1

print(ans)

Solution (Python):
S = list(input())
ans = 0
b = 0
for i in range(len(S)):
    if S[i] == 'B':
        b += 1
    else:
        ans += b
        
print(ans)

Solution (Python):

S = input()
N = len(S)
cnt = 0
ans = 0
for i in range(N):
    if S[i] == 'W':
       ans += i - cnt
       cnt += 1
       
print(ans)

Solution (Python):
def main():
    reversi = input()
    answer = 0
    count_black = [0] * len(reversi)
    if reversi[0] == "B":
        count_black[0] = 1
    for i in range(1, len(reversi)):
        if reversi[i] == "B":
            count_black[i] = count_black[i - 1] + 1
        else:
            count_black[i] = count_black[i - 1]
    for i in range(len(reversi)):
        if reversi[i] == "W":
            answer += count_black[i]
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
s = str(input())
ans,move = 0,0
for i in range(len(s)):
  if(s[i] == 'B'):
    move += 1
  else:
    ans += move
print(ans)

Solution (Python):
s = input()

ans = 0
b_count = 0
for i,c in enumerate(s):
    if c == "W":
        ans += b_count
    else:
        b_count += 1

print(ans)

Solution (Python):
def main():
    S = input()
    b = []
    w = []
    for i, v in enumerate(S):
        if v == 'B':
            b.append(i)
        else:
            w.append(i)
    if len(b) == 0 or len(w) == 0:
        return 0
    return sum(w) - (len(w) * (len(w)-1))//2

print(main())

Solution (Python):
def main():
    S = input()
    w = 0
    r = 0
    for i, s in enumerate(S):
        if s == 'W':
            r += i - w
            w += 1
    return r

print(main())

Solution (Python):


S = input().strip()


sorted = 0
cnt=0
for i,word in enumerate(S):
    if word == "W":
        cnt += i - sorted
        sorted += 1

print(cnt)

Solution (Python):
S = input()
N = len(S)
Ans = 0
B = S.count("B")
for i in range(N):
    if S[i] == "B":
        Ans += N - B - i
        B -= 1

print(Ans)

Solution (Python):
s=input()

b_count = 0
ans = 0

for s_i in s:
  if s_i=='W':
    ans += b_count
  elif s_i=='B':
    b_count += 1

print(ans)

Solution (Python):
s = input()

cnt = 0
l = 0

for i in range(len(s)):
    if s[i] == 'W':
        cnt += i-l
        l += 1

print(cnt)

Solution (Python):
S = list(input())
ans = 0
cnt = 0
for i in range(len(S)):
    if S[i]=="B":
        cnt += 1
    else:
        ans += cnt
print(ans)

Solution (Python):

s=input()
n=s.count('W')
res=0
for i in range(len(s)):
    if s[i]=='W':
        res+=i
print(res-(n-1)*n//2)

Solution (Python):
s = input()
s = [i for i in s]
w_count = s.count('W')
ans = 0
if w_count == 0:
    print(0)
else:
    number = [i for i in range(w_count)]
    w_element = [i for i,j in enumerate(s) if j=='W']
    for i in range(w_count):
        ans += abs(number[i]-w_element[i])
    print(ans)

Solution (Python):
S=input()
b=0
for i in range(0,len(S)):
    if S[i]=='B':
        b+=1

ans=0
cnt=0
for i in range(0,len(S)):
    if S[i]=='B':
        cnt+=1
        ans+=len(S)-1-i-(b-cnt)

print(ans)

Solution (Python):
def main():
    s = input().rstrip()
    begin, end = 0, 0
    ans = 0
    for i in range(len(s)):
        if s[i] == "B":
            end = i
        else:
            end = i
            ans += end - begin
            begin += 1
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
S = input()

ans = 0
cnt = 0
for i in range(len(S)):
    if S[i] == "B":
        cnt += 1
    else:
        ans += cnt

print(ans)

Solution (Python):
s=list(input())
n=len(s)
ans=0
res=0
for i in range(n):
    if s[n-1-i]=="W":
        res+=1
    else:
        ans+=res
print(ans)

Solution (Python):
S = list(input())
black = 0
ans = 0
for c in S:
    if c == "B":
        black += 1
    else:
        ans += black
print(ans)

Solution (Python):
S = input()
N = len(S)


before = 0
cnt = 0
for i, si in enumerate(S):
    if si == 'B':
        cnt += 1
        before += i

after = 0
for i in range(cnt):
    after += (N-1) - i


print(after - before)

Solution (Python):
S = input()
N = len(S)

bc = S.count('B')

bpos = 0
ans = 0
for i, si in enumerate(S):
    if si == 'B':
        bpos += 1  
        after_pos = N - bc + bpos - 1
        diff = after_pos - i
        ans += diff
        

print(ans)

Solution (Python):
S=input()
id=0
cnt=0
for i in range(len(S)):
    if S[i]=="W":
        cnt=cnt+i-id
        id=id+1
print(cnt)

Solution (Python):
S = input()
black=ans=0
for s in S:
    if s == 'B':
        black += 1
    else:
        ans += black
print(ans)

Solution (Python):
s = input()
ans = 0
tmp = ''
cnt = 0
for c in s[::-1]:
    if c == 'W':
        cnt += 1
    elif c == 'B':
        ans += cnt
print(ans)

Solution (Python):
S = input()
BC = S.count('B')
WC = len(S) - BC

ans = 0
for i in range(len(S)):
  if S[i] == 'B':
    ans += WC
  else:
    WC -= 1
print(ans)

Solution (Python):
s = input()
dat = []
wcount = 0
res = 0
for i in range(len(s)):
    if s[i] == "W":
        res += (i - wcount)
        wcount += 1
        dat.append(i)
print(res)

Solution (Python):
s=  input()
W = 'W'
B = 'B'
Bi = []
Wi = []

BC = s.count(B)
WC = len(s) - BC

for i in range(len(s)):
  if s[i] == B:
    Bi.append(i)
  else:
    Wi.append(i)
    
W_dist = sum(Wi) - int((0 + WC-1)* (WC)/2)


B_dist = int((len(s)-1 + WC) * BC /2) - sum(Bi)


print(int((W_dist + B_dist)/2))

Solution (Python):
S=input()
b=0
ans=0
for s in S:
    if s=="B":
        b+=1
    else:
        ans+=b
print(ans)

Solution (Python):
s=list(input())
c=0
ans=0
for i in range(len(s)):
  if s[i]=='W':
    ans+=i-c
    c+=1
print(ans)

Solution (Python):
s=input()
a=b=0
for i in range(len(s)):
  if s[i]=='B':
    b+=1
  else:
    a+=b
print(a)

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines







def main():
	s=input().rstrip().decode('utf-8')
	
	cnt=0
	ans=0
	
	for i in range(len(s)):
		if s[-i-1]=="W":
			cnt+=1
		else:
			ans+=cnt
	
	print(ans)
	
	
	
	
	
	
	
if __name__ == "__main__":
	main()

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines







def main():
	s=input().rstrip().decode('utf-8')
	
	cnt=0
	ans=0
	
	for i in range(len(s)):
		if s[-i-1]=="W":
			cnt+=1
		else:
			ans+=cnt
	
	print(ans)
	
	
	
	
	
	
	
if __name__ == "__main__":
	main()

Solution (Python):
def main():
    S = list(input())
    accum = [0]
    for i in range(1,len(S)):
        tmp = accum[i-1] + 1 if S[i-1] == "B" else accum[i-1]
        accum.append(tmp)
    ans = 0
    for i in range(len(S)):
        tmp = 0 if S[i] == "B" else accum[i]
        ans += tmp
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
s=input()
cnt=0
temp=0
for i in range(len(s)):
    if s[i]=='B':
        temp+=1
    elif i>=1 and s[i]=='W':
        cnt+=temp

print(cnt)

Solution (Python):
s = input()
cnt = ans = 0
for c in s:
    if c == 'B':
        cnt += 1
    else:
        ans += cnt
print(ans)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    Bcount = 0
    ans = 0
    for s in S:
        Bcount += s=="B"
        if s=="W":
            ans += Bcount
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
S=input()
ans=0
X=0
for i in range (len(S)):
	if S[i]=='W':
		ans+=i-X
		X+=1
print(ans)

Solution (Python):
S=str(input())
N=S.count('W')
L=[0]*len(S)
ans=0
X=0
Q=[]
for i in range (len(S)):
	if S[i]=='W':
		ans+=i-X
		X+=1
print(ans)

Solution (Python):
S = input()

ans_count = 0
b_count = 0
for s in S:
    if s=="B":
        b_count = b_count + 1
    if s=="W":
        ans_count = ans_count + b_count

print(ans_count)

Solution (Python):
s = list(str(input()))
d = 0
ans = 0
for i in range(len(s)):
  if s[i] == 'B':
    d += 1
  else:
    ans += d
print(ans)

Solution (Python):
s=str(input())
co=int(0)
ans=int(0)
for i in reversed(range(len(s))):
    if s[i]=='W':
        co+=1
    else:
        ans+=co

print(ans)

Solution (Python):
import sys

def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import bisect
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15

def main():
    s = input().strip()
    tmp = 0
    ans = 0
    for c in s:
        if c == "B":
            tmp += 1
        else:
            ans += tmp
            

    print(ans)


if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Solution (Python):
S=list(input())
ans=0
bl=0
for s in S:
  if s=='B':
    bl+=1
  else:
    ans+=bl
    
print(ans)

Solution (Python):
def main():
    S = [i for i in input()]
    ans = 0
    b_cnt = 0
    for i in range(len(S)):
        if S[i] == "B":
            b_cnt += 1
        elif S[i] == "W":
            ans += b_cnt
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

def solve():
    S = input()
    count = 0
    leftMostW = 0
    for i in range(len(S)):
        if S[i] == "W":
            count += i - leftMostW
            leftMostW += 1
    print(count)

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
S = input()
N = len(S)
cnt_B = 0
ans = 0
for i in range(N):
    if S[i] == "B":
        cnt_B += 1
    else:
        ans += cnt_B
print(ans)

Solution (Python):
S = input()

b = 0
ans = 0
for s in S:
    if s == "B":
        b += 1
    else:
        ans += b

print(ans)

Solution (Python):
s = input()

ans = b = 0
prev = "W"
for c in s:
    if c=="B":
        b += 1
        prev = "B"
    elif prev=="B":
        ans += b
        prev = "B"
    else:
        b = 0
        prev = "W"
print(ans)

Solution (Python):
S = input()[::-1]
w = 0
ans = 0
for e in S:
    if e == "W":
        w += 1
    else:
        ans += w
print(ans)

Solution (Python):
S = input()
ans = 0
black = 0
for c in S:
    if c == 'B':
        black += 1
    else:
        ans += black
print(ans)

Solution (Python):
if __name__ == "__main__":
    s = input()

    bcount = 0
    ans = 0

    for ss in s:
        if ss == 'B':
            bcount += 1
        else:
            ans += bcount

    print(ans)

Solution (Python):
S = input()
count = 0
ans = 0
for x in S:
    if x == "B":
        count += 1
    else:
        ans += count
print(ans)

Solution (Python):
s = input()
cnt = 0
ans = 0
for i in s:
    if i == 'B':
        cnt += 1
    else:
        ans += cnt
print(ans)

Solution (Python):
s = input()
n = len(s)

w,b = 0,0
p,q = 0,0

for i, j in enumerate(s):
    if j == "W":
        p += 1
        w += i
    else:
        q += 1
        b += i

pp = p * (p - 1) // 2
qq = n * (n - 1) // 2 - pp



print((w - pp + qq - b) // 2)

Solution (Python):
S = input()
b = ans = 0
for c in S:
    if c=='B':
        b += 1
    else:
        ans += b
print(ans)

Solution (Python):
s = input()
black = 0
ans = 0

for i in s:
    if i == 'B':
        black += 1
    else:
        ans += black

print(ans)

Solution (Python):
s = input()

x = [1 if c == 'B' else 0 for c in s]

cum = [0]
for i in range(len(s)):
    cum.append(cum[-1] + x[i])

ans = 0
for idx, c in enumerate(s):
    if c == 'W':
        ans += cum[idx+1]
print(ans)

Solution (Python):
s = input()
ans = 0
numB = 0
for i in reversed(range(len(s))):
    if s[i] == 'B':
        ans += len(s) - 1 - i - numB
        numB += 1
print(ans)

Solution (Python):
s = input()
ans = 0
count = 0
for i in range(len(s)):
    if s[i] == 'W':
        ans += i - count
        count += 1
print(ans)

Solution (Python):
s = [1 if x == "B" else 0 for x in input()]
ans = cnt = 0
for s_i in s:
    if s_i == 1: cnt += 1
    else: ans += cnt
print(ans)

Solution (Python):
s = input()
r = 0
c = 0
for i in range(len(s)):
    if s[i]=='B':
        c += 1
    else:
        r += c
print(r)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





s=list(ss())
lens=len(s)

wrr=[i for i ,x in enumerate(s) if x=="W"]
lenwrr=len(wrr)
print(sum(wrr)-(lenwrr*(lenwrr-1)//2))

Solution (Python):
s = input()
total = 0
tmp = 0
for i in range(len(s)):
    if s[i] == 'B':
        tmp += 1
    else:
        total += tmp
print(total)

Solution (Python):
s=input()
ans=0
count=0 if s[0]=="B" else 1
for i in range(1,len(s)):
        if s[i]=="W":
            ans+=i-count
            count+=1
print(ans)

Solution (Python):
from collections import Counter
s = input()
n = len(s)
c = Counter(s)
ans = 0
for i in range(n):
  if s[i] == "W":
    ans += i+1
ans -= c["W"]*(c["W"]+1)//2
print(ans)

Solution (Python):
S = input()
B_cnt = S.count("B")
ans = 0
for i in range(len(S)):
	if S[i] == "B":
		ans += i
max = 0
for i in range(len(S)-1,len(S) - B_cnt - 1,-1):
	max += i
print(max - ans)

Solution (Python):
A = list(input())

count = 0
ans = 0
for a in A:
    if a == 'B':
        count += 1
    else:
        ans += count

print(ans)

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def calc(N):
    return sum(int(x) for x in str(N))


def main():
    
    S = Scanner.string()
    N = len(S)
    sums = [0] * (N+1)
    for i in range(N):
        sums[i+1] = sums[i]
        if S[i] == "B":
            sums[i+1] += 1
    ans = 0
    for i in range(N):
        if S[i] == "W":
            ans += sums[i+1]
    print(ans)
    return


if __name__ == "__main__":
    main()

Solution (Python):
s=input()
ans=0
b=0
for c in s:
    if c=='B':
        b+=1
    else:
        ans+=b
print(ans)

Solution (Python):
S=list(input())

t=0
c=0
for i,s in enumerate(S):
    if(s=="W"):
        c+=i-t
        t+=1
print(c)

Solution (Python):
s = input()
n = len(s)
r = s.count("B")
ans = 0
for i in range(r):
  ans += n-i

for i in range(n):
  if s[i] == "B":
    ans -= i+1
  
print(ans)

Solution (Python):
from scipy.misc import comb
s = input()
n = len(s)
r = s.count("B")
ans = 0
for i in range(r):
  ans += n-i

for i in range(len(s)):
  if s[i] == "B":
    ans -= i+1
  
print(ans)

Solution (Python):
S = input()[::-1]

res = 0
prev = 0
for i, s in enumerate(S):
    if s == 'B':
        res += i - prev
        prev += 1

print(res)

Solution (Python):
from sys import stdin

s = stdin.readline().rstrip()

now = 0
count = 0

for i in range(len(s)):
    if s[i] == "W":
        count += (i-now)
        now += 1

print(count)

Solution (Python):
s = input()

ans = 0
cntb = 0

for i in range(len(s)):
    if s[i] == "B":
        cntb += 1
    elif s[i] == "W":
        ans += cntb

print(ans)

Solution (Python):
S = list(input())
N = len(S)
P = N-1
ans = 0
for i in range(N-2,-1,-1):
    if i == P-1 and S[i+1] == 'B':
        P -= 1
    if S[i] == 'B' and S[i+1] == 'W':
        S[i] = 'W'
        ans += P - i
        P -= 1
print(ans)

Solution (Python):
s=input()
n=len(s)
cnt=0
ans=0
for i in range(n):
  if s[n-i-1]=='B':
    ans+=n-1-(n-i-1)-cnt
    cnt+=1
print(ans)

Solution (Python):
s = input()
ans = 0
w_count = 0
for i in range(len(s)):
    if s[i] == 'W':
        ans += i - w_count
        w_count += 1
print(ans)

Solution (Python):
s = input()
l = len(s)
head = 0
cnt = 0
for i in range(l):
	if s[i] == "W":
		cnt += i-head
		head += 1

print(cnt)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    s = S()
    ans = 0
    w = 0
    for i, si in enumerate(s):
        if si == "W":
            ans += i-w
            w += 1
    print(ans)

    return



if __name__ == '__main__':
    solve()

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	S = input().rstrip()
	bcnt = 0
	ans = 0
	for i in range(len(S)):
		if S[i] == 'B': bcnt += 1
		if S[i] == 'W': ans += bcnt
	
	print(ans)

if __name__ == '__main__':
	main()

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	S = input().rstrip()
	bcnt = 0
	A = []
	for i in range(len(S)):
		if S[i] == 'B': bcnt += 1
		if S[i] == 'W': A.append(bcnt)
	
	print(sum(A))

if __name__ == '__main__':
	main()

Solution (Python):
S = input().strip()
A = [0 for _ in range(len(S))]
cnt = 0
for i in range(len(S)):
    if S[i]=="B":
        cnt += 1
    A[i] = cnt
cntW = 0
for i in range(len(S)):
    if S[i]=="W":
        cntW += A[i]
print(cntW)

Solution (Python):
S = input()
W = S.count("W")

A = [i for i in range(W)]

ans = 0
cnt = 0
for i in range(len(S)):
    if S[i] == "W":
        ans += i - A[cnt]
        cnt += 1

print(ans)

Solution (Python):
def examA():
    S = SI()
    cur = 0; ans = 0
    for i,s in enumerate(S):
        if s=="W":
            ans += i-cur
            cur +=1
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examA()

Solution (Python):
s=list(input())
c=0
ans=0
for i in range(len(s)):
    if s[i]=='W':
        ans+=i-c
        c+=1
print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



S = read().rstrip().decode('utf-8')

B = 0
answer = 0
for x in S:
    if x == 'B':
        B += 1
    else:
        answer += B

print(answer)

Solution (Python):
S = input()
N = len(S)
wcnt = 0
ans = 0
for i in range(N):
    if S[i] == 'W':
        ans += i - wcnt
        wcnt += 1
print(ans)

Solution (Python):
S=input()
n=len(S)
wc=0
out=0
for i in range(n):
  if S[i]=='W':
    out+=i-wc
    wc+=1
print(out)

Solution (Python):
s=input()
b=0
ans=0
for i in range(len(s)):
    if s[i]=="B":
        b+=1
    else:
        ans+=b
print(ans)

Solution (Python):
S = input()
cnt = 0
ans = 0
for s in S:
  if s == "B":
    cnt += 1
  else:
    ans += cnt
print(ans)

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(S: str):
    idx = [i for i in range(len(S)) if S[i] == 'W']
    print(sum([v-i for i,v in enumerate(idx)]))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  
    solve(S)

if __name__ == '__main__':
    main()

Solution (Python):

import sys


def solve(S: str):
    count = 0
    answer = 0

    for i in range(len(S)):
        if S[i] == "W":
            count += 1
            answer += i+1-count
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  
    solve(S)

if __name__ == '__main__':
    main()

Solution (Python):
S=input()
N=len(S)
count=0
num=0
for i in range(N):
    if S[i]=="W":
        count+=1
        num+=i
print(num-count*(count-1)//2)

Solution (Python):
s = input()
cnt = 0
res = 0
for _s in s:
    if _s == "B":
        cnt += 1
    else:
        res += cnt
print(res)

Solution (Python):
S = input()

ret = 0
w = 0
for s in S[::-1] :
  if s == 'W' :
    w += 1
  else :
    ret += w
    
print(ret)

Solution (Python):
S = list(input())
c = 0
for i in range(len(S)):
    if S[i] == 'W':
        c += i
sc = S.count('W')
print(int(c - sc*(sc-1)//2))

Solution (Python):
s = input()

numOfW = 0
ans = 0
for i in range(len(s)):
    if s[i] == "W":
        ans += i - numOfW
        numOfW += 1
print(ans)

Solution (Python):
S = input()
L = []
for i in range(len(S)):
  if S[i] == 'W':
    L.append(i)
print(sum((L[i] - i) for i in range(len(L))))