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 = input()
N = len(S)

bc = S.count('B')

bpos = 0
ans = 0
for i, si in enumerate(S):
    if si == 'B':
        bpos += 1  # 何個目のbか
        after_pos = N - bc + bpos - 1
        diff = after_pos - i
        ans += diff
        # print('diff', diff, after_pos, bpos)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
BC = S.count('B')
WC = len(S) - BC

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

Submission status: Accepted

Solution code:
s = input()
dat = []
wcount = 0
res = 0
for i in range(len(s)):
    if s[i] == "W":
        res += (i - wcount)
        wcount += 1
        dat.append(i)
print(res)

Submission status: Accepted

Solution code:
s=  input()
W = 'W'
B = 'B'
Bi = []
Wi = []

BC = s.count(B)
WC = len(s) - BC

for i in range(len(s)):
  if s[i] == B:
    Bi.append(i)
  else:
    Wi.append(i)
    
W_dist = sum(Wi) - int((0 + WC-1)* (WC)/2)
#print('W',str(W_dist))

B_dist = int((len(s)-1 + WC) * BC /2) - sum(Bi)
#print('B',str(B_dist))

print(int((W_dist + B_dist)/2))

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())
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=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:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

def main():
	s=input().rstrip().decode('utf-8')
	
	cnt=0
	ans=0
	
	for i in range(len(s)):
		if s[-i-1]=="W":
			cnt+=1
		else:
			ans+=cnt
	
	print(ans)
	
	
	
	
	
	
	
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
def main():
    S = list(input())
    accum = [0]
    for i in range(1,len(S)):
        tmp = accum[i-1] + 1 if S[i-1] == "B" else accum[i-1]
        accum.append(tmp)
    ans = 0
    for i in range(len(S)):
        tmp = 0 if S[i] == "B" else accum[i]
        ans += tmp
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
cnt=0
temp=0
for i in range(len(s)):
    if s[i]=='B':
        temp+=1
    elif i>=1 and s[i]=='W':
        cnt+=temp

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    Bcount = 0
    ans = 0
    for s in S:
        Bcount += s=="B"
        if s=="W":
            ans += Bcount
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=str(input())
N=S.count('W')
L=[0]*len(S)
ans=0
X=0
Q=[]
for i in range (len(S)):
	if S[i]=='W':
		ans+=i-X
		X+=1
print(ans)

Submission status: Accepted

Solution code:
S = input()

ans_count = 0
b_count = 0
for s in S:
    if s=="B":
        b_count = b_count + 1
    if s=="W":
        ans_count = ans_count + b_count

print(ans_count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=str(input())
co=int(0)
ans=int(0)
for i in reversed(range(len(s))):
    if s[i]=='W':
        co+=1
    else:
        ans+=co

print(ans)

Submission status: Accepted

Solution code:
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import bisect
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15

def main():
    s = input().strip()
    tmp = 0
    ans = 0
    for c in s:
        if c == "B":
            tmp += 1
        else:
            ans += tmp
            # tmp = 0

    print(ans)


if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

def solve():
    S = input()
    count = 0
    leftMostW = 0
    for i in range(len(S)):
        if S[i] == "W":
            count += i - leftMostW
            leftMostW += 1
    print(count)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

ans = b = 0
prev = "W"
for c in s:
    if c=="B":
        b += 1
        prev = "B"
    elif prev=="B":
        ans += b
        prev = "B"
    else:
        b = 0
        prev = "W"
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:
if __name__ == "__main__":
    s = input()

    bcount = 0
    ans = 0

    for ss in s:
        if ss == 'B':
            bcount += 1
        else:
            ans += bcount

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

w,b = 0,0
p,q = 0,0

for i, j in enumerate(s):
    if j == "W":
        p += 1
        w += i
    else:
        q += 1
        b += i

pp = p * (p - 1) // 2
qq = n * (n - 1) // 2 - pp

# print(pp, qq)
# print(w, b)
print((w - pp + qq - b) // 2)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
s = input()

x = [1 if c == 'B' else 0 for c in s]

cum = [0]
for i in range(len(s)):
    cum.append(cum[-1] + x[i])

ans = 0
for idx, c in enumerate(s):
    if c == 'W':
        ans += cum[idx+1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

s=list(ss())
lens=len(s)

wrr=[i for i ,x in enumerate(s) if x=="W"]
lenwrr=len(wrr)
print(sum(wrr)-(lenwrr*(lenwrr-1)//2))

Submission status: Accepted

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

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:
from collections import Counter
s = input()
n = len(s)
c = Counter(s)
ans = 0
for i in range(n):
  if s[i] == "W":
    ans += i+1
ans -= c["W"]*(c["W"]+1)//2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A = list(input())

count = 0
ans = 0
for a in A:
    if a == 'B':
        count += 1
    else:
        ans += count

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def calc(N):
    return sum(int(x) for x in str(N))


def main():
    # sys.stdin = open("sample.txt")
    S = Scanner.string()
    N = len(S)
    sums = [0] * (N+1)
    for i in range(N):
        sums[i+1] = sums[i]
        if S[i] == "B":
            sums[i+1] += 1
    ans = 0
    for i in range(N):
        if S[i] == "W":
            ans += sums[i+1]
    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=list(input())

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)
r = s.count("B")
ans = 0
for i in range(r):
  ans += n-i

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

Submission status: Accepted

Solution code:
from scipy.misc import comb
s = input()
n = len(s)
r = s.count("B")
ans = 0
for i in range(r):
  ans += n-i

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

Submission status: Accepted

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

res = 0
prev = 0
for i, s in enumerate(S):
    if s == 'B':
        res += i - prev
        prev += 1

print(res)

Submission status: Accepted

Solution code:
from sys import stdin

s = stdin.readline().rstrip()

now = 0
count = 0

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

print(count)

Submission status: Accepted

Solution code:
s = input()

ans = 0
cntb = 0

for i in range(len(s)):
    if s[i] == "B":
        cntb += 1
    elif s[i] == "W":
        ans += cntb

print(ans)

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
P = N-1
ans = 0
for i in range(N-2,-1,-1):
    if i == P-1 and S[i+1] == 'B':
        P -= 1
    if S[i] == 'B' and S[i+1] == 'W':
        S[i] = 'W'
        ans += P - i
        P -= 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    s = S()
    ans = 0
    w = 0
    for i, si in enumerate(s):
        if si == "W":
            ans += i-w
            w += 1
    print(ans)

    return


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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	S = input().rstrip()
	bcnt = 0
	ans = 0
	for i in range(len(S)):
		if S[i] == 'B': bcnt += 1
		if S[i] == 'W': ans += bcnt
	
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	S = input().rstrip()
	bcnt = 0
	A = []
	for i in range(len(S)):
		if S[i] == 'B': bcnt += 1
		if S[i] == 'W': A.append(bcnt)
	
	print(sum(A))

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
S = input().strip()
A = [0 for _ in range(len(S))]
cnt = 0
for i in range(len(S)):
    if S[i]=="B":
        cnt += 1
    A[i] = cnt
cntW = 0
for i in range(len(S)):
    if S[i]=="W":
        cntW += A[i]
print(cntW)

Submission status: Accepted

Solution code:
S = input()
W = S.count("W")

A = [i for i in range(W)]

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

print(ans)

Submission status: Accepted

Solution code:
def examA():
    S = SI()
    cur = 0; ans = 0
    for i,s in enumerate(S):
        if s=="W":
            ans += i-cur
            cur +=1
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examA()

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:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# だいたい転倒数。Wから見て左のBを数える

S = read().rstrip().decode('utf-8')

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

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(S: str):
    idx = [i for i in range(len(S)) if S[i] == 'W']
    print(sum([v-i for i,v in enumerate(idx)]))
    return



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:
#!/usr/bin/env python3
import sys


def solve(S: str):
    count = 0
    answer = 0

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


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()
N=len(S)
count=0
num=0
for i in range(N):
    if S[i]=="W":
        count+=1
        num+=i
print(num-count*(count-1)//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

ret = 0
w = 0
for s in S[::-1] :
  if s == 'W' :
    w += 1
  else :
    ret += w
    
print(ret)

Submission status: Accepted

Solution code:
S = list(input())
c = 0
for i in range(len(S)):
    if S[i] == 'W':
        c += i
sc = S.count('W')
print(int(c - sc*(sc-1)//2))

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
S = input()
L = []
for i in range(len(S)):
  if S[i] == 'W':
    L.append(i)
print(sum((L[i] - i) for i in range(len(L))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

S = list(rs())
cnt_B = 0
answer = 0
for s in S:
    if s == 'B':
        cnt_B += 1
    else:
        answer += cnt_B
print(answer)

Submission status: Accepted

Solution code:
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

S = list(rs())
W = [0] * len(S)
for i in range(len(S)):
    if S[i] == 'W':
        W[i] = 1
W = np.array(W[::-1])
W_cum = W.cumsum()[::-1]
W_cum = W_cum.tolist()
answer = 0
for i in range(len(S)):
    if S[i] == 'B':
        answer += W_cum[i]

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(n):
    if s[i]=='W':
        ans+=accum[i]
print(ans)

Submission status: Accepted

Solution code:
s=input()
m=[s[i]=="B" for i in range(len(s))]
m1=[None for i in range(len(s))]
m1[0]=m[0]
for i in range(1,len(s)):
  m1[i]=m1[i-1]+m[i]
m2=[None for i in range(len(s))]
m2[len(s)-1]=m[len(s)-1]
for i in range(len(s)-1,0,-1):
  m2[i-1]=m2[i]+m[i]
  
ans1=0
ans2=0
for i in range(1,len(s)):
  if s[i]=="W":
    ans1+=m1[i]
    ans2+=m2[i]
    
print(ans1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,w=0,0
for i,j in enumerate(input()):
    if j=="W":
        a+=i-w
        w+=1
print(a)

Submission status: Accepted

Solution code:
S = input()
B = S.count('B')
W = S.count('W')
es = 'W' * W + 'B'* B
bf = es.find('B')
blst = [0] * B
for i in range(B):
    blst[i] = bf + i
slst = [0] * B
bindex = 0
for i in range(len(S)):
    if S[i] == 'B':
        slst[bindex] = i
        bindex += 1

ans = 0
for i in range(B):
    ans += blst[i] - slst[i]

print(ans)

Submission status: Accepted

Solution code:
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

s = rs()
counter = collections.Counter(s)
res = 0
for i, c in enumerate(s):
    if c == 'W':
        counter['W'] -= 1
    else:
        res += counter['W']
print(res)

Submission status: Accepted

Solution code:
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

s = rs()
counter = collections.Counter(s)
n = len(s)
res = 0
for i, c in enumerate(s):
    if c == 'W':
        counter['W'] -= 1
    else:
        res += counter['W']
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


S = sys.stdin.buffer.readline().decode().rstrip()

b = 0
ans = 0
for i, c in enumerate(S):
    if c == 'W':
        ans += i - b
        b += 1

print(ans)

Submission status: Accepted

Solution code:
S = input()

bc = 0
result = 0
for i in range(len(S)):
    if S[i] == 'B':
        bc += 1
    if S[i] == 'W':
        result += bc
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
tmp = []
count = 1
for i, x in enumerate(S):
    if x == 'B':
        tmp.append([i, count])
        count += 1

tmp.sort(key=lambda x: x[1], reverse=True)
ans = 0
for i in range(len(tmp)):
    x = tmp[i][0]
    ans += len(S)-1-i - x
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:
# AGC029
S = input()
N = len(S)
B_cnt = 0
W_cnt = 0
ans = 0
for i in range(N-1, -1, -1):
    ##print(i, S[i])
    if S[i] == "B":
        ans += W_cnt
    else:
        W_cnt += 1
print(ans)

Submission status: Accepted

Solution code:
s = list(input())

w_cnt = 0
cnt = 0
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

idx = [i for i in range(len(s)) if s[i] == 'W']
ans = sum(i - x for x, i in enumerate(idx))

print (ans)

Submission status: Accepted

Solution code:
# AGC029A - Irreversible operation
S = input()
N = len(S)

STR = [s for s in S]
W_idx = [i for i,s in enumerate(S) if s == 'W']
ans = 0

for i in range(len(W_idx)):
    ans += W_idx[i]-i
print(ans)

Submission status: Accepted

Solution code:
S = input()
bcount = 0
ans = 0
for i in range(len(S)):
    if S[i] == "B":# countup B(= empty space)
        bcount += 1
    else:          # countup W shift value
        ans += bcount
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np


def main():
    s = input()

    b = []
    cnt = 0
    for i, e in enumerate(s):
        if e == "B":
            b.append(i)
            cnt += 1

    b = np.array(b)
    b_fin = np.arange(len(s) - cnt, len(s))

    ans = int(np.sum(b_fin - b))

    print(ans)


if __name__ == "__main__":
    main()