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

#solve
def solve():
    s = S()
    s = s[::-1]
    tmp = 0
    f = 0
    ans = 0
    for i in s:
        if i == "W":
            ans += tmp
            tmp = 0
            f = 1
        else:
            tmp += f
    print(ans+tmp)
    return


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

Submission status: Wrong Answer

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

#solve
def solve():
    s = S()
    s = s[::-1]
    tmp = 0
    f = 0
    ans = 0
    for i in s:
        if i == "w":
            ans += tmp
            tmp = 0
            f = 1
        else:
            tmp += f
    print(ans+tmp)
    return


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)


def main():
    s = input()
    cnt = 0
    for _ in range(2*10**2):
        tmp = s
        s = s.replace("BW", "WB", 1)
        if tmp == s:
            break
        cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = sorted(list(input()), reverse=True)
ans = []
tmp = 0
for i in s:
    if i == "W":
        tmp += 1
        ans.append(tmp)
print(sum(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
pie = input()

sum = 0
flag = len(pie)

for i in range(1,len(pie)):
    if (pie[i]=='B'):
        sum+=(flag-i)

print(sum)

Submission status: Wrong Answer

Solution code:
S = list(str(input()))
count= ans = idx = 0
for i in range(1,len(S)):
    if S[i-1]=="W":
        count += 1
    if S[i-1]=="B" and S[i]=="W":
        ans += i
        idx += i-1
        break
for j in range(i+1,len(S)):
    if S[j]=="W":
        ans += j-idx
        idx += 1
print(ans-count)

Submission status: Wrong Answer

Solution code:
S = list(str(input()))
count = idx = 0
for i in range(1,len(S)):
    if S[i-1]=="B" and S[i]=="W":
        count += i
        idx += 1
        break
for j in range(i+1,len(S)):
    if S[j]=="W":
        count += j-idx
        idx += 1
print(count)

Submission status: Wrong Answer

Solution code:
S = list(str(input()))
count = l = flag = 0
for i in range(1,len(S)):
    if flag==0:
        if S[i-1]=="B" and S[i]=="W":
            count += i-l
            l += 1
            flag = 1
    else:
        if S[i]=="W":
            count += i-l
            l += 1
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(S: str):
    counter = 0
    tmp = S[0]
    for s in S[1:]:
        if s == tmp[-1]:
            tmp = tmp + s
        elif s == 'W' and tmp[-1] == 'B':
            tmp = tmp + s
        else:
            counter += 2 * min(tmp.count('B'), tmp.count('W'))
            tmp = s
    counter += 2 * min(tmp.count('B'), tmp.count('W'))
    print(counter)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()

flag = False
cnt = 0
l = 0
for i in range(len(S)):
    if S[i] == 'B' and flag == False:
        flag = True
    if S[i] == 'W' and flag:
        cnt += i - l
        l += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()

b_l = 10**9
w_poslist = []
for i in range(len(S)):
    s = S[i]
    if s == "B" and i < b_l:
        b_l = i
    if s == "W":
        w_poslist.append(i)

ans = 0
for i in range(len(w_poslist)):
    ans += w_poslist[i] - b_l
    b_l += 1
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
print(sum([s[i+1]!=s[i] for i in range(len(s)-1)]))

Submission status: Wrong Answer

Solution code:
s = input()
s1 = ""
ans = 0
while True:
    s1 = s.replace('BW', 'WB',1)
    ans += 1
    s = s1
    if not "BW" in s:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
A = []

for i, s in enumerate(S):
  if s == "W":
    A.append(i)

if len(A) == 1:
  print(sum(A))
else:
  print(sum(A)-len(A))

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
A = []

for i, s in enumerate(S):
  if s == "W":
    A.append(i)

print(max(sum(A)-len(A), 0))

Submission status: Wrong Answer

Solution code:
wb = input()
li = [i for i in wb]
j = [i for i in range(len(li))]
count = 0
while 'BW' in wb:
    for i in j:
        if i != j[-1]:
            if li[i] == 'B' and li[i+1] == 'W': 
                li[i] = li[i+1]
                li[i+1] = li[i]
                count +=1
                wb = ''.join(li)
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
S=""
i=0
leng=len(s)
while(i<leng):
    if s[i]=="A":
        S+="A"
        i+=1
    elif i+1<leng and s[i]=="B" and s[i+1]=="C":
        S+="B"
        i+=2
    else:
        S+="C"
        i+=1
T=S[::-1]
l=[0]*len(T)
ans=0
t=len(T)
for i in range(len(T)-1):
    if T[i]=="B":
        l[i+1]=l[i]+1
    elif T[i]=="A":
        l[i+1]=l[i]
        ans+=l[i]
if T[-1]=="A":
    ans+=l[-1]
print(ans)

Submission status: Wrong Answer

Solution code:
import re

s = input()
a = [m.start() for m in re.finditer("W", s)]

ans = 0
for i, e in enumerate(a):
    ans += e - (i + 1)

print(ans)

Submission status: Wrong Answer

Solution code:
a,s,b=0,input(),0
for i in range(len(s)):a+=i*(s[i]=="W");b+=1
print(a-((b*(b-1))//2))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
# 文字列の入力
s = input()
# 出力
count=0
answer=0
print(s)
str_list = list(s)

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

Submission status: Wrong Answer

Solution code:
in_seq = raw_input()
listAdd = 0
cnt = 0
cnt_W = 0
for stone in in_seq:
  if stone == "W":
    #listAdd.append(cnt)
    listAdd += cnt
    cnt_W += 1
  cnt += 1
output_num = listAdd - (cnt_W - 1)
print output_num

Submission status: Wrong Answer

Solution code:
import re
import numpy as np
s = input()
wlen = list(map(len, re.findall(r"(W+)", s)))
print(np.cumsum(wlen[::-1]).sum())

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():
    s = np.array(list(input()))
    #Bの場所
    ind = np.array(np.where(s=='B'))
    #文字列の長さ
    len_ind=ind.shape[1]
    #Bの個数
    len=s.shape[0]
    #Bの移動先
    dist=np.arange(len-len_ind,len)
    #答え
    ans=np.sum(dist-ind)
    return ans

Submission status: Wrong Answer

Solution code:
def main():
    s = np.array(list(input()))
    #Bの場所
    ind = np.array(np.where(s=='B'))
    #文字列の長さ
    len_ind=ind.shape[1]
    #Bの個数
    len=s.shape[0]
    #Bの移動先
    dist=np.arange(len-len_ind,len)
    #答え
    ans=np.sum(dist-ind)
    return ans

Submission status: Wrong Answer

Solution code:
def main(s1):
    s = np.array(list(s1))
    #Bの場所
    ind = np.array(np.where(s=='B'))
    #文字列の長さ
    len_ind=ind.shape[1]
    #Bの個数
    len=s.shape[0]
    #Bの移動先
    dist=np.arange(len-len_ind,len)
    #答え
    ans=np.sum(dist-ind)
    return ans

Submission status: Wrong Answer

Solution code:
txt = input()
txt_list = list(txt)

count = 0
n_b = 0
n_w = 0
i = 0
for i in range(len(txt_list)):
    print(txt_list[i])
    if txt_list[i] == 'W':
        n_w += 1
    if (i>=1 and txt_list[i-1] == 'W' and txt_list[i] == 'B') or (i==len(txt_list)-1 and txt_list[i] == 'W'):
        count += n_b * n_w
        # print(n_b)
        # print(n_w)
        n_w = 0
    if txt_list[i] == 'B':
        n_b += 1

print(count)

Submission status: Wrong Answer

Solution code:
txt = input()
txt_list = list(txt)

num = 0
count = 0
for i in range(len(txt)):
    if txt_list[i] == 'W':
        count += i-num 
        num += 1

print(txt_list, count)

Submission status: Wrong Answer

Solution code:
txt = input()
txt_list = list(txt)

count = 0

while True:
    pre_count = count
    for i in range(len(txt)-1):
        if txt_list[i] == 'B' and txt_list[i+1] == 'W':
            tmp = txt_list[i]
            txt_list[i] = txt_list[i+1]
            txt_list[i+1] = tmp
            count += 1
    if pre_count == count:
        break

print(txt_list, count)

Submission status: Wrong Answer

Solution code:
s = input()
print(s.count('BW')*2)

Submission status: Wrong Answer

Solution code:
s = input()
print(max(s.count('B'), s.count('W')))

Submission status: Wrong Answer

Solution code:
import numpy as np
S = input()
b_num = S.count('B')
w_num = len(S) - b_num
end = 2**(w_num + 1) - 1
start = 0
for i in range(len(S)):
  if S[i] == 'W':
    start += np.power(2, i)
print(np.log2(start / end))

Submission status: Wrong Answer

Solution code:
"""AtCoder"""

S = input()

ans = 1
tmp = 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
def main29():
    S = input()
    count = 0
    start = False
    tmp = 0
    W_count = 0

    for i in range(len(S)):
        if S[i] == "W":
            if not start and i > 0:
                if S[i-1] == "B":
                    count += i - W_count
                    tmp = i
                    start = True
            elif i - tmp > 1:
                count += i - W_count
                tmp = i
            W_count += 1

    print(count)

main29()

Submission status: Wrong Answer

Solution code:
def main29():
    S = input()
    count = 0
    start = False
    tmp = 0
    W_count = 0

    for i in range(len(S)):
        if S[i] == "W":
            if not start and i > 0 and S[i-1] == "B":
                count += i
                tmp = i
                start = True
            elif i - tmp > 1:
                count += i - W_count
                tmp = i
            W_count += 1

    print(count)

main29()

Submission status: Wrong Answer

Solution code:
s=input()
counter=0
while s.find("BW"):
    s.replace("BW","WB")
    counter+=1
print(counter)

Submission status: Wrong Answer

Solution code:
s=list(input())
ans=0
wf=0
bf=0
for i in range(len(s)):
    if s[i]=='W':
        ans+=i
        wf=1
    else:
        bf=1
if wf==0 or bf==0:
    print(0)
else:
    print(ans-wf*(wf-1)//2)

Submission status: Wrong Answer

Solution code:
s=list(input())
ans=0
wf=0
bf=0
for i in range(len(s)):
    if s[i]=='W':
        ans+=i
        wf=1
    else:
        bf=1
if wf==0 or bf==0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a=input();print(min(a.count("B"),a.count("W"))*2)

Submission status: Wrong Answer

Solution code:
S= input()
print(min(S.count('B'),S.count('W'))*2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=list(input())
n=len(s)
total_b=0
cnt=0
total=0
for i in range(n):
    if s[i]=="B":
        total_b+=i
        cnt+=1
for i in range(n-cnt,n):
    total+=i
print(total-total_b)
print(total,total_b)

Submission status: Wrong Answer

Solution code:
s=list(input())
n=len(s)
total_b=0
cnt=0
total=0
for i in range(n):
    if s[i]=="B":
        total_b+=i
        cnt+=1
for i in range(n-cnt+1,n):
    total+=i
print(total-total_b)

Submission status: Wrong Answer

Solution code:
s=list(input())
n=len(s)
total_b=0
cnt=0
total=0
for i in range(n):
    if s[i]=="B":
        total_b+=i
        cnt+=1
for i in range(n-cnt+1,n):
    total+=i
print(total)

Submission status: Wrong Answer

Solution code:
hoge=input()
ans=0
count=0
white=0
for i in hoge:
  
  if(i=="W"):
    ans+=count - white
    white+=1
  count+=1
  
print(count)

Submission status: Wrong Answer

Solution code:
import re
import sys

l = line = next(map(str.strip, sys.stdin))

count = 0
prev = None
while prev is None or prev != line:
    prev = line
    count += len(re.findall("BW", line))
    line = line.replace("BW", "WB")

print(count)

line = l

count = 0
nb_bs = 0
for i, c in enumerate(line):
    if c == 'W' and nb_bs > 0:
        count += nb_bs
    elif c == 'B':
        nb_bs += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys

line = next(map(str.strip, sys.stdin))

count = 0
nb_bs = 0
for i, c in enumerate(line):
    if c == 'W' and nb_bs:
        count += nb_bs
    else:
        nb_bs += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys

line = list(list(sys.stdin)[0].strip())

count = 0
for i in reversed(range(len(line))):
  c = line[i]
  if c == 'B':
    continue  # black pieces at the end don't matter
  if line[i - 1] == 'W':
    continue  # white pieces preceded by white pieces don't matter
  if i < 1:
    break  # first piece doesn't matter
  line[i - 1] = 'W'  # change previous black piece
  count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys

line = list(list(sys.stdin)[0].strip())

count = 0
for i, c in reversed(list(enumerate(line))):
  if c == 'B':
    continue  # black pieces at the end don't matter
  if line[i - 1] == 'W':
    continue  # white pieces preceded by white pieces don't matter
  if i < 1:
    break  # first piece doesn't matter
  line[i - 1] = 'W'  # change previous black piece
  count += 2

print(count)

Submission status: Wrong Answer

Solution code:
S = input()
count_B = 0
right_W = 0
for i, c in enumerate(S):
  if c == "W":
    right_W = i
print(i)

Submission status: Wrong Answer

Solution code:
#AGC029 A - Irreversible operation
def countB(data):#dataのBの個数kosuとiの総和sumを返す
    sum=0
    kosu=0
    for i in range(len(data)):
        if data[i]=="B":
            kosu=kosu+1
            sum=sum+i
    return[sum,kosu]

text=input()
S=[]
N=len(text)
for i in range(N):
    S.append(text[i])
result=countB(S)
x=result[1]
Ans=(2*N-x-1)*x/2-result[0]
print(Ans)

Submission status: Wrong Answer

Solution code:
s=input()
t=list(s).count("W")
A=[i for i,x in enumerate (list(s)) if x=="W"]
print(int(sum(A)-t*(t+1)/2))

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
b_num = sum([1 for w in s if w == "B"])
b_pos = sum([i for i,w in enumerate(s) if w == "B"])
max_num = sum([i for i in range(l-b_num, l)])
print(max_num - b_num)

Submission status: Wrong Answer

Solution code:
line = list(raw_input())

data = []
for i in range(len(line)):
  if line[i] == 'W':
    data.append(i)

ans = 0
counter = 0
for i in data:
  ans += i-counter
  counter += 1
print line
print ans

Submission status: Wrong Answer

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

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

print(ans - cnt)

Submission status: Wrong Answer

Solution code:
s = input() + "lllllll"
n = len(s)
tt = 0
ts = 0
for i in range(n-6):
    #print(s[i])
    if s[i] == "B" and s[i+1] == "W":
        #print("Hello")
        tt+=1
        #if s[i+2] == "B" and s[i+3] == "W":tt+=1
        for h in range(1,n-i-3,2):
            if s[i+h+1] == "B" and s[i+h+2] == "W":tt+=1
        for k in range(1,i+1):
            if i - k >= 0 and s[i-k] == "B":tt+=1
            else:break
        for j in range(1,n-i):
            if i + j <= n-2 and s[i+j+1] == "W":tt+=1
            else:break
        i = i+1+max(h,j)
print(tt)

Submission status: Wrong Answer

Solution code:
s = input() + "lllllll"
n = len(s)
tt = 0
ts = 0
for i in range(n-3):
    #print(s[i])
    if s[i] == "B" and s[i+1] == "W":
        #print("Hello")
        tt+=1
        #if s[i+2] == "B" and s[i+3] == "W":tt+=1
        for j in range(1,n-i-3,2):
            if s[i+j+1] == "B" and s[i+j+2] == "W":tt+=1
        for k in range(1,i+1):
            #print(k,i)
            if i - k >= 0 and s[i-k] == "B":tt+=1
            else:break
        for j in range(1,n-i):
            #print(j,i)
            if i + j <= n-2 and s[i+j+1] == "W":tt+=1
            else:break
        i = i+j+1
print(tt)

Submission status: Wrong Answer

Solution code:
s = input() + "lllllll"
n = len(s)
tt = 0
ts = 0
for i in range(n-3):
    if s[i] == "B" and s[i+1] == "W":
        tt+=1
        if s[i+2] == "B" and s[i+3] == "W":tt+=1
        for j in range(1,i):
            if i - j >= 0 and s[i-j] =="B":tt+=1
            else:break
        for j in range(1,n-i):
            if i + j <= n-2 and s[i+j+1] =="W":tt+=1
            else:break
        i = j-1
print(tt)

Submission status: Wrong Answer

Solution code:
s = input() + "lllllll"
n = len(s)
tt = 0
for i in range(n-3):
    if s[i] == "B" and s[i+1] == "W":
        tt+=1
        for j in range(1,i):
            if i - j >= 0 and s[i-j] =="B":tt+=1
            else:break
        for j in range(1,n-i):
            if i + j <= n-2 and s[i+j] =="W":tt+=1
            else:break
        i = j-1
print(tt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()

print(S.count('BW')*2)

Submission status: Wrong Answer

Solution code:
text = input()
wcnt = 0
lensum = 0
for i, char in enumerate(text):
  if char == 'W':
    wcnt += 1
    lensum += i
ret = lensum - (wcnt * (wcnt - 1) / 2 )
print(ret)

Submission status: Wrong Answer

Solution code:
S = list(input())
S = [tmp == 'B' for tmp in S]
tmp = len(S)
i=0
ctr=0
while(1):
  print(i)
  if(i+1>=tmp):
    break
  elif(i<0):
    i+=1
  elif(S[i]==True and S[i+1]==False):
    S[i]=False
    S[i+1]=True
    ctr += 1
    i -= 1
  else:
    i+=1
print(ctr)

Submission status: Wrong Answer

Solution code:
S = list(input())
ctr = 0
flag = 0
print(S[1])
tmp = len(S)
while (1):
  for i in range(tmp-1):
    if(S[i]=='B' and S[i+1]=='W'):
      S[i]='W'
      S[i+1]='B'
      ctr +=1
      # print(S)
      break
    if(i == tmp-2):
      flag = 1
  if(flag==1):
    break

print(ctr)

Submission status: Wrong Answer

Solution code:
string = str(input())
n = 0

for _ in range(len(string)):

    try:
       n = n + string.index("W")
       string = "B" + string[2:]
    
    except ValueError:
        break

print(n-1)

Submission status: Wrong Answer

Solution code:
list1=list(input())
list1.reverse()
a=0
count=0
for i in range(len(list1)):
    if list1[i]=="W":
        a=i
        break
for i in range(a+1,len(list1)):
    if list1[i]=="B":
        count+=i-a
        a+=1
print(count)

Submission status: Wrong Answer

Solution code:
s=[i for i in input()]
#print(s)

k=0
cntb=0
cnta=0
ans=0
while k<len(s):
  if s[k]=='B':
    cntb=cnta+1+cntb
  if s[k]=='W':
    cnta=cntb
    ans=ans+cnta
    cntb=0
  k+=1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
s = list(input())
n = len(s)
half = s[0:n//2]
if n%2 == 1:
    back = s[n//2+1:]
else:
    back = s[n//2:]
a = collections.Counter(half)
b = collections.Counter(back)

pair1 = [a["B"],b["W"]]
pair2 = [a["W"],b["B"]]
print((min(pair1)+min(pair2))*2)

Submission status: Wrong Answer

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

count = 0
count2 = 0
kekka = 0
for i in range(len(S)):
	if(S[i] == 'W'):
		count = count + 1
		count2 = count2 + i
for j in range(count):
	kekka = kekka + N - j

print(kekka-count2)

Submission status: Wrong Answer

Solution code:
from sys import stdin
a=  stdin.readline().strip()
a= list(a)
a.reverse()
ans= 0
cur =0
for i in a:
 if i=='W':
  cur+=1
 else:
  ans+= 1
print ans

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#coding:utf-8

s = input()
res = 0
rm=0

for i in s[::-1]:
  if i == 'B':
    s = s.rstrip("B")
    break

n = 0
for i in s[::-1]:
  n += 1
  if i == 'B':
    res += n

res/=2
print(int(res))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = list(input())
count = 0
for i in range(3):
    for j in range(len(s)-1):
        if(s[j]=='B'):
            if(s[j + 1]=='W'):
                s[j]="W"
                s[j+1]="B"
                count += 1
            else:
                continue
        else:
            continue
print(count)

Submission status: Wrong Answer

Solution code:
S = str(input())
print(S.count('BW')*2);

Submission status: Wrong Answer

Solution code:
letters = input()
L=len(letters)
flag = 0
j=0
while j<L :
	i=0
	while i<L :
		if letters[i]=="s" and letters[i+1]=="w" :
			letters.replace(letters[i],letters[i+1])
		i=i+1
		flag = flag + 1
	j=j+1

print(flag)

Submission status: Wrong Answer

Solution code:
import sys
import math
S = list(input())
size = len(S)

if size == 1:
    print(0)
    sys.exit()

B_size = sum([ 1 for i in S if i == 'B' ])
B_size2 = sum([ i for i,j in enumerate(S) if j == 'B' ])
ans= sum(range(0, size)[-B_size:]) - B_size2
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
slist = list(s)
l = len(s)
n = 0
j = 1
start = 0
end = l-1

while j != 0:
  j = 0
  for i in range(start, end):
    if slist[i:i+2] == ['B','W']:
      slist[i:i+2] = ['W','B']
      n += 1
      j = 1
#      end = i+1
  start += 1
  end -= 1

print(n)

Submission status: Wrong Answer

Solution code:
s = input()
slist = list(s)
l = len(s)
n = 0
j = 1
start = 0
end = l-1

while j != 0:
  j = 0
  for i in range(start, end):
    if slist[i:i+2] == ['B','W']:
      slist[i:i+2] = ['W','B']
      n += 1
      j = 1
      end = i
  start += 1
#  end -= 1

print(n)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N=(stdin.readline().rstrip())
def str_del(str,index):
    str = str[:index]+str[index+1:]
    return str
ans=0
for i in range(10000):
    index=N.find("W")
    if index==-1:
        break
    ans=ans+index
    N=str_del(N,index)
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
size = len(S)
import math
B_size = sum([ 1 for i in S if i == 'B' ])
B_size2 = sum([ i for i,j in enumerate(S) if j == 'B' ])
ans= sum(range(0, size)[-B_size:]) - B_size2
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
n = len(s)-1
count = 0

def a(i):
    global count
    if s[i] == "B" and s[i + 1] == "W":
        s[i] = "W"
        s[i + 1] = "B"
        count += 1
        if(i>0):
            if s[i - 1] == "B" and s[i] == "W":
                pass
        # if(i>0) and s[i-1] == "B" and s[i] == "W":
        #     a(i-1)

[a(i) for i in range(n)]
# for i in range(n):
#     a(i)

print(count)

Submission status: Wrong Answer

Solution code:
s = list(input())
n = len(s)-1
count = 0

def a(i):
    global count
    if s[i] == "B" and s[i + 1] == "W":
        s[i] = "W"
        s[i + 1] = "B"
        count += 1
        # if(i>0) and s[i-1] == "B" and s[i] == "W":
        #     a(i-1)

[a(i) for i in range(n)]
# for i in range(n):
#     a(i)

print(count)

Submission status: Wrong Answer

Solution code:
S = input()
num = 0
c = 100
for i in range(int(len(S)/2)):
	num += S.count('BW')
	S = S.replace('BW','WB')

print(num)

Submission status: Wrong Answer

Solution code:
def main(a):
  s=0
  t=0
  for i in range(0,len(a)):
    if a[i]=="B":
      s+=len(a)-i-1
      t+=1
  return s-t*(t-1)/2

a=input()
print(main(a))

Submission status: Wrong Answer

Solution code:
def main():
        s = input()
        start = forward = backward = 0
        intervals = []
        
        if len(s) > 3:
            for i in range(1, len(s)):
                if s[start] != s[i]:
                    intervals.append((start, i-1, s[start]))
                    if s[start] == 'B':
                        forward += 1
                    else:
                        backward += 1
                    start = i
            intervals.append((start, len(s)-1, s[start]))
            print(len(intervals))
        elif s =='BBW' or 'BWW':
            print(2)
        elif s =='WBW' or 'BWB' or 'BW':
            print(1)
            
        else:
            print(0)
main()

Submission status: Wrong Answer

Solution code:
#
# coding: utf-8

s=input()
n=0

a=s[0]
for i in s:
    b=i
    if a+b=="BW":
        n+=1
    a=b

print(n)

Submission status: Wrong Answer

Solution code:
S = str(input())
count = 0;
while(1):
  count=count+1;
  S = S.replace('BW','WB',1);
  if 'BW' not in S:break;
print(count)

Submission status: Wrong Answer

Solution code:
def main():
        s = input()
        start = forward = backward = 0
        intervals = []
        
        if len(s) > 3:
            for i in range(1, len(s)):
                if s[start] != s[i]:
                    intervals.append((start, i-1, s[start]))
                    if s[start] == 'B':
                        forward += 1
                    else:
                        backward += 1
                    start = i
            intervals.append((start, len(s)-1, s[start]))
            print(len(intervals))
        
        elif s =='WBW' or 'BWB' or 'BW':
            print(1)
            
        else:
            print(0)
main()

Submission status: Wrong Answer

Solution code:
S = str(input())
count = 0;
for i in range(100000):
  count=count+1;
  S = S.replace('BW','WB',1);
  if 'BW' not in S:break;
print(count)

Submission status: Wrong Answer

Solution code:
s = raw_input() 
ans = 0
b = len(s) - 1 
a = 0 
for i in xrange(len(s)):
  if s[i] == 'B':
    ans += b - i 
    b -= 1
  else:
    ans += i - a
    a += 1
print ans

Submission status: Wrong Answer

Solution code:
def main(a):
  s=0
  for i in range(1,len(a)):
    if a[i]=="B":
      s+=len(a)-i
  return s

a=input()
print(main(a))

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 i > 0 and S[i-1] == 'W' and S[i] == 'W':
        ans -= 1
    i+=1
if S[size-1] == 'B':
    ans -= 1    
print(ans)