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:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    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


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
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 make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

s = sr()
count = 0
ans = 0
for i,c in enumerate(s):
    if c == 'W':
        ans+=(i-count)
        count+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy
from numpy.core.defchararray import count
S = numpy.array([0 if s == 'B' else 1 for s in input()])

count = 0
bcount = 0

for i, s in enumerate(S):
    if s == 0:
        bcount += 1
    else:
        count += bcount

print(count)

Submission status: Accepted

Solution code:
s = list(input())

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

print(count)

Submission status: Accepted

Solution code:
s = input()

w = 0
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
s=input()
 
ans=0
b_cnt=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()
lenS = len(S)
bcnt = S.count('B')
wcnt = lenS - bcnt
if bcnt > wcnt:
    ms = 'W'
    rc = wcnt
else:
    ms = 'B'
    rc = bcnt
sum = 0

for i, s in enumerate(S):
    if rc == 0:
        break
    if s == ms:
        if ms == 'W':
            sum += i-rc+1
        elif ms == 'B':
            sum += lenS-i-rc
        rc -= 1
print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()

ans=0
b_cnt=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:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    ans = 0
    b = 0

    for char in s:
        if char == "B":
            b += 1
        else:
            ans += b

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()

if __name__=='__main__':
    sl = list(S())
    ans = 0
    c = 0
    for i,item in enumerate(sl):
        if item=='W':
            ans += c
        else:
            c += 1

    print(ans)
    exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    s = list(readline().rstrip())
    sumS = 0
    m = s.count('B')
    for i in range(len(s) - 1):
        if s[i] == 'B':
            sumS += (len(s) - m) - i
            m -= 1
    print(sumS)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
size = len(s)
b_num = 0
w_num = 0

for each in s:
    if each == 'W':
        w_num += 1
    else:
        b_num += 1

ans = 0
b_left = w_num
for i in range(size):
    if s[i] == 'B':
       ans += b_left - i
       b_left += 1

print(ans)

Submission status: Accepted

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

print(p)

Submission status: Accepted

Solution code:

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

S = input()

ans = 0

a = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

b_count = 0
ans = 0

for pos in range(len(S)):
    if S[pos] == 'B':
        b_count += 1
    else:
        ans += b_count

print(ans)

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

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

S = input()

ans = 0;
for i, s in enumerate(S):
    if s == "B":
        ans += len(S) - i
        
for i in range(1,S.count("B")+1):
    ans -= i
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    S = input()
    Wcount = 0
    ans = 0
    for i in range(len(S)):
        if S[i] == 'W':
            ans += i-Wcount 
            Wcount += 1
    print(ans)
resolve()

Submission status: Accepted

Solution code:
s = input()
s = s[::-1]

num = []
cnt = 0

for i in range(len(s)):
    if s[i] =="W":
        cnt +=1
    else:
        num.append(cnt)
print(sum(num))

Submission status: Accepted

Solution code:
s = input()

ans, b = 0, 0
for i in s:
    if i == "B":
        b += 1
    else:
        ans += b

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    S = input().rstrip('\n')
    w = 0
    for s in S[::-1]:
        if s == 'W':
            w += 1
        else:
            ans += w
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

w_count = 0
move = 0
for i in range(len(S)-1,-1,-1):
    if S[i] == "B":
        move += w_count
    else:
        w_count += 1

print(move)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s=input()
c=0
a=0
for i in s:
    if i =="W":
        a += c
    else:
        c += 1
print(a)

Submission status: Accepted

Solution code:
s = list(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 = str(input())
cnt = 0
ans = 0
for i in range(len(S)):
  if S[i] == 'W':
    ans += i
    cnt += 1
ans -= (cnt-1)*cnt//2
print(ans)

Submission status: Accepted

Solution code:
S = input()

b_count = 0
result = 0
for i in S:
    if i == 'B':
        b_count += 1
        w_count = 0
    else:
        if b_count != 0:
            result += b_count

print(result)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
b_num = 0
prev_score = 0

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

nxt_score = n * (n - 1) // 2 - (n - b_num) * (n - 1 - b_num) // 2
print(nxt_score - prev_score)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
n = len(s)
c = 0
ans = 0
for i in range(n):
    if s[i]=="W":
        ans += c
    else:
        c += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    s=input()
    l=0
    man=0
    for i,v in enumerate(s):
        if v == "W":
            man += i-l
            l += 1
    print(man)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
cnt_b = 0
ans = 0
for c in s:
    if c == "B":
        cnt_b += 1
    else:
        ans += cnt_b

print(ans)

Submission status: Accepted

Solution code:
s = input()
N = len(s)
sl = [0]*N
cnt = 0
for i in range(N):
    if s[i]=='B':
        cnt+=1
    else:
        sl[i] = cnt
print(sum(sl))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
ls = len(s)
ss = sorted(s, reverse=True)
cnt = [0, 0]
ans = 0
w = 0

while ss[w] == "W":
    w += 1
    if ls == w:
        break

for i in range(ls):
    if s[i] == "B":
        ans += w + cnt[0] - i
    else:
        ans += i - cnt[1]
    cnt[s[i] != "B"] += 1

print(ans//2)

Submission status: Accepted

Solution code:
S=input()
X=K=0
for i in range(1,len(S)+1):
    if S[i-1]=="W":
        X+=i
        K+=1
print(X-(K*(K+1))//2)

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()

    ret, cnt = 0, 0
    for s in S:
        if s == 'B':
            cnt += 1
        if s == 'W':
            ret += cnt
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
s = s[::-1]

cnt = 0
b = -1

for idx in range(len(s)):
    if s[idx] is 'W':
        continue
    b += 1
    cnt = cnt + idx - b

print(cnt)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc029/tasks/agc029_a
# Wをなるべく右に詰めようとしたときに移動する距離の総和が答え
ans = 0
cnt = 0  # Wの移動先
for i, s in enumerate(input()):
    if s == 'W':
        ans += i - cnt
        cnt += 1
print(ans)

Submission status: Accepted

Solution code:
S = input()

count = 0
black = 0
white = 0

for i in range(len(S)-1):
    if S[i] == 'B':
        black +=1
    else :
        white +=1
    if  S[i+1] == 'W':
        count += i+1 -white

print(count)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
s=input().rstrip()
idousaki=0
ans=0
for i in range(len(s)):
    if s[i]=="W":
        ans+=(i-idousaki)
        idousaki+=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
S = list(map(str, input()))
ans = 0
L = []
for x, s in enumerate(S):
  if s == "B":
    L.append(x)
num = len(S) - len(L)
for l in L:
  ans += num - l
  num += 1
print(ans)

Submission status: Accepted

Solution code:
s = list(input())

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    S = list(input())
    Bcnt = 0
    ans = 0
    for i in range(len(S)):
        if S[i] == 'B':
            Bcnt += 1
        else:
            ans += Bcnt
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    S = input()
    l = []
    for i in range(len(S)):
        if S[i] == 'W':
            l.append(i-len(l))
    print(sum(l))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


s = S()
ans = 0
w_cnt = 0
for i in range(len(s)):
    if s[i] == "W":
        ans += i - w_cnt  # その W の場所までにあった B の数
        w_cnt += 1

print(ans)

Submission status: Accepted

Solution code:
s=input()
check=list(s)
n=len(s)
cntb=0
for i in check:
    if i=='B':
        cntb+=1
minus=sum([i+1 for i in range(n) if check[i]=='B' ])
plus=sum(range(n-cntb+1,n+1))
print(plus-minus)

Submission status: Accepted

Solution code:
S = input()


idx_w = 0
idxes_b = []

for i, s in enumerate(S):
    if s == 'B':
        idxes_b.append(i)
    elif s == 'W':
        idx_w = i

idxes_b = [b for b in idxes_b if idx_w > b]

ans = 0
for i, b in enumerate(idxes_b[::-1]):
    ans += idx_w - b - i

print(max(0, ans))

Submission status: Accepted

Solution code:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
w = s.count('W')

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
s=input()

cnt=0
ans=0

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

print(ans)

Submission status: Accepted

Solution code:
S = input()[::-1]
ans = 0
cnt = 0
for s in S:
    if s == "W":
        cnt += 1
    else:
        ans += cnt
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

left = 0
ans = 0

for x in s:
    if x == 'B':
        left += 1
        continue
    ans += left

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans,cnt = 0,0
for i in s[::-1]:
  if i == "W":
    cnt += 1
  else:
    ans += cnt
print(ans)

Submission status: Accepted

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

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]


S = input()

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

print(ans)

Submission status: Accepted

Solution code:
s = reversed(input())
# Bの右にあるWの総数を数える
ans = 0
cnt = 0
for x in s:
    if x=='W':
        cnt += 1
    else:
        ans += cnt

print(ans)

Submission status: Accepted

Solution code:
s = input()
l = [char for char in s]
ans = 0
c = 0
for val in range(len(l)):
    if l[val] == "W":
        ans += (val - c)
        c+=1
print(ans)

Submission status: Accepted

Solution code:
s = input()

n = len(s)

ans = 0

cnt = 0

for i in range(n):
    if s[i] == "B":
        cnt += 1
    else:
        ans += cnt
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

s = input()

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

Submission status: Accepted

Solution code:
S = input()
ans = 0
wc = 0
for i in reversed(S):
    if i == "W":
        wc += 1
    else:
        ans += wc
print(ans)

Submission status: Accepted

Solution code:
S = input()
k1 = k2 = 0
for i in S[::-1]:
  if i == 'W':
    k2 += 1
  else:
    k1 += k2
print(k1)

Submission status: Accepted

Solution code:
S = input()
ans = 0
count = 0
for i in S:
    if i == 'B':
        count += 1
    elif i == 'W':
        ans += count
print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
count = 0
for i in S:
    if i == 'B':
        count += 1
    elif i == 'W':
        ans += count
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

tmp = 0
rlt = 0

for s in S:
  if s == "B":
    tmp += 1
  else:
    rlt += tmp
    
print(rlt)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)
#print(S)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

import numpy as np
B = []
W = []
for i in range(len(s)):
    if s[i] == "B":
        B.append(i)
    elif s[i] == "W":
        W.append(i)

print(sum(np.array(W) - np.array([i for i in range(len(W))])))

Submission status: Accepted

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

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=input()
n=len(s)
ret=0
pos=0
for i in range(n):
    if s[i]=="W":
        ret+=i-pos
        pos+=1
print(ret)

Submission status: Accepted

Solution code:
s = input()
ans = 0
cnt = 0
for ind,si in enumerate(s):
    if(si=='W'):
        ans += ind
        cnt += 1

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

Submission status: Accepted

Solution code:
r = input()

s = 0
c = 0

for i in range(len(r)):
  if r[i] == "W":
    s += i - c
    c += 1

print(s)

Submission status: Accepted

Solution code:
S = str(input())
#Sを分割してリスト化
l = list(S)

#各Wに対して、それより左にある黒の数を足したものが答え

ans = 0

#これまでに見つけたBの数
b=0

for i in range(len(l)):
  if l[i] == "W": #白の場合
    ans += b
  else: #黒の場合
    b += 1

print(ans)

Submission status: Accepted

Solution code:
s = str(input())
l = list(s)
b = l.count("B")
w = l.count("W")
ans = 0
counter = 0
for i in range(len(l)):
    if l[i] == "W":
        ans += (i - counter)
        counter += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

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

Submission status: Accepted

Solution code:
S = input()
sumW = sum([i for i in range(len(S)) if S[i] == 'W'])
n = S.count('W')
newW = n * (n - 1) // 2
print(sumW - newW)

Submission status: Accepted

Solution code:
#import random, string

#def randomname(n):
#    candidate_text = ["W","B"]
#    randlst = [random.choice(candidate_text) for i in range(n)] #()の中身を string.ascii_letters + string.digits とすると大小英数字
#    return ''.join(randlst)

S = [0] + list(input())
#S = [0] + list(randomname(2*10**5))

N = len(S) - 1

#頭のWは無視
i = 1
while 1:
    #print(i,S[i])

    if i == N:
        print(0)
        break
    elif S[i] == "W":
        i += 1
    else:
        #print("BW pattern")

        ans = 0
        start = i
        B_count = 1

        for j in range(start+1,N+1):
            if S[j] == "W":
                ans += B_count
            elif S[j] == "B":
                B_count += 1
        print(ans)
        break

Submission status: Accepted

Solution code:
s=input()

ans=0
b_cnt=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:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

S = input()

flg = False
cnt = 0
ans = 0

for i in range(len(S)):
	if flg == False and S[i] == "B":
		flg = True
		start = i

	if flg and S[i] == "W":
		ans += i - start - cnt
		cnt += 1

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    s = list(input()[:-1].decode())
    ans = 0
    count = 0
    for i in range(len(s)):
        if s[i] == 'W':
            ans += i - count
            count += 1
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

Solution code:
S = input()

b_cumsum = [0] * len(S)
now = 0
for i in range(len(S)):
    if S[i] == "B":
        b_cumsum[i] = now + 1
        now += 1
    else:
        b_cumsum[i] = now

S = S[::-1]
b_cumsum = b_cumsum[::-1]
ans = 0
for i, s in enumerate(S):
    if s == "W":
        ans += b_cumsum[i]

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter, defaultdict, deque
s = input()
#n,a,b = map(int,input().split())
# al = list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
s=input()
bl=[]
wl=[]
for j,si in enumerate(s):
  if si=="B":
    bl.append(j)
  else:
    wl.append(j)

blen=len(bl)
wlen=len(wl)

ans=0
for i,j in zip(wl,range(wlen)):
  ans+=abs(i-j)
  
print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

s=input()
n=len(s)
l=[0]*n
c=0
for i in range(n):
    if s[-1-i]=="W":
        c+=1
    l[-1-i]=c
ans=0
for i in range(n):
    if s[i]=="B":
        ans+=l[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
S=S[::-1]
B_index=[i for i, x in enumerate(S) if x == 'B']
for i in range(len(B_index)):
    B_index[i]=B_index[i]-i
print(sum(B_index))

Submission status: Accepted

Solution code:
string,ans,cnt = input(),0,1
length = len(string)
b_cnt = string.count("B")
for i in range(length):
    if string[i]=="B":
        ans+=length-b_cnt-i
        b_cnt-=1
print(ans)

Submission status: Accepted

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


def solve(S: str):
    count = 0
    S = [s for s in S]

    count = 0
    sub_count = 0

    for s in S:
        if s == 'W':
            count += sub_count
        else:
            sub_count += 1
                
        
    print(count)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
ans = 0
count = 0

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

print(ans-count*(count-1)//2)

Submission status: Accepted

Solution code:
s=list(input())
co=0
ans=0
for (c,i) in zip(s,range(len(s))):

  if c== "W":
    ans+=i-co
    co+=1
    
print(ans)

Submission status: Accepted

Solution code:
S = input()

res = 0
bc = 0
for s in S:
    if s == "B":
        bc += 1
    else:
        res += bc

print(res)

Submission status: Accepted

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

Submission status: Accepted

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