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):
S=input()[::-1]
n=len(S)
l=list(i for i in range(n) if S[i]=='B')
k=len(l)*(len(l)-1)//2
print(sum(l)-k)

Solution (Python):
S = input()

S.lstrip("W")
def f(s):
    count = 1
    for i, si in enumerate(s):
        if si == 'W':
            yield (i+1) - count
            count += 1

print(sum(f(S)))

Solution (Python):
def main():
    txt = input()

    w_cnt = 0
    cnt = 0
    for char in reversed(txt):
        if char == 'W':
            w_cnt += 1
        else:
            cnt += w_cnt
    print(cnt)
    return

main()

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

Solution (Python):


import itertools


S = [len(i) for i in input().split('B')]



SS = S[:0:-1]




print(sum(itertools.accumulate(SS)))

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

Solution (Python):
Moji=input()
current_poit=0
privious_W=0
c=0
for char in Moji:
    if char == 'W':
        c=c+(current_poit-privious_W)
        privious_W=privious_W+1
    current_poit=current_poit+1
print(c)

Solution (Python):
S = input()
n = 0 
s = 0 
for i in range(len(S)):
	if S[i] == 'W':
		n += 1
		s += i + 1
print(int(s - n * (n + 1) / 2))

Solution (Python):
def query_sum(bit, idx):
    sum_ = 0
    while idx > 0:
        sum_ += bit[idx]
        idx -= idx & -idx
    return sum_


def add_sum(bit, idx, value):
    """
    add value to a[i].
    """
    while idx <= len(bit):
        bit[idx] += value
        idx += idx & -idx


S = input()
bit = [0] * (len(S) + 1000)
num_whites = 0
for i, char in enumerate(S, start=1):
    if char == "W":
        add_sum(bit, i, 1)
        num_whites += 1


num_flips = 0
for i, char in enumerate(S, start=1):
    if char == "B":
        this_num_flips = num_whites - query_sum(bit, i)
        num_flips += this_num_flips

print(num_flips)

Solution (Python):
s=input()
ls=len(s)
k=1
ans=0

for i in range(ls):
    if s[i]=="W":
        ans+=i-k+1
        k+=1

print(ans)

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

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

n = len(s)
m = 0
cnt=0

for i in range(n):
    if s[i]=="W":
        m+=i
        cnt +=1

SUM = cnt*(cnt-1)//2
print(m-SUM)

Solution (Python):
S = input()
bcount = 0
total = 0
for i in S:
    if i == "B":
        bcount += 1
    else:
        total += bcount
print(total)

Solution (Python):



from collections import deque
import bisect


def main():
    s = input()

    b = []
    for i in range(len(s)):
        if s[i] == "B":
            b.append(i)

    b.reverse()
    ans = 0
    for i in range(len(b)):
        ans += len(s) - i - 1 - b[i]

    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
s = list(input())
widx = [i for i, color in enumerate(s) if color == 'W']
arr = list(range(len(widx)))
print(sum(widx) - sum(arr))

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

print(ans)

Solution (Python):
_s = input()
s = [_s[i] for i in range(len(_s))]

count = 0




b = 0

for i in range(len(s)):
    if s[i] == "B":
        b += 1
    else:
        count += b
print(count)

Solution (Python):
sS = input().rstrip()
iL = len(sS)

iC = 0
iWC = 0
for i in range(iL):
    if sS[i] == 'W':
        iC += i - iWC
        iWC +=1
print(iC)

Solution (Python):
s = input()
count = 0
num = 0
for n, i in enumerate(s):
  if i == 'W':
    num += 1
    count += n
print(int(count-num*(num-1)/2))

Solution (Python):
s = str(input())
a = []
m = len(s)
for i in range(m):
  if s[i] == "B":
    a.append(i)
n = len(a)
x = 0
for j in range(n):
  x += m-j-1
print(x-sum(a))

Solution (Python):
S = input()

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

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

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

Solution (Python):
s = list(str(input()))
num = 0
add = 0
for i in s:
  if i == "B":
    add += 1
  if i == "W":
    num = num + add
print(num)

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

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

Solution (Python):
c = 0
a = 0
for x in input().strip()[::-1]:
    if x == 'W':
        c += 1
    else:
        a += c
print(a)

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

whitenum = 0
count = 0

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

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

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

Solution (Python):
from itertools import accumulate

Ss = input()

As = [1 if S == 'B' else 0 for S in Ss]
accAs = accumulate(As)

ans = 0
for i, (A, accA) in enumerate(zip(As, accAs)):
    if A == 0:
        ans += accA
print(ans)

Solution (Python):
S=input()

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

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

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

Solution (Python):
def main():
    S = input()
    retval = 0
    b = 0
    for i in range(len(S)):
        if S[i] == "B":
            b += 1
        else:
            retval += b
    print(retval)


if __name__ == "__main__":
    main()

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

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

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

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

Solution (Python):

def inpl(): return list(map(int, input().split()))
S = input()

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

print(ans)

Solution (Python):
s = input()

answer = 0
black_count = 0
for i in range(len(s)):
    if s[i] == "B":
        black_count += 1
    else:
        answer += black_count

print(answer)

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

Solution (Python):



def solve():
    s = input()
    ans = 0
    ls = [0] * s.count('W')
    idx = 0
    for i in range(len(s)):
        if s[i] == 'W':
            ls[idx] = i
            idx += 1
    cnt = 0
    for i in ls:
        ans += (i - cnt)
        cnt += 1
    print(ans)

if __name__=="__main__":
    solve()

Solution (Python):
listS = list(input())
listS.reverse()

wcounter = 0
bcounter = 0
index=0
while index < len(listS):
    if listS[index] == "W":
        wcounter+=1
    else:
        bcounter+=wcounter
    index+=1

print(bcounter)

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()
cnt = 0
white = 0
for i, s in enumerate(S):
  if s == 'W':
    cnt += i - white
    white += 1
print(cnt)

Solution (Python):
S = input()

w = sum(i for i,x in enumerate(S) if x == 'W')

N = sum(1 for x in S if x == 'W')

print(w - (N-1)*N//2)

Solution (Python):
S = input()

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

Solution (Python):
s = input()

last = 0
ans = 0
for i in reversed(range(len(s))):
    if s[i] == "W":
        last += 1
    else:
        ans += last
        

print(ans)

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

cnt=0
for i in range(len(S)):
    if S[i]=="W":
        cnt+=i+1
print(cnt-(w+1)*w//2)

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

Solution (Python):


import sys
from collections import Counter



INF = float('inf')
MOD = 10 ** 9 + 7


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


S = input()

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

print(ans)

Solution (Python):
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict


S = input()

bCnt = 0
ret = 0
for s in S:
    if s == "B":
        bCnt +=1
    if s == "W":
       ret += bCnt



print(ret)

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

Solution (Python):
s=raw_input()

ss="".join(sorted(s,reverse=True))

ns=sum([k for k in range(len(s)) if s[k]=="W"])
ns2=sum([k for k in range(len(s)) if ss[k]=="W"])

print ns-ns2

Solution (Python):
A = str(input());
ans = 0;
now = 0;

for i in A:
    if i=="B":
        now+=1;
    elif i=="W":
        ans+=now;

print(ans);

Solution (Python):
s = list(input())
ans = 0
w = 0
for i,j in enumerate(s):
  if j == "W":
    ans += (i - w)
    w += 1
print(ans)

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

Solution (Python):
ans, w_idx = 0, 0
for i, s in enumerate(input()):
    if s != 'W':
        continue
    ans += i - w_idx
    w_idx += 1
print(ans)

Solution (Python):
s = input()
ans = 0
w = 0
j = 0
for i in s:
    if i == "W":
        ans += j - w
        w += 1
    j += 1
print(ans)

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

print(sum)

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

Solution (Python):
S = input()
s = reversed(S)
bs = [i for i, v in enumerate(s) if v == "B"]
count = 0
for ifor, ifrom in enumerate(bs):
    count += ifrom - ifor
print(count)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()

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

Solution (Python):
S = input()



Ws = [x == "W" for x in S]

nB = sum(Ws)
ans = 0
for n,x in enumerate(Ws):
	if x:
		ans += n
ans -= nB*(nB-1)//2
print(ans)

Solution (Python):
S=input()
Bcount=0
answer=0

for i in range(len(S)):
  if S[i]=='B':
    Bcount+=1
  if S[i]=='W':
    answer+=Bcount

print(answer)

Solution (Python):





"""
agc 029
"""

s = input()

tmp = 0
ans = 0
for i in s:
    if i == 'B':
        tmp += 1
    if i == 'W':
        ans += tmp

print(ans)

Solution (Python):
s = input()
n = len(s)
ans = 0
count = 0
for i, c in enumerate(reversed(s)):
    if c=='B':
        ans += i-count
        count += 1
print(ans)

Solution (Python):
S=input()

numW = S.count("W")
count=0
for i in range(len(S)):
	if S[i]=='B':
		count+=numW
	else:
		numW-=1

print(count)

Solution (Python):
S = input()

res = 0
p = len(S) - 1
for n, s in enumerate(S):
    if s == "B":
        res += p - n
        p -= 1

print(res)

Solution (Python):

import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
sys.setrecursionlimit(10**6)
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


S = input()


count = 0
ans = 0
for s in S:
    if s == "B":
        count += 1
    else:
        ans += count
print(ans)

Solution (Python):
s = input()
ans = 0
l = len(s)
i = l-1
num = 0
while i >= 0:
    if s[i] == "B":
        num += 1
        ans += l-i-num
    i -= 1
print(ans)

Solution (Python):

s=list(input())
n = len(s)
res = 0
c = 0
for i in range(n):
    if s[i] == 'B':
        c += 1
    else:
        res += c
print(res)

Solution (Python):
s = input()

blist = [0 for i in range(len(s))]
for i in range(len(s)):
    if s[i] == "B":
        blist[i] = 1

for i in range(len(s)-1):
    blist[i+1] += blist[i]

count = 0
for i in range(len(s)):
    if s[i] == "W":
        count += blist[i]

print(count)

Solution (Python):
s = input()

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

Solution (Python):
S = input()
bs = [0]
for c in S:
    bs.append(bs[-1] + int(c=='B'))

ans = 0
for b,c in zip(bs[1:],S):
    if c == 'W':
        ans += b
print(ans)

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

print(ans)

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

Solution (Python):
from collections import Counter
S = input()
L = len(S)
n = Counter(S)['B']
now = 0
ans = 0
for i in range(L):
    if S[i] == 'B':
        continue
    if S[i] == 'W':
        ans += i - now
        now += 1
print(ans)

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

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

tot = 0
b = 0

for i in s:
    if(i == 'W'):
        tot += b
    else:
        b += 1
print(tot)

Solution (Python):
S = input()[::-1]
ans = 0
tmp = 0
bcnt = 0
N = len(S)
for i in range(N):
    if S[i]=="W":
        tmp += 1
    else:
        ans += tmp
        bcnt += 1
        tmp = i+1-bcnt

print(ans)

Solution (Python):
S=input()

SR=S[::-1]

A=[0]*len(S)
if SR[0]=="W":
    A[0]=1


for i in range(1,len(S)):
    if SR[i]=="W":
        A[i]=A[i-1]+1
    else:
        A[i]=A[i-1]

ANS=0

for i in range(len(S)):
    if SR[i]=="B":
        ANS+=A[i]

print(ANS)

Solution (Python):
S=input()
ans=0
tmp=0
for x in S:
    if x=='W':
        ans+=tmp
    else:
        tmp+=1
print(ans)

Solution (Python):
s = input()
tmpw = 0
ans = 0
for c in s:
    if c == 'W':
        tmpw += 1
    else:
        ans -= tmpw
ans += (len(s)-tmpw)*tmpw
print(ans)

Solution (Python):
S = input()

B = 0
ans = 0
for s in S:
    if s == 'B':
        B += 1

    if s == 'W':
        ans += B

print(ans)

Solution (Python):
s = input()
n = len(s)
a,c = 0,0
for i in range(n):
  if s[i] == "B":
    c += 1
    a += i
print((2*n-1-c)*c//2-a)

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

Solution (Python):

s=input()
times=1
sum=0
for i in range(len(s)):
    if s[i]=='W':
        sum+=i+1-times
        times+=1
print(sum)

Solution (Python):
S  = input()

b_count = 0
ans = 0

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

print(ans)

Solution (Python):



 
import sys
import math



 

fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile


mod=1000000007
 

def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 

s=str(input())
ans=0

cb=0
for i in range(len(s)):
    if(s[i]=='W'):
        ans+=cb
    else:
        cb+=1

print(ans)
    
    

if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

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

Solution (Python):

import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    
    import numpy
    def dprint(*args, **kwargs):
        
        
        print(*args,  file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') 
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') 
    atexit.register(lambda :sys.stdout.close())     
    
 

S = input()
r = 0
tb = 0
for c in S:
    if c== 'B':
        tb+=1
    else:
        r += tb

print(r)

Solution (Python):
S = input()
sumW = 0
total = 0
for i in reversed(range(len(S))):
    if S[i] == "W":
        sumW += 1
    elif S[i] == "B":
        total += sumW
print(total)

Solution (Python):
s = raw_input().strip()
ans = x = 0
for i, c in enumerate(s):
    if c == 'W':
        ans += i - x
        x += 1
print ans

Solution (Python):
s = reversed(input())
stack = 0
ans = 0
for i in s:
    if i == 'W':
        stack += 1
    else:
        ans += stack
print(ans)

Solution (Python):
S = input()

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

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

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

Solution (Python):
s = input()

cou = 0
ans = 0
for i in s:
    if i == 'B':
        cou += 1
    else:
        ans += cou
print(ans)

Solution (Python):
S = input()
ans = 0
cnt = 0
for i, c in enumerate(S[::-1]):
    if c=="B":
        ans += i - cnt
        cnt += 1
print(ans)

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

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

Solution (Python):

S_list = list(input())

res = 0
cnt = 0

for s in S_list:
    if s == "B":
        cnt += 1
    else:
        res += cnt

print(res)

Solution (Python):



N = input()

num_B = 0
ans = 0
for i in N:
    if i == 'W':
        ans += num_B
    else:
        num_B += 1

print(ans)

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

Solution (Python):




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

Solution (Python):
s = input()

cnt = 0
res = 0

for c in s:
    if c == 'B':
        cnt += 1
    if c == 'W':
        res += cnt

print(res)

Solution (Python):

s = input()
ans = 0
b = 0
for c in s:
    if c == 'W':
        ans += b
    elif c == 'B':
        b += 1
print(ans)

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

Solution (Python):


from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

S = raw_input()[::-1]

ans = 0
cnt = 0
for c in S:
    if c == 'W':
        cnt += 1
    else:
        ans += cnt

print ans