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:
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

s = S()

# n個のオセロストーンが1列にある。長さnの文字列sで石の状態はあらわされていて、
# i番目の石が白：w、黒:bであらわされている。
# 以下の操作を行う

# iがb,i+1がwなiを一つ選び、二つとも裏返す。

# 最大でこの作業を何回行うことができるか。

# 例
# bwbwbwbwbw ⇒ wbwbwbwbwb
# bwwbbbwwwbwb　⇒　wbwbbbwwwbwb　⇒ wwbbbwwwbwb　⇒ wwbbwbwwbwb　⇒ wwbwbbwwbwb　⇒
# wwwbbbwwbwb　⇒ wwwbbwbwbwb　⇒ wwwbwbbwbwb　⇒ wwwwbbbwbwb　⇒ wwwwbbbwbwb　⇒ 

# 最終的にwwwwwwbbbbbになるので、結論としてはwを左に動かした回数をカウントすればよい。
# このカウントは、左から見て行ってwが出た位置より左のbの数を足し上げればよい。
black = 0
ans = 0
for stone in s:
    if stone == "b":
        black = black + 1
    else:
        ans = ans + black
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

ind = []
for i in range(len(s)):
    if s[i] == "B":
        ind.append(i)

target = list(range(len(s)))[len(ind):]

ans = 0
for t, i in zip(target, ind):
    ans += t-i

print(ans)

Submission status: Wrong Answer

Solution code:
S = 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:
import sys
input = sys.stdin.readline

S=list(input())
S.reverse()

sum = 0
n = 0
for i in range(len(S)):
    if S[i] == 'B':
        sum += (i-n)
        n += 1

print(sum)

Submission status: Wrong Answer

Solution code:
S=input()

start=0
for i in range(len(S)):
    if S[i]=='B':
        break

    start=i

left_W=start
ans=0
if start<len(S)-1:
    for i in range(start+1,len(S)):
        if S[i]=='W':
            ans+=i-left_W
            left_W+=1

print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())

a = S[:int(len(S)/2)]
b = S[int(len(S)/2):len(S)]
cnt = 0
for i in range(len(a)):
    if a[i] == "B":
        cnt += i+1
for j in range(len(b)):
    if b[j] == "B":
        cnt += j+1
        
print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()

if S.find("B")==-1:
    print(0)

if S.find("W")==-1:
    print(0)

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

B_count = S.count("B")
destination_B_index_sum = (len(S)*B_count) - sum(range(B_count))

print(max(0, destination_B_index_sum - B_index_sum))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S=list(input())
a=[0]*len(S)
cnt=0
j=len(S)-1
for i in range(len(S)-1,-1,-1):
  if S[i]=='W':
    a[i]=a[j]+1
    j=i
  else:
    a[i]=0
print(sum(a))

Submission status: Wrong Answer

Solution code:
import math

S = list(input())

b = 0
t = 0

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

if len(S) == 1:
    print(0)

else:
    print(math.factorial(b))

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """BBW"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """BWBWBW"""
        output = """6"""
        self.assertIO(input, output)


def resolve():
    s = str(input())
    ans = 0
    while True:
        origin = s
        s = s.replace('BW', 'WB', 1)
        if origin == s:
            break
        ans += 1
    print(ans)

    return


if __name__ == "__main__":
    unittest.main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
first = s.find('B')

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy
from numpy.core.defchararray import count
S = numpy.array([0 if s == 'B' else 1 for s in input()])

count = 0
bcount = 0
for s, i in enumerate(S):
    if s == 0:
        bcount += 1
    else:
        count += bcount

print(count)

Submission status: Wrong Answer

Solution code:
s = list(input())

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

Submission status: Wrong Answer

Solution code:
s=list(input())
ans=0
ch=0
for x in range(len(s)):
  if s[x]=='W':
    ans+=(x-ch)
    
print(ans)

Submission status: Wrong Answer

Solution code:
#2
s = list(input())
l = len(s)
cnt = 0

for i in range(l*l):
    for j in range(l-1):
        if s[j] =="B" and s[j+1] == "W":
            cnt += 1
            s[j],s[j+1] = s[j+1],s[j]
            break
        else:
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
#2
s = list(input())
l = len(s)
cnt = 0

for i in range(l):
    for j in range(l-1):
        if s[j] =="B" and s[j+1] == "W":
            cnt += 1
            s[j],s[j+1] = s[j+1],s[j]
            break
        
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0

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

Submission status: Wrong Answer

Solution code:
S = input()

b_count = 0
w_count = 0
result = 0
for i in S:
    if i == 'B':
        b_count += 1
        w_count = 0
    else:
        if b_count != 0:
            w_count += 1
            result += b_count * w_count        

print(result)

Submission status: Wrong Answer

Solution code:
S = input()

b_count = 0
w_count = 0
result = 0
for i in S:
    if i == 'B':
        b_count += 1
        w_count = 0
    else:
        w_count += 1
        result += b_count * w_count        

print(result)

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

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


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

    S = iss()

    ret, cnt = 0, 0
    for s in reversed(S):
        if s == 'W':
            cnt += 1
        if s == 'B' and cnt != 0:
            ret += cnt
            if cnt > 1:
                cnt = 2
            else:
                cnt = 1
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
S = list(S)
total = 0
count = 0
K = True
while K:
  for i in range(1,len(S)):
    if S[i-1]=="B" and S[i]=="W":
      S[i-1]="W"
      S[i]="B"
      total += 1
    else:
      count += 1
      if count==len(S):
        K = False
      
print(total)

Submission status: Wrong Answer

Solution code:
S = input()

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

Submission status: Wrong Answer

Solution code:
S = list(input())

print(S)

count = 0
i = 0
while i < len(S)-1:
    if S[i]=='B' and S[i+1]=='W':
        S[i]='W'
        S[i+1]='B'
        count += 1
        if i > 0:
            i -= 1
        else:
            i += 1
    else:
            i += 1
print(count)

Submission status: Wrong Answer

Solution code:
print(0)

Submission status: Wrong Answer

Solution code:
S = input()

#%%
idx_w = 0
idxes_b = []

for i, s in enumerate(S):
    if s == 'B':
        idxes_b.append(i)
    elif s == 'W':
        idx_w = i

#%%
ans = 0
for i, b in enumerate(idxes_b[::-1]):
    ans += idx_w - b - i

print(max(0, ans))

Submission status: Wrong Answer

Solution code:
S = input()

#%%
idx_w = 0
idxes_b = []

for i, s in enumerate(S):
    if s == 'B':
        idxes_b.append(i)
    elif s == 'W':
        idx_w = i

#%%
ans = 0
for i, b in enumerate(idxes_b[::-1]):
    ans += idx_w - b - i

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

s = list(input())
if 'W' not in s or 'B' not in s:
    print(0)
    exit()
c = Counter(s)
ans = min(c['W'], c['B'])*2
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
import numpy as np
B = []
W = []
for i in range(len(s)):
    if s[i] == "B":
        B.append(i)
    elif s[i] == "W":
        W.append(i)

print(max(sum(abs(np.array(B) - np.array([i for i in range(len(B))]))), sum(abs(np.array(W) - np.array([i for i in range(len(W))])))))

Submission status: Wrong Answer

Solution code:
s = input()
B = []
W = []
for i in range(len(s)):
    if s[i] == "B":
        B.append(i)
    elif s[i] == "W":
        W.append(i)
        
import numpy as np
print(max(sum(np.array(B) - np.array([i for i in range(len(B))])), sum(np.array(W) - np.array([i for i in range(len(W))]))))

Submission status: Wrong Answer

Solution code:
r = input().split()

s = 0

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

print(s)

Submission status: Wrong Answer

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

ans = 0

count = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
tmp = 0
#saving the number of black
#counting the numbers

for c in s:
	if s == "B":
		tmp += 1
	else:
		ans += tmp

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
tmp = 0
#saving the number of black
#counting the numbers

for c in s:
	if s == "B":
		tmp += ans
	else:
		ans += tmp

print(ans)

Submission status: Wrong Answer

Solution code:
N=input()
count=0
if N.count('BW')==0:
    print(0)
    exit

temp_count=1

while temp_count!=0:
    count+=N.count('BW')
    newN=N.replace('BW','WB')
    temp_count=newN.count('BW')
    N=newN

print(count)

Submission status: Wrong Answer

Solution code:
S = input()

# 1. S を BB..BWW...W の塊 M に分割
# 2. 各塊 M に対して、右から n>=1 番目の B を塊の右端から n 番目に移動させるためには len(W_in_M) 回の移動が必要

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
#sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
s=list(input())
k=0
i=0
while(i+1<len(s)):
    if(s[i]=="B" and s[i+1]=="W"):
        s[i],s[i+1]=s[i+1],s[i]
        k+=1
    i+=1
print(k)

Submission status: Wrong Answer

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
#sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
s=input()
k=0
while("BW" in s):
    s=s.replace("BW","WB")
    k+=1
print(k)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def integration(s):
  itg = [0]
  counter = 0
  for x in s:
    if x == "B":
      counter += 1
    itg.append(counter)
  return itg

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

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

Submission status: Wrong Answer

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

total=0
while S.find("B")<S.rfind("W"):
    b=S.find("B")
    w=S.find("W",b)
    total+=w-b
    s[b]="W"
    s[w]="B"
    S="".join(s)
print(total)

Submission status: Wrong Answer

Solution code:
S = list(input())

count = 0
state = S[0]
for i in range(0,len(S)-1):
    if S[i] == "B" and S[i+1] == "W":
        count += 2
    
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = str(input())
ans = 1
for i in range(1,S.count('BW')+1):
  ans *= i

ans += (S.count('B') - S.count('BW'))

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

b = s.count("B")
w = s.count("W")

print(len(s) - (max(b, w) - min(b, w)))

Submission status: Wrong Answer

Solution code:
s = input()

b = s.count("B")
w = s.count("W")

print(len(s) - (b - w))

Submission status: Wrong Answer

Solution code:
S=list(input())
print(S)
i=0
count=0
while True:
    if S[i]=='B' and S[i+1]=='W':
        S[i]='W'
        S[i+1]='B'
        i-=2
        count+=1
        if i<0:
            i=0
        continue
    if i > len(S)-3:
        print(count)
        break
    i+=1

Submission status: Wrong Answer

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

cnt =  0
cnt_W = 0
for i in range(n):
	if s[i] == 'W':
		cnt += i
		cnt_W += 1

print(cnt - cnt_W)

Submission status: Wrong Answer

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

cnt = 0
ans = 0

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

Submission status: Wrong Answer

Solution code:
S = input()
if len(S) == 2:
    if S == "BW":
        print(1)
    else:
        print(0)
else:
    nbw = S.count("BW")
    print(nbw * 2)

Submission status: Wrong Answer

Solution code:
s = str(input())
n = len(s)
count = 0
max_W = 0

for i in range(n):
    if s[i] == 'W':
        count += i
        max_W = i

if max_W == s.count('W') - 1 or s.count('W') == 0 or s.count('W') == n:
    print(0)
    exit()

print(count)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
def encoding_run_length(l):
    return [(v, len(list(g))) for v, g in groupby(l)]

print(len(encoding_run_length(input())))

Submission status: Wrong Answer

Solution code:
S = str(input())
counter = 0
isOne = False
for i, v in enumerate(S):
    if isOne:
        if v == 'W':
            counter += 1
        else:
            pass
    else:
        if v == 'B':
            isOne = True

print(2 * counter)

Submission status: Wrong Answer

Solution code:
S = list(input())
black_ind = [i for i, s in enumerate(S) if s == 'B']
current_ind_sum = sum(black_ind)
import numpy as np
final_list = np.arange(len(S))[-len(black_ind):]
print(sum(final_list)-current_ind_sum)

Submission status: Wrong Answer

Solution code:
count=0
osero=input()
s=[]
for i in osero:
  s.append(i)
for i in range(len(s)-1):
  for j in range(i,len(s)-1):
    if s[j]=='B' and s[j+1]=='W':
      s[j]='W'
      s[j+1]='B'
      count+=1
print(count)

Submission status: Wrong Answer

Solution code:
# AtCoder
S = input()
print(S.count('BW')*2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s =list(str(input()))
s_replace = [1 if i == "B" else 0 for i in s]

count = 0
ans = 0

for i in range(len(s_replace)):
  if s_replace[i] == 1:
    count += 1
    continue
  else:
    ans = ans + count
    count = 0
    
print(ans)

Submission status: Wrong Answer

Solution code:
S=list(input())
N=len(S)
n=S.count("W")
s=0
i=0
while "B" in S[:n]:
  if S[i]=="B" and S[i+1]=="W":
    S[i]="W" 
    S[i+1]="B"
    s+=1
    i=i
  else:
    i+=1
    if i>=N-1:
      break
print(s)

Submission status: Wrong Answer

Solution code:
import collections
S=list(input())
N=len(S)
n=S.count("W")
s=0
i=0
while "B" in S[:n] and i<=N-1:
  if S[i]=="B" and S[i+1]=="W":
    S[i]="W" 
    S[i+1]="B"
    s+=1
    i=i
  else:
    i+=1
    if i>=N-1:
      break
print(s)

Submission status: Wrong Answer

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

def main():
    s = input()
    total = 0

    for i in range(len(s)-1):
        if s[i] == "B":
            total += 1
            if s[i] == "B" and s[i+1] == "W":
                yield total

print(sum(main()))

Submission status: Wrong Answer

Solution code:
s = list(input().rstrip())
r=0
bm=0
while r<len(s)-1:
    if s[r]=="B" and s[r+1]=="W":
        break
    bm+=1
    r+=1
ans=0
for i in range(r, len(s)):
    if s[i]=="W":
        ans+=bm
    if s[i]=="B":
        bm+=1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s=input()

cnt=0
cum=0

for i in range(len(s)):
    if s[i]=='W':
        cnt+=1
        cum+=i
print(cum-int((cnt+1)*cnt/2))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc029/tasks/agc029_a
s = input()

ans = 0
for i in range(len(s) - 1):
    if s[i] == 'B' and s[i + 1] == 'W':
        ans += 1
ans *= 2
print(ans)

Submission status: Wrong Answer

Solution code:
import copy

S = list(input())
# new_S = copy.deepcopy(S)
length = len(S)
is_proc = [0] * (length - 1)

for i in range(length - 1):
    if S[i] != S[i+1]:
        if S[i] == "B":
            S[i] = "W"
        else:
            S[i] = "B"
        is_proc[i] = 1

# print("is_proc: {}".format(is_proc))

for i in range(length-1):
    if not is_proc[i]:
        if S[i] != S[i+1]:
            is_proc[i] = 1

# print("is_proc: {}".format(is_proc))
print(sum(is_proc))

Submission status: Wrong Answer

Solution code:
s = input()

t = 1
for i in range(1, len(s)):
    if s[i] != s[i - 1]:
        t += 1
print(t)

Submission status: Wrong Answer

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

ans = 0
cnt = 0
i = 0
ok = False
for _ in range(a):
    if i >= a-1: break
    if i < a and S[i:i+2] == list("BW"):
        i += 2
        if ok: 
            cnt += 1
            continue
        ok = True
        cnt += 1
    else:
        if S[i] == "B":
            if i + 2 < a and S[i+1:i+3] == list("BW"):
                ans += 1
        elif ok and S[i] == "W": ans += 1
        i += 1
        if cnt > 0: 
            ans += cnt * (cnt+1) // 2
            cnt = 0
            ok = False
if cnt > 0: 
            ans += cnt * (cnt+1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
print(S.count("BW") * 2)

Submission status: Wrong Answer

Solution code:
S=input()
wh=S.rfind('B')
l=len(S)
count=0
B=S.count('B')
for i in range(0,B):
    wh=S.rfind('B')
    count=count+len(S)-(wh)
    S=S.rstrip('W')
    S=S[:wh-1]+'W'+S[wh+1:]

print(count)

Submission status: Wrong Answer

Solution code:
S=input()
wh=S.rfind('B')
l=len(S)
count=0
B=S.count('B')
for i in range(0,B):
    wh=S.rfind('B')
    count=count+len(S)-(wh+1)
    S=S.rstrip('W')
    S=S[:wh-1]+'W'+S[wh+1:]

print(count)

Submission status: Wrong Answer

Solution code:
S = input()

count_white = 0
ans = [0] * len(S)

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

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

Submission status: Wrong Answer

Solution code:
S = input()

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

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
l = list(S)
count = 0
end = False
while end != True:
    for i in range(len(l)-1):
        temp_count = 0
        if l[i] == "B" and l[i+1] == "W":
            l[i] = "W"
            l[i+1] = "B"
            count += 1
            temp_count += 1
    if temp_count == 0:
        end = True
print(count)

Submission status: Wrong Answer

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
from collections import Counter
#template
#issueから始める
S = list(input())
n = len(S)
count = 0
d = 0
for i in range(n):
    if S[i] == 'B':
        count += abs(n//2 + d - i)
        d+=1
print(count)

Submission status: Wrong Answer

Solution code:
S = input()

count = [0] * len(S)
count[0] = 1 if S[0] == 'B' else 1

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#AGC29_A
s=input()
count=0
memo=0
if s[-2:]=="BW":
    count+=1
    t=True
    for i in range(2,len(s)):
        block=s[-(i+1)]
        if block=='W':
            t=False
            if not bool(memo):
                memo+=1
            else:
                memo+=1
        elif block=='B':
            if s and not bool(memo):
                count+=1
            else:
                count+=(1+max(t,memo))
                memo=(1 if memo==1 else 0)
                t=True

else:
    t=True
    for i in range(len(s)):
        block=s[-(i+1)]
        if block=='W':
            t=False
            if not bool(memo):
                memo+=1
            else:
                memo+=1
        elif block=='B':
            if not count==0:
                if s and not bool(memo):
                    count+=1
                else:
                    count+=(1+max(t,memo))
                    memo=(1 if memo==1 else 0)
                    t=True

print(count)

Submission status: Wrong Answer

Solution code:
#AGC29_A
s=input()
count=0
memo=0
if s[-2:]=="BW":
    count+=1
    for i in range(2,len(s)):
        block=s[-(i+1)]
        if block=='W':
            if not bool(memo):
                memo+=1
            else:
                memo+=1
        elif bool(memo) and block=='B':
            count+=(1+memo)
            memo=(1 if memo==1 else 0)

else:
    for i in range(2,len(s)):
        block=s[-(i+1)]
        if block=='W':
            if not bool(memo):
                memo+=1
            else:
                memo+=1
        elif bool(memo) and block=='B':
            count+=(1+memo)
            memo=(1 if memo==1 else 0)

print(count)

Submission status: Wrong Answer

Solution code:
#AGC29_A
s=input()
count=0
memo=0
if s[-2:]=="BW":
    count+=1
    for i in range(2,len(s)):
        block=s[-(i+1)]
        if block=='W':
            if not bool(memo):
                memo+=1
            else:
                memo+=1
        elif block=='B':
            count+=(1+memo)
            memo=(1 if memo==1 else 0)

else:
    for i in range(2,len(s)):
        block=s[-(i+1)]
        if block=='W':
            if not bool(memo):
                memo+=1
            else:
                memo+=1
        elif block=='B':
            count+=(1+memo)
            memo=(1 if memo==1 else 0)

print(count)

Submission status: Wrong Answer

Solution code:
def main():
    s = input().rstrip()
    cnt = 0
    ans = 0
    for i in range(len(s)):
        if s[i] == "B":
            cnt += 1
        else:
            ans += cnt
            if i < len(s)-1 and s[i+1] == "W" and cnt > 0:
                cnt = 1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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[0]!='W'and s[i]=='W':
        cnt+=temp

print(cnt)

Submission status: Wrong Answer

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-1]=='B' and s[i]=='W':
        cnt+=temp

print(cnt)

Submission status: Wrong Answer

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

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

count = 0
for i in reversed(range(1, n)):
    if  A[i-1] == 'B' and A[i] == 'W':
        count += 1

print(count * 2)

Submission status: Wrong Answer

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

count = 0
for i in reversed(range(1, n)):
    if  A[i-1] == 'B' and A[i] == 'W':
        A[i-1] = 'W'
        A[i] = 'B'
        count += 1

print(count * 2)

Submission status: Wrong Answer

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

count = 0
for _ in range(n):
    for i in reversed(range(1, n)):
        if  A[i-1] == 'B' and A[i] == 'W':
            A[i] = 'B'
            A[i-1] = 'W'
            count += 1

print(A)
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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