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:
def hasbw(a):
    s=-1
    for ii in range(len(a)):
        if a[ii] == "B" and s == -1:
            s = ii
        if a[ii] == "W" and s != -1:
            return s,ii,ii-s
    return -1, -1, -1

if __name__ == "__main__":    
    oth = input()
    i = 0

    while True:
        h, w, l = hasbw(oth)
        if h == -1:
            break
        oth = oth[:h] + ''.join(list(reversed(oth[h:w+1]))) + oth[w+1:]
        i += l
    print(i)

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0
flag = True

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:
s = list(input())
count = 0
iter_flag = True
while iter_flag:
    for i in range(len(s)-1):
        if s[i]+s[i+1] == "BW":
            s[i] = "W"
            s[i+1] = "B"
            count += 1
            break
        if i == len(s)-2 and s[i] + s[i+1] != "BW":
            iter_flag = False
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = input()
num = 0
count = None

while count != 0:
    count = N.count("BW")
    num += count
    N = N.replace("BW", "WB")

print(num)

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

is_all_swappd = False
n_swap = 0
n_white = s.count('W')
for i in range(n_white):
    w_idx = None
    if i == 0:
        w_idx = s.find('W')
    else:
        w_idx = s[last_w_idx + 1:].find('W') + last_w_idx + 1
    n_swap += s[:w_idx].count('B')
    last_w_idx = w_idx

print(n_swap)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

S = input()


def irekae(str):
    return str.replace('BW', 'WB', 1)


count = 0
while 'BW' in S:
    S = irekae(S)
    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
a = [0]*len(S)
for i in range(len(S)):
    if S[i] == 'B':
        a[i] = 1

r = 0
chk = True
while chk:
    chk = False
    flg = False
    for i in range(len(a)-1):
        if flg:
            flg = False
            continue
        if a[i] == 1 and a[i+1] == 0:
            chk = True
            flg = True
            a[i] = 0
            a[i+1] = 1
            r += 1
print(r)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input().rstrip())
N = len(S)
C = 0
while True:
    flag = 0
    for i in range(N-1):
        #print(S)
        if S[i] == "B":
            if S[i+1] == "W":
                S[i] = 'W'
                S[i+1] = 'B'
                C += 1
                flag += 1
    
    if flag == 0:
        break
print(C)

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')&(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().strip())
is_irrversible = 0
answer = 0
while is_irrversible == 0:
    answer_when_start = answer
    for i in range(len(S)-1):
        if S[i] == 'B' and S[i+1] == 'W':
            S[i],S[i+1] = 'W','B'
            answer += 1
    if answer_when_start == answer:
        is_irrversible = 1
print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
listS = list(S)
done = False

x = 0
n = 0

while not done:
	for i in range(len(listS)-1):
		if listS[i] == "B" and listS[i+1] == "W":
			listS[i] = "W"
			listS[i+1] = "B"
			x += 1
			n += 1

	if x == 0:
		print(n)
		done = True
	x = 0

Submission status: Time Limit Exceeded

Solution code:
s = input()

counter = 0
while 'BW' in s:
    counter += s.count('BW')
    s = s.replace('BW', 'WB')

print(counter)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys

S = input()
count,chk_count=0,0
for i in range(sys.maxsize):
    chk_count=count
    count+=S.count("BW")
    S=S.replace("BW","WB")
    if chk_count == count:
        print(count)
        exit()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt = 0
while i < len(S) - 1:
    key = i
    #print(i)
    if S[i] == "B" and S[i + 1] == "W":
        S[i] = "W"
        S[i + 1] = "B"
        cnt += 1
        j = i - 1
        while True:
            #print(0, 0, j, S[j], S[j + 1])
            if j < 0:
                break
            if S[j] == "B" and S[j + 1] == "W":
                S[j] = "W"
                S[j + 1] = "B"
                #print(10000)
                cnt += 1
                key = j
                j -= 1
            else:
                break
    i = key
    i += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

i = 0
answer = 0

def back_check(S, m, answer):
	for i in range(m, 0, -1):
		m_color = S[i-1]
		n_color = S[i]
		if m_color == 'B' and n_color == 'W':
			S[i-1] = 'W'
			S[i] = 'B'
			answer += 1
		else:
			break

	return S, answer

while i < len(S)-1:
	i_color = S[i]
	j_color = S[i+1]
	if i_color == 'B' and j_color == 'W':
		S[i] = 'W'
		S[i+1] = 'B'
		answer += 1
		S, answer = back_check(S, i, answer)

	i += 1

print(answer)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

S = input()
S = list(S)
S = np.array(S)

index_black = np.where(S=="B")[0]

count = 0
for i in index_black:
    count += np.sum(S[i+1:]=="W")

print(count)

Submission status: Time Limit Exceeded

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

ans = 0

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



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

    if  'BW' not in s:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

total = 0
cnt = s.count("BW")
while cnt > 0:
    total += cnt
    s = s.replace("BW", "WB")
    cnt = s.count("BW")

print(total)

Submission status: Time Limit Exceeded

Solution code:
S=list(input())

while S[0]=="W":
	S.pop(0)

n=S.count("W")

c=0
for i in range(n):
	c+= S.index("W")-i
	S[S.index("W")]="X"

print(c)

Submission status: Time Limit Exceeded

Solution code:
N = input()
num = 0

while 1:
    count = N.count("BW")
    num += count

    if count == 0:
        break
    
    else:
        N = N.replace("BW", "WB")

print(num)

Submission status: Time Limit Exceeded

Solution code:
black = "B"
white = "W"
s = ""

def main():
    global s
    s = [c for c in input()]
    ans = one()
    tmp = ans
    while tmp != 0:
        tmp = one()
        ans += tmp
    print(ans) 

def one():
    global s
    ans = 0
    for i in range(len(s) - 1):
        if s[i] == black and s[i+1] == white:
            s[i], s[i+1] = s[i+1], s[i]
            ans += 1
    return ans

main()

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
def n(S, count=0):
    S = list(S)
    for i in range(len(S)-1):
        if S[i] == "B" and S[i+1] == "W":
            S[i] = "W"
            S[i+1] = "B"
            return n(S, count+1)
    return count
print(n(S), flush=True)

Submission status: Time Limit Exceeded

Solution code:
s = [_ for _ in input()]


def f(s):
  result = 0
  for i in range(len(s)-1):
    if s[i] == 'B' and s[i+1] == 'W':
      result += 1
      s[i] = 'W'
      s[i+1] = 'B'
  return result

result = 0
while True:
  temp = f(s)
  if temp == 0:
    break
  else:
    result += temp
print(result)

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_list = list(s)
s_len = len(s)
count = 0
count_cur = 0
count_before = None
while(count != count_before):
  count_cur = 0
  for i in range(s_len-1):
    if s_list[i] == 'B' and s_list[i+1] == 'W':
      count_cur += 1
      s_list[i] = 'W'
      s_list[i+1] = 'B'
  count_before = count
  count += count_cur 

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input().rstrip())
N = len(S)
C = 0
for h in range(1000):
    for i in range(N-1):
        if S[i] == "B":
            if S[i+1] == "W":
                S[i] = 'W'
                S[i+1] = 'B'
                C += 1
print(C)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
count=0
i=0
while True:
  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
        i+=1
        flag=0
  if flag==1:
    break

print(count)

Submission status: Time Limit Exceeded

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

for i in range(len(listS)):
	if listS[i] == "B":
		listS[i] = 0
	if listS[i] == "W":
		listS[i] = 1
		
done = False

x = 0
n = 0

while not done:
	for i in range(len(listS)-1):
		if listS[i] < listS[i+1]:
			listS[i] = 1
			listS[i+1] = 0
			x += 1
			n += 1

	if x == 0:
		print(n)
		done = True
	x = 0

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = 0
while True:
    idx = S.find('BW')
    if idx == -1:
        break
    S = S[:idx] + 'WB' + S[idx +2:]
    N += 1
print(N)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = input()
num = 0

while 1:
    count = N.count("BW")
    if count == 0:
        break
    
    else:
        N = N.replace("BW", "WB", 1)
        num += 1

print(num)

Submission status: Time Limit Exceeded

Solution code:
S=list(input())

while S[0]=="W":
	S.pop(0)


c=0
while "W" in S:
	c+=S.index("W")
	S.pop(S.index("W"))

print(c)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
cnt = 0
ans = 0
while True:
    if 'W' not in s:
        break
    
    for i in range(len(s)):
        if s[i] == 'B':
            cnt += 1
        else:
            ans += cnt
            cnt = 0
            s.pop(i)
            break

print(ans)

Submission status: Time Limit Exceeded

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

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')&(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:
def countup(S,x):
    counting = S[:x]
    return counting.count("B")



S = input()

count = 0
for i in range(len(S)):
    if S[i] == "W":
        count += countup(S,i)

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input().strip()
Sb = [c == "B" for c in S]

def reverse(Sb,i):
    _list = Sb.copy()
    _list[i] = not _list[i]
    return _list

def operate_onestep(Sb):
    _list = Sb.copy()
    cnt = 0
    flg = True
    while flg:
        flg = False
        for i in range(len(_list)-1):
            if _list[i] and not _list[i+1]:
                cnt += 1
                _list = reverse(_list,i)
                _list = reverse(_list,i+1)
                flg = True
    return cnt

print(operate_onestep(Sb))

Submission status: Time Limit Exceeded

Solution code:
st = input()
lst = [i for i in st]
N = len(lst)
idx = 0
while(True):
    ind = 0
    for i in range(N - 1):
        if lst[i] == 'B' and lst[i + 1] == 'W':
            idx += 1
            ind += 1
            lst[i] = 'W'
            lst[i + 1] = 'B'
    if ind == 0:
        break

print(idx)

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0
while 'BW' in S:
    for i in range(len(S)):
        if S[i:i+2] == 'BW':
            lS = list(S)
            lS[i:i+2] = ['W', 'B']
            S = ''.join(lS)
            count += 1
print(count)

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:
#!/mnt/c/Users/moiki/bash/env/bin/python
s = input()
s = s.replace('B', '1')
s = s.replace('W', '0')
s = list(s)

# print(s)
cnt = 0
def bsort(a):
    global cnt
    for i in range(len(a)-1):
        for j in range(i, len(a)):
            if int(a[j-1]) > int(a[j]):
                cnt += 1
                a[j-1] = '0'
                a[j] = '1'

bsort(s)
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def count(s):
    if "W" not in s or not s:
        return 0
    w_idx = s.index("W")
    return w_idx + count(s[:w_idx] + s[w_idx + 1:])
s = list(input())
print(count(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
count = 0
flag = 1
while flag:
    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
                break
        elif i+1 == len(S):
            flag = 0
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0
for i, c in enumerate(s):
    # print(i, c)
    if c == 'B':
        num_W=0
        for ac in s[i:]:
            # print(ac)
            if ac == 'W':
                num_W+=1
            # print('num = ', num_W)
        ans += num_W
    # print("ans = ", ans)

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(len(listS)):
	if listS[i] == "B":
		listS[i] = 0
	if listS[i] == "W":
		listS[i] = 1
		
done = False

listX = []
listN = []

while not done:
	for i in range(len(listS)-1):
		if listS[i] < listS[i+1]:
			listS[i] = 1
			listS[i+1] = 0
			listN.append(0)
			listX.append(0)

	if len(listX) == 0:
		print(len(listN))
		done = True
	listX.clear()

Submission status: Time Limit Exceeded

Solution code:
S=input()
count=0

while 'BW' in S:
    ind=S.index('BW')
    S=S[:ind]+'WB'+S[ind+2:]
    count=count+1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = input()
a = [i for i in n]
ans = 0
n = len(n)
for j in range(20000):
    flag = 1
    for i in range(n-2,-1,-1):
        if a[i+1] == "W" and a[i] == "B":
            a[i] = "W"
            a[i+1] = "B"
            ans += 1
            flag = 0
            x = i+1
            while x<n-1:
                if a[x+1] == "W" and a[x] == "B":
                    a[x] = "W"
                    a[x+1] = "B"
                    ans += 1
                    x+=1
                else:
                    break
    if flag ==1:
        break
print(ans)

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")
    if cnt==0:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
word = input()


#%%
# word = "BBBWWW"


#%%
ans = 0
for i in range(len(word)):
    if word[i] == "B":

        ans += len(word[i+1:].replace("B",""))
    
print(ans)
#%%


#%%

Submission status: Time Limit Exceeded

Solution code:
S = input()
list = []
a = 0
for i in range(len(S)):
    list.append(S[i])

while True:
    b = a
    for i in range(len(S)-1):
        if list[i]=='B' and list[i+1]=='W':
            list[i]='W'
            list[i+1]='B'
            a += 1
    if a == b:break
print(a)

Submission status: Time Limit Exceeded

Solution code:
black = "B"
white = "W"

def main():
    s = [c for c in input()]
    ans = one(s)
    tmp = ans
    while tmp != 0:
        tmp = one(s)
        ans += tmp
    print(ans) 

def one(s):
    ans = 0
    for i in range(len(s) - 1):
        if s[i] == black and s[i+1] == white:
            s[i], s[i+1] = s[i+1], s[i]
            ans += 1
    return ans

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
S = input()
cnt = sum(S[0:i].count("B") for i in range(len(S)) if S[i]=="W")
print(cnt)

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=input()
count=0

def search_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return False

while 'BW' in S:
    ind=search_index(S,'BW')
    S=S[:ind]+'WB'+S[ind+2:]
    count=count+1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

count = 0
end = False
while not end:
    S2 = S.replace('BW', 'WB', 1)
    count += 1
    if S2 == S:
        count -= 1
        end = True
    S = S2
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

is_all_swappd = False
n_swap = 0
while is_all_swappd is not True:
    start_idx = s.find('BW')
    if start_idx != -1:
        s_list = list(s)
        s_list[start_idx], s_list[start_idx+1] = \
            s_list[start_idx+1], s_list[start_idx]
        n_swap += 1
        s = "".join(s_list)
    else:
        is_all_swappd = True

print(n_swap)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
count=0
end=0
while "BW" in S:
    i=S.count("BW")
    #i=S.find("BW") + 1
    S=S.replace("BW","WB",i)
    #count+=i-end
    count+=i
    #end+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
count = 0
found = True
while found:
  found = False
  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
      found = True
print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

S = list(input())
count,chk_count=0,0
for i in range(sys.maxsize):
    chk_count=count
    for j in range(len(S)-1):
        if S[j]=="B" and S[j+1]=="W":
            S[j],S[j+1] ="W","B"
            count+=1
    if chk_count == count:
        print(count)
        exit()

Submission status: Time Limit Exceeded

Solution code:
S = input().strip()
Sb = [c == "B" for c in S]

def reverse(Sb,i):
    _list = Sb.copy()
    _list[i] = not _list[i]
    return _list

def operate(Sb):
    _list = Sb.copy()
    cnt = 0
    while True:
        for i in range(len(_list)-1):
            if _list[i] and not _list[i+1]:
                cnt += 1
                _list = reverse(_list,i)
                _list = reverse(_list,i+1)
                break
        else:
            break
    return cnt
  
print(operate(Sb))

Submission status: Time Limit Exceeded

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

while True:
    i = 0
    _cnt = 0
    while i<len(S)-1:
        if S[i] == 'B' and S[i+1] == 'W':
            S[i] = 'W'
            S[i+1] = 'B'
            _cnt += 1
            i += 1
        else:
            i += 1
    cnt += _cnt
    if _cnt == 0:
        break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def hasbw(a):
    for ii in range(len(a)-1):
        if a[ii] == "B" and a[ii+1] == "W":
            return ii
    return -1

if __name__ == "__main__":    
    oth = input()
    i = 0

    while True:
        h = hasbw(oth)
        if h == -1:
            break
        oth = oth[:h] + "WB" + oth[h+2:]
        i += 1
    print(i)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
slist = list(S)
L = len(slist)
count = 0
for i in range(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
  else:
    fcount = 0
    for j in range(L-1):
        if j < L-1 and slist[j] == "B" and slist[j+1] == "W":
          slist[j],slist[j+1] = slist[j+1],slist[j]
          fcount+=1
    if fcount != 0:
      count+=fcount
      i = 0
print(count)

Submission status: Time Limit Exceeded

Solution code:
L = list(input())

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

cnt = 0

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
        j = i-1
        while j >= 0 and S[j] == 'B' and S[j+1] == 'W':
            S[j] = 'W'
            S[j+1] = 'B'
            cnt += 1
            j -= 1

ans = cnt
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
S = S[::-1]

R = 0

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

print(R)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

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


print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
count=0
end=0
while "BW" in S:
    i=S.find("BW") + 1
    S=S.replace("BW","BB",1)
    count+=i-end
    end+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = 0
while True:
    index = S.find('BW')
    if index == -1:
        break
    S = S.replace('BW', 'WB', 1)
    N += 1
print(N)

Submission status: Time Limit Exceeded

Solution code:


s = list(input())

count = 0

flag = True

while True:
    flag = True
    for i in range(len(s) - 1):
        if s[i] == 'B' and s[i+1] == 'W':
            count += 1
            s[i] = 'W'
            s[i+1] = 'B'
            flag = False
    if flag == True:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
count = 0
judge = 0
while True:
    if judge == len(S)-1:
        break
    else:
        judge = 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
            else:
                judge += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
s = list(S)
if len(s) == 1:
    print("1")
else:
    num_list = [s[:i].count("B") if s[i] == "W" else 0 for i in range(1, len(s))]
    print(str(sum(num_list)))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
ans = 0
judge = True

while judge:
    count = 0
    for i in range(1,len(s)):
        if s[-i] == "W" and s[-i-1] == "B":
            ans += 1
            s[-i] = "B"
            s[-i-1] = "W"
            count += 1
    if count == 0:
        judge =False
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
a = 0
while s.count("BW") > 0:
    i = s.rfind("BW")
    s = s[:i] + "W" + "B" + s[i+2:]
    a += 1
print(a)

Submission status: Time Limit Exceeded

Solution code:
S=list(input())

def func(ls, n):
    m=0
    for i in range(len(ls)-1):
        if ls[i]=='B' and ls[i+1]=='W':
            ls[i]='W'
            ls[i+1]='B'
            n+=1
            m+=1
    if m==0:
        return n
    else:
        return func(ls, n)
print(func(S,0))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=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 = list(input())
count = 0


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

print(count)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
k=s.count("W")
c=0
for i in range(k):
    t=s.index("W")
    c+=t-i
    s[t]=0
print(c)

Submission status: Time Limit Exceeded

Solution code:
S = input()
s = list(S)
num_list = [s[:i].count("B") if s[i] == "W" else 0 for i in range(1, len(s))]
print(str(sum(num_list)))

Submission status: Time Limit Exceeded

Solution code:
n = input()
a = [i for i in n]
ans = 0
for j in range(20000):
    flag = 1
    for i in range(len(n)-2,-1,-1):
        if a[i+1] == "W" and a[i] == "B":
            a[i] = "W"
            a[i+1] = "B"
            ans += 1
            flag = 0
    if flag ==1:
        break
print(ans)