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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
counter=0

while S.find('W') != -1:
    for i in range(len(S)):
        if S[i]=='B':
            counter+=1
        else:
            temp = S[:i]+S[i+1:]
            S =temp
            break

print(counter)

Submission status: Time Limit Exceeded

Solution code:
S = input()
num = 0
c = 100
for i in range(1000000000000000000000):
	if S.count('BW') == 0: break
	num += S.count('BW')
	S = S.replace('BW','WB')
print(num)

Submission status: Time Limit Exceeded

Solution code:
arg = input()

src = arg
sum_n = 0

while (1):
    count = src.count("BW")
    src = src.replace('BW', 'WB')
    sum_n += count
    if count == 0 :
        break

print(sum_n)

Submission status: Time Limit Exceeded

Solution code:
Ans=0
N=input()

while 'BW' in N:
    i=N.index('BW')
    N=N.replace('BW','WB',1)
    Ans+=1
else:
    print(Ans)

Submission status: Time Limit Exceeded

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

ans = 0

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



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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
src = input()
count = 0

for  i in range(9999999):
    if 'BW' in src :
       src = src.replace('BW', 'WB', 1)
       count += 1
    else:
        break
print( count )

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 15 22:14:32 2018

@author: doppe
"""

def reverse(num, str):
    
    firstFlg = 0
    slice = 0
    reverceFlg = 0
    blackFlg = -1
    for i in range(0, len(str)):
        if (str[i] == "B"):
            blackFlg = 1
            if firstFlg != -1:
                slice = firstFlg
            firstFlg = -1
        elif (firstFlg >= 0 and str[i] == "W"):
            firstFlg += 1
        elif (blackFlg == 1 and str[i] == "W"):
            str[i - 1] = "W"
            str[i] = "B"
            blackFlg = 1
            reverceFlg =1
            num += 1
        else:
            blackFlg = -1
    if (reverceFlg == 1):
        return reverse(num, str[slice:])
    return num
        
    
str = input()
num = 0
str_list = list(str)
l = reverse(num, str_list)
print(l)

Submission status: Time Limit Exceeded

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


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

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

    print(total)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
src = input()
count = 0

for  i in range(99999999999999):
    if 'BW' in src :
       src = src.replace('BW', 'WB', 1)
       count = count + 1
    else:
        break
print( count )

Submission status: Time Limit Exceeded

Solution code:
S=input()
count=0
while 1:
    tmp=S.count('BW')
    if tmp==0:
        break

    count+=tmp
    S=S.replace('BW','WB')[S.find('B'):S.rfind('W')+1]
print(count)

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()
res = 0
it = re.finditer('W+', S)
for match in it:
    # print(match.group())
    res += S[:match.start()].count('B') * len(match.group())
print(res)

Submission status: Time Limit Exceeded

Solution code:
# AtCoder Grand Contest 029
# December 15, 2018
#

S = input()
count = 0

while True:
  if S.find('BW') >= 0:
    S = S.replace('BW', 'WB', 1)
    count += 1
  else:
    break

print(count)

Submission status: Time Limit Exceeded

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

sum = 0
i = 0
flag = 0
while  i < len(s) :

    if s[i] == 'B':
        flag +=1
        i = i+1
    else:
        sum += flag
        s[i] = 'B'
        s[i-flag] = 'W'
        i = i - flag + 1
        flag = 0           

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

while j > 0:
  j = 0
  for i in range(l-1):
    if slist[i] == 'B' and slist[i+1] == 'W':
      slist[i] = 'W'
      slist[i+1] = 'B'
      n += 1
      j += 1

print(n)

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_list = list(s)
s_len = len(s)
count = 0
num = 1
while(num != 0):
  num = s.count('BW')
  s = s.replace('BW','WB')
  count += num
print(count)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
det = 0
count = 0

while True:
  #"BW"の並びがあることを検出する。
  for i in range(len(S)-1):
    if (S[len(S) - i - 1] == "W") and (S[len(S) - i - 2] == "B"):
      break
  for i in range(len(S)-1):
    if (S[len(S) - i - 1] == "W") and (S[len(S) - i - 2]) == "B":
      if i == 0:
        S = S[:len(S) - i - 2] + "WB"
        count += 1
        break
      elif 0 < i < len(S) - 1:
        S = S[:len(S) - i - 2] + "WB" + S[len(S) - i:]
        count += 1
        break
      else:
        S = "WB" + S[len(S) - i:]
        count += 1
        break
  else:
    break
  
print(count)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

s = input()
s_arr = list(s)

n = 0
l = len(s_arr)
while True:
    counter = 0
    for i in range(l):
        if i == l-1:
            break
        if s_arr[i] == 'B':
            if s_arr[i+1] == 'W':
                s_arr[i] = 'W'
                s_arr[i+1] = 'B'
                counter += 1
                n += 1
    if counter == 0:
        break
print(n)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
n = len(s) - 1
count=0
i=0
while i!=n:
    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
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re


def solve(ms):
    ans = 0
    rpc = 1
    while rpc > 0:
        r = re.subn("BW", "WB", ms)
        rpc = r[1]
        ans = ans + rpc
        ms = r[0]
    return ans


print(solve(input()))

Submission status: Time Limit Exceeded

Solution code:
s=input()
ans=0
s=s[::-1]
while True:
    t=s.replace('WB','BW',1)
    if t != s:
        s=t
        ans+=1
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

def isFinished(S):
    for i in range(len(S) - 1):
        if S[i] == 'B' and S[i+1] == 'W':
            return True
    return False

def solve(S):
    count = 0
    while isFinished(S):
        black_pos = -1
        for i in range(len(S)):
            if S[i] == 'B':
                black_pos = i
            elif S[i] == 'W' and black_pos != -1:
                count += i - black_pos
                S[black_pos] = 'W'
                S[i] = 'B'
                black_pos = -1
    return count

if __name__ == "__main__":
    S = input()
    print(solve(list(S)))

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
count = 0
n = len(s) - 1
i=0
while True:
    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

    if i==n:
        break

print(count)

Submission status: Time Limit Exceeded

Solution code:
i = (input())

s = [c for c in i]

n = len(i)

c = 0
f = True
while(f):
    f = False
    for i in range(n-1):
        if s[i] == 'B' and s[i+1] == 'W':
            tmp = s[i]
            s[i] = s[i+1]
            s[i+1] = tmp
            c += 1
            f = True
            break

print(c)

Submission status: Time Limit Exceeded

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

while True:
    i = 0
    fg = False
    while i < size -1:
        if S[i] == 'B' and S[i+1] == 'W':
            ans += 1
            S[i] = 'W'
            S[i+1] = 'B'
            fg = True
        i += 1
    if fg == False:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

R = 0

while 'BW' in S:
    R += S.count('BW')
    S  = S.replace('BW', 'WB')

print(R)

Submission status: Time Limit Exceeded

Solution code:
S = input()

counter = 0
arr = list(S)
while True:
    x = 0
    for i in range(len(arr)-1):
        if arr[i] == 'B' and arr[i+1] == 'W':
            arr[i] = 'W'
            arr[i+1] = 'B'
            counter += 1
            x = 1
            break
    if x == 0:
        break

print(counter)

Submission status: Time Limit Exceeded

Solution code:
S = input()
det = 0
count = 0

while True:
  #"BW"の並びがあることを検出する。
  for i in range(len(S)-1):
    if (S[len(S) - i - 1] == "W") and (S[len(S) - i - 2] == "B"):
      det += 1
  if det == 0:
    break
  else:
    det = 0
    for i in range(len(S)-1):
      if (S[len(S) - i - 1] == "W") and (S[len(S) - i - 2]) == "B":
        if i == 0:
          S = S[:len(S) - i - 2] + "WB"
          count += 1
          break
        elif 0 < i < len(S) - 1:
          S = S[:len(S) - i - 2] + "WB" + S[len(S) - i:]
          count += 1
          break
        else:
          S = "WB" + S[len(S) - i:]
          count += 1
          break

print(count)

Submission status: Time Limit Exceeded

Solution code:
src = input()
count = 0

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

print( count )

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=200000
T = []
for i in range(N):
	C=int(S.count('BW'))
	T.append(int(C))
	S=S.replace('BW','WB')
	if C==0:
		break
print(sum(T))

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
N=len(S)
a=[]
y=[]
x=0
a=list(S)


while 'BW' in S :
    a=list(S)
    for y in reversed((a)):

        for i in range (0,N-1):
            if a[i]=='B' and a[i+1]=='W' :
                a[i]='W'
                a[i+1]='B'
                x=x+1
                S=''.join(a)
print(x)

Submission status: Time Limit Exceeded

Solution code:
import re


def solve(ms):
    ans = 0
    rpc = 1
    while rpc > 0:
        r = re.subn('BW', 'WB', ms)
        rpc = r[1]
        ans = ans + rpc
        ms = r[0]
    return ans


print(solve(input()))

Submission status: Time Limit Exceeded

Solution code:
B = input()
Bin = []
lb = len(B)
for i in range(lb):
    if B[i] == "W":
        Bin.append(0)
    else:
        Bin.append(1)
Bin.append(2)
num = 0
i = lb - 1
while i >= 0:
    if Bin[i] == 1 and Bin[i+1] == 0:
        Bin[i] = 0
        Bin[i+1] = 1
        num = num + 1
        i = i + 1
    else:
        i = i - 1
print(num)

Submission status: Time Limit Exceeded

Solution code:
def reverse(num, str):
    
    firstFlg = 0
    reverceFlg = 0
    blackFlg = -1
    for i in range(0, len(str)):
        if (str[i] == "B"):
            blackFlg = 1
            firstFlg = -1
        elif (firstFlg >= 0 and str[i] == "W"):
            firstFlg += 1
        elif (blackFlg == 1 and str[i] == "W"):
            str[i - 1] = "W"
            str[i] = "B"
            blackFlg = 1
            reverceFlg =1
            num += 1
        else:
            blackFlg = -1
    if (reverceFlg == 1):
        if firstFlg == -1:
            firstFlg = 0
        return reverse(num, str[firstFlg:])
    return num
        
    
str = input()
num = 0
str_list = list(str)
l = reverse(num, str_list)
print(l)

Submission status: Time Limit Exceeded

Solution code:
S = input()

counter = 0
arr = list(S)
while True:
    x = 0
    for i in range(len(arr)-1):
        if arr[i] == 'B' and arr[i+1] == 'W':
            arr[i] = 'W'
            arr[i+1] = 'B'
            counter += 1
            x = 1
    if x == 0:
        break

print(counter)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    S = list(input())
    S = S[::-1]
    
    L = len(S)
    C = 0
    BC = 0
    
    while 'B' in S:
        temp = S.index('B')
        S[temp] = 'Z'
        C += temp - BC
        BC +=1
    
    print(C)

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()
count=0
num=1
while num!=0:
    num=S.count("BW")
    S=re.sub("BW", "WB", S, num)
    count+=num
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_list = list(s)
s_len = len(s)
count = 0
while(1):
  ind = s.find('BW')
  if ind == -1:
    break
  s_list[ind] = 'W'
  s_list[ind+1] = 'B'
  s = ''.join(s_list)
  count += 1
print(count)

Submission status: Time Limit Exceeded

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


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

Submission status: Time Limit Exceeded

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

while True:
    i = 0
    fg = False
    while i < size -1:
        if S[i] == 'B' and S[i+1] == 'W':
            ans += 1
            S[i] = 'W'
            S[i+1] = 'B'
            fg = True
            break
        i += 1
    if fg == False:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
ans=0
while True:
    t=s.rfind('BW')
    if t != -1:
        s="".join((s[:t],'WB',s[t+2:]))
        ans+=1
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
s.reverse()
nb = s.count("B")
l = len(s)
ret = 0 
for i in range(nb):
    for j in range(l-i):
        if s[j+i]=="B":
            ret += j
            s[j+i]="W"
            break
print(ret)

Submission status: Time Limit Exceeded

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


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

    total = 0
    s_list = list(s)
    for _ in range(num):
        for i in range(num-1):
            end = num - i
            start = end - 2
            if s_list[start:end] == ["B", "W"]:
                total += 1
                s_list[start:end] = ["W", "B"]
    print(total)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
a = 1
count=0
while True:
    a = S.count("BW")
    count+=a
    if S == S.replace("BW","WB"):
        break
    else:
        S = S.replace("BW","WB")
print(count)

Submission status: Time Limit Exceeded

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

sum = 0
i = 0
while True:
    if s[i] == 'B' and s[i+1] == 'W':
        s[i] = 'W'
        s[i+1] = 'B'
        sum += 1
        if i > 0:
            i = i - 1
        else:
            i += 1
    else:
        i += 1
    
    if i >= len(s) - 1:
        break

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()
count=0
while True:
    pS=S
    S=re.sub("BW", "WB", S,1)
    if pS==S:
        break
    else:
        count+=1
print(count)

Submission status: Time Limit Exceeded

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

def check():
  flag=0
  for j in range(len(s)-1):
    if s[j]=='B' and s[j+1]=='W':
      flag=1
  return flag

ans=0
while check()==1:
  for j in range(len(s)-1):
    if s[j]=='B' and s[j+1]=='W':
      ans+=1
      s[j]='W'
      s[j+1]='B' 
  check()

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

def isFinished(S):
    for i in range(len(S)):
        if i != len(S) - 1:
            if S[i] == 'B' and S[i+1] == 'W':
                return True
    return False

def solve(S):
    count = 0
    while isFinished(S):
        for i in range(len(S)):
            if i != len(S) - 1:
                if S[i] == 'B' and S[i+1] == 'W':
                    count += 1
                    S[i], S[i+1] = S[i+1], S[i]
    return count

if __name__ == "__main__":
    S = input()
    print(solve(list(S)))

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0

while True:
    cnt = s.count("BW")
    if cnt > 0:
        s = s.replace("BW", "WB")
        count += cnt
    else:
        break

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
a = 1
count=0
while a != 0:
    a = S.count("BW")
    count+=a
    S = S.replace("BW","WB")
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = 0
import re
re.sub('BB+',"BB",S)
re.sub("WW+",'WW',S)
if 'BWBWBW' in S:
    n += 6*S.count('BWBWBW')
    S = S.replace('BWBWBW','WB')
while 'BW' in S:
    n += S.count('BW')
    S = S.replace('BW','WB')
print(n)

Submission status: Time Limit Exceeded

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

def check():
  flag=0
  for j in range(len(s)-1):
    if s[j]=='B' and s[j+1]=='W':
      flag=1
  return flag

ans=0
while check()==1:
  for j in range(len(s)-1):
    if s[j]=='B' and s[j+1]=='W':
      ans+=1
      s[j]='W'
      s[j+1]='B' 
  check()

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys


def bubble_sort(arr):
    counter = 0
    for i in range(len(arr)):
        for j in range(len(arr) - 1, i, -1):
            if arr[j] < arr[j - 1]:
                arr[j], arr[j - 1] = arr[j - 1], arr[j]
                counter += 1
    return arr, counter


def solve():
    input = sys.stdin.readline
    S = list(input().replace("B", "2").replace("W", "1"))[:-1]
    S, counter = bubble_sort(S)

    print(counter)


solve()

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
count = 0

def black_and_white(S):
  global count
  for i in range(0,len(S)-1):
    if(S[i] == "B" and S[i+1] == "W"):
      count += 1
      tmp = S[i]
      S[i] = S[i+1]
      S[i+1] = tmp
      return True
  return False

while(1):
  if not black_and_white(S): break

print(count)

Submission status: Time Limit Exceeded

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

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

print(counter1)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0
for i, s in enumerate(S):
    if s == 'B':
        count += S[i + 1:].count('W')
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = 0
import re
while 'BW' in S:
    re.sub('BB+',"BB",S)
    re.sub("WW+",'WW',S)
    n += S.count('BW')
    S = S.replace('BW','WB')
print(n)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
s=list(input())
count=0
while True:
  flag=1
  i=bisect_left(s,"B")
  while i+1 <len(s):
    if s[i]=="B" and s[i+1]=="W":
      s[i]="W"
      s[i+1]="B"
      count+=1
      i+=1
      flag=0
    else:
      i+=1
      continue
  if flag==1:
    print(count)
    exit()

Submission status: Time Limit Exceeded

Solution code:
s=input()
ans=0

while True:
    t=s.rfind('BW')
    if t != -1:
        s=s[:t]+'WB'+s[t+2:]
        ans+=1
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
slist = list(str(input()))
L = len(slist)
count = 0
fcount = 0
i = 0
while i < L:
    if i < L-1 and slist[i] == "B" and slist[i+1] == "W":
        slist[i],slist[i+1] = slist[i+1],slist[i]
        count+=1
        fcount+=1
        i+=1
    elif i == L-1:
        if fcount == 0:
            break
        else:
            i = 0
            fcount = 0
    else:
        i+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
count=S.count("BW")
end=0
def sigma(i):
    a=[b for b in range(i+1)]
    return sum(a)
place=[]
i=0
while "BW" in S:
    i=S[i:].find("BW") + 1 + i
    place.append(i)
    S=S[:i-1]+S[i-1:].replace("BW","BB",1)

count=sum(place)-sigma(count-1)
print(count)

Submission status: Time Limit Exceeded

Solution code:
B = input()
Bin = []
lb = len(B)
Bin.append(2)
for i in range(lb):
    if B[i] == "W":
        Bin.append(0)
    else:
        Bin.append(1)
num = 0
i = 0
while i < lb:
    if Bin[i] == 1 and Bin[i+1] == 0:
        Bin[i] = 0
        Bin[i+1] = 1
        num = num + 1
        i = i - 1
    else:
        i = i + 1
print(num)

Submission status: Time Limit Exceeded

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

i=0
while i<n-1:
    if S[i]=='B' and S[i+1]=='W':
        S[i],S[i+1]='W','B'
        ans+=1
        if i: i-=1
        else: i=1
    else:
        i+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
a=0
while S.find("BW")!=-1:
    S=S.replace("BW","WB",1)
    a+=1
print(a)

Submission status: Time Limit Exceeded

Solution code:
temp=input()
S=list(temp)
counter1=0
counter2=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
        i=0

print(counter1)

Submission status: Time Limit Exceeded

Solution code:
S=raw_input()
count=0

while 1:
    tmp=S.count('BW')
    if tmp==0:
        break

    count=count+tmp
    S=S.replace('BW','WB')

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
count = 0
iter_flag = True
while iter_flag:
    ope_flag = False
    for i in range(len(s)-1):
        if s[i]+s[i+1] == "BW":
            s[i] = "W"
            s[i+1] = "B"
            count += 1
            ope_flag = True
        if i == len(s)-2 and ope_flag == False:
            iter_flag = False
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = [_ for _ in input()]
w_count = s.count('W')

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

print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

flag = True

count = 0

while flag:
    M = S
    S = S.replace("BW", "WB", 1)
    if M == S:
        flag = False
    else:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_list = [o for o in s]
count = 0
flag = True
while True:
    for i in range(len(s_list)-1):
        if s_list[i] == 'B' and s_list[i+1] == 'W':
            s_list[i] = 'W'
            s_list[i+1] = 'B'
            flag = False
            count += 1
    if flag:
        print(count)
        exit()
    else:
        flag = True

Submission status: Time Limit Exceeded

Solution code:
def do(input):
    return input.replace("BW", "WB", 1)


if __name__ == '__main__':
    input = input()
    count = 0
    while(True):
        result = do(input)
        if result == input:
            break
        count +=  1
        input = result

    print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
c = 0
try:
  while True:
    l = s.index('W') - s.index('B')
    c += l
    s = s.replace('W', 'B', 1)
    s = s[1:]
except ValueError:
  print(c)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())

sum = 0
while True:
    count = s.count('BW')
    if count > 0:
        sum += count
        s = s.replace('BW','WB')
    else:
        break
print(sum)

Submission status: Time Limit Exceeded

Solution code:
S = input()[::-1]
c = 0
while S.find("WB") != -1:
    S = S.replace("WB", "BW", 1)
    c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
slist = list(S)
L = len(slist)
count = 0
fcount = 0
i = 0
while i < L:
    if i < L-1 and slist[i] == "B" and slist[i+1] == "W":
        slist[i],slist[i+1] = slist[i+1],slist[i]
        count+=1
        fcount+=1
        i+=1
    elif i == L-1:
        if fcount == 0:
            break
        else:
            i = 0
            fcount = 0
    else:
        i+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
N=(stdin.readline().rstrip())
ans=0
for i in range(1000000):
    cnt=N.count("BW")
    ans=ans+cnt
    N=N.replace("BW","WB")
    N=N.lstrip("W")
    N=N.rstrip("B")
    if cnt==0:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
ans=0
while True:
    if 'BW' in s:
        t=s.rfind('BW')
        s=s[:t]+'WB'+s[t+2:]
        ans+=1
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

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

ans=0

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

count=0
pre=-1
while True:
    if count==pre:
        break
    pre=count
    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)

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0
flag = True

while flag:
    flag = False
    for i in range(len(S)-1):
        c = S.count("BW")
        count += c
        if c:
            flag = True
        S = S.replace("BW", "WB")

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
count = 0
end_flag = 1
change_flag = 1
while end_flag:
    change_flag = 1
    for i in range(len(S)):
        if i+1 != len(S):
            if (S[i] == "B") and (S[i+1] == "W"):
                S[i] = "W"
                S[i+1] = "B"
                count += 1
                change_flag = 0
        elif (i+1 == len(S)) and (change_flag == 1):
            end_flag = 0
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
count = 0
judge = 0
if len(S) % 2 == 0:
    n = len(S) - 1
else:
    n = len(S)
while True:
    if judge == len(S)-1:
        break
    else:
        judge = 0
        for i in range(0,len(S)-1,2):
            if S[i] == "B" and S[i+1] == "W":
                S[i] = "W"
                S[i+1] = "B"
                count += 1
            else:
                judge += 1
        for j in range(1,n,2):
            if S[j] == "B" and S[j+1] == "W":
                S[j] = "W"
                S[j+1] = "B"
                count += 1
            else:
                judge += 1

print(count)

Submission status: Time Limit Exceeded

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

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
    cnt += S[:i+1].count('B')
    S = S[:i+1] + S[i+2:]
#    print(S)
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

S = input()
count = 0
while 'BW' in S:
    count += S.count("BW")
    S = S.replace('BW','WB')

print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
count=0

while 1:
    tmp=S.count('BW')
    if tmp==0:
        break

    count=count+tmp
    S=S.replace('BW','WB')

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
while S.find("BW")!=-1:
  ans+=S.count("BW")
  S=S.replace("BW","WB")

print(ans)

Submission status: Time Limit Exceeded

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

b = []
n = 0
J = 0
flag = True
for i in range(len(a)):
    b.append(a[i])
c = b

while(flag):
    for i in range(len(b) - 1) :
        if( c[i] == 'B' and c[i + 1] == 'W'):
            c[i] = 'W'
            c[i + 1] ='B'
            n+=1
            J += 1
        else:
            pass
    if(J==0):flag = False
    J = 0


print(n)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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