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



Sample input:
BBW


Sample output:
2

Submission status: Accepted

Solution code:
s = input()

ans = 0
c=0
N = len(s)


for i in range(N):
    if s[N-i-1]=='W':
        c+=1
    else:
        ans+=c

print(ans)

Submission status: Accepted

Solution code:
s = input()
list = list(s)
count=0
b=0

for i in range(len(list)):
  if(list[i] == "W"):
    count+=b
    continue
  else:
    if(i == len(list)-1):
      break
    b += 1
      
print(count)

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
ans = 0
c = 0
if "B" in s:
    b = s.index("B")
else:
    print(0)
    exit()
for i in range(b+1, n):
    if s[i] == "W":
        ans += i - b - c
        c += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
data = list(input())

count = 0
# i = 0
# while 1:
count_b = 0
for i in range(len(data)):
    # print(i)
    if data[i] == 'W':
        count += count_b
        # count += 1
        # data[i], data[i+1] = 'B', 'W'
        # break
    else:
        count_b += 1
    # else:
    #     break
print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
S = input()
len_S = len(S)
w_num = 0
operation_num = 0
for Ind in range(len_S-1,-1,-1):
	if S[Ind] == "W":
		w_num += 1
	elif S[Ind] == "B":
		operation_num += w_num

print(operation_num)

Submission status: Accepted

Solution code:
a=list(input())
count=0
wc=0
for num,i in enumerate(a):
    if i=="W":
        count+=num-wc
        wc+=1

print(count)

Submission status: Accepted

Solution code:
s=input()
a=[]
cnt=0
for i in range (len(s)):
    if s[i]=='B':
        a.append(0)
    else:
        cnt+=len(a)        
print(cnt)

Submission status: Accepted

Solution code:
S = input()
n = 0
r = -1
x = 0
while True:
    r = S.find("W", r+1)
    if r == -1:
        break
    x += r - n
    n += 1

print(x)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
flag = 0

ans = 0
ans2 = 0
Bcount = 0
Wcount = 0
for i in range(N):
    if S[i] == 'B':
        ans2 += N - 1 - i
        Bcount += 1
for i in range(N):
    if S[i] == "W":
        Wcount += 1
        ans += i + 1
for i in range(Bcount):
    ans2 -= i
for i in range(Wcount):
    ans -= i
print(min(ans,ans2))

Submission status: Accepted

Solution code:
chars = list(input())
W = chars.count('W')
base = 0
count = 0
for i, c in enumerate(chars):
    if c == 'W':
        count += i - base
        base += 1
print(count)

Submission status: Accepted

Solution code:
s=list(input())
B=0;W=0;b=0;w=0
for i in range(len(s)):
  if s[i]=='B':B+=i+1
  elif s[i]=='W':W+=i+1
x=B-W
t=sorted(s)
t.reverse()
for j in range(len(t)):
  if t[j]=='B':b+=j+1
  elif t[j]=='W':w+=j+1
y=b-w
print(int(abs(x-y)/2))

Submission status: Accepted

Solution code:

def solve(S):
    if len(S) == 1:
        return 0

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


if __name__ == "__main__":
    print(solve(input()))

Submission status: Accepted

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

b = S.count("B")
ans = 0

for k in range(N):
    if S[k] == "B":
        ans += N-b-k
        b -= 1
print(ans)

Submission status: Accepted

Solution code:
a=input()
len_a=len(a)
#maxpoint=len_a * (len_a+1) / 2
point=0
howmany_w=0
for a_n in range(len(a)):
	if a[a_n]=='W':
		point+=(len_a-a_n)
		howmany_w+=1

maxpoint = (len_a - howmany_w/2 + 1/2) * (howmany_w)

kaisu=maxpoint-point
print(int(kaisu))

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
i = []
for j in range(n):
  if s[j] == "W":
    i.append(j)
c = 0
for k in range(len(i)):
  c += i[k]-k
print(c)

Submission status: Accepted

Solution code:
S = list(input())
count_B = 0
ans = 0
for i in range(len(S)):
    if S[i] == "B":
        count_B += 1
    elif S[i] == "W":
        ans += count_B
print(ans)

Submission status: Accepted

Solution code:
S = input()
S_list = []
for i in S:
    S_list.append(i)

w_count = S.count("W")
b_count = S.count("B")
c = 0

for i in range(len(S)):

    if S[i] == "B":
        c += w_count
    else:
        w_count -= 1

print(c)

Submission status: Accepted

Solution code:
N = input()
re = []
for i ,val in enumerate(N):
	if val == "W":
		re.append(i - len(re))
print( sum(re) )

Submission status: Accepted

Solution code:
xs = list(input().rstrip())
bcount = 0
count = 0
for x in xs:
  if x == 'B':
    bcount += 1
  else:
    count += bcount

print(count)

Submission status: Accepted

Solution code:
S = input()

def f(S):
    if len(S)==1 :
        return 0
    else :
        result = 0; b = 0
        for i in S :
            if i == 'B' :
                b+=1
            else:
                result += b
        return result
print(f(S))

Submission status: Accepted

Solution code:
S = input()
countW = 0
countB = 0
for i in range(len(S)):
  if S[i]=="B":
    countB+=1
  if S[i]=="W":
    countW += countB
print(countW)

Submission status: Accepted

Solution code:
S = input()

ans=0

W=0

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

Submission status: Accepted

Solution code:
from itertools import groupby as gb
s = input()
g = gb(s)
flag = False
if s[0]=='W':
    flag = True
BW = []
for k,v in g:
    if flag:
        flag = False
        continue
    BW.append(len(list(v)))
if len(BW)%2==0:
    BW.append(0)
tmp = 0
res = 0
for i in range(0,len(BW)-1,2):
    a,b = BW[i]+tmp, BW[i+1]
    res += a * b
    BW[i+2] += a
    #print(a,b,i)
print(res)
#print(BW)

Submission status: Accepted

Solution code:
S = [c for c in input()]

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

print(ans)

Submission status: Accepted

Solution code:
s = str(input())
num = 0
ans = 0
cou = 0
nu = 0
co = 0
for i in range(len(s)):
    if s[i] == "W":
        num += cou
        cou = 0
        ans += num
    else:
        cou += 1
print(ans)

Submission status: Accepted

Solution code:
s = raw_input()

sum = 0
itr = 0
for i in range(len(s)):

    if s[i] == "W":
        sum = sum - itr + i
        itr = itr + 1


print(sum)

Submission status: Accepted

Solution code:
import sys
import collections
input = sys.stdin.readline

S = input()
c = collections.Counter(S)["W"]
ans = 0

for s in S:
    if s == "B":
        ans += c
    elif s == "W":
        c -= 1

print(ans)

Submission status: Accepted

Solution code:
s = input()
a = []
for i in range(len(s)):
    if s[i] == 'W':
        a.append(i+1)
res = 0
for i in range(len(a)):
    res += a[i] - (i+1)
print(res)

Submission status: Accepted

Solution code:
S = input()
c = 0
ans = 0
for i in range(len(S)):
    if S[i] == "W":
       ans += i
       c += 1

ans -= c * (c-1)//2
print(ans)

Submission status: Accepted

Solution code:
S = str(input())

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

Submission status: Accepted

Solution code:
s=[1 if i == 'W' else 0 for i in input()]

a = sum(s)

for i in range(len(s)):
    if s[i] == 0:
        s = s[i:]
        break


ret = 0
k = 0
for i in range(len(s)):
    if s[i] == 0:
        k +=1
        continue
    ret += k
print(ret)

Submission status: Accepted

Solution code:
S = input()
ans = 0
N = len(S)
B = [0] * (N + 1)
if S[0] == "B":
    B[0] = 1

for i in range(1, N):
    B[i] = B[i - 1] + int(S[i] == "B")

for i in range(N):
    if S[i] == "W":
        ans += B[i]

print(ans)

Submission status: Accepted

Solution code:
# encoding: utf-8
S = input()

ans = 0
state = 0
for i, Si in enumerate(S):
    # process
    if state < 1 and Si == 'B':
        state += 1
        marker = i
    elif state > 0 and Si == 'W':
        ans += i - marker
        marker += 1

print(ans)

Submission status: Accepted

Solution code:
s = input()

cnt = 0
w = 0
for i, c in enumerate(s):
    if c == 'B':
        continue
    else:
        cnt += (i-w)
        w += 1

print(cnt)

Submission status: Accepted

Solution code:
s = input()

w_count = 0
swap_count = 0
for index, stone in enumerate(s):
	if stone == 'W':
		swap_count += index - w_count
		w_count += 1


print(swap_count)

Submission status: Accepted

Solution code:
S = list(input())

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

print(ans)

Submission status: Accepted

Solution code:
S = input()

len_S = len(S)

ans = 0
B_count = 0

for i in range(len_S):
    pos_from_end = len_S-i-1
    c = S[pos_from_end]
    if c == "B":
        ans += len_S-1-B_count-pos_from_end
        B_count += 1

print(ans)

Submission status: Accepted

Solution code:
S = input()

ans = 0
f = -1

for i, s in enumerate(S):
    if f != -1 and s == 'W':
        ans += i - f
        f += 1
    elif f == -1 and s == 'B':
        f = i

print(ans)

Submission status: Accepted

Solution code:
S = input()
cnt = 0
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
black = S[-1] == 'B'
cnt = 0
for i in range(N-2, -1, -1):
    if S[i] == 'B':
        cnt += N - 1 - i - black
        black += 1
print(cnt)

Submission status: Accepted

Solution code:
s = input()

ws = 0
res = 0
for i, c in enumerate(s):
    if c == 'W':
        res += i - ws
        ws += 1
print(res)

Submission status: Accepted

Solution code:
S = input()[::-1]
find_w = False
w_count = 0
result = 0

for i, c in enumerate(S):
    if not find_w:
        if c == "B":
            continue
        else:
            find_w = True
            w_count += 1
    else:
        if c == "B":
            result += w_count
        else:
            w_count += 1

print(result)

Submission status: Accepted

Solution code:
# coding: utf-8

import math
import fractions
import heapq
import collections
import re
import array
import bisect

from collections import Counter, defaultdict


def array2d(dim1, dim2, init=None):
    return [[init for _ in range(dim2)] for _ in range(dim1)]

II = lambda: int(input())
MI = lambda: map(int, input().split())




def mc(s):
    l = len(s)
    if l <= 1: return 0
    s1 = s[:l//2]
    s2 = s[l//2:]
    count = mc(s1) + mc(s2)
    count += sum(s1) * (len(s2) - sum(s2))
    return count


def main():
    s = list(input().strip())
    s = [(c == "B") for c in s]
    return mc(s)


if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
#coding:utf-8
s = input()
ls = []
cnt_b =0
for i in range(len(s)):
    if s[i] == "W":
        ls.append(cnt_b)
    else:
        cnt_b+=1
print (sum(ls))

Submission status: Accepted

Solution code:
s=input()
size,v=0,0

for i in range(len(s)):
  if s[i]=="B":
    size+=1
  else:
    v+=size

print(v)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S = list(input())

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import itertools


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

#print(S)

SS = S[:0:-1]

#print(SS)


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#! usr/bin/env python
# -*- coding: utf-8 -*-

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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

count = 0
# BB...BW...->WBBBBBB...
# つまり連続している分だけカウントが増える
# そして連続数は変わらない
# WWとなったら連続=0とする
b = 0
# 各wにおいて自分より左にあるBの数だけカウントされる
for i in range(len(s)):
    if s[i] == "B":
        b += 1
    else:
        count += b
print(count)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())

whitenum = 0
count = 0

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
S=input()

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
S = input()
cnt = 0
white = 0
for i, s in enumerate(S):
  if s == 'W':
    cnt += i - white
    white += 1
print(cnt)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
s = input()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
from collections import Counter


# input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


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


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

print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

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

print(ans);

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(sum)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
S = input()
#S = "BWBWBW"
#S = "BBW"

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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc 029
"""

s = input()

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

print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
S = input()

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

print(res)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# cook your dish here
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

tot = 0
b = 0

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
S = input()

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

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

print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#map(int,input().split())
s=input()
times=1
sum=0
for i in range(len(s)):
    if s[i]=='W':
        sum+=i+1-times
        times+=1
print(sum)

Submission status: Accepted

Solution code:
S  = input()

b_count = 0
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
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

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
s=str(input())
ans=0

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

print(ans)
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Submission status: Accepted

Solution code:
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)