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:
inputS = input()
S = list(inputS)
count = 0
tmpI = 0
tmpJ = 0

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

Submission status: Time Limit Exceeded

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

tmpJ = 0
for i in range(len(S)):
  if S[i] == 'W':
    for j in range(tmpJ,i):
      if S[j] == 'B':
        tmpJ = j + 1
        S[i] = 'B'
        count += (i-j)
        break
print(count)

Submission status: Time Limit Exceeded

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

tmpJ = 0
for i in range(len(S)):
  if S[i] == 'W':
    for j in range(tmpJ,i):
      if S[j] == 'B':
        tmpJ = j + 1
        S[i] = 'B'
        S[j] = 'W'
        count += (i-j)
        break
print(count)

Submission status: Time Limit Exceeded

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

for i in range(len(S)):
  if S[i] == 'W':
    for j in range(i):
      if S[j] == 'B':
        S[i] = 'B'
        S[j] = 'W'
        count += (i-j)
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(map(str,input()))
i = 0
ans = 0
while i < len(S)-1:
    if S[i] + S[i+1]=='BW':
        ans += 1
        S[i]='W'
        S[i+1]='B'
        if i>0:
            i -= 1
    else:
        i += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
ans = 0
while(s.count('W') != 0):
    ans += s.index('W')
    s.remove('W')
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
 
f = True
cnt = 0
while f:
  f = False
  for i in range(len(S)-1):
    if S[i]=='B' and S[i+1]=='W':
      S[i] = 'W'
      S[i+1] = 'B'
      cnt += 1
      f = True
print(cnt)

Submission status: Time Limit Exceeded

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

    return
resolve()

Submission status: Time Limit Exceeded

Solution code:
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
resolve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re

s = input()
cnt = 0

def replace(match):
    global cnt
    if (match.group(1) == None):
        n = len(match.group(0))//2
        w = ["W" for i in range(n)]
        b = ["B" for i in range(n)]
        res = w + b
        cnt += n*(n+1)//2
    else:
        res = ["B" for i in range(len(match.group(1)) - 1)]
        res.insert(0, "W")
        cnt += len(match.group(1)) - 1

    return "".join(res)

while True:
    result = re.subn('(B{2,}W)|(BW)+', replace, s)

    if result[1] == 0:
        print(cnt)
        break
    else:
        s = result[0]

Submission status: Time Limit Exceeded

Solution code:
import re
s = input()
replaced = -1
c = 0

while replaced != 0:
    s, replaced = re.subn("BW", "WB", s)
    c += replaced

print(c)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

ans = 0
flg = True
while flg:
    flg = False
    for i in range(len(s) - 1):
        if s[i] == 'B' and s[i + 1] == 'W':
            s[i] = 'W'
            s[i + 1] = 'B'
            ans += 1
            flg = True

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
a=0
f=True
while f:
  for i in range(1,len(s)):
    if s[i]=='W' and s[i-1]=='B':
      a+=1
      s[i]='B'
      s[i-1]='W'
      break
  else:
    f=False
    
print(a)

Submission status: Time Limit Exceeded

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

ans = 0
for i in numpy.where(S == 1)[0]:
    ans += numpy.count_nonzero(S[:i] == 0)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy
S = numpy.array([0 if s == 'B' else 1 for s in input()])
ans = [sum(S[i + 1:]) for i in numpy.where(S == 0)[0]]
print(sum(ans))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

i = 0
while i == 0:
    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]
            i = 0
            break
        i = 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()

if __name__=='__main__':
    sl = list(S())
    flag = True
    c = 0
    while flag:
        flag = False
        for i in range(0,len(sl)-1):
            if sl[i]=='B' and sl[i+1]=='W':
                sl[i],sl[i+1] = 'W','B'
                c += 1
                flag = True

    print(c)
    exit()

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    s = list(readline().rstrip())
    sumS = 0
    for i in range(len(s) - 1):
        if s[i] == 'B':
            sumS += s[i: len(s)].count('W')
    print(sumS)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
p = 0
flg = True
while flg:
    flg = False
    for i in range(len(s)-1):
        if s[i] == 'B' and s[i+1] == 'W':
            s[i] = 'W'
            s[i+1] = 'B'
            p += 1
            flg = True

print(p)

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = 0
pos = 0
while True:
    tmp = S.find('W', pos)
    if tmp == -1:
        break
    ans += S[:tmp].count('B')
    pos = tmp + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re
 
S = input()
ans = 0
while True:
    S, n = re.subn('BW', 'WB', S)
    if n == 0:
        break
    ans += n
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()

cnt = 0
idx = 0
while "BW" in S:
    if S[idx:idx+2] == "BW":
        cnt += 1
        S = S[:idx] + "WB" + S[idx+2:]
        idx = 0
    else:
      idx += 1
      
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import re

S = input()
ans = 0
while True:
    S, n = re.subn('BW', 'WB', S)
    if n == 0:
        break
    ans += n

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
ans = 0
ans2 = 0
s = input()
l = len(s)
t = 1
for i in range(l):
  print(f'a={t}')
  same = True
  while same:
    if s[i] != s[t]:
      i = t
      print(f'b={t}')
      same = False
    else:
      ans += 1
print(max(ans, ans2))

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

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

Solution code:
import collections
s = list(input())
Ans = 0
c = collections.Counter(s)
d = c['B']
for i in range(len(s)):
    if s[i] == 'B':
        for j in range(len(s)-i-1):
            if s[i+j+1]=='W':
                Ans += j+1
                s[i] = 'W'
                s[i+1] = 'B'
                s[i+j+1] = 'B'
                break
    if i == d:
        break
print(Ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def main():
    S = list(input())
    BW = {'B':[], 'W':[]}
    cnt = {'B':0, 'W':0}
    pre = S[0]
    cnt[pre] += 1
    for i in range(1, len(S)):
        now = S[i]
        if pre == now:
            cnt[pre] += 1
        else:
            BW[pre].append(cnt[pre])
            cnt[pre] = 0
            cnt[now] = 1
            pre = now
        # print(cnt)
        # print(BW)
    if cnt[pre] != 0:
        BW[pre].append(cnt[pre])

    if S[0] == 'W':
        BW['W'].pop(0)
    if S[-1] == 'B':
        BW['B'].pop(-1)
    ans = 0
    for i in range(len(BW['B'])):
        ans += sum(BW['B'][:i+1])*BW['W'][i]
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def main():
    S = list(input())
    BW = {'B':[], 'W':[]}
    cnt = {'B':0, 'W':0}
    pre = S[0]
    cnt[pre] += 1
    for i in range(1, len(S)):
        now = S[i]
        if pre == now:
            cnt[pre] += 1
        else:
            BW[pre].append(cnt[pre])
            cnt[pre] = 0
            cnt[now] = 1
            pre = now
        # print(cnt)
        # print(BW)
    if cnt[pre] != 0:
        BW[pre].append(cnt[pre])

    if S[0] == 'W':
        BW['W'].pop(0)
    if S[-1] == 'B':
        BW['B'].pop(-1)
    ans = 0
    for i in range(len(BW['B'])):
        ans += sum(BW['B'][:i+1])*BW['W'][i]
    print(ans)
if __name__ == '__main__':
    main()

#PLAN1
    # S = list(input())
    # check = 0
    # cnt = 0
    # i = 0
    # while(check == 0) :
    #     check = 1
    #     for i in range(len(S)-1):
    #         if S[i] == 'B' and S[i+1] == 'W':
    #             S[i], S[i+1] = 'W', 'B'
    #             cnt += 1
    #             check = 0
    #             break
    # print(cnt)

# PLAN2
# S = list(input())
# state = 0
# CNT = 0
# while(state != 1):
# # for x in range(50):
#     first_W = 0
#     for i in range(len(S)):
#         if state == 0:
#             if S[i] == 'B':
#                 B_cnt = 1
#                 state = 1
#             else:
#                 first_W += 1
#         elif state == 1:
#             if S[i] == 'B':
#                 B_cnt += 1
#             else:
#                 W_cnt = 1
#                 state = 2
#         elif state == 2:
#             if S[i] == 'W':
#                 W_cnt += 1
#             else:
#                 state = 0
#                 break
#     # print(state)
#     if state == 2:
#         state = 0
#         S = ['W']*(W_cnt+first_W) + ['B']*B_cnt
#     else:
#         CNT += W_cnt*B_cnt
#         S = ['W']*(W_cnt+first_W) + ['B']*B_cnt + S[i:]
#     # print(S)
# print(CNT)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def main():
    S = list(input())
    check = 0
    cnt = 0
    i = 0
    while(check == 0) :
        check = 1
        for i in range(len(S)-1):
            if S[i] == 'B' and S[i+1] == 'W':
                S[i], S[i+1] = 'W', 'B'
                cnt += 1
                check = 0
                break
    print(cnt)
                
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s=[0 if i == "B" else 1 for i in input()]
    l=len(s)
    count = 0
    while True:
        p = count
        for i in range(l-1):
            if s[i] == 0 and s[i+1] == 1:
                s[i] = 1
                s[i+1] = 0
                count += 1
        if p == count:
            break
    print(count)
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
check=list(s)
n=len(s)
cnt=0
if n==1:
    print(0)
else:
    flag=False
    while 1:
        for i in range(n-1):
            if check[i]=='B' and check[i+1]=='W':
                cnt+=1
                check[i]='W'
                check[i+1]='B'
                break
            if i==n-2:
                flag=True
        if flag:
            break
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = []
for i in range(len(s)-1, -1, -1):
    if s[i] == 'B':
        l.append(0)
    else:
        l.append(1)
cnt = 0

for j in range(len(s)):
    for i in range(j, len(s) - 1, 2):
        if l[i] == 1 and l[i+1] == 0:
            l[i] = 0
            l[i+1] = 1
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0

while "BW" in S:
    s = list(S)
    i = S.index("BW")
    s[i] = "W"
    s[i + 1] = "B"
    S = "".join(s)
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=len(S)
s=[]
[s.append(i) for i in S]
cnt=0
cnt_o=10
while cnt!=cnt_o:
    cnt_o=cnt
    for i in range(N-1):
        if s[i]=='B' and s[i+1]=='W':
            cnt+=1
            s[i] = 'W'
            s[i+1]='B'

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

s = input()

def fact(n):
  ans = 1
  for i in range(2,n+1):
    ans*=i
  return ans

m = max(s.count("B"),s.count("W"))
print(fact(m))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import numpy as np
import functools
import operator
import collections
import itertools

S=input()
ans=0
Wcount=0
SS=S
#print(S[0])
#S=S.split()
#print(S[0])

for i in range(len(S)):
    SS=S[i:]
    s=collections.Counter(SS)
    if S[i]=="B":
        #print(S)
        Wcount=s["W"]
        ans+=Wcount
    if s["B"]==0:
        break
    #s=collections.Counter(S)
    #if s["W"]==0:
        #print(ans)
        #sys.exit()
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import numpy as np
import functools
import operator
import collections
import itertools

S=input()
ans=0
Wcount=0
SS=S
#print(S[0])
#S=S.split()
#print(S[0])

for i in range(len(S)):
    if S[i]=="B":
        SS=S[i:]
        s=collections.Counter(SS)
        #print(S)
        Wcount=s["W"]
        ans+=Wcount
    #s=collections.Counter(S)
    #if s["W"]==0:
        #print(ans)
        #sys.exit()
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = list('x'+input())
#n,a,b = map(int,input().split())
# al = list(map(int,input().split()))

cnt = 0
i = 1
while i < len(s):
    if s[i-1] == 'B' and s[i] == 'W':
       cnt += 1
       s[i] = 'B'
       s[i-1] = 'W'
       i -= 2
    else:
        i += 1


print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys


def solve(S: str):
    count = 0
    S = [s for s in S]
    
    while True:
        sub_count = 0
        for i in range(len(S)-1):
            if S[i] == 'B' and S[i+1] =='W':
                S[i], S[i+1] = 'W', 'B'
                sub_count += 1

        if sub_count == 0:
            break
        count += sub_count
        
    print(count)
    return


# Generated by 1.1.7.1 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: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[13]:


S = list(input())


# In[14]:


ans = 0
for i in range(S.count("W")):
    ans += S.index("W")-i
    S[S.index("W")] = "B"
print(ans)


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = list(readline().decode().rstrip())[::-1]
l = len(S)

cnt = 0
for _ in range(l - 1):
    for i in range(l - 1):
        if S[i:i + 2] == ['W', 'B']:
            S[i:i + 2] = ['B', 'W']
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

while "BW" in "".join(S):
	for i in range(len(S)-1):
		if S[i]=="B" and S[i+1]=="W":
				S[i]="W"
				S[i+1]="B"
				cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=input()
count=0
AnyOperated=True

while AnyOperated==True:
    temp_count=count
    if N.count('BW')>0:
        count+=N.count('BW')
        newN=N.replace('BW','WB')
        N=newN
    if temp_count==count:
        AnyOperated=False
    else:
        pass

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
n = len(S)
flag = True
cnt = 0
while flag:
    flag = False
    for i in range(n-1):
        if S[i] == 'B' and S[i+1] == 'W':
            S[i] = 'W'
            S[i+1] = 'B'
            flag = True
            cnt += 1
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
a=input()
N=list(a)
count=0
AnyOperated=True

while AnyOperated==True:
    temp_count=count
    for n in range(len(N)-1):
        if N[n]=='B' and N[n+1]=='W':
            N[n]='W'
            N[n+1]='B'
            count+=1
        else:
            pass
    if temp_count==count:
        AnyOperated=False
    else:
        pass
    
print(count)

Submission status: Time Limit Exceeded

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
kprev=-1
while(kprev!=k):
    kprev=k
    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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=list(input())
count=0
a=2*10**5+1
while count!=a:
    a=count
    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

print(count)

Submission status: Time Limit Exceeded

Solution code:
s=str(input())
temps=list(s)
temp=0
for i in range(0,len(temps)):
  if temps[i]=="W":
    temps[i]=1
  if temps[i]=="B":
    temps[i]=0
for i in range(0,len(temps)):
  if temps[i]==0:
    temp=temp+sum(temps[i+1:len(s)])
print(temp)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
flag = True
count = 0
while flag:
	flag = False
	for i in range(len(s) - 1):
		if s[i:i+2] == "BW":
			s = s[:i] + "WB" + s[i+2:]
			count += 1
			flag = True
print(count)

Submission status: Time Limit Exceeded

Solution code:
def rle(t):
    tmp2, num, ans = t[0], 1, []
    for i in range(1, len(t)):
        if tmp2 == t[i]:
            num += 1
        else:
            ans.append([tmp2, num])
            tmp2 = t[i]
            num = 1
    ans.append([tmp2, num])
    return ans


S = input()

s = list(map(str, S))
l = rle(S)
count = 0
while True:
    count2 = 0
    for j in range(len(s) - 1):
        if s[j] == 'B' and s[j+1] == 'W':
            s[j] = 'W'
            s[j+1] = 'B'
            count += 1
            count2 += 1
    if count2 == 0:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
S_list=list(S)
num_B = S.count('W')
count = 0
for nb in range(num_B):
  i = nb
  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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
S = S()
ans = 0
while 1:
    if S.count('BW')==0:
        break
    ans += S.count('BW')
    S = S.replace('BW','WB')
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
ans = 0
while True:
    for i in range(len(s)-1):
        if s[i]+s[i+1]=='BW':
            s[i], s[i+1] = s[i+1], s[i]
            ans += 1
            break
    else: break
    continue
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

while True:
    count = 0
    for i in range(0, len(S)-1):
        if S[i] == "B" and S[i+1] == "W":
            count += 1
            S[i] = "W"
            S[i+1] = "B"
    if count > 0:
        ans += count
    else:
        print(ans)
        exit()

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

ans = 0
for i in range(len(s)):
    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"


print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
prev = None
while prev != ans:
    prev = ans
    ans += S.count("BW")
    S = S.replace("BW", "WB")
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    s=list(input())
    cnt=0
    while True:
        flag=True
        for i in range(len(s)-1):
            if s[i]=='B' and s[i+1]=='W':
                cnt+=1
                s[i],s[i+1]='W','B'
                flag=False
        if flag:
            break
    print(cnt)
resolve()

Submission status: Time Limit Exceeded

Solution code:

def resolve():
    s=input()
    cnt=0
    while s.count('BW')>=1:
        s=list(s)
        for i in range(len(s)-1):
            if s[i]=='B' and s[i+1]=='W':
                cnt+=1
                s[i],s[i+1]='W','B'
        s=''.join(s)
    print(cnt)

resolve()

Submission status: Time Limit Exceeded

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

ans = 0
count = 0
for i in range(n):
    if s[i] == "W":
        ans += s[: i].count("B")

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
ans = 0
while S.count('BW') > 0:
  ans += S.count('BW')
  S = S.replace('BW','WB')

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0
for i in range(1,len(s)):
  if s[i] == "W":
    a = s[:i].count("W")
    b = len(s[:i+1])
    ans += b - a - 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt = 0

while s.count('BW'):
    cnt += s.count('BW')
    s = s.replace('BW', 'WB')
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = 0
while True:
	if "BW" not in S:
		break
	ans += S.count("BW")
	S = S.replace("BW", "WB")

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = 0
while True:
	if "BW" not in S:
		break
	S = S.replace("BW", "WB", 1)
	ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
while "BW" in S:
    S = S.replace("BW", "WB", 1)
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:

def main():
	S = list(input())
	n = len(S)
	ans = 0

	while(True):
		count = 0

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

		if(count == 0):
			break

		ans += count
		
	print(ans)

if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


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

Submission status: Time Limit Exceeded

Solution code:
S = input()

cnt = 0
while 'BW' in S:
    S = S.replace('BW', 'WB', 1)
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = str(input())
    count = 0
    for i in range(1, len(N)):
        target = N[i]
        if target == 'W':
            for j in range(0, i):
                if N[j] == 'B':
                    count = count + 1
    print(count)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_list = []
for i in range(len(s)):
  s_list.append(s[i])
answer = 0
answer_old = 1
answer_new = -1
i = 0
while answer_new != answer_old:
  answer_old = answer
  for j in range(i,len(s)):
    if s_list[j] == "B":
      i = j
      break
  for j in range(i,len(s)-1):
    if s_list[j] == "B" and s_list[j+1] == "W":
      s_list[j] = "W"
      s_list[j+1] = "B"
      answer += 1
  answer_new = answer
print(answer)

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_list = []
for i in range(len(s)):
  s_list.append(s[i])
answer = 0
answer_old = 1
answer_new = -1
while answer_new != answer_old:
  answer_old = answer
  for i in range(len(s)-1):
    if s_list[i] == "B" and s_list[i+1] == "W":
      s_list[i] = "W"
      s_list[i+1] = "B"
      answer += 1
    answer_new = answer
print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
ss =[1 if s=='B' else 0 for s in input()]

def babble_sort(arr,ans):
    length = len(arr)

    for i in range(length):
        for j in reversed(range(i+1, length)):
            if arr[j-1] > arr[j]:
                arr[j-1], arr[j] = arr[j], arr[j-1]
                ans+=1
    return ans

ans = babble_sort(ss,0)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
Ans = 0
sousa = 1
while sousa >= 1:
    sousa = 0
    for i in range(len(S)-1):
        if S[i] == 'B' and S[i+1] == 'W':
            S[i] = 'W'
            S[i+1] = 'B'
            Ans += 1
            sousa += 1
print(Ans)