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: Time Limit Exceeded

Solution code:
s = list(input())
n = len(s)
c = 0
while True:
  k = 0
  can = False
  for i in range(n-1):
    if k < n-1:
      if s[k] == "B" and s[k+1] == "W":
        s[k] = "W"
        s[k+1] = "B"
        can = True
        c += 1
        k += 2
      else:
        k += 1
  if not can:
    print(c)
    break

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
s = S
while s.find('BW') > -1:
    ans = ans + 1
    s = s.replace('BW', 'WB', 1)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
b = input()
a = [i for i in b]
out = 0
for k in range(len(a)):
	for i in range(len(a) - 1):
		if a[i] == 'B' and a[i + 1] == 'W':
			out += 1
			a[i] = 'W'
			a[i + 1] = 'B'
		
print(out)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
c=0
while True:
  a=s.count('BW')
  if a:
    c+=a
    s=s.replace('BW','WB')
  else:
    break
print(c)

Submission status: Time Limit Exceeded

Solution code:
def change(S):
    for i in range(len(S)-1):
        if S[i] == "B" and S[i+1] == "W":
            ans = S[:i] + "WB" + S[i+1+1:]
            break
    return ans


S = input()

count = 0
while "BW" in S:
    S = change(S)
    count += 1

print(count)

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    S = input()
    count = 0

    while 'BW' in S:
        idx = S.index('BW')
        S = S[:idx] + 'WB' + S[idx + 2:]
        count += 1

    print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(raw_input())
c = 0
while 'BW' in "".join(S):
    idx = "".join(S).index('BW')
    S[idx] = 'W'
    S[idx + 1] = 'B'
    c += 1

print c

Submission status: Time Limit Exceeded

Solution code:
S=list(input())
n=len(S)
ans=0
flag=True
while flag:
    flag=False
    for i in range(n-1):
        if S[i]=='B' and S[i+1]=='W':
            S[i],S[i+1]='W','B'
            ans+=1
            flag=True
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
count=0
while "BW" in S:
    S=S.replace("BW","WB",1)
    count+=1
print(count)

Submission status: Accepted

Solution code:
# coding: utf-8

def main():
    S = list(input())
    b = 0
    ans = 0
    for s in S:
        if s == 'B':
            b += 1
        else:
            ans += b

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def resolve():
    S = input()
    sub = "BW"
    cnt = 0
    sum = 0

    # 左端からのWと右端からのBは無関係のため除外
    st = 0
    end = 0
    for i, s in enumerate(S):
        if s == "B":
            break
        else:
            st += 1

    for i, s in enumerate(S[::-1]):
        #print(s)
        if s == "W":
            break
        else:
            end += 1

    #print(st, end)
    S = S[st:len(S)-end]
    #print(S)

    foundB = False
    for i, s in enumerate(S):
        if s == "B":
            cnt += 1
            foundB = True
        elif s == "W":
            sum += cnt
            foundB = False
        
        #print(s, cnt, sum)

    print(sum)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
cnt = 0
ans = 0
for c in S[::-1]:
  if c == 'W':
    cnt += 1
  else:
    ans += cnt

print(ans)

Submission status: Accepted

Solution code:
s = list(str(input()))
bCnt = 0
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
S = list(str(input()))
k = 0
t = -1
N = len(S)
for i in range(N):
  if S[i] == 'B':
    k += N - i - 1
    t += 1
ans = k -  t*(t+1)/2
print(int(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:
def input_int():
    return(int(input()))

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

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

def run():
    s = input()

    b_count = s.count('B')

    b_to_end_sum = 0
    for i in range(len(s)):
        target = s[i]
        if target == 'B':
            b_to_end_sum += (len(s) - i - 1)

    result = b_to_end_sum - sum([i for i in range(b_count)])
    print(result)

run()

# bbww
# bwdw 1
# wddw 1
# wdwd 1
# wwdd 1
#
# wwwwbbbbwbw
#
# wwwwdddwdwd 2
#
# wwwwddwdwdd 2
#
# wwwwdwdwddd 2
# wwwwwdwdddd 1
# wwwwwwddddd

Submission status: Accepted

Solution code:
S = input()

cnt = 0
b = 0
for i,s in enumerate(S):
  if s == "W":
    cnt+=b
  else:
    b+=1
print(cnt)

Submission status: Accepted

Solution code:


def main():
    s = input()
    n = len(s)
    cn = 0
    ans = 0
    for i in range(n):
        if s[i] == 'W':
            ans += (i - cn)
            cn += 1
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

num_b = 0
ans = 0
for v in S:
    if v == 'B':
        num_b += 1
    else:
        ans += num_b

print(ans)

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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 LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

s = S()

# n個のオセロストーンが1列にある。長さnの文字列sで石の状態はあらわされていて、
# i番目の石が白：w、黒:bであらわされている。
# 以下の操作を行う

# iがb,i+1がwなiを一つ選び、二つとも裏返す。

# 最大でこの作業を何回行うことができるか。

# 例
# bwbwbwbwbw ⇒ wbwbwbwbwb
# bwwbbbwwwbwb　⇒　wbwbbbwwwbwb　⇒ wwbbbwwwbwb　⇒ wwbbwbwwbwb　⇒ wwbwbbwwbwb　⇒
# wwwbbbwwbwb　⇒ wwwbbwbwbwb　⇒ wwwbwbbwbwb　⇒ wwwwbbbwbwb　⇒ wwwwbbbwbwb　⇒ 

# 最終的にwwwwwwbbbbbになるので、結論としてはwを左に動かした回数をカウントすればよい。
# このカウントは、左から見て行ってwが出た位置より左のbの数を足し上げればよい。
black = 0
ans = 0
for stone in s:
    if stone == "B":
        black = black + 1
    else:
        ans = ans + black
print(ans)

Submission status: Accepted

Solution code:
s = input()

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

cnt = s.count("B")

target = list(range(len(s)))[-cnt:]

ans = 0
for t, i in zip(target, ind):
    ans += t-i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

S = input()
s_list = []
for i, s in enumerate(S):
  if s == 'W':
    s_list.append(i)
t_list = [i for i in range(len(s_list))]
answer = 0
for i in range(len(s_list)):
  answer += s_list[i] - t_list[i]
print(answer)

Submission status: Accepted

Solution code:
def main():
    s = input()
    count = 0
    b_count = []
    for v in s:
        if v == "B":
            count += 1
        if v == "W":
            b_count.append(count)
    print(sum(b_count))

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

s = list(reversed(input().strip()))
black = 0
ans = 0

for i, v in enumerate(s):
    if v == 'W':
        continue
    else:
        ans += (i - black)
        black += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/local/bin/python3
# https://atcoder.jp/contests/agc029/tasks/agc029_a

S = list(input())
next_w = 0
ans = 0

for i in range(len(S)):
    if S[i] == 'W':
        back = i - next_w
        ans += back
        next_w = i - back + 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()

ans = 0
cnt = 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())

Wcnt = 0
res = 0

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

S=list(input().strip())
S.reverse()

sum = 0
n = 0
for i in range(len(S)):
    if S[i] == 'B':
        sum += (i-n)
        n += 1
print(sum)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
S = list(input())

cnt_b = 0 
ans = 0

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

Submission status: Accepted

Solution code:
s = list(input())

ans = 0

cntB = 0

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    s = input()
    count = 0
    black_count = 0
    for i in range(len(s)):
        if s[i] == 'B':
            black_count += 1
        if s[i] == 'W':
            count += black_count

    print(count)


if __name__ == "__main__":
    main()

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()
ans,cnt=0,0
for i in range(len(s)):
  if s[i]=="B":
    cnt+=1
  else:
    ans+=cnt
print(ans)

Submission status: Accepted

Solution code:
S = list(input())
cntb = 0
cntw = 0
for i in range(len(S)):
    if S[i] == "B":
        cntb +=1
    if S[i] == "W":
        cntw += cntb
print(cntw)

Submission status: Accepted

Solution code:
import sys
a = [ c for c in input()]
B = 0
W = 0
for i in range(len(a)):
    if a[i] == "B":
        B += 1
    else:
        W += B

print(W)

Submission status: Accepted

Solution code:
str = input()

n = len(str)
p = 0
ans = 0
for i in range(n):
    if str[i] == 'W':
        ans += i - p
        p += 1

print (ans)

Submission status: Accepted

Solution code:
# A
S = input()
cnt = 0
B_cnt = 0
ans = 0
for s in reversed(S):
    # print(s)
    if s == "B":
        ans += (cnt - B_cnt)
        B_cnt += 1
    cnt += 1
    # print("B_cnt: " + str(B_cnt))
    # print("Cnt:" + str(cnt))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

pre, pst=0,0
for i in range(num):
    if s[i]=='B': pre+=i

s=sorted(s,reverse=1)
for i in range(num):
    if s[i]=='B': pst+=i

print(pst - pre)

Submission status: Accepted

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

s = v()
w_a = [1 if i=="W" else 0 for i in s]
w_cnt = list(itertools.accumulate(w_a))

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush

sys.setrecursionlimit(10**6)
INF = 10**20

def mint():
    return map(int,input().split())
def lint():
    return map(int,input().split())
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])

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

Submission status: Accepted

Solution code:
S=input()

start=0
for i in range(len(S)):
    start=i
    if S[i]=='B':
        break

left_W=start
ans=0
if start<len(S)-1:
    for i in range(start+1,len(S)):
        if S[i]=='W':
            ans+=i-left_W
            left_W+=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

print(ans)

Submission status: Accepted

Solution code:
s = input()
black = 0
ans = 0

for i in range(len(s)):
    if s[i] == 'W':
        ans += black
    else:
        black += 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]=='W':
    ans+=i-cnt
    cnt+=1
print(ans)

Submission status: Accepted

Solution code:
s=input()

ans=0
cnt=0
for i,j in enumerate(s):
  if j=="W":
    ans+=i-cnt
    cnt+=1
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = str(input())

_sum = 0
ans = 0

for s in S:
  
  if s == "B":
    _sum += 1
    
  elif s == "W":
    ans += _sum
    
print(ans)

Submission status: Accepted

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

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

cnt = 0
for i in range(len(W)):
  cnt += W[i] - i
  
print(cnt)

Submission status: Accepted

Solution code:
S = list(input())

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

Submission status: Accepted

Solution code:
S = input()

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

B_count = S.count("B")
destination_B_index_sum = (len(S)*B_count) - sum(range(B_count))

print(max(0, destination_B_index_sum - B_index_sum))

Submission status: Accepted

Solution code:
S = input()

p = 0
ans = 0

for i, c in enumerate(S):
  if c == 'B':
    continue
  ans += (i - p)
  p += 1
  
print(ans)

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

num = s.count('W')

before = 0
for i in range(len(s)):

    if s[i]=='W':
        before += i


after = 0
for j in range(num):
    after+=j

print(before-after)

Submission status: Accepted

Solution code:
S = input()

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

print(ans)

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
#coding: utf-8

S = input()

ret  = 0
numW = 0
for c in reversed(S):
    if c == 'B':
        ret += numW
    else:
        numW+=1

print(ret)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
a = input()
b = int(len(a))
c = int(0)
d = int(0)
e = int(0)
for i in range(b):
  if a[i] == "W":
    c += 1

for i in range(b):
  if a[i] == "W":
    e = e + int(i) - d
    d += 1

print(e)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())

cnt = [0]*len(S)

cnt_B = 0
for i,j in enumerate(S):
    if j == 'B':
        cnt_B += 1
    if j == 'W':
        cnt[i] = cnt_B
print(sum(cnt))

Submission status: Accepted

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

WWW = S.count("W")

for i in range(N):
    if S[i] == "B":
        ans += WWW
    if S[i] == "W":
        WWW -= 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

cur_b = 0

ans = 0
for s in S:
    if s == 'B':
        cur_b += 1
    else:
        ans += cur_b

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]


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:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


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


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


S = S()
num_w = S.count('W')
num_b = len(S) - num_w
left_w_pos = 0
ans = 0
for i, s in enumerate(S):
    if (s == 'W'):
        ans += (i-left_w_pos)
        left_w_pos += 1
print(ans)

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    s = S()
    alldic = collections.Counter(s)
    wnum = alldic["W"]
    leftdic = collections.Counter(s[:wnum])
    leftbnum = leftdic["B"]
    right_w_in = wnum-1
    left_b_in = right_w_in + 1
    ans = leftbnum

    for i,x in enumerate(s):
        if i<=right_w_in:
            if x == "B":
                ans += right_w_in - i
        elif i>=left_b_in:
            if x == "W":
                ans += i - left_b_in
    
    print(ans)
main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

w_list = [0]
ans=0
for i in range(len(S)):
    if S[i]=='W':
        w_list.append(i+1)

for i in range(1,len(w_list)):
    ans += w_list[i]-i
    
print(ans)

Submission status: Accepted

Solution code:
othello = input()
bef = 0
sumall = 0
count = 0

for i in range(len(othello)):
    sumall += i
    if(othello[i] == 'B'):
        bef += i
        count += 1

sumelse = 0
for i in range(len(othello)-count):
    sumelse += i

aft = sumall - sumelse

print(aft - bef)

Submission status: Accepted

Solution code:
S=input()
cnt=0
ans=0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

count=S.count("W")
a=0
mylist=[]

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

for j in range(len(mylist)):
    a=a+mylist[j]-j-1
print(a)

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

valueB = 0
for i in range(count):
  valueB += (len(S) - 1 - i)
  
print(valueB - valueA)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
len_s = len(s)
cnt_b = s.count('B')
diff_list = [i for i in range(len_s - cnt_b, len_s)][::-1]
b_idx = []

for idx, el in enumerate(s):
    if el == 'B':
        b_idx.append(idx)
    else:
        pass

total = 0
for pos, idx in zip(diff_list, b_idx):
    total += pos - idx
print(total)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=[x for x in input()]
ans=0
W_cnt=S.count('W')

for s in S:
  if s=='W':
    W_cnt-=1
  elif s=='B':
    ans+=W_cnt
print(ans)

Submission status: Accepted

Solution code:
S = input()
res = 0
w_ind = 0
for i, s in enumerate(S):
    if s == "B":
        pass
    elif s == "W":
        res += i - w_ind
        w_ind += 1
print(res)

Submission status: Accepted

Solution code:
s = list(input())
l = []
for i in range(len(s)):
    if s[i] == "W":
        l.append(i)
print(sum(l) - s.count("W")*(s.count("W")-1)//2)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
S = input().strip()
l=len(S)
motomoto=0
b=S.count('B')
saisyuu=((2*l-b-1)*b)//2
for i in range(l):
    if S[i]=='B':
        motomoto+=i
print(saisyuu-motomoto)

Submission status: Accepted

Solution code:
import math

S = list(input())

t = 0

res = 0

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

if len(S) == 1:
    print(0)

elif S.count("B") == 1 and S[-1] == "B":
    print(0)

else:
    print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
ans = 0
cnt = 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())

ans = 0
black = 0

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

print(ans)

Submission status: Accepted

Solution code:
S = input()
W = []
 
for i, s in enumerate(S):
  if s == 'W':
    W.append(i)

idx = 0
ans = 0
for w in W:
  ans += w-idx
  idx += 1

print(ans)

Submission status: Accepted

Solution code:
def resolve():
    s = str(input())
    ans = 0
    ind = []
    for i, char in enumerate(s):
        if char == 'W':
            ind.append(i)
    lst = 0
    # print(ind)
    for i in ind:
        ans += (i - lst)
        lst += 1

    # idx = s.index('W')
    print(ans)
    return


resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

b = 0
c = 0
for i in range(len(s)):
    if s[i] == "B":
        b += 1
    else:
        c += b

print(c)

Submission status: Accepted

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

print(counter)

Submission status: Accepted

Solution code:
S = input()
w_position_list = []
for i, s in enumerate(S):
    if s == 'W':
        w_position_list.append(i)
n_w = len(w_position_list)
res = sum(w_position_list) - (n_w *(n_w-1)/2)
print(int(res))

Submission status: Accepted

Solution code:
def solve():
    S = input()
    ans = 0
    B_cnt = 0
    for s in S:
        if s == 'W':
            ans += B_cnt
        else:
            B_cnt += 1
    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline


def main():
  S = input()[:-1]

  cnt = 0
  nw = 0
  for i, s in enumerate(S):
    if s == 'W':
      cnt += (i-nw)
      nw += 1

  print(cnt)


if(__name__ == '__main__'):
  main()

Submission status: Accepted

Solution code:
import sys

s = input()
first = s.find('B')

if first == -1:
    print(0)
    sys.exit()

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

print(ans)

Submission status: Accepted

Solution code:
S = input()
n = len(S)
l = [0 if S[i] == 'B' else 1 for i in range(n)]
cnt = 0
lenB = 1
for i in range(n-1):
    if l[i] == 0 and l[i+1] == 0: lenB += 1
    if l[i] == 0 and l[i+1] == 1:
        l[i+1] = 0
        cnt += lenB
print(cnt)

Submission status: Accepted

Solution code:
S=input()
N=len(S)
answer=0
saidai=N-1
for n in range(N):
    if S[n]=='B':
        answer+=saidai-n
        saidai-=1

print(answer)

Submission status: Accepted

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

ans, cntB = 0, 0
for i in range(n):
    if s[i] == 'B':
        cntB += 1
    else:
        ans += cntB

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
cnt=s.count('W')
a=[i for i,x in enumerate(s) if x=='W']
ans=0
for i in range(cnt):
  ans+=a[i]-i
print(ans)