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:
x= input()
l_w = []
for i in range(len(x)):
    if x[i] == 'W':
        l_w.append(i)
#print(l_w)
sum = 0
st = 0
for i,j in enumerate(l_w):
    sum += j-st
    st+= 1
print(sum)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[30]:


S = list(input())


# In[31]:


w_count = S.count("W")
print(sum([idx for idx,x in enumerate(S) if x == "W"]) - (w_count-1)*w_count//2)


# In[ ]:

Submission status: Accepted

Solution code:
st = list(map(lambda x: x=='B',input()))[::-1]

ans = 0

count = 0

for i, v in enumerate(st):
    if v:
        ans += i - count
        count += 1

print(ans)

Submission status: Accepted

Solution code:
#import numpy as np
#import functools
#import operator
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with
#from itertools import permutations as perm
#import collections

#N = int(input())
#a,b= map(int,input().split())
#P = list(map(int,input().split()))
#B = list(map(int,input().split()))
S= str(input())
#prod = functools.partial(functools.reduce, operator.mul)
#c=np.array(A)
#p=np.prod(A)

w = S.count('W')
b = S.count('B')
c=0
v=0
for i in range(len(S)):
    if S[i]=='B':
        v+=1
        c += (len(S)-b + v) - (i +1)
print(c)

Submission status: Accepted

Solution code:
S = input()

b_cnt = 0
C = [0] * len(S)
for i in range(len(S)):
    if S[i] == 'B':
        # 白の個数+1
        b_cnt += 1
    if S[i] == 'W':
        # それまでにあった白の個数を記録
        C[i] = b_cnt

print(sum(C))

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    S = input()

    ret = 0
    cntW = 0
    cntB = 0
    for i, si in enumerate(S):
        #cntW,cntB
        if si=='W':
            cntW+=1
            ret+=cntB
        else:
            cntB+=1

    print(ret)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = readline().decode().rstrip()

res = 0
b_cnt = 0

for c in S:
    if c == 'B':
        b_cnt += 1
    elif c == 'W':
        res += b_cnt

print(res)

Submission status: Accepted

Solution code:
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

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

Submission status: Accepted

Solution code:
s = input()

a = 0
b = s.count('B')
move = 0

for i in reversed(range(len(s))):
    if s[i] == 'B':
        move += (len(s) - a - (i + 1))
        a += 1
print(move)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

s = input()
ans = 0
tmp = 0
#saving the number of black
for c in reversed(s):
    if c == 'W':
        tmp += 1
    else:
        ans += tmp
print(ans)

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

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

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
S = S()
N = len(S)
ans = 0
count = 0
for i in range(N):
  if S[i] == "B":
    ans += N-1-i
    count += 1
print(ans-(count-1)*count//2)

Submission status: Accepted

Solution code:
def main():
    S = input()
    ans = 0
    wc = 0

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
sl = []
for i in range(len(S)):
    sl.append(S[i])
count = 0
memo = 0
for i in range(len(S)-1):
    if sl[i] == "B" and sl[i+1] == "W":
        count += 1+memo
        sl[i+1] = "B"
    elif sl[i] == "B" and sl[i+1] == "B":
        memo += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
a = []
w_lt = 0
flag = True
for i in range(len(S)):
    if S[i] == "W":
        a.append(i)
    else:
        flag = False
if not flag:
    suma = 0
    for i in range(len(a)):
        suma += a[i] - i
    print(suma)
else:
    print("0")

Submission status: Accepted

Solution code:
S = list(input())
n = len(S)
cnt_b = 0
cnt = 0
for i in range(n):
    if S[i] == 'B':
        cnt_b += 1
        cnt += i
ans = int((2*n - cnt_b -1)*cnt_b*0.5 - cnt)
print(ans)

Submission status: Accepted

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

def linput():
	return list(map(float,input().split()))

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def main():
	S = input().rstrip()
	
	res = 0
	B = 0
	
	for s in S:
		if s=='B': B+=1
		else: res += B
	print(res)

if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


s = input()
n = len(s)
end = n-1
movement = 0
for i in range(n-1, -1, -1):
    if s[i] == 'B':
        movement += end - i
        end -= 1
print(movement)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if wcnt==len(s):
    print(0)
else:
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()

    ans = 0
    n_white = 0
    for s in S[::-1]:
        if s == "W":
            n_white += 1
        else:
            ans += n_white

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


w_sum = 0
w_n = 0
for i, c in enumerate(s):
    if c == "W":
        w_sum += i
        w_n += 1
    
print(w_sum - w_n*(w_n-1)//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div
# endregion
S = list(rs())
ans = 0
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:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
#sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
s=list(input())
A=[]
for i in range(len(s)):
    if(s[i]=="W"):
        A.append(i)
k=0
i=0
for x in A:
    k+=(x-i)
    i+=1
print(k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	#b , c = tin()
	s = input()
	ret = 0
	pp_b = 0
	for c in s:
		if c == 'B':
			pp_b += 1
		else:
			ret += pp_b
	return ret
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(sum(count))

Submission status: Accepted

Solution code:
s = input()

w = []
for i in range(len(s)):
	if s[i] == "W":
		w.append(i)
res = 0

for i in range(len(w)):
	res += w[i] - i
print (res)

Submission status: Accepted

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

count = 0
suma = 0
for i in S:
  if i=="W":
    suma += count
  else:
    count += 1
print(suma)

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

Submission status: Accepted

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

counts = [0] * len(s)

for i, c in enumerate(s):
    prev = counts[i - 1] if i > 0 else 0
    if c == 'B':
        counts[i] = prev + 1
    else:
        counts[i] = prev

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

print(allowable)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
def rle(t):
    tmp2, num, ans = t[0], 1, []
    for i in range(1, len(t)):
        if tmp2 == t[i]:
            num += 1
        else:
            ans.append([tmp2, num])
            tmp2 = t[i]
            num = 1
    ans.append([tmp2, num])
    return ans


S = input()

s = list(map(str, S))
l = rle(S)
now = [[], [], []]
for i in range(len(S)):
    if S[i] == 'B':
        now[0].append(i)
for j in range(len(now[0])):
    now[1].append(len(S) - len(now[0]) + j)
    now[2].append(now[1][j] - now[0][j])
print(sum(now[2]))

Submission status: Accepted

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

def main():
    S = input()
    cnt_w = [0]*(len(S) + 1)
    for i in range(len(S) - 1,-1,-1):
        if S[i] == 'W':
            cnt_w[i] = cnt_w[i + 1] + 1
        else:
            cnt_w[i] = cnt_w[i + 1]
    ans = 0
    for i in range(len(S)):
        if S[i] == 'B':
            ans += cnt_w[i]
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S=input()
S_list=list(S)
num_B = S.count('W')
count = 0
i = 0
for nb in range(num_B):
  while S_list[i] != 'W': i+=1
  count += i - nb
  S_list[nb],S_list[i]=S_list[i],S_list[nb]
  i+=1
print(count)

Submission status: Accepted

Solution code:
S = input()

cnt = 0
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
ls=len(s)
ans=0
wpoint=[i for i, v in enumerate(s) if v=="W"]
wnum=len(wpoint)

for i in range(wnum):
    ans+=wpoint[i]-i
print(ans)

Submission status: Accepted

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
S = S()
ans,target_index = 0,0
for i in range(len(S)):
    if S[i]=='W':
        ans += i-target_index
        target_index += 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()
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:
def integration(s):
  itg = [0]
  counter = 0
  for x in s:
    if x == "B":
      counter += 1
    itg.append(counter)
  return itg

def solve(itg, left, right):
  n = right-left
  if n <= 1:
    return 0
  mid = (left+right)//2
  a = solve(itg, left, mid)
  b = solve(itg, mid, right)
  res = a + b + (itg[mid]-itg[left])* \
    (right-mid-(itg[right]-itg[mid]))
  return res

s = input()
print(solve(integration(s), 0, len(s)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
c = 0
current_B_counter = 0
for s in S:
    if s == "B":
        current_B_counter += 1
    if s == "W":
        c += current_B_counter

print(c)

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:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    S = input().rstrip('\n')
    ans = 0
    cnt = 0
    for s in S:
        if s == "B":
            cnt += 1
        else:
            ans += cnt
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
l = len (s)
se = set()
for i in range(l):
    if s[i]=='W':
        se.add(i)
n = len(se)

ans = sum(se) - n*(n-1)//2
print(ans)

Submission status: Accepted

Solution code:
s = [i == "W" for i in list(input())]
n = len(s)
w = []
for i in range(n):
    if s[i]:
        w.append(i)
ans = 0
for i in range(len(w)):
    ans += w[i]-i
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 = list(input())

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

print(ans)

Submission status: Accepted

Solution code:


def resolve():
    s=list(input())
    ans=[]
    cnt=0
    for i in s:
        if i=='B':
            cnt+=1
        else:
            ans.append(cnt)
    print(sum(ans))
resolve()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
S=list(input())
total_count=0
b_count=0

for n in range(len(S)):
    if S[n]=='B':
        b_count+=1
    if S[n]=='W':
        total_count+=b_count
print(total_count)

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
    i += 1
print(ans)

Submission status: Accepted

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

ans = 0
bnum = 0

for i in range(N):
    if S[i] == "B":
        bnum += 1
    else:
        ans += bnum

print(ans)

Submission status: Accepted

Solution code:
# A - Irreversible operation

S = input()

count = 0
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
S = input()
W = []
for i in range(len(S)):
    if S[i] == "W":
        W.append(i)

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

print(c)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
s=input()
l=len(s)
c=s.count('W')
ans='W'*c+'B'*(l-c)
w=0
b=0
for i in range(l):
    if i<=c-1 and s[i]!='W':
        w+=i
    if i>=c and s[i]!='B':
        b+=i
print(b-w)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
S = input()
W = []
for i in range(len(S)):
    if S[i] == "W":
        W.append(i)

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

print(ans)

Submission status: Accepted

Solution code:
s = str(input())

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

Submission status: Accepted

Solution code:
import itertools
import sys
import numpy as np
import collections

S=input()
wc=0
cnt=0
for i , s in enumerate(S):
    if s=='W':
        if i!=wc:
            cnt += i-wc
        wc += 1
    else:
        continue
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
S = np.array(list(map(str, input().rstrip())))

S[np.where(S=="W")] = 1
S[np.where(S=="B")] = 0
S = S.astype(int)
now = np.where(S==1)[0]
goal = np.arange(now.shape[0])

print((now - goal).sum())

Submission status: Accepted

Solution code:
# AGC029
# A
# Irreversible operation
import itertools

s_list = input()

gr = itertools.groupby(s_list)

num_b = 0
ans = 0

for key,group in gr:
    if key == "B":
        num_b += len(list(group))
    else:
        ans += num_b * len(list(group))
    
print(ans)

Submission status: Accepted

Solution code:
s = input()
opcount = 0
wcount = 0
bcount = 0
for i in range(len(s)):
  if s[i] == "B":
    bcount += 1
  else:
    if bcount>0:
      opcount += i-wcount
      wcount += 1
    else:
      wcount += 1
print(opcount)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    S = input()

    cnt = 0
    ans = 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:
s = input()
B_index = [i for i,x in enumerate(s) if x == 'B']
a = sum(B_index)
b = 0
for i in range(len(s) - 1, len(s) - 1 - s.count('B'), -1):
    b += i
print(b-a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
s = sys.stdin.readline().strip()
print(sum([a-b for a, b in zip(list(range(s.count('W'), len(s))), [i for i, c in enumerate(s) if c == 'B'])]))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = read().rstrip().decode()
cnt = 0
ans = 0
for i, ss in enumerate(s):
    if ss == 'W':
        ans += i - cnt
        cnt += 1
print(ans)

Submission status: Accepted

Solution code:
S = list(str(input()))

count = 0
Wcount = 0


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

print(count)

Submission status: Accepted

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

last = sum(range(cnt))
print(ind-last)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
def main():
    cnt = 0
    num_w = 0
    A = list(input())
    for i in range(len(A)):
        if A[i] == "W":
            cnt += i - num_w
            num_w += 1
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()

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

a = 0
for i in range(s.count("W")):
  a += i

print(ans - a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())

cntW = 0
res = 0
for i, s in enumerate(S):
    if s == "W":
        res += i - cntW
        cntW += 1

print(res)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

S = list(input())

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

print(ans)

Submission status: Accepted

Solution code:
S = input()

tmp = 0
ans = 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()
cnt = 0
b_cnt = 0
for c in s:
    if c == 'B':
        b_cnt += 1
    else:
        cnt += b_cnt
print(cnt)

Submission status: Accepted

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