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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

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



if __name__ == '__main__':
    main()

Solution (Python):
S = input()
N = S.count('W')
B = sum([b for b in range(N) if S[b] == 'B'])
W = sum([w for w in range(N, len(S)) if S[w] == 'W'])
print(W-B)

Solution (Python):
S = input()
N = S.count('W')
B = sum([b for b in range(1, N+1) if S[b-1] == 'B'])
W = sum([w for w in range(N+1, len(S)+1) if S[w-1] == 'W'])
print(W-B)

Solution (Python):
S = input()
N = S.count('W')

B = [b for b in range(1, N + 1) if S[b-1] == 'B']
W = [w for w in range(N+1, len(S)+1) if S[w-1] == 'W']


print(sum(W) - sum(B))

Solution (Python):
S = input()
N = S.count('W')

B = [b for b in range(1, N + 1) if S[b-1] == 'B']
W = [w for w in range(N+1, len(S)+1) if S[w-1] == 'W']


ans = 0
for b, w in zip(B, W):
    ans += w - b

print(ans)

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

s = 0
countw = 0
for i, v in enumerate(S):
    if v == 'B' and i == 0:
        continue
    elif v == 'W':
        countw += 1
    elif v == 'B':
        s += countw

print(s)

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

print(ans)

Solution (Python):
S=input()
ans = 0
w_cnt = 0
for n,i in enumerate(S):
    if i=="W":
        ans += n-w_cnt
        w_cnt += 1
print(ans)

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

Solution (Python):

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

cnt = 0
ans = 0

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

print(ans)

Solution (Python):
s=list(input())
count = 0
black = 0
for name in s:
    if name == 'B':
        black += 1
    else:
        count += black
print(count)

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()

    cnt_B = 0
    res = 0
    for i in s:
        if i == "B":
            cnt_B += 1

        if i == "W":
            res += cnt_B

    print(res)


if __name__ == '__main__':
    resolve()

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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    S = input().rstrip('\n')
    cc = 0
    itr = 0
    for i in range(len(S)):
        if S[i] == 'W':
            itr += 1
            cc += i - (itr - 1)
    S = S[::-1]
    itr = 0
    for i in range(len(S)):
        if S[i] == 'B':
            itr += 1
            cc += i - (itr - 1)
    print(cc//2)
    return

if __name__ == '__main__':
    main()

Solution (Python):
s = input()

white_cnt = 0
res = 0
for index, stone in enumerate(s):
    i = index + 1
    if stone == 'W':
        white_cnt += 1
        res += i - white_cnt
print(res)

Solution (Python):
S = input()
w = S.count('W')
ans = 0
c = 0
for i, s in enumerate(S):
    if s == 'B':
        ans += w - i + c
        c += 1
print(ans)

Solution (Python):
s = input()
w = 0
b = 0
wa = 0
ba = 0
l = len(s)
 
for i in range(l):
  if s[i] == 'W':
    wa += i - w
    w += 1
  if s[-1-i] == 'B':
    ba += i - b
    b += 1
    
print(min(ba, wa))

Solution (Python):
s=input()
for i in range(len(s)):
    if s[i]=="B":
        break
new_s = s[i:]

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

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



s = input()
n = len(s)
ans = 0









cnt = 0
for i in range(n):
    if s[i] == "W":
        cnt += 1
        ans += i
ans -= (cnt - 1) * cnt // 2
print(ans)

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

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

"""
    最終的には W..W...B...B のような並びになる。
    元の状態から B がどれだけ右に進んだかの総和が答え。
"""

""" White version """
cnt_initial = 0
cnt_w = 0
for i in range(N):
    if S[i] == 'W':
        cnt_initial += i
        cnt_w += 1
ans = cnt_initial - sum([i for i in range(cnt_w)])


""" Black version """















print(ans)

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

"""
    最終的には W..W...B...B のような並びになる。
    元の状態から B がどれだけ右に進んだかの総和が答え。
"""




cnt_initial = 0
cnt_b = 0
for i in range(N):
    if S[i] == 'B':
        cnt_initial += i
        cnt_b += 1


cnt_final = sum([i for i in range(N - cnt_b, N)])

ans = cnt_final - cnt_initial
print(ans)

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

"""
    最終的には W..W...B...B のような並びになる。
    元の状態から B がどれだけ右に進んだかの総和が答え。
"""

def sum_contin_int(l, r):
    return (r * (r + 1) - l * (l - 1)) // 2

cnt_initial = 0
cnt_b = 0
for i in range(N):
    if S[i] == 'B':
        cnt_initial += i
        cnt_b += 1

cnt_final = sum_contin_int(N - cnt_b, N - 1)

ans = cnt_final - cnt_initial
print(ans)

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

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

    w = s.count('W')
    a = [int(i) for i in range(w)]
    cnt -= sum(a)

    return cnt

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

Solution (Python):
S = [i for i in input()]
ans = 0
c = 0
'''while S[0] == 'W':
    S = S[1:]
    '''
for i,s in enumerate(S):
    if s == 'B':
        c += 1
    else:
        ans += c
print(ans)

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

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

count=0
total=0
for i in range(n):
  if s[i]=="W":
    total+=i
    count+=1

print(int(total - (count-1)*count/2))

Solution (Python):
S=input()
Bcount=0
ans=0
for i in S:
  if i=='B':
    Bcount+=1
  if i=='W':
    ans+=Bcount
print(ans)

Solution (Python):
s = input()

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

print(ans)

Solution (Python):
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):
    return map(type,input().split())



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

resolve()

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

Solution (Python):
s=input()

s=list(s)

kazu = []

for i in range(len(s)):
    if s[i] == 'W':
        kazu.append(i)
ans = 0
for i in range(len(kazu)):
    ans += kazu[i]-i
print(ans)

Solution (Python):
S = input()
ans = 0
w_num = 0
b_num = 0
for i, s in enumerate(S):
    if s == 'W':
        ans += i - w_num
        w_num += 1
    else:
        b_num += 1
print(ans)

Solution (Python):
S = input()
total_w = [0]*len(S)
cnt_w = S.count('W')

cnt = 0
for i in range(len(S)):
    if S[i]=='W':
        cnt += 1
    total_w[i] = cnt_w - cnt

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

print(ans)

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

Solution (Python):
import sys


def main():
    s = input()

    b = 0
    for c in s:
        if c == "B":
            b += 1
        else:
            yield b

print(sum(main()))

Solution (Python):
import sys


def main():
    s = input()
    total = 0

    for i in range(len(s)-1):
        if s[i] == "B":
            total += 1
            if s[i] == "B" and s[i+1] == "W":
                yield total
        else:
            if s[i] == "W" and s[i+1] == "W":
                yield total

print(sum(main()))

Solution (Python):
s = list(input().rstrip())
r=0
bm=0
while r<len(s)-1:
    if s[r]=="B" and s[r+1]=="W":
        bm+=1
        break
    elif s[r]=="B":
        bm+=1
    r+=1
ans=0
for i in range(r+1, len(s)):
    if s[i]=="W":
        ans+=bm
    if s[i]=="B":
        bm+=1

print(ans)

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

Solution (Python):
S = input()

n_left_white = 0
ans = 0

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

print(ans)

Solution (Python):
s = input()
a = b = 0

for x in s:
    a += b*(x=="W")
    b += x=="B"
print(a)

Solution (Python):
S = input()

W_index_num = [n for n,v in enumerate(S) if v == 'W']
ans = 0
cnt = 0

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

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

Solution (Python):
s=input()
lst=[]
countw=0

for i in  reversed(range(len(s))):
    if s[i]=='W':
        countw+=1
    lst.append(countw)
lst=lst[::-1]
for j in range(len(s)):
    if s[j]=='W':
        lst[j]=0
print(sum(lst))

Solution (Python):
s=input()

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

Solution (Python):
S = input()
if len(set(S)) == 1:
    print(0)
    exit()
ans = 0
num = 0
for i in range(len(S)):
    if S[i] == "W":
        ans += i - num
        num += 1
print(ans)

Solution (Python):
c = b = 0
for s in input():
  c += b*(s=="W")
  b += s=="B"
print(c)

Solution (Python):
import sys
sys.setrecursionlimit(10000000)


dxdy=((1,0),(0,1))

def pin(type=int):
    return map(type,input().rstrip().split())



def resolve():
    S=input()
    ans=0
    
    hidari=0
    for i,c in enumerate(S):
        if c=="W":
            ans+=i-hidari
            hidari+=1
    print(ans)

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """BBW"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """BWBWBW"""
        output = """6"""
        self.assertIO(input, output)


if __name__ == "__main__":
    


    resolve()

Solution (Python):
S = input()
if len(set(S)) == 1:
    print(0)
    exit()
ans = 0
num = 0
for i in range(len(S)):
    if S[i] == "W":
        ans += i - num
        num += 1
print(ans)

Solution (Python):
















S = input()
ans = 0
word = ""
Slist = list(S.split("W"))
for s in Slist[:-1]:
    ans += len(word + s)
    word = word + s
print(ans)

Solution (Python):
def myAnswer(S:list) -> int:
   N = 0
   counter = 0
   for n,s in enumerate(S):
      if(s == "W"):
         counter += n - N
         N += 1
         

   return counter

def modelAnswer():
   tmp=1
def main():
   S = list(input())
   print(myAnswer(S[:]))
if __name__ == '__main__':
   main()

Solution (Python):

s = input()
tmp = 0
cnt = 0
for idx,j in enumerate(s):
    if j =="W":
        cnt += idx - tmp
        tmp += 1
print(cnt)

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

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

to = -1
ans = 0
for i in range(L-1,-1,-1):
  if S[i] == 'W':
    to = max(to,i)
  else:
    if to == -1:
      continue
    else:
      ans += to - i
      to -= 1
      
print(ans)

Solution (Python):
S = input()
ans = - int((1 + S.count('W')) * S.count('W')/2)
num = 0

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
N = len(S)
tmp = 0
ans = 0
A = 0
B = 0
b_num = 0
for i in range(1, N+1):
    if S[i-1] == "B":
        b_num += 1
        A += i

all_wa = N * (N + 1) // 2
B = all_wa - (N - b_num) * (N - b_num + 1) // 2

print(B - A)

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

Solution (Python):
import sys
from sys import stdin

s = stdin.readline().rstrip()
ans = 0
count = 0
for i in s:
    if i == 'B':
        count += 1
    else:
        ans += count
print(ans)

Solution (Python):
s = list(input())
ans = 0
b_count = 0
w_count = 0

for i in range(len(s)):
    if s[i] == 'B':
        b_count += 1
    else:
        w_count += 1
        ans += b_count
print(ans)

Solution (Python):


s=input()

cnt=0
cum=0

for i in range(len(s)):
    if s[i]=='W':
        cnt+=1
        cum+=i
print(cum-int((cnt-1)*cnt/2))

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

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

print(ans)

Solution (Python):
S=input()

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

Solution (Python):

s = input()

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

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

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

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

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



for i in range(len(blacks)):
    blacks[len(blacks) - i - 1] = len(S) - i - 1 - blacks[len(blacks) - i - 1]

print(sum(blacks))

Solution (Python):


def swap(s,i,j):
    return s[:i] + s[j] + s[i] + s[j+1:]
cnt = 0
S = input()
bcnt = 0
ans = 0
for i in S:
    if i =="B":
        bcnt +=1
    else:
        ans += bcnt
print(ans)

Solution (Python):
s_l = list(input())
count_tot = 0
count = 0

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

print(count_tot)

Solution (Python):
s = input()
w = 0
for i in s:
    if i == 'W':
        w += 1

ans = 0
ind = 0
for i in range(len(s)):
    if s[i] == 'B':
        ans += w+ind-i
        ind += 1

print(ans)

Solution (Python):

"""
@author: H_Hoshigi
min sec
"""



"""
BWのn個の連続（長さ2n）は、n+(n-1)+(n-2)+...+1 = n(n+1)//2回の操作で、
n個のBとn個のWの連続に置き換えられる。
"""
"""
ようするにバブルソートをしている。
k番目のWが文字列Sのi文字目ならば、
その移動距離は、(i-k)回になる。
これを足せばよい。
"""

def main():
    S = input()
    N = len(S)
    counter = 0
    k = 0
    for i in range(N):
        if S[i] == "W":
            counter += (i-k)
            k += 1
    print(counter)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    cunt_b=0
    ans=0
    for ss in s:
        if ss=='B':
            cunt_b+=1
        else:
            ans+=cunt_b
    print(ans)

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    cunt_b=0
    ans=0
    for ss in s:
        if ss=='B':
            cunt_b+=1
        else:
            ans+=cunt_b
    print(ans)

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    n=len(s)
    flag=-1
    for i in range(n):
        if s[i]=='W':
            flag=i
        else:
            break
    cunt_b=0
    cunt_w=0
    ans=0
    for i in range(n):
        if s[i]=='B':
            cunt_b+=1
        elif cunt_b>0:
            ans+=i-flag-1-cunt_w
            cunt_w+=1
    print(ans)



if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    n=len(s)
    flag=-1
    for i in range(n):
        if s[i]=='W':
            flag=i
        else:
            break
    cunt_b=0
    cunt_w=0
    ans=0
    for i in range(n):
        if s[i]=='B':
            cunt_b+=1
        elif cunt_b>0:
            ans+=i-flag-1-cunt_w
            cunt_w+=1
    print(ans)



if __name__=='__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline


def read():
    S = list(input().strip())
    return S,

def solve(S):
    N = len(S)
    count = 0
    l = 0
    r = N-1
    while r >= 0 and S[r] != 'W':
        r-=1
    s = list()
    c = 0
    for i in range(r, -1, -1):
        d = r - i
        if S[i] == 'B':
            s.append(d - c)
            c += 1
    return sum(s)

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

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

Solution (Python):
s = input()

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

print(ans - a)

Solution (Python):
S = input()

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

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

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

Solution (Python):
N = input()
ans = 0
ct = 0
for i in N:
    if i == 'B':
        ct += 1
    if i == 'W':
        ans = ans + ct
print(ans)

Solution (Python):
def resolve():
    '''
    code here
    '''
    S = [item for item in input()]

    res = 0
    w_cnt = 0
    for i, v in enumerate(S):
        if v == 'W':
            res += i+1
            w_cnt += 1

    res -= w_cnt * (w_cnt + 1)//2
    print(res)
if __name__ == "__main__":
    resolve()

Solution (Python):
st=input()
B=[1 if st[0]=='B' else 0]
tot=0
for i in range(1,len(st)):
    if st[i]=='B':
        B.append(B[i-1]+1)
    else:
        B.append(B[i-1])
        tot+=B[i-1]
print(tot)

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    S=str(input())
    cnt=0
    b=0
    for i in S:
        if i=='B':
            b+=1
        else:
            cnt+=b
    print(cnt)

resolve()

Solution (Python):
S = input()

first_b = -1
for i in range(0, len(S)):
    if S[i] == 'B':
        first_b = i
        break

last_w = len(S)
for i in range(len(S) - 1, -1, -1):
    if S[i] == 'W':
        last_w = i
        break


if first_b == -1 or last_w == len(S):
    print(0)
    exit(0)

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

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

print(ans)

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


print(ans)

Solution (Python):
S = input()
answer = 0
white_counter = 0
for i, s in enumerate(S):
    if s =='W':
        answer += (i-white_counter)
        white_counter += 1

print(answer)

Solution (Python):
s=input()

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

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

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

for i in range(len(s)):
    if s[i] == 'W':
        ans += (i-t)
        t += 1
print(ans)

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

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

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

Solution (Python):
s=list(input())
n=len(s)
ans=0
w=0
for index,value in enumerate(s):
    if value=="W":
        ans+=index-w
        w+=1
print(ans)

Solution (Python):
s = input()
b_idx = list(reversed([i for i, x in enumerate(s) if x == "B"]))
ans = 0
for i in range(len(b_idx)):
    ans += (len(s)-(i+1)) - b_idx[i]
print(ans)

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

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

print(cnt)

Solution (Python):
s=input()
count = 0
c_black = 0
for s0 in s:
    if s0 == 'W':
        count += c_black
    else:
        c_black += 1
print(count)

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

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

Solution (Python):
s = input()
li = list(s)
sum_index = 0
count = 0
for i,l in enumerate(li):
    if l == 'W':
        count += 1
        sum_index += i+1
hidari = (1+count)*count//2

print(sum_index-hidari)

Solution (Python):
S = input()

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

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

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

ans = 0
count_b = 0
n = len(s)
for i in range(n):
    if s[i] == 'B':
        count_b += 1
    if s[i] == 'W':
        ans += count_b

print(ans)

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

if __name__ == '__main__':
    solve()

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

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

Solution (Python):
S = list(input())
step = 0
ans = 0
for i, s in enumerate(reversed(S)):
    if s == 'W':
        step += 1
    if s == 'B':
        if step != 0:
            S[-(i-step)-1] = 'B'
            S[-i-1] = 'W'
            ans += step
print(ans)

Solution (Python):
s = input()
ans = 0
cnt = 0
for i,j in enumerate(s[::-1]):
  if j == 'B':
    ans += i - cnt
    cnt += 1
print(ans)

Solution (Python):
S = input()

count_white = 0
ans = [0] * len(S)

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

Solution (Python):
s = input()

b_n = []
c = 0
for i in s:
    if i == 'B':
        c += 1
    
    else:
        b_n.append(c)

print(sum(b_n))

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

Solution (Python):
S = input()
 
ans = 0
b_count = 0

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

print(ans)

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

Solution (Python):
S = input()

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

print(ans)

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

Solution (Python):
S = input()

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

Solution (Python):
S = input()

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

print(ans)

Solution (Python):




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

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