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:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

s = input()
l = [0]*(len(s))
if s[0] == 'B':
    l[0] = 1
ans = 0
for i, c in enumerate(s[1:]):
    if c == 'B':
        l[i+1] = 1
    elif c == "W":
        ans += l[i]
    l[i+1] += l[i]
print(ans)

Submission status: Accepted

Solution code:
s = list(str(input()))
sm = [1 if s[i] == 'B' else 0 for i in range(len(s))]
smr = list(reversed(sm))
t =[]
for i in range(len(s)):
    if smr[i] == 1:
        t.append(i)
u = [i for i in range(len(t))]
v = [t[i] - u[i] for i in range(len(t))]
ans = sum(v)
print(ans)

Submission status: Accepted

Solution code:
S = input()
L = [0]
for i in S[::-1]:
    if i == "W":
        L.append(0)
    if i == "B":
        L[-1] += len(L)-1 

print(sum(L))

Submission status: Accepted

Solution code:
import re
import sys

line = next(map(str.strip, sys.stdin))

count = 0
nb_bs = 0
for i, c in enumerate(line):
    if c == 'W' and nb_bs > 0:
        count += nb_bs
    elif c == 'B':
        nb_bs += 1

print(count)

Submission status: Accepted

Solution code:
a=list(input())
l=[]
for i in range(1,len(a)+1):
  if a[-i]=="B":
    l.append(i)
m=len(l)
print(sum(l)-((m+1)*m)//2)

Submission status: Accepted

Solution code:
S = input()
count_ans = 0
count_B = 0
right_W = 0
for i, c in enumerate(S):
	if c == "W":
		count_ans += count_B
	else:
		count_B += 1
print(count_ans)

Submission status: Accepted

Solution code:
#AGC029 A - Irreversible operation
def countB(data):#dataのBの個数kosuとiの総和sumを返す
    sum=0
    kosu=0
    for i in range(len(data)):
        if data[i]=="B":
            kosu=kosu+1
            sum=sum+i
    return[sum,kosu]

text=input()
S=[]
N=len(text)
for i in range(N):
    S.append(text[i])
result=countB(S)
x=result[1]
Ans=int((2*N-x-1)*x/2-result[0])
print(Ans)

Submission status: Accepted

Solution code:
a=b=0
for s in input():
 if s>'B':a+=b
 else:b+=1
print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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):
    # Wを見つけたら、動かせるだけ左に動かす
    if S[i] == 'W':
        ans += i - w_sm
        # 今左に溜まっているWの数
        w_sm += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = input()

black = 0
ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

S = str(input())
S = list(S)
#print(S)
#S = np.array(S).reshape(-1,1)
#print(S)
count = 0
count_w = 0
for id, i in enumerate(S):
    #print(i)
    if str(str(i))==str('W'):
        count += id - count_w
        count_w += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

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

print(time)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

print(count)

Submission status: Accepted

Solution code:
s = list(raw_input())
count = 0
i,j = len(s), len(s)
# traverse to find b with i,
# j indicates the right continuous B, which menas that s[j-1]=W and s[j:] will be B
while j-1>=0 and s[j-1] == 'B': 
    j -= 1
#s[j-1] will be 'W'
i = j -1
while i>=0:
    ## 
    while i>=0 and s[i] == 'W': i-=1
    # find a 'B', then switch i, j-1
    if i>=0:
        count += (j-i-1)
        s[i],s[j-1] = s[j-1],s[i] #BW to WB
    # *BWWWWBBBB  *WWWWBBBBB
    j -= 1
    i -= 1
print(count)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

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

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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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:
c = 0
s = 0
for i in input():
    if i == "W":
        s += c
    else:
        c += 1
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
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)

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

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

print(cnta)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
a=0
b=0
for i in range(len(S)):
    if S[-i-1]=="B":
        a+=i-b
        b+=1
print(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

steps = 0
accumulated_W = 0

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

print(steps)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(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:
def a_irreversible_operation(S):
    n = len(S)
    ans = 0
    num_black_stone = 0
    # 1回操作を行うと、黒色の石は右に1つずれる。
    # よって、操作を行っていくと、右端にもう動かせない黒色の石が溜まっていく。
    for k, s in enumerate(S):
        if s == 'B':
            ans += n - k - 1 - num_black_stone  # 注目している黒色の場所から右に動かせる回数
            num_black_stone += 1
    # なお、BBWW...(ここから右は白のみ) となっている場合は、右の黒から
    # 先に裏返していったほうが回数が多くなるが、上の処理(左の石から見ていく)で問題ない。
    return ans

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
S=input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

result = 0

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

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

S = stdin.readline().rstrip()
#S = input()
white = 0
total = 0
for i in range(len(S)):
    if S[i] == "W":
        total += (i - white)
        white += 1
        
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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) #Wの個数
x=sum(y) #Wのi番目の合計

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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