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

tmp=[i for i, x in enumerate(S) if x == 'W']
print(sum(tmp)-sum(range(len(tmp))))

Submission status: Accepted

Solution code:
S = input()
B = 0
W = 0
cnt = 0

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

print(cnt)

Submission status: Accepted

Solution code:
import math

def bitsum(bit,i):
    s = 0
    while i > 0:
        s += bit[i]
        i -= i&(-i)
    return s

def bitadd(bit,i,x):
    while i <= n:
        bit[i] += x
        i += i&(-i)
    return bit

s = input()
a = [2 if o == 'B' else 1 for o in s]
n = int(len(a))

n_ = int(math.log2(n)) + 1
bit = [0] * (2**n_)
bit.insert(0,0)

ass = 0
for j in range(n):
    ass += j-bitsum(bit,a[j])
    bit = bitadd(bit,a[j],1)
print(ass)

Submission status: Accepted

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    S = list(input().replace("B", "2").replace("W", "1"))[:-1]
    N = len(S)
    ans = N * (N - 1) // 2
    data = [0] * (N + 1)

    def add(k, v):
        while k <= N:
            data[k] += v
            k += k & -k

    def get(k):
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s

    for a in map({a: i + 1 for i, a in enumerate(sorted(S))}.__getitem__, S):
        ans -= get(a)
        add(a, 1)

    print(ans)


solve()

Submission status: Accepted

Solution code:
import sys
import socket

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('a1.in')


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


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    s = read_str()
    n = len(s)
    res = 0
    w = 0
    for i in range(n - 1, -1, -1):
        if s[i] == 'B':
            res += w
        else:
            w += 1
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
S=input()
counter=0
result = 0

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

print(result)

Submission status: Accepted

Solution code:
#coding:utf-8

s = input()
s_arr = list(s)

n = 0
l = len(s_arr)

ans = 0
b_count = 0
for i in range(l, 0, -1):
    if i == l:
        if s_arr[i-1] == 'B':
            b_count += 1
    else:
        if s_arr[i-1]=='B':
            ans += l - i - b_count
            b_count += 1


print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
s=list(input())
count=0
# print('lens',len(s))
indexes = [i for i, x in enumerate(s) if x == "B"]
ideal=sorted([len(s)-i-1 for i in range(len(indexes))])
# print(indexes)
# print(ideal)
for i in range(len(indexes)):
  count+=ideal[i]-indexes[i]

print(count)

Submission status: Accepted

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

S = input()

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

print(output)

Submission status: Accepted

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Grand_Contest029-A
#  https://agc029.contest.atcoder.jp/tasks/agc029_a

def  irr_operation(givenString):

	allLength = len(givenString)
	allRange = range(0,allLength)
	bCounter =0
	bPosition = []
	for i in allRange:
		if givenString[i] == 'B':
			bPosition.append(i)
			bCounter=bCounter+1

	collectPosition =[]
	bLength = len(bPosition)
	bRange = range(allLength-bLength,allLength)
	for i in bRange:
		collectPosition.append(i)

	bLengthRange = range(0,bLength)
	diffPosition = 0
	for i in bLengthRange:
		diffPosition = diffPosition+(collectPosition[i]-bPosition[i])

	answer = diffPosition
	return answer


if __name__ == '__main__':
	bwstring = input()
	solution=irr_operation(bwstring)
	print(solution)

Submission status: Accepted

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

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

print(sum)

Submission status: Accepted

Solution code:
S = input()

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

print(count)

Submission status: Accepted

Solution code:
S = input()
p = 0
b = 0

for i in S:
    if i == "B":
        b += 1
    elif i == "W":
        p += b 
print(p)

Submission status: Accepted

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


def main():
    """Function."""
    s = str(input())

    total = 0
    b_count = 0
    for i in range(len(s)):
        if s[i] == "B":
            b_count += 1
        if s[i] == "W":
            total += b_count

    print(total)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

sum = []
for i in range(size):
    if S[i] == 'B':
        sum.append(1)
    else:
    	sum.append(0)
    
    if not i == 0:
        sum[i] += sum[i - 1]

count = 0
for i in range(size):
    if (S[i] == 'W'):
        count += sum[i]

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
s=input()
x=len(s)
b=[0]*x
for i in range(-1,-x-1,-1):
    if i==-1and s[i]=="W": b[-1]=1
    elif s[i]=="W": b[i]=b[i+1]+1
    else: b[i]=b[i+1]
ans=chk=0
for i in range(x):
    if s[i]=="B":
        ans+=b[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
#s = 'BWBWBW'*100000
pos = 0
w_pos = 0
found_pos = 0
cnt = 0

while True:
    pos = s.find('W')
    if pos == -1:
        break
    cnt += (pos+found_pos - w_pos)
    w_pos+=1
    s = s[pos+1:]
    found_pos += (pos+1)
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
l = []
i = 0
n = len(s)
while i < n:
    j = 0
    while i < n and s[i] == 'B':
        j += 1
        i += 1
    l.append(j)

    j = 0
    while i < n and s[i] == 'W':
        j += 1
        i += 1
    l.append(j)
# print(l)
res = 0
for i in range(0, len(l), 2):
    if l[i] > 0:
        res += l[i] * l[i + 1]
    if i + 2 < len(l):
        l[i + 2] += l[i]
print(res)

Submission status: Accepted

Solution code:
S = input()

count = 0

BC = 0

for i in range(len(S)):
    S1 = S[i:i+1]
    if S1 == "B":
        BC += 1
    
    if BC > 0 and S1 == "W":
        count += BC

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
n = 0
k = 0
m = len(S)
for i in range(m):
    if S[i] == 'B':
        n += m - (i+1) -k
        k += 1
print(n)

Submission status: Accepted

Solution code:
s=input()
black_count=0
count = 0
for c in s:
    if c == "B":
        black_count += 1
    else:
        count += black_count

print(count)

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
pos = []
cnt = 0
for i in range(n):
  if s[i] == "W":
    pos.append(i)
    cnt += 1

print(sum(pos) - cnt * (cnt - 1) // 2)

Submission status: Accepted

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

black_count = 0
swap_count = 0

for i in range(len_S):
    if S[(len_S - 1) - i] == 'B':
        swap_count += i - black_count
        black_count += 1

print(swap_count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
b = input()
nes = []
nowb = 0
noww = 0
counter = 0
for i in b:
	if i == 'B':
		if noww == 0:
			nowb += 1
		else:
			counter += nowb * noww
			nowb += 1
			noww = 0
	else:
		if nowb != 0:
			noww += 1
		
counter += nowb * noww

print(counter)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
S=input()
count=0
def sigma(i):
    a=[b for b in range(0,i+1)]
    return sum(a)
place=0
flag=0
start=0
for i in range(len(S)):
    if S[i]=="B":
        flag=1
    elif S[i]=="W":
        if flag == 1:
            count += 1
            place += i - start
        else:
            start+=1
ans=place-sigma(count-1)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    A=stdin.readline()
    #A = list(map(int,stdin.readline().replace('B', '0').replace('W', '1')))

    wc = A.count('W')
    indices = [i for i, x in enumerate(A) if x == 'W']
    if wc > 0:
      print(sum(indices) - 1*wc*(wc-1) //2 )
    else:
      print(sum(indices))

input = lambda: stdin.readline()
main()

Submission status: Accepted

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

def x():
    global y
    y += 1
    return y

c = [i-x() for i in range(len(S)) if S[i]=="B"]
print(sum(c))

Submission status: Accepted

Solution code:
#coding:utf-8

S = input()

margin = 0
for i, moji in enumerate(S):
    if moji == 'B':
        margin = i
        break

idx_list = []
for i, moji in enumerate(S[margin:]):
    if moji == 'W':
        idx_list.append(i)

q = len(idx_list) - 1
print(sum(idx_list) - int(0.5 * q * (q + 1)))

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    A=stdin.readline().replace('B', '0').replace('W', '1')
    #A=list(map(int,bw))
    #A = list(map(int,stdin.readline().replace('B', '0').replace('W', '1')))

    wc = A.count('1')
    indices = [i for i, x in enumerate(A) if x == '1']
    if wc > 0:
      print(sum(indices) - 1*wc*(wc-1) //2 )
    else:
      print(sum(indices))

input = lambda: stdin.readline()
main()

Submission status: Accepted

Solution code:
#coding: utf-8
a = input()

b = []
w = []
for i in range(len(a)):
    b.append(a[i])

for i in  range(len(a)):
    if (b[i] == 'W') :
        w.append(i)

n = 0
for i in range(len(w)):
    n += w[i] - i

print(n)

Submission status: Accepted

Solution code:
a = list(input())

su = 0
dd = 0
co = 0
for i in range(len(a)-1,-1,-1):
	if a[i] == 'W':
		co += 1
	if co >= 1:
		if a[i] == 'B':
			su += (len(a)-1 - i) - dd
	if a[i] == 'B':
		dd += 1

print(su)

Submission status: Accepted

Solution code:
from sys import stdin

s = stdin.readline().rstrip()

count = 0
white = 0
for i, stone in enumerate(s):
    if stone == 'W':
        count += (i - white)
        white +=1
print(count)

Submission status: Accepted

Solution code:
S = input()
res = 0
count_b = 0
for i, s in enumerate(S[::-1]):
    
    if s == "B":
        res += i - count_b
        count_b += 1
print(res)

Submission status: Accepted

Solution code:
S = input()
counter = 0
# while True:
#     tmp=S.count('BW')
#     if tmp == 0:
#         print(counter)
#         break
#     else:
#         counter+=tmp
#         S=S.replace('BW','WB')

# i=0
# while True:
#     tmp = S[i:].find('W')
#     print(S[i:])
#     if tmp == -1:
#         print(counter)
#         break
#     else:
#         counter += tmp
#         i+=1

sum=0
for i in range(len(S)):
    if S[i]=='W':
        sum+=i
        counter+=1

n=counter-1
minus=n*(n+1)/2
print(int(sum-minus))

Submission status: Accepted

Solution code:
s = input()
total = 0
w_count = 0
for i in range(1, len(s)+1):
    if s[-i] == 'W':
        w_count += 1
    elif s[-i] == 'B':
        total += w_count

print(total)

Submission status: Accepted

Solution code:
import numpy as np
S = input()
# S = 'BWBWBW'
S_mask = np.array([True if s=='W' else False for s in S])
# print(S_mask.sum())
W_indices = np.where(S_mask)[0]
# print(idx.sum())
W_num = S_mask.sum()
# print(idx)
print(W_indices.sum() - (W_num-1)*W_num//2)

Submission status: Accepted

Solution code:
b_count = 0
count = 0
input_list = list(input())
for s in input_list:
 if s == 'B':
  b_count = b_count + 1
 if s == 'W': 
  count = count + b_count
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
lens=len(s)
s=list(s)
ans=0
a=[i for i, x in enumerate(s) if x == 'B']
lena=len(a)
k=0
for j in a:
    ans+=lens-(j+1)-k
    k+=1
print(ans)

Submission status: Accepted

Solution code:
arange = input()

times = 0
bottom = arange.find("B")
white_pos = arange[bottom:].find("W") + bottom

while bottom != -1 and white_pos != -1:
  times += white_pos - bottom
  bottom += 1
  
  pos = arange[white_pos+1:].find("W")
  if pos == -1:
    break
  white_pos += pos + 1
  
print(times)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 文字列の入力
s = input()
B_num = s.count('B')
length = len(s)

target = 'B'
index = -1
num = 0
v_sum = 0
while True:
    index = s.find(target, index + 1)
    if index == -1:
        break
    num += 1
    v_sum += (length-1)-(B_num- num)-index
print (v_sum)

Submission status: Accepted

Solution code:
black = "B"
white = "W"

def move_cost(s):
    a = 0
    count = 0
    for i, c in enumerate(s):
        if c == white:
            a += i
            count += 1
    count -= 1
    return a - count*(count+1)//2


print(move_cost(input()))

Submission status: Accepted

Solution code:
S = list(input())

i = 0
answer = 0
b_count = 0

while i < len(S)-1:
	i_color = S[i]
	j_color = S[i+1]
	if i_color == 'B' and j_color == 'B':
		b_count += 1
	elif i_color == 'B' and j_color == 'W':
		S[i] = 'W'
		S[i+1] = 'B'
		answer = answer + b_count + 1
	else:
		b_count = 0

	i += 1

print(answer)

Submission status: Accepted

Solution code:
import numpy as np

S = input()
S = list(S)
S = np.array(S)

index_black = np.where(S=="B")[0]
diff = np.array([i for i in range(len(S)-len(index_black),len(S))])
count = int(np.sum(np.abs(diff-index_black)))
print(count)

Submission status: Accepted

Solution code:
s = list(input())
l = len(s)
n, psum = 0, 0
for i in range(l):
    if s[i] == 'W':
        n += 1
        psum += i

nsum = (n*(n - 1))/2

print(int(psum - nsum))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input().strip())
is_irrversible = 0
answer = 0
position_key_sum = 0
number_of_white = 0
sigma = 0
for i in range(len(S)):
    if S[i] == 'W':
        position_key_sum += (i+1)
        number_of_white += 1
        sigma += number_of_white
answer = position_key_sum - sigma
print(answer)

Submission status: Accepted

Solution code:
# your code goes here
import numpy as np

def main():
	s = input()
	ans = 0
	w = 0
	for i in range(len(s)):
		c = s[len(s)-1-i]
		if(c == 'B'):
			if(w > 0):
				ans += w
		else:
			w += 1
	
	print(ans)
	
main()

Submission status: Accepted

Solution code:
S = raw_input()
n = 0
wc = 0
s_pos = 0
for i, c in enumerate(S):
    if c == "W":
        n += 1
        wc += i - s_pos
        s_pos = n

n = 0
bc = 0
s_pos = 0
for i, c in enumerate(reversed(S)):
    if c == "B":
        n += 1
        bc += i - s_pos
        s_pos = n

print max(wc, bc)

Submission status: Accepted

Solution code:
S = input()

count = 0

i = 0

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


print(count)

Submission status: Accepted

Solution code:
s = input()

w_cnt = 0
_b_cnt = 0
b_flag = False
cnt = 0
for si in list(s)[::-1]:
    if si == 'B':
        _b_cnt += 1
    if si == 'W':
        cnt += w_cnt * _b_cnt
        w_cnt += 1
        _b_cnt = 0
cnt += w_cnt * _b_cnt

print(cnt)

Submission status: Accepted

Solution code:
def main():
    s = input()
    black_site = []
    for i, c in enumerate(s):
        if c == "B":
            black_site.append(i)
    count = len(s)-1
    ans = 0
    for i in reversed(black_site):
        ans += count - i 
        count -= 1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = [i for i in input()]
B_pos_ls = []
for i, x in enumerate(s):
    if x == 'B':
        B_pos_ls.append(i)
res = 0
B_pos_ls.sort(reverse=True)
last_B_pos = len(s) - 1
for B_pos in B_pos_ls:
    res += last_B_pos - B_pos
    last_B_pos -= 1
print(res)

Submission status: Accepted

Solution code:
s = input()

is_all_swappd = False
n_swap = 0
n_white = s.count('W')
for i in range(n_white):
    w_idx = None
    if i == 0:
        w_idx = s.find('W')
    else:
        w_idx = s[last_w_idx + 1:].find('W') + last_w_idx + 1
    n_swap += w_idx - i
    last_w_idx = w_idx

print(n_swap)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
S = input()

idx = []
i = 0
W_flag = False
for s in S:
    if not W_flag:
        if s == "W":
            continue
        elif s == "B":
            W_flag = True
    
    if s == "W" and W_flag:
        idx.append(i)
    i+=1
print(int(np.sum(idx) - ((0+len(idx)-1)*len(idx)/2)))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
sum = 0
count = 0
flg = False
S = S[::-1]

for i in range(N):
  if S[i] == 'W':
    count += 1
    flg = True
  elif S[i] == 'B' and flg:
    sum += count
print(sum)

Submission status: Accepted

Solution code:
s = list(input())

cnt = 0
prev_cnt = 0
result = 0
for i in range(len(s)):
    if s[i] == "B":
        cnt += 1
    if s[i] == "W":
        cnt += prev_cnt
        result += cnt
        prev_cnt = cnt
        cnt = 0
print(result)

Submission status: Accepted

Solution code:
s = list("BWBWBW" * 10000)

s = list(input())
ret, counter = 0, 0
for a in s:
    if a == "B":
        counter += 1
    else:
        ret += counter
print(str(ret))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

i = len(s) - 1
ans = 0
t = 0
while i >= 0:
    if s[i] == 'W':
        t += 1
    else:
        ans += t
    i -= 1

print(ans)

Submission status: Accepted

Solution code:
s = input()

ans = 0

num_B=0
num_W=0

for ele in s:
    # print(ele, num_W,num_B, ans)
    if ele == 'B':
        ans += num_B*num_W
        num_B+=1
        num_W=0
    else:
        num_W+=1
ans += num_B*num_W
print(ans)

Submission status: Accepted

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

m1 = s.count('B')
m2 = s[n-m1::].count('B')

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

print(c)

Submission status: Accepted

Solution code:
s=list(input())

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

def kasan(n):
  if n==0:
    return 0
  else:
    return kasan(n-1) + n

saigo = ((wNum-1)+0)*wNum//2
print(ima-saigo)

Submission status: Accepted

Solution code:
S = input()
list = []
a,b = 0,0
for i in range(len(S)):
    list.append(S[i])

for i in range(len(list)):
    if list[i]=='W':
        a += i
        a -= b
        b += 1
print(a)

Submission status: Accepted

Solution code:
S = list(input())
def f(S):
    N = S.count("B")
    k = N
    i = len(S)-1
    res = 0
    while i >= 1:
        if S[i] == "B":
            k -= 1
        else:
            res += k
        i -= 1
    return res
print(f(S), flush=True)

Submission status: Accepted

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

from sys import stdin

def load():
    n = stdin.readline()
    return n

def calc(n):
    countup = False
    whites = 0
    total = 0

    for i,x in enumerate(n):
        if x == 'B':
            countup = True
        elif x == 'W':
            if countup:
                total += i - whites
            whites += 1
    return total

n = load()
print(calc(n))

Submission status: Accepted

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

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

    W_count = S.count('W')
    idx, count, result = 0, 0, 0

    while count < W_count:
        if S[idx] == 'W':
            result += idx - count
            count += 1
        idx += 1

    print(result)

Submission status: Accepted

Solution code:
count  = 0
ans = 0
s = list(input())

for item in s:
  if item == "W":
    ans += count
  else:
    count += 1
print(ans)

Submission status: Accepted

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

s=input()
v=[]
for i in range(len(s)):
  if s[i]=="B":
    v.append(i)
a=0
n=0
for i in range(len(s)-len(v),len(s))[::-1]:
  n+=i-v[a]
  a+=1
print(n)

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    S = input()

    n = [0] * (len(S) + 1)
    for i, s in enumerate(S, start=1):
        if s == 'W':
            n[i] = n[i-1] + 1
        else:
            n[i] = n[i-1]
    ans = 0
    for i, s in enumerate(S, start=1):
        if s == 'B':
            ans += n[-1] - n[i]
    print(ans)

input = lambda: stdin.readline().rstrip()
main()

Submission status: Accepted

Solution code:
S = input()

N = len(S)
B_idx = []
W_idx = []

for i, s in enumerate(S):
    if s == 'B':
        B_idx.append(i)
    else:
        W_idx.append(i)

ans_B = 0
ans_W = 0

counter = 0
for w in W_idx:
    ans_W += (w - counter)
    counter += 1

counter = 0
for b in reversed(B_idx):
    ans_B += (N - b - 1 - counter)
    counter += 1
    
ans = max(ans_B, ans_W)
    
print(ans)

Submission status: Accepted

Solution code:
s = input()
s = list(s)
count_b = [0] * len(s)
for i in range(len(s)):
    if s[i] == 'B':
        if i == 0:
            count_b[i] = 1
        else:
            count_b[i] = count_b[i-1] + 1
    else:
        if i > 0:
            count_b[i] = count_b[i-1]
count = 0
for i in range(len(s)):
    if s[i] == 'W':
        count += count_b[i]
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
word = input()


#%%
# word = "BWBWBW"


#%%
word.count("W")
#%%
ans = 0
to_plus = word.count("W")
for i in range(len(word)):
    if word[i] == "B":
        ans += to_plus
    else:
        to_plus -= 1

    
print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
cntw = 0
cnt = 0

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

print(cnt)

Submission status: Accepted

Solution code:
S = input()

result = 0
w_count = 0

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

print(result)

Submission status: Accepted

Solution code:
S=list(input())

#while S[0]=="W":
#	S.pop(0)

#n=S.count("W")

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

print(c)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=raw_input()
L=[]

t=0
for x in S:
	if x=='W': t+=1
	L.append( t )
	
ans=0
for i , x in enumerate(S):
	if x=='B':
		ans+=L[-1]-L[i]

print ans

Submission status: Accepted

Solution code:
S = list(input())

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

    if S[i] == 'B' and S[i+1] == 'W':
        S[i] = 'W'
        S[i+1] = 'B'
        cnt += Bseq
        Bseq = Bseq-1

ans = cnt
print(ans)

Submission status: Accepted

Solution code:
S = input()

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

print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
op = 0
w = 0
for c in s[::-1]:
  if c is "W":
    w += 1
  else:
    op += w
    n -= 1
print(op)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
s = input()
# s = s.replace('B', '1')
# s = s.replace('W', '0')
# s = list(s)
index = 0
sum = 0
for e,c in enumerate(s):
    if c == 'W':
        sum += e - index
        index += 1
        

        
# # print(s)
# cnt = 0
# def bsort(a):
#     global cnt
#     for i in range(len(a)-1):
#         for j in range(i, len(a)):
#             if int(a[j-1]) > int(a[j]):
#                 cnt += 1
#                 a[j-1] = '0'
#                 a[j] = '1'

# bsort(s)
print(sum)

Submission status: Accepted

Solution code:
S = input()

ans = 0
c = 0

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

Submission status: Accepted

Solution code:
def main():
    ss = input()
    b = 0;
    ans = 0;
    for s in ss:
        if (s == 'B'):
            b += 1
        else:
            ans += b

    print(ans)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0
temp = 0

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

print(int(ans))

Submission status: Accepted

Solution code:
S = str(input())

count = 0

now = 0

for s in S:
    if s == 'B':
        now += 1
    else:
        count += now

print(count)

Submission status: Accepted

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

wc, bc = 0, 0
wd, bd = 0, 0
for i, s in enumerate(S):
  if s == 'W':
    wc += 1
    wd += i - wc + 1
  else:
    bc += 1
    bd += len(S) - 1 - i - bc + 1
print((wd + bd) // 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np


m = list(input())
#print(m)
answer = 0
num_b = 0
for i in range(len(m)):
    if m[i] == 'W':
        answer += num_b
    else:
        num_b += 1

print(answer)

Submission status: Accepted

Solution code:
a = input()
b = [0 if i == "W" else 1 for i in list(a)]

b_sum = sum(b)
b_aggr = 0
b_len= len(b)
for i in range(b_len):
    if b[i] == 1:
        b_aggr += (b_len - i - 1)
b_cali = b_sum * (b_sum - 1) / 2
print(int(b_aggr-b_cali))

Submission status: Accepted

Solution code:
s = list(input())

ans = 0
buffer = 1
for i in range(len(s) - 1):
    if s[i] == 'W':
        buffer = 1
        continue
    elif s[i + 1] == 'W':
        s[i] = 'W'
        s[i + 1] = 'B'
        ans += buffer
        # buffer = 1
    else:
        buffer += 1

print(ans)

Submission status: Accepted

Solution code:
S = str(input())
bw_list = [s for s in S]

sum = 0
count = 0
for j in range(len(S)):
    if bw_list[j] == 'B':
        continue
    elif bw_list[j] == 'W':
            count += 1
            sum += (j+1) - count
print(sum)

Submission status: Accepted

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

Submission status: Accepted

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