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

#print(S)

n = 1 if S[0] == "W" else 0# number of white string
count = 0
for i in range(1, len(S)):
    if S[i] == "W":
        count += i - n
        n += 1
        #print("n is", n)
        #print("count is ", count)
print(count)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    S = input()
    ans = 0
    bcount = 0
    for i in range(len(S)):
        if S[i] == 'B':
            bcount += 1
        else:
            ans += bcount

    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
b = 0
res = 0
for i in s:
    if i == 'B':
        b += 1
    else:
        res += b
print(res)

Submission status: Accepted

Solution code:
s = input()
l =  len(s)
dif = 0
ans = 0
for i in range(l):
    if s[i]=="W":#黒白逆
        ans += (i-dif)#
        dif += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def f(s):
    ret = 0
    n = len(s)
    for i in range(n):
        if s[i] == "W":
            ret += i
    return ret

s = list(input())
nW = s.count("W")
ans = 0
ans += f(s)
for i in range(1, nW):
    ans -= i
print(ans)

"""
BWBWBW
WBWBWB
WWBWBB
WWWBBB

先頭までの距離（i）- 何番目のWか+1
ni - 1~nW +1
"""

Submission status: Accepted

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

cnt_B = S.count('B')
idx_B = N - cnt_B

for i in range(N):
    if S[i] == 'B':
        ans += idx_B - i
        idx_B += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

S = input()

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 = 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()
accum = [0]
num = 0
count = 0
for i in range(len(s)):
    if s[i] == 'B':
        num += 1
    else:
        count += accum[i]
    accum += [num]
print(count)

Submission status: Accepted

Solution code:
def main():
    s = input()
    length = len(s)-1
    count = s.count('B')
    init = sum([i for i in range(len(s)) if s[i] == "B"])
    processed = sum(range(length-count+1, length+1))

    print(processed-init)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
answer = [0] * (len(S) + 1)

for i in reversed(range(len(S))):
    if S[i] == 'W':
        answer[i] = answer[i + 1] + 1
    else:
        answer[i] = answer[i + 1]

cnt = 0
for i in range(len(answer) - 1):
    if answer[i] == answer[i + 1]:
        cnt += answer[i]

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()

ans=0
black=0

for c in S:
    if c=='B':
        black+=1
    else:
        ans+=black

print(ans)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
cnt = 0
ans = 0
for i in range(len(S)):
  if S[i] =="B":
    ans += i-cnt
    cnt += 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 += 1

for i in range(cnt):
    ans -= i
print(ans)

Submission status: Accepted

Solution code:
s = input()[::-1]
ans = []
tmp = 0
for i in s:
    if i == "W":
        tmp += 1
    elif i == "B":
        ans.append(tmp)
print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
def solve(s):
    ans = 0
    num = 0
    for c in s[::-1]:
        if c == "W":
            num += 1
        else:
            ans += num
    return ans

s = input()
print(solve(s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
total_l = 0
for i in range(len(s)):
  if s[i] == "W":
    total_l += i
minus = sum(list(range(s.count("W"))))
print(total_l - minus)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s = input().rstrip()

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s = input()

ans = 0
pos = 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
pos = 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=S.count("W");print(sum(i*(S[i]>"B")for i in range(len(S)))-w*~-w//2)

Submission status: Accepted

Solution code:
S = input()
r = 0
nB = 0
for c in S:
  if c == "B":
    nB += 1
  if c == "W":
    r += nB
print(r)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    S=input()
    ans=0
    b=0
    for s in S:
        if s=="B": b+=1
        else: ans+=b
    print(ans)
resolve()

Submission status: Accepted

Solution code:
S=input();print(sum([i for i, s in enumerate(S) if s=='W'])-(S.count('W')*(S.count('W')-1))//2)

Submission status: Accepted

Solution code:
S = input()

ans = 0
right = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
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 = [c for c in input()]
ans = 0
black = 0
for i in range(len(S)):
    if S[i] == "W":
        ans += black
    else:
        black += 1
print(ans)

Submission status: Accepted

Solution code:
S=list(input())
S=S[::-1]
N=len(S)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
W = 0

for i in S:
    if i == "W":
        W += 1

Bl = []

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

Wl = []

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

N = len(Bl)
ans = 0

for i in range(N):
    ans += Wl[i] - Bl[i]

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
S=input()
N=len(S)

sum=0
k=0

for i in range(N):
    if S[i]=="W":
        sum+=(i-k)
        k+=1

print(sum)

Submission status: Accepted

Solution code:
S = list(input())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
pie = input()

sum_B = 0
wum = 0
num = 0

for i in range(0,len(pie)):
    if (pie[i]=='W'):
        wum+=1
        fl = i
        flag=i
for i in range(i-1,-1,-1):
    if (pie[i]=='B'):
        if (wum>0):
            sum_B+=(flag-i-num)
            num+=1
        else:
            break

print(sum_B)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#AGC029A https://atcoder.jp/contests/agc029/tasks/agc029_a
import sys
#import collections

#n= int(input())
#s= input()
#tmp = input().split()
#n,m = list(map(lambda a: int(a), tmp))
s= input()

n=len(s)

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

Submission status: Accepted

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

def main():
    S = input().strip()
    w = 0
    n = 0
    for i,c in enumerate(S):
        if c == "W":
            n += i-w
            w += 1
    print(n)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    s = input()
    ans = 0
    w = 0
    for i in range(len(s)):
        if s[i] == "W":
            ans += i-w
            w += 1
    print(ans)
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#Solve
if __name__ == "__main__":
    A()

Submission status: Accepted

Solution code:
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

s=input().rstrip()
n=len(s)
now=[0]*(n+1)
for i in range(n):
    if s[i]=="B":
        now[i+1]=now[i]+1
    else:
        now[i+1]=now[i]

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

Submission status: Accepted

Solution code:
S = input()
cnt = 0
for i, s in enumerate(S):
    if s == 'W':
        cnt += i;
cnt -= S.count('W') * (S.count('W') - 1) // 2
print(cnt)

Submission status: Accepted

Solution code:
def main():
    S = input()
    ans = 0
    count = 0
    for i in range(len(S)):
        if S[i] == "B":
            count += 1
        else:
            ans += count
    return ans

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

Submission status: Accepted

Solution code:
S=list(input())
N=len(S)
cnt=0
if S[0]=="W":
    idx=1
else:
    idx=0

for i in range(1,N):
    if S[i]=="W":
        cnt+=i-idx
        idx+=1


print(cnt)

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
s = input()

b = 0
ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(S: str):
    counter = 0
    c = 0
    for i, s in enumerate(S):
        if s == 'W':
            counter += i - c
            c += 1
    print(counter)
    return


# Generated by 1.1.4 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=input()
ans=0
k=0
for i in range(len(s)):
	if s[i]=="W":
		ans+=i-k
		k+=1
print(ans)

Submission status: Accepted

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

ans = 0
# if S[0] == 'B':
#     tmp = 1
# else:
#     tmp = 0

tmp = 1 if S[0] == 'B' else 0

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

print (ans)

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
left = [0] * N

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

print (ans)

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
left = [0] * N
right = [0] * N

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

# if S[N -1] == 'W':
#     right[N - 1] = 1
# for i in range(N - 2, -1, -1):
#     if S[i] == 'W':
#         pass

ans = 0
for i in range(N):
    if S[i] == 'W':
        ans += left[i]

print (ans)

Submission status: Accepted

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

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
B = input()
lenB = len(B)

cntB = 0
checkB = [0]*lenB
indB = []
for i, b in enumerate(B):
    if b == 'B':
        cntB += 1
        indB.append(i)

dif = 0
i = 0
for j in range(lenB-cntB, lenB):
    dif += j - indB[i]
    i += 1

print(dif)

Submission status: Accepted

Solution code:
B = input()
lenB = len(B)

cntB = 0
checkB = [0]*lenB
indB = []
for i, b in enumerate(B):
    if b == 'B':
        cntB += 1
        indB.append(i)

dif = 0
i = 0
for j in range(lenB-cntB, lenB):
    dif += j - indB[i]
    i += 1

print(dif)

Submission status: Accepted

Solution code:
S = input()
b = 0
ans = 0
for s in S :
    if s == "B" :
        b += 1
    else :
        ans += b
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:
S = input()

ans = 0
cnt = 0
for i, c in enumerate(reversed(S)):
    if c == 'B':
        ans += i - cnt
        cnt += 1
print(ans)

Submission status: Accepted

Solution code:
S = input()
bias = 0
ans = 0
for i,c in enumerate(S):
  if c == "W":
    ans += i -bias
    bias += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

S = input().rstrip()

left_B = 0
answer = 0
for x in S:
    if x == 'B':
        left_B += 1
        continue
    answer += left_B

print(answer)

Submission status: Accepted

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

print(a)

Submission status: Accepted

Solution code:
S = list(input())
S = S[::-1]

ans = 0
count_w = 0

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

print(ans)

Submission status: Accepted

Solution code:
# 2019/08/08

s=input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
a=input()
bs=[i for i,j in enumerate(a) if j=="B"]
ws=[i for i,j in enumerate(a) if j=="W"]
cnt=0
for w in ws:
	cnt+=bisect.bisect(bs,w)
print(cnt)

Submission status: Accepted

Solution code:
# Bはすべて右に詰まるので各Bの右からの距離の総和
# （逆でもいい Wの左）
s = input()
n = len(s)
w = 0
pack_w = 0
for i in range(n):
    if s[i] == "W":
        w += i - pack_w
        pack_w += 1

print(w)

Submission status: Accepted

Solution code:
def sum_n(n):
    #n-1の和を求めたい
    ans = 0
    for i in range(n):
        ans += i
    return ans

def main():
    s = list(input())
    ans = 0
    cnt = 0
    for i,dst in enumerate(s):
        if dst=="W":
            ans += i
            cnt += 1
    ans -= sum_n(cnt)
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
ans = 0

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

Submission status: Accepted

Solution code:
# AGC029A - Irreversible operation
def main():
    S = input().rstrip()
    blk, ans = 0, 0
    for i in S:
        if i == "B":
            blk += 1
        else:
            ans += blk
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
S = list(stdin.readline().rstrip())
ls = len(S)
ans = 0
num_b = 0
for i in range(ls):
    if S[i] == 'B':
        num_b += 1
    else:
        ans += num_b
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
B_position=[]

for k,v in enumerate(S):
    if v=='B':
        B_position.append(k)

ans=0
L=len(S)

for i in B_position[::-1]:
    ans+=L-i-1
    L-=1

print(ans)

Submission status: Accepted

Solution code:
s = list(input())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

b_l = 10**9
w_poslist = []
for i in range(len(S)):
    s = S[i]
    if s == "B" and i < b_l:
        b_l = i
    if s == "W":
        w_poslist.append(i)
if b_l == 10**9:
    print(0)
else:
    ans = 0
    for i in range(len(w_poslist)):
        if w_poslist[i] < b_l:
            continue
        ans += w_poslist[i] - b_l
        b_l += 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s_list = list(input())

result = 0
wcnt = 0
for i,s in enumerate(s_list):
    if s == "W":
        result += i - wcnt
        wcnt += 1

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(reversed(list(input())))
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:
#!/usr/bin/env python
from collections import defaultdict, deque
import math
from math import factorial
import re

BIGNUM = 10 ** 9 + 7

def main():
    #L, N = map(int, input().split())
    S = list(input())

    black_index = []
    for index, s in enumerate(S):
        if s == 'B':
            black_index.append(index)

    num = 0
    for i, index in enumerate(black_index):
        right_num = len(S) - (index+1)
        n = right_num - (len(black_index) - i - 1)
        num += n
    print(num)

if __name__ == '__main__':
    main()

Submission status: Accepted

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


def main():
    s = input()[::-1]
    w_count = 0
    ans = 0

    for si in s:
        if si == 'W':
            w_count += 1
        else:
            ans += w_count

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

S = input()
N = len(S)

w_num_arr = np.zeros(N)
b_num_arr = np.zeros(N)


if S[-1] == "W":
    w_num_arr[-1] = 1

for i in range(N-1-1, -1, -1):
    if S[i] == "W":
        w_num_arr[i] = w_num_arr[i+1] + 1
    else:
        w_num_arr[i] = w_num_arr[i+1]

ans = 0
for i in range(N):
    if S[i] == "B":
        ans += int(w_num_arr[i])

print(ans)

Submission status: Accepted

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



def main():
    S = input()
    
    p = 0
    c = 0

    for i, s in enumerate(S):
        if s == 'W':
            c += 1
            p += i

    print(p - c*(c-1)//2)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

flag = False
cnt = 0
for i in range(len(S)):
    if S[i] == 'B' and flag == False:
        flag = True
        l = i
    if S[i] == 'W' and flag:
        cnt += i - l
        l += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

seq = 0
ans = 0
for i, s in enumerate(list(input())):
    if s == 'W':
        seq += 1
        ans += i + 1 - seq
print(ans)

Submission status: Accepted

Solution code:
s = input()
cnt_b, cnt_w = 0,0
ans = 0
for i, x in enumerate(s):
    if x == 'W':
        ans += cnt_b
        cnt_w += 1
    else:
        cnt_b += 1
print(ans)

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
import heapq
INF = float("inf")
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###


S = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
b = input()
white = 0
bl = []
for k in b:
    if k == 'B':
        bl.append(1)
    else:
        white += 1
        bl.append(0)
k = 0
wp = white
ans = 0
for p in bl:
    if p==1:
        ans += wp - k
        wp += 1
    k += 1

print(ans)

Submission status: Accepted

Solution code:
S=list(input())
#print(S)

wlist=[]
for i in range(len(S)):
  if S[i]=="W":
    wlist.append(i)
    
#print(wlist)
answer=0
for i in range(len(wlist)):
  answer+=wlist[i]-i
  
print(answer)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
A = []

for i, s in enumerate(S):
  if s == "W":
    A.append(i)
n = len(A)-1
print(sum(A)-(n+1)*n//2)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
A = []

for i, s in enumerate(S):
  if s == "W":
    A.append(i)
n = len(A)-1
print(sum(A)-(n+1)*n//2)

Submission status: Accepted

Solution code:
S = list(input())
cumu=[0]
cnt = 0
for i in S:
    if(i=='B'):
        cumu.append(cumu[-1]+1)
    else:
        cumu.append(cumu[-1])

for ind,i in enumerate(cumu[1:]):
    if(S[ind]=='W'):
        cnt+=i

print(cnt)

Submission status: Accepted

Solution code:
s = input()

b = 0
ans = 0

for i in s:
    if i == "B":
        b += 1
    elif i == "W":
        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()

cntB = 0
ans = 0

for ch in S:
    if ch == 'B':
        cntB += 1
    else:
        ans += cntB
print(ans)

Submission status: Accepted

Solution code:
S = input()

cntB = 0
cntW = 0
ans = 0

idx = 0

while idx < len(S):
    #print(idx,cntB,cntW,ans)
    if S[idx] == 'B':
        cntB += 1
        idx += 1
    else:
        while idx < len(S):
            if S[idx] == 'W':
                cntW += 1
                idx += 1
                #print(idx,cntW)
            else:
                ans += cntB*cntW
                cntW = 0
                break
        ans += cntB*cntW
        
print(ans)

Submission status: Accepted

Solution code:
def tyousei(a):
    tyousei_ = [0]
    for i in range(a):
        tyousei_.append(tyousei_[i]+i+1)
    return tyousei_[a]

s = input()
count = 0
length = 0

for i in range(len(s)):
    if s[i]=='B':
        length = length + i
        count = count + 1
    
print((len(s)-1)*count-length-tyousei(count-1))

Submission status: Accepted

Solution code:
s=input()
r=len(s)
bs=[]
for i in range(r):
  if s[i]=='B':
    bs.append(i+1)
l=len(bs)
ans=0
for i in range(l):
  ans+=r-bs[i]-(l-i-1)
print(ans)

Submission status: Accepted

Solution code:
# 最終形態はWwWW...BBB...
# Wが左に詰めて移動する距離の総数
s = input()
ans = 0
wc = 0
for si, sv in enumerate(s):
    if sv == "W":
        ans += si - wc
        wc += 1
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
wb = input()
li = [i for i in wb]
b = 0
count = 0
for i in li:
    if i =='B':
        b+=1
    else:
        count += b
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = list(input())
ans = 0
N = len(S)
flag = False
cntb = 0
cnt = 0
for i in range(N):
    if S[i] == 'B':
        cntb += 1
    elif S[i] =='W':
        cnt += cntb
        
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ans = 0
b = 0

for s in input():
    if s == 'B':
        b += 1
    else:
        ans += b

print(ans)

Submission status: Accepted

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

for i in S:
    if i == 'W':
        ans += tmp
    else:
        tmp += 1

print(ans)

Submission status: Accepted

Solution code:
S = input()

c, last_w = 0, 0
for i, s in enumerate(S):
	if "W" == s:
		c += i - last_w
		last_w += 1
print(c)