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:
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) 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 MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


s = input()[::-1]
index = s.find('W')
s = s[index:]
cnt = 0
b_cnt = 0
for i, b in enumerate(s):
    if b == 'B':
        cnt += i - b_cnt
        b_cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
S = input()

B_nums = []
for s in S:
    if len(B_nums) == 0:
        B_nums.append(1 if s == "B" else 0)
    else:
        B_nums.append((B_nums[-1] + 1) if s == "B" else B_nums[-1])

res = 0
for index, s in enumerate(S):
    if s == "W":
        res += B_nums[index]

print(res)

Submission status: Accepted

Solution code:
S = input()

B_num = S.count("B")
W_num = S.count("W")

B_start = W_num # 一番左のBがいていいindex

res = 0
for i in range(B_start + 1):
    if i == len(S):
        break
    if S[i] == "B":
        res += B_start - i
        B_start += 1
        while(B_start < len(S) and S[B_start] == "B"):
            B_start += 1

print(res)

Submission status: Accepted

Solution code:
s = str(input())

len_s = len(s)
cnt = 0
ans = 0
for i in range(1,len_s+1):
    if s[-i] == 'B':
        ans += cnt
    else:
        cnt += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = list(input())

b = 0
c = 0

for i in a:
  if i == 'W':
    b += c
  else:
    c += 1
    
print(b)

Submission status: Accepted

Solution code:
s = input()

cnt = 0
black = 0
for string in s:
  if string == "B":
    black += 1
  else:
    cnt += black

print(cnt)

Submission status: Accepted

Solution code:
s = input().rstrip()

ans = 0
w_num = 0
for i, c in enumerate(s):
    if c == "W":
        ans += i - w_num
        w_num += 1

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
A - Irreversible operation
https://atcoder.jp/contests/agc029/tasks/agc029_a

"""
import sys


def solve(S):
    ans = 0
    black = S.count('B')
    white = S.count('W')
    for ch in S[::-1]:
        if ch == 'B':
            black -= 1
        else:
            ans += black
    return ans


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
S = input()

white = [i for (i, s) in enumerate(S) if s == 'W']
ideal = [i for i in range(len(white))]

print(sum(w - i for (w, i) in zip(white, ideal)))

Submission status: Accepted

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

white, black, ans = 0, 0, 0
for i in range(1, n):
    if s[-i] == 'W':
        black = 0
        white += 1
        if s[-i-1] == 'B':
            if i == n-1:
                black += 1
                ans += black*white
    else:
        black += 1
        if s[-i-1] == 'B':
            if i == n-1:
                black += 1
                ans += black*white
        else:
            ans += black*white
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cb = 0
m = 0
for c in s:
    if c == "W":
        m += cb
    else:
        cb += 1

print(m)

Submission status: Accepted

Solution code:
s = input()
ans = 0
ss = s.count('B')
sss = len(s)
index = -1
sum_s = 0

for i in range(ss):
    index = s.find('B', index+1)
    ans += sss-index-1
    sum_s += i
    
ans -= sum_s
print(ans)

Submission status: Accepted

Solution code:
S = input()

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

print(out)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
count = 0
num = 0

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

print(count)

Submission status: Accepted

Solution code:
S = input()
black_count = 0
counter = 0
for i, c in enumerate(reversed(S)):
    if c == 'B':
        counter += i - black_count
        black_count += 1
print(counter)

Submission status: Accepted

Solution code:
import re

S = input()
Bs = S.count('B')
Ws = len(S) - Bs
res = 0

ite = re.finditer('W', S)
for i, j in enumerate(ite):
  res += (j.start() - i)
  
print(res)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
a = []
for i, ss in enumerate(s):
    if ss == "W":
        a.append(i+1)
w_num = s.count("W")
sum_a = (w_num * (w_num + 1)) // 2
ans = sum(a) - sum_a
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:

x=[]
S=str(input())
for i in range(len(S)):
    if S[i]=="W":
        x.append(i+1)

for j in range(len(x)):
    x[j]=x[j]-j-1
print(sum(x))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

s = input()
a = [m.start() for m in re.finditer("W", s)]

ans = 0
for i, e in enumerate(a):
    ans += e - i

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,s,b=0,input(),0
for i in range(len(s)):a+=i*(s[i]=="W");b+=(s[i]=="W")
print(a-((b*(b-1))//2))

Submission status: Accepted

Solution code:
s = input()

if s[0]=="W":
    l = [1]
else:
    l = [0,1]

for i in range(1,len(s)):
    if s[i]==s[i-1]:
        l[-1]+=1
    else:
        l.append(1)

rightw = sum(l[2::2])

ans = 0

for i in range(len(l)//2):
    ans += l[2*i+1]*rightw
    if i!=len(l)//2-1:
        rightw -= l[2*i+2]

print(ans)

Submission status: Accepted

Solution code:
S = input()
cnt = 0
ans = 0
left = 0
for i in range(len(S)):
    if S[i] == 'W':
        cnt += S[left:i].count('B')
        ans += cnt
        left = i
print(ans)

Submission status: Accepted

Solution code:
S = input()

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

print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
in_seq = raw_input()
listAdd = 0
cnt = 0
cnt_W = 0
for stone in in_seq:
  if stone == "W":
    
    cnt_move = cnt - cnt_W
    listAdd += cnt_move
    cnt_W += 1
  cnt += 1
print listAdd

Submission status: Accepted

Solution code:
osero = input();
len = len(osero);
con_b = 0;
con = 0;
for i in range(0,len):
	if osero[i]=='B':
		con_b = con_b + 1;
	if osero[i] =='W':
		con = con + con_b;
print(con)

Submission status: Accepted

Solution code:
S=input()

position = 0
answer = 0
for i, s in enumerate(S):
  if s=='W':
    answer += i-position
    position += 1
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

S = [x for x in input()]

min = 0
count = 0
for i, x in enumerate(S):
    if x == 'W':
        count += i - min
        min += 1
        
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
s = list(input())
count = 0
ans = 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()[::-1]
w = 0
res = 0
for s in S:
	if s == 'W':
		w += 1
	else:
		res += w
print(res)

Submission status: Accepted

Solution code:
s = input()

cnt = 0
result = 0
for v in reversed(s):
    if v == "W":
        cnt += 1
    else:
        result += cnt
print(result)

Submission status: Accepted

Solution code:
s = input()

res = 0
W_cnt = 0
for x in s[::-1]:
    if x == "W":
        W_cnt += 1
    else:
        res += W_cnt
print(res)

Submission status: Accepted

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

count = 0 #黒の数
for i in range(n):
    if s[i] == 'B':
        count = count + 1

ans = 0
c = n - count
for i in range(n):
    if s[i] == 'B':
        ans = ans + (c - i)
        c = c + 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
s = np.array(list(input()))
#Bの場所
ind = np.array(np.where(s=='B'))
#文字列の長さ
len_ind=ind.shape[1]
#Bの個数
len=s.shape[0]
#Bの移動先
dist=np.arange(len-len_ind,len)
#答え
ans=np.sum(dist-ind)
print(ans)

Submission status: Accepted

Solution code:
txt = input()
txt_list = list(txt)

count = 0
n_b = 0
n_w = 0
i = 0
for i in range(len(txt_list)):
    if txt_list[i] == 'W':
        n_w += 1
    if (i>=1 and txt_list[i-1] == 'W' and txt_list[i] == 'B') or (i==len(txt_list)-1 and txt_list[i] == 'W'):
        count += n_b * n_w
        n_w = 0
    if txt_list[i] == 'B':
        n_b += 1

print(count)

Submission status: Accepted

Solution code:
txt = input()
txt_list = list(txt)

num = 0
count = 0
for i in range(len(txt)):
    if txt_list[i] == 'W':
        count += i-num 
        num += 1

print(count)

Submission status: Accepted

Solution code:
S = list(input())
W_i = [i for i,j in enumerate(S) if j == 'W']
W_n = S.count('W')
cur = 0
ans = 0
for i in W_i:
  ans += i-cur
  cur += 1
print(ans)

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:
S = input()
b = 0
ans = 0
for c in S:
    if c == 'B':
        b += 1
    else:
        ans += b
print(ans)

Submission status: Accepted

Solution code:
S = input()
white = 0
for i in range(len(S)):
  if S[i] == 'W':
    white += 1
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 = list(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()
n = len(s)
count = 0
m = 0
for i in range(n):
    if s[i] == 'W':
        count += i - m
        m += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding: utf-8
s = list(input())
ans = 0
b = 0
for i in range(len(s)):
    if s[i] == "W":
        ans += i - b
        b += 1
print(ans)

Submission status: Accepted

Solution code:
S = input()
B = 0
count = 0
for s in S:
    if s == "B":
        B += 1
    elif s == "W":
        count += B
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

ans = 0
white = [0]*len(S)
w = 0

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

Submission status: Accepted

Solution code:
S = input()
num, cnt = 0, 0
for k in range(len(S)):
  if S[k] == 'B':
    num += 1
  else:
    cnt += num
print(cnt)

Submission status: Accepted

Solution code:
"""AtCoder"""

S = input()

ans = 0
tmp = 0

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

print(ans)

Submission status: Accepted

Solution code:
S = input()

counter = 0
ans = 0

for index, char in enumerate(S):
    if(char == "W"):
        ans += index - counter
        counter += 1

print(int(ans))

Submission status: Accepted

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

ans = 0
b = 0
for ss in s:
    if ss == 'W':
        ans += b
    else:
        b += 1
print(ans)

Submission status: Accepted

Solution code:
S = list(input())
B = 0
W = 0
for i in range(len(S)):
    if S[i] == 'B':
        B += 1
    else:
        W += 1
Num = 0
Count = 0
for i in range(len(S)):
    if S[i] == 'W':
        Count += (i-Num)
        Num += 1
print(Count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
l = len(s)
a = [0 for i in range(l)]
cur = 0
for i, ele in enumerate(s[::-1]):
  a[i] = cur
  if ele =="W":
    cur += 1

ans = 0
for i in range(l):
  if s[i]=="B":
    ans += a[l-i-1]
print(ans)

Submission status: Accepted

Solution code:
def main29():
    S = input()
    count = 0
    start = False
    tmp = 0
    W_count = 0

    for i in range(len(S)):
        if S[i] == "W":
            if not start and i > 0:
                if S[i-1] == "B":
                    count += i - W_count
                    tmp = i
                    start = True
            else:
                count += i - W_count
                tmp = i
            W_count += 1

    print(count)

main29()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
string = input()
length = len(string)
bnum = len([x for x in string if x == "B"])
ans = 0
for i in range(length):
    if string[i] == "B":
        ans += length-i-1
        
ans = ans - int(bnum*(bnum-1)/2)
print(ans)

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)

S = S()
result = 0
w_count = 0
for sidx, s in enumerate(S[::-1]):
    if s == "W":
        w_count += 1
    else:
        result += w_count

#  b_count = 0
#  for sidx, s in enumerate(S):
#      if sidx == len(S)-1: break
#      if s == "B":
#          b_count += 1
#      else:
#          result += b_count
print(result)

Submission status: Accepted

Solution code:
s = input()
w = 0
b = 0
ans = 0
slist = []
for i in s:
    slist.append(i)
slist.reverse
for i in slist:
    if i == "B":
        w += 1
    else:
        b += 1
        ans += w

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = str(input())
S_ = [idx for idx, x in enumerate(S) if x=='W']
print(sum(S_) - sum([_ for _ in range(len(S_))]))

Submission status: Accepted

Solution code:
cnt = ans = 0
for c in input():
  if c is 'W':
    ans += cnt
  else:
    cnt += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
l = len(S)
a = [l-i for i,c in enumerate(S) if c=="B"]
b = len(a)
print(sum(a) - b*(b+1)//2)

Submission status: Accepted

Solution code:
S = input()
w_count = [0]*len(S)
if S[0] == 'W':
    w_count[0] = 1

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

#print(w_count)
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

# W = [i for i, x in enumerate(S) if x == 'W']
# B = [i for i, x in enumerate(S) if x == 'B']
#
# print(sum([len([b for b in B if b < w]) for w in W]))

dp = [0] * (N + 1)
ans = 0
for i in range(1, N + 1):
    if S[i-1] == 'B':
        dp[i] = dp[i-1] + 1
    else:
        dp[i] = dp[i-1]
        ans += dp[i]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = list(input())
b_n = N.count("B")
point = 0
for i in range(len(N)):
    if N[i] == "B":
        point += i
future_point = (b_n * (len(N) - 1 - b_n + 1 + len(N) - 1)) // 2
print(future_point - point)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

S = list(sys.stdin.readline().rstrip())
cnt_w = S.count('W')
loc_w = [i+1 for i,c in enumerate(S) if c == 'W']
print(sum(loc_w)-cnt_w*(cnt_w+1)//2)

# BW  BBW  WBWB
# ↓   ↓     ↓
# WB  WBB  WWBB

Submission status: Accepted

Solution code:

s=input()
answer=0
counter=0
for i in range(len(s)-1,-1,-1):
    if s[i]=="B":
        answer += len(s)-i-1-counter
        counter += 1
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input();x=[k for k,v in enumerate(s)if v=="W"];print(sum(x)-sum(range(len(x))))

Submission status: Accepted

Solution code:
a=b=0
for s in input():a+=b*(s>'B');b+=s<'W'
print(a)

Submission status: Accepted

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

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:

import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    S = (input_raw[0])
    count = 0
    w_count = 0
    for i in range(len(S)):
        if S[i] == "W":
            count += (i - w_count)
            w_count += 1
    print count

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=list(input())
ans=0
wf=0
bf=0
for i in range(len(s)):
    if s[i]=='W':
        ans+=i
        wf+=1
    else:
        bf=1
if wf==0 or bf==0:
    print(0)
else:
    print(ans-wf*(wf-1)//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)
if n <= 1:
  print(0)
  exit()
else:
  left = 0
  ans = 0
  for i in range(n):
    if s[i] == 'W':
      left+= 1
      ans += (i+1)-left
      #print(left)
print(ans)

Submission status: Accepted

Solution code:
X = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
 
arr = [0 if s == "W" else 1 for s in S]
sorted_arr = sorted(arr)
  
state = sum([arr[i] * i for i in range(len(S))])
final_state = sum([sorted_arr[i] * i for i in range(len(S))])
 
print(final_state - state)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
S = input()
ans = reduce(
    lambda acc, s: (acc[0] + acc[1], acc[1]) if s == 'B' else (acc[0], acc[1] + 1),
    reversed(S),
    (0, 0)
)[0]
print(ans)

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())

mode = 0
count = 0

ans = 0

for c in s:
    if mode == 0:
        if c == 'W':
            continue
        else:
            mode = 1
            count = 1
    else:
        if c == 'B':
            count += 1
        else:
            ans += count

print(ans)

Submission status: Accepted

Solution code:
s=list(input())
w=[i for i in range(len(s)) if s[i]=="W"]
ideal=[j for j in range(s.count('W'))]
print(sum([i-j for i,j in zip(w,ideal)]))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
# 各 W の左にある B の数の和を求める
ans = 0
num_B = 0
for c in s:
    if c == "B":
        num_B += 1
    else:
        ans += num_B
print(ans)

Submission status: Accepted

Solution code:
S = input()

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

print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
b = 0
for s in S:
    if s == 'W':
        ans += b
    else:
        b += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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 = list(input())
cnt = 0
cnt_B = 0

for i in range(len(s)):
    if s[i] == 'B':
        cnt += len(s) - (i + 1 + cnt_B)
        cnt_B += 1
        
print(cnt)

Submission status: Accepted

Solution code:
S = [1 if(_ =="B") else 0 for _ in input()]+[1]
ans = 0
if(S.index(1) == len(S)-1):
    print(0)
else:
    S.pop(-1)
    first = S.index(1)
    count = first
    start = first
    for s in S[start:]:
        if(s == 0):
            ans += count -first
            first += 1
        count += 1
    print(ans)

Submission status: Accepted

Solution code:
S = input()
indexes = [i for i, x in enumerate(S) if x == "W"]
print(sum([x-i for i, x in enumerate(indexes)]))

Submission status: Accepted

Solution code:
s = str(input())

wcount=0
w_place=0
for i in range(len(s)):       
    if s[i]=="W":
        wcount+=1
        w_place+=i+1
print(int(w_place-(1+wcount)*wcount/2))

Submission status: Accepted

Solution code:
S = input()

count = 0
for i in range(len(S)):
    if S[i] == 'W':
        continue
    else:
        break
S = S[i:]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# S_i=BかつS_i+1=Wのときにi番目とi+1番目の石を入れ替える操作に等しい。
# つまり各白石について自身よりも左側に黒石がいくつあるかを数えれば良い。
S = list(input())
# 入れ替え総数を数える変数です。
count = 0
# 黒石の数を数えておく変数です。
count_b = 0
for s in S:
  if s == 'B':
    count_b += 1
  else:
    count += count_b
print(count)

Submission status: Accepted

Solution code:
S = input()
ans, tmp = 0, 0
for s in S[::-1]:
  if s == 'B':
    ans += tmp
  else:
    tmp += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
import numpy as np
import sys

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
N = len(s)
num = s.find("B")

cnt = 0
ans = 0
for i in range(max(0,num-1),N):
    if s[i] == "B":
        cnt += 1
    else:
        ans += cnt

print(ans)

Submission status: Accepted

Solution code:
S = list(input())

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

print(Ans)

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()
res = 0
count = 0
for i in range(len(S)):
    if S[i] == 'B':
        count += 1
    if S[i] == 'W':
        res += count
       
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
Ws = []
for i in range(len(S)):
    if S[i] == 'W': Ws.append(i)
def func(n): return (n+1)*n//2
print(sum(Ws)-func(len(Ws)-1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ss=input()
ans=0
b_count=0
for s in ss:
    if s=='B': b_count+=1
    if s=='W': ans+=b_count
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
N=(stdin.readline().rstrip())
N=list(N)
cnt=0
ans=0
for i in N:
    if i=="B":
        cnt+=1
    else:
        ans+=cnt
print(ans)

Submission status: Accepted

Solution code:
s = input()

acc = 0

for i in range(len(s)):
  if s[i] != 'W':
    break

for j in range(i, len(s)):
  if s[j] == 'W':
    acc += j - i
    i += 1

print(acc)

Submission status: Accepted

Solution code:
# https://beta.atcoder.jp/contests/agc029/tasks/agc029_a


def main():
    S = list(input())
    count = 0
    w_offset = 0
    for i in range(len(S)):
        if S[i] == "W":
            count += i - w_offset
            w_offset += 1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
total_b=0
cnt=0
total=0
for i in range(n):
    if s[i]=="B":
        total_b+=i
        cnt+=1
for i in range(n-cnt,n):
    total+=i
print(total-total_b)
#print(total,total_b)

Submission status: Accepted

Solution code:
N = input()
cnt1 = 0
for x in N:
  if x == 'B':
    cnt1 += 1
N = N[::-1]
ans =  0
cnt2 = 0
for i in range(len(N)):
  if N[i] == 'B':
    ans += i - cnt2
    cnt2 += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
S=sys.stdin.readline()
l=len(S)
w_idx=0
cnt=0
for i in range(l):
    if S[i]=='W':
        cnt+=i-w_idx
        w_idx+=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ar = list(input())
wc = ar.count("W")
count = 0
for i in range(len(ar)):
    if ar[i] == "B":
        count += wc
    else:
        wc -= 1
print(count)

Submission status: Accepted

Solution code:
hoge=input()
ans=0
count=0
white=0
for i in hoge:
  
  if(i=="W"):
    ans+=count - white
    white+=1
    
  count+=1
  
print(ans)