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: Wrong Answer

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

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

print(counter)

Submission status: Wrong Answer

Solution code:
S = list(input())
size = len(S)
ans = size
i = 0
while i < size -1:
    if S[i] == 'B' and S[i+1] == 'B':
        ans -= 1
    if S[i] == 'W' and S[i+1] == 'W':
        ans -= 1
    i+=1
if S[size-1] == 'B':
    ans -= 1    
print(ans)

Submission status: Wrong Answer

Solution code:
S = input().split('W')
S = [i for i in S if i]
cnt = 0
for i in range(len(S)):
    cnt += cnt + len(S[i])

print(cnt)

Submission status: Wrong Answer

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
        ans += B_count
    elif S[i] == 'B':
        B_count += 1

print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
size = len(S)
ans = size
i = 0
while i < size -1:
    if S[i] == 'B' and S[i+1] == 'B':
        ans -= 1
    i+=1
if S[size-1] == 'B':
    ans -= 1    
print(ans)

Submission status: Wrong Answer

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

ans = 0

if 'BW' not in s:
    print(0)
    exit(0)

'''

while 'BW' in s:
    s = s.replace('BW', 'WB', 1)
    ans += 1

print(ans)
'''

indexes = [i for i, x in enumerate(ss) if x == 'W']


if len(indexes) == 1:
    print(indexes[0])
    exit(0)

ans = indexes[0] + 1

import numpy as np
d = np.array(indexes)

d = np.diff(d)

ans += sum(d)

print(ans)

Submission status: Wrong Answer

Solution code:
S = input().strip()
Sb = [c == "B" for c in S]
 
def reverse(Sb,i):
    _list = Sb.copy()
    _list[i] = not _list[i]
    return _list

def operate(Sb):
    _list = Sb.copy()
    cnt = 0
    flg = True
    t_start = 0
    t_end = len(Sb)
    while flg:
        flg = False
        try:
            t_start = _list[t_start:].index(True) + t_start
        except:
            break
        try:
            t_end = t_end -  list(reversed(_list[:t_end])).index(False)
        except:
            break
        
        for i in range(t_start,t_end-1):
            if _list[i] and not _list[i+1]:
                cnt += 1
                _list = reverse(_list,i)
                _list = reverse(_list,i+1)
                flg = True
    return cnt, _list, t_start, t_end
 
print(operate(Sb))

Submission status: Wrong Answer

Solution code:
import re
import numpy as np
s = input()
ind = [m.start() for m in re.finditer('B', s)]
print(sum(np.cumsum([t - s - 1 for s, t in zip(ind, ind[1:])])) + len(ind)*(len(s)-ind[-1]-1) if len(ind) else 0)

Submission status: Wrong Answer

Solution code:
S = list(input())
cnt = 0
i = 0

cnt = 0
ans = 0

cnt_bw = 0
cnt_b = 0
for i in range(len(S) - 1):
    if S[i] == "B" and S[i + 1] == "B":
        cnt_b += 1
    elif S[i] == "B" and S[i + 1] == "W":
        ans += cnt_b
        cnt_b = 0


for i in range(len(S) - 1):
    if S[i] == "B" and S[i + 1] == "W":
        cnt_bw += 1
    elif S[i] == "B" and S[i + 1] == "B":
        ans += (1 + cnt_bw) * cnt_bw // 2
        cnt_bw = 0

ans += (1 + cnt_bw) * cnt_bw // 2

print(ans)

Submission status: Wrong Answer

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
for i in range(len(S)):
    if S[i]=="B":
        flag=1
    elif S[i]=="W":
        if flag == 1:
            count += 1
            place += i
        else:
            count-=1
ans=place-sigma(count-1)
print(ans)

Submission status: Wrong Answer

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

cnt = 0
ans = 0
for i in range(n - 1):
  if s[i] == "B" and s[i + 1] == "W":
    ans += 1
    ans += cnt
    cnt = 0 if cnt == 0 else 1
    s[i] = "W"
    s[i + 1] = "B"
  elif s[i] == "B":
    cnt += 1
print(ans)

Submission status: Wrong Answer

Solution code:
src = input()
print(src)
count = 0

while src.find('BW') > -1 :
    src = src.replace('BW', 'WB', 1)
    count = count + 1

print( count )

Submission status: Wrong Answer

Solution code:
S=input()
Bhist = []
 
l = 0
cnt = 0
# 最終的にはwwww...wb...bbbという文字列に入れ替わる
# 左からi番目の"bw" の "w"が連続wにたどるくまでの回数を計算するには？
# xxxxxbw.....
# このときxは wのみ、bのみ、もしくはwww...b...となっている
while True:
    i = S.find("BW")
    if i < 0:
        break
    l += S[:i+1].count('B')
    #cnt = cnt + cnt + l
    #Bhist.append(S[:i+1].count('B'))
    #cnt += sum(Bhist)
    cnt += l
    S = S[i+2:]
#    print(S)
print(cnt)

Submission status: Wrong Answer

Solution code:
import math

S = input()

if S[-1] == "B":
    S = list(S.split('W'))[-1]
else:
    S = S.split("W")

cnt = 0
for i in range(len(S)):
    cnt += len(S[i])

cnt = math.factorial(cnt)

print(cnt)

Submission status: Wrong Answer

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

if "B" not in s or "W" not in s:
  print(0)

cnt = 0
ans = 0
for i in range(n - 1):
  if s[i] == "B" and s[i + 1] == "W":
    ans += 1
    ans += cnt
    cnt = 0 if cnt == 0 else 1
    s[i] = "W"
    s[i + 1] = "B"
  elif s[i] == "B":
    cnt += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

    A=[0,0,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: Wrong Answer

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: Wrong Answer

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
	else:
		if a[i] == 'B':
			dd += 1
print(su)

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

    A=[0,0,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: Wrong Answer

Solution code:
S = input()
n = 0
import re
re.sub('BB+',"BB",S)
re.sub("WW+",'WW',S)


while 'BW' in S:
    n += 6*S.count('BWBWBW')
    S = S.replace('BWBWBW','WB')
    n += S.count('BW')
    S = S.replace('BW','WB')
print(n)

Submission status: Wrong Answer

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
			dd += 1

if ''.join(a) == "BWB":
	print(1)
else:            
	print(su)

Submission status: Wrong Answer

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

counter = 0

def check(shit):
	global counter
	if len(shit) <= 1:
		return
	if shit[0][0] == 'B' and shit[1][0] == 'W':
		counter += shit[0][1] * shit[1][1]
		if len(shit) >= 3:
			shit[2][1] += shit[0][1]
			check(shit[2:])
	
check(nes)
print(counter)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
s = list(input())

count = 0

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

print(len(s)-count)

Submission status: Wrong Answer

Solution code:
S = list(input())
count = 0
src = list('BW')
dst = list('WB')
for i in range(len(S)-1):
    if S[i:i+2] == src:
        S[i:i+2] = dst
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
a = list(input())

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

Submission status: Wrong Answer

Solution code:
s = input()
s_list = [o for o in s]
count = 0
for i in range(len(s_list)-1):
    if s_list[i] == 'B' and s_list[i+1] == 'W':
        count +=1
print(int(count*2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
arange = input()

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

while bottom != -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: Wrong Answer

Solution code:
temp=input()
S=list(temp)
counter1=0
counter2=0
counter3=0 
i=0

while True:
    if S[i]=='B' and S[i+1]=='W':
        S[i]='W'
        S[i+1]='B'
        counter1 +=1
    i +=1
    if i ==len(S)-1:
        if counter1==counter2:
            break
        counter2=counter1
        counter3+=1
        i=counter3

print(counter1)

Submission status: Wrong Answer

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 = np.sum(np.abs(diff-index_black))
print(count)

Submission status: Wrong Answer

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: Wrong Answer

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
print(sum-counter)

Submission status: Wrong Answer

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

a=[]
for i in range(n):
    if s[i]=="B":
        a.append(0)
    else:
        a.append(1)

count=0
pre=-1
for i in range(n):
    if i+1<n and a[i]==0 and a[i+1]==1:
        a[i]=1
        a[i+1]=0
        count+=1
    
print(count*2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
b = input()
a = [i for i in b]
counter = 0
def check(shit):
	if shit == []:
		return
	global counter
	i = 0
	countb = 0
	countw = 0
	while i < len(shit) and shit[i] == 'B':
		i += 1
		countb += 1
	while i < len(shit) and shit[i] == 'W':
		i += 1
		countw += 1
	if countb == 0 or countw == 0:
		return
	counter += countb * countw
	check(['B'] * countb + shit[countb + countw:])
	
check(a)
print(counter)

Submission status: Wrong Answer

Solution code:
arange = input()

times = 0
bottom = arange.find("B")
white_pos = arange.find("W")

while bottom != -1 and bottom < white_pos:
  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: Wrong Answer

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

cnt = 0
# 最終的にはwwww...wb...bbbという文字列に入れ替わる
# 左からi番目の"bw" の "w"が連続wにたどるくまでの回数を計算するには？
# xxxxxbw.....
# このときxは wのみ、bのみ、もしくはwww...b...となっている
while True:
    i = S.find("BW")
    if i < 0:
        break
    Bhist.append(S[:i+1].count('B'))
    cnt += sum(Bhist)
    S = S[i+2:]
#    print(S)
print(cnt)

Submission status: Wrong Answer

Solution code:
a = list(input())

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
S = input()
bcount=S.count('B')
wcount=S.count('W')
if S[-1]=="B":
    ans=bcount*wcount-1
    if ans<0:
        ans=0
else:
    ans=bcount*wcount
    if ans<0:
        ans=0
print(ans)

Submission status: Wrong Answer

Solution code:
str = input()

l = list(str)

N = len(l)

#print(l[4])

cnt = 0

for j in range(1,N):

    for i in range(j,N):

      if l[i-1] == "B" and l[i] == "W":
          l[i-1] = "W"
          l[i] = "B"
          cnt = cnt + 1

      #print(l)

print(cnt)

Submission status: Wrong Answer

Solution code:
arange = input()

times = 0
bottom = arange.find("B")
white_pos = arange.find("W")

while True:
  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: Wrong Answer

Solution code:
n = input()
a = [i for i in n]
ans = 0
n = len(n)
W = 0
B = 0
for i in range(n):
    if a[i] == "W":
        W +=1
    else:
        break
for i in range(n-1,-1,-1):
    if a[i] == "B":
        B+=1
    else:
        break
B1 = a.count("B")-B
W1 = a.count("W")-W
print(n-B-W-abs(B1-W1))

Submission status: Wrong Answer

Solution code:
n = input()
a = [i for i in n]
ans = 0
n = len(n)
W = 0
B = 0
for i in range(n):
    if a[i] == "W":
        W +=1
    else:
        break
for i in range(n-1,-1,-1):
    if a[i] == "B":
        B+=1
    else:
        break
B1 = a.count("B")
W1 = a.count("W")
print(n-B-W-abs(B1-W1))

Submission status: Wrong Answer

Solution code:
s = list(input())
s1 = s.copy()
count = 0

while True:
    nochange=0
    n = len(s)-1
    for i in range(n):
        if s1[i] == "B" and s1[i+1] == "W":
            s1[i]="W"
            s1[i+1]="B"
            count+=1
        else:
            nochange+=1
    if nochange == n:
        break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a = list(input())

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


print(su)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print(0)
#if wNum==0:
#  print(0)
#else:
#  saigo = kasan(wNum-1)
#  print(ima-saigo)

Submission status: Wrong Answer

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

idx = []
i = 0
for s in S:
    if s == "W":
        idx.append(i)
    i+=1
print(int(np.sum(idx) - (len(idx))))

Submission status: Wrong Answer

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
			dd += 1

print(su)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

from sys import stdin

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

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

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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


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

    total = 0
    for _ in range(num//2+1):
        print(_)
        count = s.count("BW")
        if count == 0:
            break
        else:
            total += count
            s_list = list(s)

            for i in range(num):
                if s_list[i:i+2] == ["B", "W"]:
                    s_list[i:i+2] = ["W", "B"]
            print(s_list)

            s = "".join(s_list)

    print(total)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
s = list(input())
a = [1 if i == "B" else 0 for i in s]
print(a)
ans = 0
while True:
    j = 0
    for i in range(len(a) - 1):
        if a[i] == 1 and a[i+1] == 0:
            a[i] = 0
            a[i+1] = 1
            j = 1
            ans += 1
            break
    if j == 0:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
s = s[::-1]
res = 0
f = 1
p = 0
while(f):
    f = 0
    for i in range(p,len(s)-1):
        if s[i] == "W" and s[i+1] == "B":
            res += 1
            s[i] = "B"
            s[i+1] = "W"
            f = 1
        #print(i,i+1)
        p += 1
else:
    print(res)

Submission status: Wrong Answer

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

for i in range(len(list)-1):
  if(list[i] == "W"):
    count+=b
    continue
  else:
    if(i == len(list)-1):
      break
    b += 1
      
print(count)

Submission status: Wrong Answer

Solution code:
S = input()

p = 0
offset = 0
i = 0
while i < len(S) - 1:
    if S[i] == "W":
        offset += 1
    elif S[i] == "B" and S[i + 1] == "W":
        p += i - offset + 1
        i += 1
        offset += 1
    i += 1
    
print(p)

Submission status: Wrong Answer

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

count = 0
# i = 0
# while 1:
count_b = 0
for i in range(len(data)):
    # print(i)
    if data[i] == 'W':
        count += count_b
        # count += 1
        # data[i], data[i+1] = 'B', 'W'
        # break
    else:
        count_b += 1
    # else:
    #     break
print(count)

Submission status: Wrong Answer

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


m = list(input())
print(m)
answer = 0

for i in range(len(m)):
    if m[i] == 'W':
        for j in range(i):
            if m[j] == 'B':
                answer += 1

print(answer)

Submission status: Wrong Answer

Solution code:
s = [x for x in input()]
check = 0
iti = 0
while True:
    c = 0
    che = 0
    for i in range(iti,len(s)):
        if s[i] == 'B':
            c = 1
        if s[i] == 'W' and c == 1:
            s[i] = 'B'
            s[i-1] = 'W'
            che = 1
            check += 1
            iti = i-1
            break
    if che == 0:
        break
print(check)

Submission status: Wrong Answer

Solution code:
a=input()
len_a=len(a)
#maxpoint=len_a * (len_a+1) / 2
point=0
howmany_w=0
for a_n in range(len(a)):
	if a[a_n]=='W':
		point+=(len_a-a_n)
		howmany_w+=1

maxpoint = (len_a - howmany_w/2 + 1/2) * (howmany_w)

kaisu=maxpoint-point
print(kaisu)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
S = input()
print(S.count('w')*2)

Submission status: Wrong Answer

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

ans = 0
state = 0
marker = 0
for i, Si in enumerate(S):
    # process
    if state < 1 and Si == 'B':
        state += 1
    elif state > 0 and Si == 'W':
        ans += i - marker
        marker += 1

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
black = 0
cnt = 0
for i in range(N-2, -1, -1):
    if S[i] == 'B':
        cnt += N - 1 - i - black
        black += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
S=input()[::-1]
n=len(S)
l=list(i for i in range(n) if S[-i]=='B')
k=len(l)*(len(l)-1)//2
print(sum(l)-k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = list(map(str,input().split("W")))
ans = 0
num = 0
ss = []
for i in s:
    if i != '':
        ss.append(i)
for i in ss:
    num += len(i)
    ans += num
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

w = sum(i for i,x in enumerate(S) if x == 'W')

N = len(S)//2

print(w - (N-1)*N//2)

Submission status: Wrong Answer

Solution code:
s = list(map(str,input().split("W")))
ans = 0
num = 0
if s[-1] == '':
    s.remove(s[-1])
for i in s:
    num += len(i)
    ans += num
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

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

Submission status: Wrong Answer

Solution code:
a = list(input())

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

print(su)

Submission status: Time Limit Exceeded

Solution code:

def resolve():
    S = input()
    sub = "BW"
    cnt = 0
    st = S.find("B")
    S = S[st:]
    while True:
        res = S.find(sub)
        if res == -1:
            break
        cnt += 1
        S = S[:res] + "WB" + S[res+2:]
    print(cnt)


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:

def resolve():
    S = input()
    sub = "BW"
    cnt = 0
    while True:
        res = S.find(sub)
        if res == -1:
            break
        cnt += 1
        S = S[:res] + "WB" + S[res+2:]
    print(cnt)


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

ans = 0
while True:
    tmp = 0
    for i in range(len(S)-1):
        if S[i] == "B" and S[i+1] == "W":
            S[i] = "W"
            S[i+1] = "B"
            tmp += 1
    if not tmp:
        break
    ans += tmp
        
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
M = []
for i in range(len(S)):
    M.append(S[i])
z = 0
ans = 0
while z == 0:
    for i in range(len(M)):
        if i == len(M) - 1:
            z = 1
            print(ans)
        elif M[i] == 'B' and M[i + 1] == 'W':
            ans += 1
            M[i] = 'W'
            M[i + 1] = 'B'
            break

Submission status: Time Limit Exceeded

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

loop_idx = 0
loop_len = -(-len(S)//2)
cnt = 0

if len(S) == 1:
    pass
else:
    while loop_idx < loop_len:
        """
        if S[0] == "W":
                S.pop(0)
        if S[-1] == "B":
                S.pop(-1)
        """
        for i in range(len(S)-1,loop_idx,-1):
            if S[i]=="W" and S[i-1] == "B":
                cnt += 1
                S[i],S[i-1] = "B","W"
        loop_idx += 1
        #print(S)
print(cnt)

Submission status: Time Limit Exceeded

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

loop_idx = 0
loop_len = -(-len(S)//2)
cnt = 0

if len(S) == 1:
    pass
else:
    while loop_idx < loop_len:
        if S[0] == "W":
            S.pop(0)
        if S[-1] == "B":
            S.pop(-1)
        for i in range(len(S)-1,0,-1):
            if S[i]=="W" and S[i-1] == "B":
                cnt += 1
                S[i],S[i-1] = "B","W"
        loop_idx += 1
print(cnt)

Submission status: Time Limit Exceeded

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

loop_idx = 0
cnt = 0

if len(S) == 1:
    pass
else:
    while loop_idx < -(-len(S)//2):
        for i in range(len(S)-1,0,-1):
            if S[i]=="W" and S[i-1] == "B":
                cnt += 1
                S[i],S[i-1] = "B","W"
        loop_idx += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

ans = 0

for i in range(len(s)):
    if s[i] == 'B':
        ans += s[i+1:].count('W')

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    count = 0

    for i in range(1, len(s)):
        if s[i] == 'W':
            part_s = s[0:i]
            count += part_s.count('B')

    print(count)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
a = input()
cnt = 0
while True:
    c = a.count("BW")
    a = a.replace("BW","WB")
    if c != 0:
        cnt += c
    else:
        print(cnt)
        sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
a = input()
S = [s for s in a]

cnt = 0
while True:
    b = a
    c = a.count("BW")
    a = a.replace("BW","WB")
    if c != 0:
        cnt += c
    else:
        print(cnt)
        sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
a = input()
S = [s for s in a]
# #print(l)

cnt = 0
while True:
    b = a
    a = a.replace("BW","WB",1)
    if b != a:
        cnt += 1
    else:
        print(cnt)
        sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
a = input()
S = [s for s in a]
#print(l)

#BWを探してWBに書き換える。
cnt = 0
while True:
    b = False
    for i in range(len(a)-1):    
        if S[i] == "B" and S[i+1] == "W":
            S[i] = "W"
            S[i+1] = "B"
            cnt += 1
            b = True
    if b == False:
        print(cnt)
        sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
a = input()
S = [s for s in a]
#print(l)

#BWを探してWBに書き換える。
cnt = 0
while True:
    b = False
    for i in range(len(a)-1):    
        if S[i] == "B" and S[i+1] == "W":
            S[i] = "W"
            S[i+1] = "B"
            cnt += 1
            b = True
            break
    if b == False:
        print(cnt)
        sys.exit(0)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

_sum = 0

for i in range(1, len(S)):
  if S[i] == "W":
    _sum += S.count("B", 0,i)
    
print(_sum)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

cnt = 0
for i in range(len(S)):
    if S[i] == "W":
        cnt += S[:i].count("B")
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())

num = s.count('W')

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

    if s[i] == 'B':
        position=i
        break

ans = 0

while num>0:

    for j in range(len(s)-1):

        if s[j]=='B' and s[j+1]=='W':

            s[position]='W'
            s[j+1]='B'

            position+=1
            dist = j+2-position
            ans+=dist
            num-=1

            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as C
s=list(input())
l=[]
ans=0
for i in range(len(s)):
  if s[i] == "W":
    l.append(i)
for i in l:
  #print(s[:i], C(s[:i])["B"])
  s[i]="_"
  ans+=C(s[:i])["B"]
print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
S = list(input())
S = deque(S)

ans = 0
N = len(S)
going = True
while going:
    tmp = S.copy()
    for i in range(N - 1):
        if S[i] == "B" and S[i + 1] == "W":
            S[i] = "W"
            S[i + 1] = "B"
            ans += 1

    for i in range(N - 1, 0, -1):
        if S[i] == "W" and S[i - 1] == "B":
            S[i] = "B"
            S[i - 1] = "W"
            ans += 1
    if S == tmp:
        going = False

print(ans)
# print(S)

Submission status: Time Limit Exceeded

Solution code:
s = input()
c = 0
while 'BW' in s:
    c += 1*s.count('BW')
    s = s.replace('BW', 'WB')
print(c)

Submission status: Time Limit Exceeded

Solution code:
inputS = input()
S = list(inputS)
count = 0
tmpI = 0
tmpJ = 0

for _ in range(inputS.count('W')):
  i = inputS.find('W',tmpI)
  tmpI = i + 1
  j = inputS.find('B',tmpJ)
  tmpJ = j + 1
  S = list(inputS)
  S[i] = 'B'
  inputS = ''.join(S)
  count += (i-j)    
print(count)