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()
a=b=0
for i in range(len(s)):
  if s[i]=='B':
    b+=1
  else:
    a+=b
print(a)

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):
s = input()
white = []
for i, c in enumerate(s):
    if c == "W":
        white.append(i)
white.sort()
ans = 0
for i, p in enumerate(white):
    ans += p - i
print(ans)

Solution (Python):


import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = list(input())
N = len(S)

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

Solution (Python):
s=input()
t=list(s).count("W")
A=[i for i,x in enumerate (list(s)) if x=="W"]
print(int(sum(A)-t*(t-1)/2))

Solution (Python):
num = 0
sum = 0
for i,j in enumerate(input()):
    if j =="W":
        num += 1
        sum += i
num = num*(num-1)//2
print(sum -num)

Solution (Python):
S = input()

Wnum = [0 for i in range(len(S))]
wmax = S.count('W')
if S[0] == 'W':
    Wnum[0] = 1

for i in range(1,len(S)):
    if S[i] == 'W':
        Wnum[i] = Wnum[i-1] + 1
    else:
        Wnum[i] = Wnum[i-1]

ans = 0
for i in range(len(S)):
    if S[i] == 'B':
        ans += wmax - Wnum[i]

print(ans)

Solution (Python):
s = input()
t = list(s).count('W')
a = [i for i, x in enumerate(list(s)) if x == 'W']
b = int((t - 1) * t / 2)
print(sum(a)-b)

Solution (Python):
S = input()
count = 0
posi = 0

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

Solution (Python):
s = input('')
bc = 0
c = 0

for i in range(0,len(s)):
  if s[i] == 'B':
    bc += 1
  elif s[i] == 'W':
    c += bc
    
print(c)

Solution (Python):
S = input()
posi = 0
count = 0

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

Solution (Python):
S = input()

black = 0
ans = 0

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

print(ans)

Solution (Python):
a = input()
b = 0
bt = 0
w = 0
wt = 0
for i in range(len(a)):
    if a[i] == "B":bt = 1
    if bt == 1 and a[i] == "B":b+=1
    if a[i] =="W":
        w+=b
        wt +=1
print(w)

Solution (Python):
S = input()
start = 0
count = 0

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

Solution (Python):
S = input()
count = 0
ans = 0
if S[0] == "W":
    count += 1
for i in range(1, len(S)):
    l = S[i - 1]
    r = S[i]

    if r == "W":
        ans += i - count 
        count += 1

print(ans)

Solution (Python):
import numpy as np

S = str(input())
S = list(S)



count = 0
count_w = 0
for id, i in enumerate(S):
    
    if str(str(i))==str('W'):
        count += id - count_w
        count_w += 1
print(count)

Solution (Python):
s = input()
l = len(s)
b_num = sum([1 for w in s if w == "B"])
b_pos = sum([i for i,w in enumerate(s) if w == "B"])
max_num = sum([i for i in range(l-b_num, l)])
print(max_num - b_pos)

Solution (Python):
line = list(raw_input())

data = []
for i in range(len(line)):
  if line[i] == 'W':
    data.append(i)

ans = 0
counter = 0
for i in data:
  ans += i-counter
  counter += 1
print ans

Solution (Python):


s = list(input())
time = 0
count = 0
for i in range(len(s)):
  if s[i] == "W":
    time += i - count
    count += 1

print(time)

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 = list(input())
n = len(s)

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

l.sort(reverse=True)

res = 0
cnt = 0
for idx in l:
    res += n-idx-1 - cnt
    cnt += 1

print(res)

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

ans = 0
countw = 0
for i, c in enumerate(S):
    if c == 'W':
        ans += i - countw
        countw += 1

print(ans)

Solution (Python):
S = input()

cnt = 0
cnt_B = 0

for i in range(len(S)):
    if S[i] == 'W':
        cnt += cnt_B
    else:
        cnt_B += 1

print(cnt)

Solution (Python):
import sys

s = sys.stdin.readline()
w_index = [i for i in range(len(s)) if s[i] == 'W']
ans = 0
for i in range(len(w_index)):
    ans += (w_index[i] - i)
print(ans)

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

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

cntb = S.count('B')
cntw = S.count('W')

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

Solution (Python):
S = input()
s = list(S)
l_s = len(s)
ans = 0
black_index = 0
for i in range(1, l_s)[::-1]:
    if s[i] == 'B':
        black_index += 1
        continue

    if s[i-1] == 'B':
        ans += l_s - i - black_index
        s[i] = 'B'
        s[i-1] = 'W'
        black_index += 1
print(ans)

Solution (Python):
S = input()
N = len(S)
B = [0] * N
for i in range(0, N):
    B[i] = int(S[i] == 'B')
    if i > 0:
        B[i] += B[i - 1]
P = 0
for i in range(1, N):
    if S[i] == 'W':
        P += B[i]
print(P)

Solution (Python):
s = input()

count = 0
black = 0
for i in s:
  if i=='W':
    count += black
  else:
    black+=1

print(count)

Solution (Python):
s = list(raw_input())
count = 0
i,j = len(s), len(s)


while j-1>=0 and s[j-1] == 'B': 
    j -= 1

i = j -1
while i>=0:
    
    while i>=0 and s[i] == 'W': i-=1
    
    if i>=0:
        count += (j-i-1)
        s[i],s[j-1] = s[j-1],s[i] 
    
    j -= 1
    i -= 1
print(count)

Solution (Python):
S = list(input())
posi = 0
count = 0

for i in range(len(S)):
    if S[i] == 'W':
        count += i - posi
        posi += 1

print(count)

Solution (Python):


"""
https://atcoder.jp/contests/agc029/tasks/agc029_a
"""

import sys
import re


s = sys.stdin.readline().rstrip()
e = 0
n = 0

for chr in s:
    if chr == 'W':
        e += n

    if chr == 'B':
        n += 1

print(e)

Solution (Python):
S = list(input())
cnt = call = 0
for i, a in enumerate(S):
  if a == 'W':
    cnt += i-call
    call += 1
print(cnt)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    r = 0
    c = 0
    for t in s:
        if t == 'B':
            c += 1
        else:
            r += c
    return r


print(main())

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

Solution (Python):
S = input()

counts_black = S.count('B')
index = 0

for i in range(len(S)):
    if S[i] == 'B':
        index += i


print(sum(list(range(len(S)-counts_black, len(S)))) - index)

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

Solution (Python):
text = input()
wcnt = 0
lensum = 0
for i, char in enumerate(text):
  if char == 'W':
    wcnt += 1
    lensum += i
ret = int(lensum - (wcnt * (wcnt - 1) / 2 ))
print(ret)

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=raw_input()
import numpy as np

S_list=np.array([s for s in S])
S_W=np.where(S_list=="W")[0]
print sum(S_W[i]-i for i in range(len(S_W)))

Solution (Python):
s=input()
count=0
b=s.count("B")
w=s.count("W")
for x in range(len(s)):
    if s[x:x+1] == "B":
        count += w
        b-=1
    elif s[x:x+1] == "W":
        w-=1
        
print(count)

Solution (Python):
s=input()
count=0
b=s.count("B")
w=s.count("W")
for x in range(len(s)):
    if s[x:x+1] == "B":
        count += w
        b-=1
    elif s[x:x+1] == "W":
        w-=1
    if w == 0:
        break

print(count)

Solution (Python):
s=""

while True:
    try:
        s=input()
        if len(s)== s.count("B")+s.count("W"):
            break
    except:
        s=input()
count=0
b=s.count("B")
w=s.count("W")
for x in range(len(s)):
    if s[x:x+1] == "B":
        count += w
        b-=1
    elif s[x:x+1] == "W":
        w-=1

print(count)

Solution (Python):
s = input()
w_count = s.count('W')
shoki = 0
for i in range(len(s)):
  if s[i] == 'W':
    shoki += i
saigo = sum(range(w_count))
print(shoki-saigo)

Solution (Python):
s = input()
b_count = s.count('B')
shoki = 0
for i in range(len(s)):
  if s[i] == 'B':
    shoki += i
saigo = sum(range(len(s) - b_count,len(s)))
print(saigo-shoki)

Solution (Python):

from sys import stdin

s_in = lambda: stdin.readline()[:-1]  
d_in = lambda: int(stdin.readline())  
ds_in = lambda: list(map(int, stdin.readline().split()))  

S = s_in()
N = len(S)
right_black = N

ans = 0
for i, s in enumerate(S[::-1]):
    if s == 'B':
        idx = N - i
        ans += right_black - idx
        right_black -= 1

print(ans)

Solution (Python):
S = input()
cc = 0
res = 0
for i in range(len(S)):
    if S[i] == "W":
        cc += 1
        res += i

print(res - cc*(cc-1)//2)

Solution (Python):
s = input()

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

Solution (Python):
gos = input()
ans = 0
longgo = len(gos)
whites = 0

for i in range(longgo):
    if gos[i] == 'W':
        ans += i
        whites += 1
    else:
        pass

def triangle(n):
    ret = 0
    i = n
    while (i > 0):
        ret += i
        i = i - 1
    return ret

print(ans - triangle(whites - 1))

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

def main():
	s = input()
	ans = 0
	countw = 0
	for i in range(len(s)-1,-1,-1):
		if s[i] == "W":
			countw += 1
		else:
			ans += countw
	print(ans)

main()

Solution (Python):
S = input()

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

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

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

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

Wn = S.count("W")

if Wn == 0:
	print(0)
else:
	x = 0
	for i in range(len(S)):
		if S[i] == "W":
			x += i
	print(x - int(Wn * (Wn - 1) / 2))

Solution (Python):
string = str(input())

Wi = [i for i, x in enumerate(string) if x == 'W']
Wi = [x - i for i, x in enumerate(Wi)]

print(sum(Wi))

Solution (Python):
list1=list(input())
list1.reverse()
a=0
count=0
for i in range(len(list1)):
    if list1[i]=="W":
        a=i
        break
for i in range(a,len(list1)):
    if list1[i]=="B":
        count+=i-a
        a+=1
print(count)

Solution (Python):
s = input()
 
ans = 0
black = 0
for i, moji in enumerate(s):
  if moji == "B":
    black  += 1
  if moji == "W":
    ans += black
  
print(ans)

Solution (Python):

def A():
    S = list(input())
    W = [0 for i in range(len(S))]
    B = [0 for i in range(len(S))]
    ans = 0
    if S[0] == "B":
               B[0] = 1
    else:
        W[0] = 1

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

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

Solution (Python):
c = 0
s = 0
for i in input():
    if i == "W":
        s += c
    else:
        c += 1
print(s)

Solution (Python):
a=input()
n=len(a)
s=[]
sb=0

for i in range(n):
  s.append(a[i])
b=s.count("B")
w=n-b
fb=int((2*n-b-1)*b/2)

for i in range(n):
  if s[i]=="B":
    sb+=i

print(fb-sb)

Solution (Python):
S = input()


S = S[::-1]


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

print(ans)

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

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

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

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

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

Solution (Python):
S=list(input())
B_pos=[i+1 for i in range(len(S)) if S[i]=="B"]
B_pos.reverse()

moved_B_pos=len(S)
total=0

for i in B_pos:
    total+=moved_B_pos-i
    moved_B_pos-=1

print(total)

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

Solution (Python):
S = str(input())
slist = list(S)
L = len(slist)
count = 0
fcount = 0
for i in range(L):
  if slist[i] == "W":
    count+=(i-fcount)
    fcount+=1
print(count)

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

s = str(input())

cnt = 0
b_cnt = 0

for c in s:
    if c == 'B':
        b_cnt += 1
    else:
        cnt += b_cnt
print(cnt)

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=[i for i in input()]


cntb=0
cnta=0
for k in range(len(s)):
  if s[k]=='B':
    cntb+=1
  if s[k]=='W':
    cnta+=cntb

print(cnta)

Solution (Python):
S = input()
b = 0
res = 0
for  s in S:
    if s == "W" and b > 0:
        res += b
    elif s == "B":
        b += 1
print(res)

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

Solution (Python):
str = input()

w_num = 0
count = 0
for i, color in enumerate(str):
    if color == 'W':
        count += i - w_num
        w_num += 1


print(count)

Solution (Python):
S=input()
a=0
b=0
for i in range(len(S)):
    if S[-i-1]=="B":
        a+=i-b
        b+=1
print(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()
ans = 0
cnt = 0
for i in s:
    if i == 'B':
        cnt += 1
    else:
        ans += cnt
print(ans)

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

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

ans = 0
wnum = 0
for i in range(n):
    if s[i] == 'W':
        wnum += 1
        ans += i+1-wnum

print(ans)

Solution (Python):
s = input()
num = 0
st = 0
for i,x in enumerate(s):
  if x=='W':
    num += (i-st)
    st += 1
print(num)

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):
L = list(input())
memo = L.count("W")
ans = 0
for i in range(len(L)) :
    if L[i] == "W" :
        memo -= 1
    else :
        ans += memo
print(ans)

Solution (Python):
S = 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()

steps = 0
accumulated_W = 0

for i, x in enumerate(list(S)):
    if x == 'W':
        steps += i - accumulated_W
        accumulated_W += 1

print(steps)

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 = 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):
str = input()
ans = 0
step = 0
for i in range(len(str)):
  if str[i] == 'W':
    ans += i-step
    step +=1
print(ans)

Solution (Python):
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
s.sort()
s.reverse()
for j in range(len(s)):
  if s[j]=='B':b+=j+1
  elif s[j]=='W':w+=j+1
y=b-w
print(int(abs(x-y)/2))

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

print(a - b)

Solution (Python):
l=[i for i,s in enumerate(input()[::-1])if s=='B']
m=len(l)
print(sum(l)-m*~-m//2)

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):
def a_irreversible_operation(S):
    n = len(S)
    ans = 0
    num_black_stone = 0
    
    
    for k, s in enumerate(S):
        if s == 'B':
            ans += n - k - 1 - num_black_stone  
            num_black_stone += 1
    
    
    return ans

S = input()
print(a_irreversible_operation(S))

Solution (Python):

S = input()
N = len(S)
S = list(S)

count = 0
count2 = 0
kekka = 0
for i in range(len(S)):
	if(S[i] == 'B'):
		count = count + 1
		count2 = count2 + i
for j in range(count):
	kekka = kekka + N - j-1

print(kekka-count2)

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

Solution (Python):
s=input()
counter,sum,countw=0,0,0
for c in s:
    if(c=='W'):
        sum +=counter-countw
        countw+=1
    counter+=1    
print(sum)

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

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

Solution (Python):
s = input()

right = len(s) - 1
i = right
ans = 0
while i >= 0:
    if s[i] == 'B':
        
        ans += right - i
        right -= 1
    i -= 1
print(ans)

Solution (Python):

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

Solution (Python):
S=input()

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

Solution (Python):
from sys import stdin
a=  stdin.readline().strip()
a= list(a)
a.reverse()
ans= 0
cur =0
for i in a:
 if i=='W':
  cur+=1
 else:
  ans+= cur
print ans

Solution (Python):
S = input()

result = 0

n = 0
for i, c in enumerate(S):
    if c == "W":
        result += i - n
        n += 1

print(result)

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

Solution (Python):
s = input()

wf = s.count('W')

tot = (wf*(wf+1))//2

ind = 0

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

print(ind - tot)

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

su = 0
dd = 0
co = 0
for i in range(len(a)):

		if a[i] == 'W':
			su += i - dd
			dd += 1

print(su)

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

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



print(ans)

Solution (Python):
import sys
import math
S = list(input())
size = len(S)

B_size = sum([ 1 for i in S if i == 'B' ])
if B_size == 0:
    print(0)
    sys.exit()

B_size2 = sum([ i for i,j in enumerate(S) if j == 'B' ])
ans= sum(range(0, size)[-B_size:]) - B_size2
print(ans)

Solution (Python):
s=input()
r=w=0
for c,i in zip(s,range(len(s))):
	if c=='W':
		r+=i-w
		w+=1
print(r)

Solution (Python):
from sys import stdin

S = stdin.readline().rstrip()

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

Solution (Python):
import re
s = input()
iter = re.finditer('W', s)
indices = [m.start(0) for m in iter]
cnt = len(indices)
total = sum(indices)
print(total - (cnt * (cnt -1)) // 2)

Solution (Python):
def solve(s):
    ans = 0
    d = 0
    sl = len(s)
    for i in range(sl):
        if s[i] == "B":
            ans = ans + (sl - i - 1 - d)
            d = d + 1
    return ans


print(solve(input()))

Solution (Python):
S = input()

count = 0
pre_index = 0
pre_count = 0
for index, value in enumerate(S):
    if value == 'W':
        n = S[pre_index:index].count('B')
        count += n + pre_count
        pre_count = n + pre_count
        pre_index = index

print(count)

Solution (Python):

S = input()
bcount=S.count('B')
wcount=S.count('W')
Slen=len(S)
ans=0
bb=0
for i in range(Slen):
    if i!=Slen:
        if S[Slen-i-1]=="B":
            ans=ans+bb
        else:
            bb=bb+1
print(ans)

Solution (Python):
s = list(input())
i = 0
count = 0
for n in range(len(s) - 1, -1, -1):
    if s[n] == 'B':
        count += (len(s) - i) - (n + 1)
        i += 1

print(count)

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

count = 0
w_cnt = 0

for index in range(len(s))[::-1]:
    if s[index] == "W":
        w_cnt += 1
    else:
        count += w_cnt

print(count)

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

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

Solution (Python):
S = input()
a = list(S)
count = 0
c=0
b=[i for i, x in enumerate(a) if x == 'W']

for i in b:
  c+=i-count
  count+=1

print(c)

Solution (Python):
def main(a):
  s=0
  t=0
  for i in range(0,len(a)):
    if a[i]=="B":
      s+=len(a)-i-1
      t+=1
  return s-t*(t-1)/2

a=input()
print(int(main(a)))

Solution (Python):
S = input()
a = list(S)
count = 0
c=0
b=[i for i, x in enumerate(a) if x == 'W']

for i in b:
  c+=i-count
  count+=1

print(c)

Solution (Python):
s = list(input())
s.reverse()
wl = 0 
rwl = 0 
ret = 0 
l = len(s)
for i in range(l):
    if s[i] == "W":
        wl += 1
    else:
        ret += rwl + wl
        rwl += wl
        wl = 0 
print(ret)

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

count = 0
num = 0
idx = -1
while True:
  idx = S.find('W', idx + 1)
  if idx < 0:
    break
  count += idx - num
  num += 1

print(count)

Solution (Python):
S = input()
white = []
count = 0

for i in range(len(S)):
  if S[i] == "W":
    white.append(i)

for i in range(len(white)):
  count += white[i] - i

print(count)

Solution (Python):
S=str(input())
N=len(S)
a=[]
y=0
x=0
z=0
a=list(S)

y=([i for i, p in enumerate(a) if p == 'W'])
z=len(y) 
x=sum(y) 

b=(1/2)*z*(z-1)
print(int(x-b))

Solution (Python):
source = input()
cost = 0
base = 0

for i in range(len(source)):
  if source[i] is "W":
    cost += i - base
    base += 1
    continue
  
print(cost)

Solution (Python):
S = input().strip()

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

Solution (Python):
def run(S):
    '''
    Bをすべて右に、Wをすべて左に移動する回数を求める
    '''
    cnt = 0
    n = len(S)
    cnt_B = 0
    cnt_W = 0
    for i in range(len(S)):
        if S[i] == 'B':
            cnt_B += 1
            cnt += n - (i+cnt_B)
        else:
            cnt += i - cnt_W
            cnt_W += 1
    return int(cnt / 2)


def main():
    S = input()
    print(run(S))


if __name__ == '__main__':
    main()

Solution (Python):
S=input()

tmp=[i for i, x in enumerate(S) if x == 'W']
print(sum(tmp)-sum(range(len(tmp))))

Solution (Python):
S = input()
B = 0
W = 0
cnt = 0

for i in S:
    if i == "W":
        cnt += B
    else:
        B += 1

print(cnt)

Solution (Python):
import math

def bitsum(bit,i):
    s = 0
    while i > 0:
        s += bit[i]
        i -= i&(-i)
    return s

def bitadd(bit,i,x):
    while i <= n:
        bit[i] += x
        i += i&(-i)
    return bit

s = input()
a = [2 if o == 'B' else 1 for o in s]
n = int(len(a))

n_ = int(math.log2(n)) + 1
bit = [0] * (2**n_)
bit.insert(0,0)

ass = 0
for j in range(n):
    ass += j-bitsum(bit,a[j])
    bit = bitadd(bit,a[j],1)
print(ass)

Solution (Python):
import sys


def solve():
    input = sys.stdin.readline
    S = list(input().replace("B", "2").replace("W", "1"))[:-1]
    N = len(S)
    ans = N * (N - 1) // 2
    data = [0] * (N + 1)

    def add(k, v):
        while k <= N:
            data[k] += v
            k += k & -k

    def get(k):
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s

    for a in map({a: i + 1 for i, a in enumerate(sorted(S))}.__getitem__, S):
        ans -= get(a)
        add(a, 1)

    print(ans)


solve()

Solution (Python):
import sys
import socket

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('a1.in')


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


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    s = read_str()
    n = len(s)
    res = 0
    w = 0
    for i in range(n - 1, -1, -1):
        if s[i] == 'B':
            res += w
        else:
            w += 1
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

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

print(ans)

Solution (Python):
S=input()
counter=0
result = 0

for i in range(len(S)):
    if S[i]=='B':
        counter+=1
    else:
        result +=counter

print(result)

Solution (Python):


s = input()
s_arr = list(s)

n = 0
l = len(s_arr)

ans = 0
b_count = 0
for i in range(l, 0, -1):
    if i == l:
        if s_arr[i-1] == 'B':
            b_count += 1
    else:
        if s_arr[i-1]=='B':
            ans += l - i - b_count
            b_count += 1


print(ans)

Solution (Python):
S = list(input())
ans = 0
B_count = 0
for i in range(len(S)-1):
    if S[i] == 'B' and S[i+1] == 'W':
        B_count += 1
        S[i+1] = 'B'
        ans += B_count
        B_count -= 1
    elif S[i] == 'B':
        B_count += 1

print(ans)

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

indexes = [i for i, x in enumerate(s) if x == "B"]
ideal=sorted([len(s)-i-1 for i in range(len(indexes))])


for i in range(len(indexes)):
  count+=ideal[i]-indexes[i]

print(count)

Solution (Python):


S = input()

head_w = 0
output = 0
for i, s in enumerate(S):
    if s == "W":
        output += i - head_w
        head_w += 1

print(output)

Solution (Python):




def  irr_operation(givenString):

	allLength = len(givenString)
	allRange = range(0,allLength)
	bCounter =0
	bPosition = []
	for i in allRange:
		if givenString[i] == 'B':
			bPosition.append(i)
			bCounter=bCounter+1

	collectPosition =[]
	bLength = len(bPosition)
	bRange = range(allLength-bLength,allLength)
	for i in bRange:
		collectPosition.append(i)

	bLengthRange = range(0,bLength)
	diffPosition = 0
	for i in bLengthRange:
		diffPosition = diffPosition+(collectPosition[i]-bPosition[i])

	answer = diffPosition
	return answer


if __name__ == '__main__':
	bwstring = input()
	solution=irr_operation(bwstring)
	print(solution)

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

sum = 0
bcount = 0
for i in range(len(s)):
    if s[i] == 'B' :
        bcount += 1
    else :
        sum += bcount

print(sum)

Solution (Python):
S = input()

white = 0
count = 0
for i, s in enumerate(S):
    if s == "W":
        count += i-white
        white += 1

print(count)

Solution (Python):
S = input()
p = 0
b = 0

for i in S:
    if i == "B":
        b += 1
    elif i == "W":
        p += b 
print(p)

Solution (Python):



def main():
    """Function."""
    s = str(input())

    total = 0
    b_count = 0
    for i in range(len(s)):
        if s[i] == "B":
            b_count += 1
        if s[i] == "W":
            total += b_count

    print(total)


if __name__ == "__main__":
    main()

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

sum = []
for i in range(size):
    if S[i] == 'B':
        sum.append(1)
    else:
    	sum.append(0)
    
    if not i == 0:
        sum[i] += sum[i - 1]

count = 0
for i in range(size):
    if (S[i] == 'W'):
        count += sum[i]

print(count)

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

Solution (Python):


s=input()
x=len(s)
b=[0]*x
for i in range(-1,-x-1,-1):
    if i==-1and s[i]=="W": b[-1]=1
    elif s[i]=="W": b[i]=b[i+1]+1
    else: b[i]=b[i+1]
ans=chk=0
for i in range(x):
    if s[i]=="B":
        ans+=b[i]
print(ans)

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

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