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 = input()
n = len(s)
# 各 B の左にある B の数の和が答え
ans = 0
for i in range(1, n):
    if s[i] == "W":
        ans += s[:i].count("B")
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
num = 0
while(True):
    num += S.count("BW")
    S = S.replace("BW", "WB")
    if not "BW" in S:
        break
print(num)

Submission status: Time Limit Exceeded

Solution code:
def reverse(word):
    cnt=0
    while "BW" in word:
        word=word[0:word.find("BW")]+"WB"+word[word.find("BW")+2:]
        cnt+=1
    return cnt
print(reverse(input()))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()[::-1]
B='BW';A='WB'
a=0
L=len(S)
i=0
while i<=L-2:
  if S[i:i+2]==A:
    S=S[0:i]+B+S[i+2:]
    a+=1
    i=0
  i+=1
print(a)

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0
while True:
    c = S.count('BW')
    if c == 0:
        break
    S = S.replace('BW', 'WB')
    count += c
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
ans=0
while True:
    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"
            ans+=1
    for j in range(s.count("W")):
        if s[j]=="W":
            cnt+=1
    if cnt==s.count("W"):
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# https://beta.atcoder.jp/contests/agc029/tasks/agc029_a


def main():
    S = list(input())
    count = 0
    while len(S) > 0:
        if S.count("B") == 0:
            break
        if S[-1] == "B":
            S = S[0:-1]
            continue

        for i in range(len(S)-1, -1, -1):
            if S[i] == "B":
                count += len(S) - 1 - i
                # print("{}, {}".format(len(S) - 1, i))
                S[i] = "W"
                S = S[0:-1]
                break

    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
s = sorted(S)[::-1]
def change(x):
    n = len(x) - 1
    rev = x[::-1]
    indexB = x.index('B')
    indexW = n -  rev.index('W')
    x[indexB] = 'W'
    x[indexW] = 'B'
    return indexW - indexB
cnt = 0 
while True:
    if s == S:
        break
    cnt += change(S)
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
ar = list(input())
count = 0
tc = 0
while True:
    i = 0
    while True:
        if ar[i] == "B" and ar[i+1] == "W":
            ar[i],ar[i+1] = ar[i+1],ar[i]
            i += 2
            count += 1
            tc += 1
        else:
            i += 1
        if i >= len(ar)-1:
            break
    if count == 0:
        break
    else:
        count = 0
print(tc)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

input_s = input()
s_lst = [1 if s == 'B' else 0 for s in input_s]

s_lst = np.array(s_lst)
count = 0

for i in range(len(s_lst)-1 , 0, -1):
    for j in range(i):
        if (s_lst[j] == 1) and (s_lst[j+1] == 0):
            s_lst[j] = 0
            s_lst[j+1] = 1
            count += 1
            
s = s_lst.tolist()
s = ['B' if s == 1 else 'W' for s in s_lst.tolist()]
s = ''.join(s)
print(count)

Submission status: Time Limit Exceeded

Solution code:
input_s = input()
s_lst = [s for s in input_s]
count = 0

for i in range(len(s_lst)-1 , 0, -1):
    for j in range(i):
        if (s_lst[j] == 'B') and (s_lst[j+1] == 'W'):
            s_lst[j] = 'W'
            s_lst[j+1] = 'B'
            count += 1
            
s = ''.join(s_lst)
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
L = []
for i in S[::-1]:
    if i == "W":
        L.append(0)
    if i == "B":
        L = [ j+1 for j in L ]

print(sum(L))

Submission status: Time Limit Exceeded

Solution code:
import re
import sys

line = next(sys.stdin).strip()

count = 0
to_add = len(re.findall('BW', line))
while to_add:
    count += to_add
    line = line.replace('BW', 'WB')
    to_add = len(re.findall('BW', line))

print(count)

Submission status: Time Limit Exceeded

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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = list(input())
N = len(S)

i = 1
cnt = 0
while i < N:
    if S[i-1] == 'B' and S[i] == 'W':
        S[i-1], S[i] = S[i], S[i-1]
        cnt += 1
        # 入れ替わったら、1マス後ろを再確認
        if i > 1: 
            i -= 2
    i += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=input()
ans=0
for  i in range(10**5):
  if s.count("BW")==0:
    print(ans)
    exit()
  ans+=s.count("BW")
  s=s.replace("BW","WB")

Submission status: Time Limit Exceeded

Solution code:
s=input()
ans=0
for  i in range(10**5):
  if s.count("BW")==0:
    print(ans)
    exit()
  s=s.replace("BW","WB",1)
  ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
c = 0
while 'BW' in s:
  c += 1
  s = s.replace("BW", "WB", 1)
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()[::-1];i=0
while'WB'in s:s=s.replace('WB','BW',1);i+=1
print(i)

Submission status: Time Limit Exceeded

Solution code:
s=list(input().replace(""," ").split())
cnt=0
exchange=1
while exchange!=0:
  exchange=0
  for i in range(len(s)-1):
    if s[i]=="B" and s[i+1]=="W":
      cnt+=1
      s[i],s[i+1]=s[i+1],s[i]
      exchange+=1
print(cnt)

Submission status: Time Limit Exceeded

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

ans = 0


def check():

    counter = 0
    for i in range(0, len(str)-1):
        if(str_list[i] == 'B' and str_list[i+1] == 'W'):
            counter += 1
            ans += 1
            str_list[i] = 'W'
            str_list[i+1] = 'B'
    if counter != 0:
        check()
    else:
        global ans
        print(ans)


check()

Submission status: Time Limit Exceeded

Solution code:
S = input()
counter = 0
while True:
    tmp = S.replace("BW", "WB", 1)
    if S == tmp:
        break
    S = tmp
    counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
S = input()
counter = 0
while True:
    if S == S.replace("BW", "WB", 1):
        # 終わった
        break
    S = S.replace("BW", "WB", 1)
    counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
for i in range(len(s)):
  ans += s.count("BW")
  s = s.replace("BW", "WB")
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input().rstrip())

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()

cnt = 0

for i in range(len(S)):
    if (i != 0):
        if S[i] == 'W':
            for _ in range(i):
                if S[_] == 'B':
                    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()


count = 0

for i,x in enumerate(s):
  if x=='B':
    count += s[i:].count('W')

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

idx = [i for i,x in enumerate(s) if x =='W']


count = 0
for i in idx:
  count += s[0:i].count('B')
  
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
s = input()
S = []
for i in s:
  if i =='B':
    S.append(1)
  else:
    S.append(0)
idx = [i for i,x in enumerate(S) if x ==0]
S = np.array(S)
count = 0
for i in idx:
  count += S[0:i].sum()
  
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

"""
https://atcoder.jp/contests/agc029/tasks/agc029_a
"""

import sys
import re


s = sys.stdin.readline().rstrip()
s2 = ''
cnt = 0

while True:
    s = re.sub('^W+','',s)
    s = re.sub('B+$','',s)
    s2 = s.replace('BW', 'WB', 1)
    if s2 == s:
        break
    cnt += 1
    s = s2


print(cnt)

Submission status: Time Limit Exceeded

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

"""
https://atcoder.jp/contests/agc029/tasks/agc029_a
"""

import sys


s = sys.stdin.readline().rstrip()
s2 = ''
cnt = 0

while True:
    s2 = s.replace('BW', 'WB', 1)
    if s2 == s:
        break
    cnt += 1
    s = s2


print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
pattern = ['B', 'W']
count = 0
while True:
    now_count = 0
    for k in range(len(s) - 1):
        if s[k:k+2] == pattern:
            s[k:k+2] = ['W', 'B']
            now_count = now_count + 1
    if now_count == 0: break
    else: count = count + now_count
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
ans = 0
for i in range(s.count("W")):
    ans += s.index("W")
    s.pop(s.index("W"))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

state = list(input())
print_state = "".join(state)

times = 0
while "BW" in print_state:
    for i in range(len(state)):
        if state[i] == "B":
            if i < len(state)-1 and state[i+1] == "W":
                state[i] = "W"
                state[i+1] = "B"
                times += 1
                print_state = "".join(state)
                
print(times)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

state = list(input())
print_state = "".join(state)

times = 0
while "BW" in print_state:
    for i in range(len(state)):
        if state[i] == "B":
            if i < len(state)-1 and state[i+1] == "W":
                state[i] = "W"
                state[i+1] = "B"
                times += 1
                print_state = "".join(state)
                
print(times)

Submission status: Time Limit Exceeded

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

count = 0

while True:
    flag = False
    i = S.find('BW')
    if i == -1:
        flag = True
    else:
        S = S[:i] + 'WB' + S[i+2:]
        count += 1
    if flag:
        break

print(count)

Submission status: Time Limit Exceeded

Solution code:
k = 0
try:
    s=[]
    while True:
        t = input()
        s.append(t)
        
except EOFError:
    pass
k = len(s[0])

a = {}
i = 0
for i in  range (k):
  if(s[0][i] == "B"):
    #a.append(0)
    a[i] = 0
  else:
    #a.append(1)
    a[i] = 1
#  print(a[i])
#print(a)

count = 0

#print(a[0])

while(1):
  loop_count = 0
  i = 0
  while (i < k-1):
    
    if(a[i] == 0 and a[i+1] == 1):
      a[i]  = 1
      a[i+1] = 0
      count += 1
      loop_count += 1
      
    i += 1
    
    
  if(loop_count == 0):
    break;
print(count)

Submission status: Time Limit Exceeded

Solution code:
k = 0
try:
    s=[]
    while True:
        t = input()
        s.append(t)
        
except EOFError:
    pass
k = len(s[0])

a = {}
i = 0
for i in  range (k):
  if(s[0][i] == "B"):
    #a.append(0)
    a[i] = 0
  else:
    #a.append(1)
    a[i] = 1
#  print(a[i])
#print(a)

count = 0

#print(a[0])

while(1):
  loop_count = 0
  i = 0
  while (i < k-1):
    
    if(a[i] == 0 and a[i+1] == 1):
      a[i]  = 1
      a[i+1] = 0
      count += 1
      loop_count += 1
      i = 0
    i += 1
    
    
  if(loop_count == 0):
    break;
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(ctr)

Submission status: Time Limit Exceeded

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

for _ in range(len(string)):

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

print(n)

Submission status: Time Limit Exceeded

Solution code:
list1=list(input())
count=0
fin=0
while fin==0 and len(list1)>1:
    frug=0
    for i in range(len(list1)-1):
        if list1[i]=="B" and list1[i+1]=="W":
            count+=1
            list1[i]="W"
            list1[i+1]="B"
            frug=1
        if i==len(list1)-2 and frug==0:
            fin=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a=input()
n=len(a)
s=[]
for i in range(n):
  s.append(a[i])
flag=1
cnt=0

while(flag==1):
  flag=0
  for i in range(n-1):
    if s[i]=="B" and s[i+1]=="W":
      s[i]="W"
      s[i+1]="B"
      i+=1
      flag=1
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
l=input()
c=0

while("BW" in l):
  c += l.count("BW")
  l=l.replace("BW","WB")

print(c)

Submission status: Time Limit Exceeded

Solution code:
def turn_over(text):
    if "BW" in text:
        return True, text.replace("BW", "WB", 1)
    else:
        return False, text


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

    while (True):
        is_BW, text = turn_over(text)
        if is_BW:
            total += 1
        else:
            break

    print(total)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
narabi = list(input())
kaisu = 0

while True:
    owari = True
    for num,(isi, tugi) in enumerate(zip(narabi[:-1],narabi[1:])):
        if isi=="B" and tugi=="W":
            narabi[num]="W"
            narabi[num+1]="B"
            kaisu+=1
            owari=False
    if owari:
        break

print(kaisu)

Submission status: Time Limit Exceeded

Solution code:
narabi = list(input())
kaisu = 0

while True:
    for num,(isi, tugi) in enumerate(zip(narabi[:-1],narabi[1:])):
        if isi=="B" and tugi=="W":
            narabi[num]="W"
            narabi[num+1]="B"
            kaisu+=1
            break
    else:
        break
print(kaisu)

Submission status: Time Limit Exceeded

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

for k in range(len(s)):
  if s[k]=='B':
    s[k]=1
  if s[k]=='W':
    s[k]=0

#print(s)
ans=0
for k in range(len(s)):
  if s[k]==0:
    ans+=sum(s[:k])

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
c = 0
s = input()
while 'BW' in s:
    s = s.replace('BW', 'WB', 1)
    c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
import collections
s = list(input())
n = len(s)
check = True
counter = 0
while check:
    temp = False
    for i in range(n-1):
        if s[i] == "B" and s[i+1] == "W":
            s[i] = "W"
            s[i+1] = "B"
            counter += 1
            temp = True
    if temp == False:
        check = False
print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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
            break
    i+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = 'B'  
y = 'W'

str_list = list(input())

i = 0
cnt = 0
old_cnt = -1
while True:
    if str_list[i] == 'B' and str_list[i+1] == 'W':
        str_list[i] = 'W'
        str_list[i+1] = 'B'
        cnt += 1
    i += 1
    if i == len(str_list) - 1:
        i = 0
        if old_cnt == cnt:
            break
        else:
            old_cnt = cnt
            continue
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count = 0
while True:
    S = S.replace("BW", "#")
    tmp_count = S.count("#")
    count += tmp_count
    S = S.replace("#", "WB")

    if tmp_count == 0:
        break

print(count)

Submission status: Time Limit Exceeded

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

count = 0
while True:
    DID = 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
            DID = True

    if not DID:
        break

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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):
        if(s[j]=='B'):
            if(s[j + 1]=='W'):
                s[j]="W"
                s[j+1]="B"
                count += 1
            else:
                continue
        else:
            continue
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_len = int(len(s))
count = 0
n = int(s_len*(s_len+1)/4)
for _ in range(n):
  num = s.count('BW')
  if num == 0:
    break
  s = s.replace('BW','WB',int(s_len/2))
  count += num
print(count)

Submission status: Time Limit Exceeded

Solution code:
Ans=0
N=input()

while 'BW' in N:
    r=N.count('BW')
    N=N.replace('BW','WB',r)
    Ans+=r
print(Ans)

Submission status: Time Limit Exceeded

Solution code:
import math
S = input()
b = S.count('B')
num = max(b,len(S)-b)
print(math.factorial(num))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
Ans=0
N=input()

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_len = int(len(s))
count = 0
n = int(s_len*(s_len+1)/4)
for _ in range(n):
  num = s.count('BW')
  s = s.replace('BW','WB')
  count += num
print(count)

Submission status: Time Limit Exceeded

Solution code:
s=input()
ans=0
lastWi=s.rfind('W')
if lastWi==-1 or s=='B' or s=='W':
    print(0)
    exit()
s=s[:lastWi+1]
while True:
    bi=s.find('B')
    if bi != -1:
        ans += s[bi:].count('W')
        s=s[bi+1:]
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def changeStr(in_str, tgt_idx):
    work_str = ""

    # Left
    if tgt_idx != 0:
        work_str = in_str[:tgt_idx]

    # Target
    if in_str[tgt_idx] == "W":
        work_str += "BW"
    else:
        work_str += "WB"
    
    # Right
    if tgt_idx < len(in_str) -2:
        work_str += in_str[tgt_idx+2:]
    
    return work_str

# Input
s = input()

idx = 0
sav_idx = -1
max_idx = -1
cnt = 0
ret_flg = False
while idx < len(s)-1:

    if idx == sav_idx:
        idx += 1
    # BW or WB
    if (s[idx] == "B" and s[idx+1] == "W") or (s[idx] == "W" and s[idx+1] == "B"):
        s = changeStr(s, idx)

        cnt += 1
        sav_idx = idx
        if max_idx < idx:
            max_idx = idx

        idx -= 1
        ret_flg = True
        if idx < 0:
            idx = 0

    # BB or WW
    else:
        if ret_flg == False:
            idx += 1
        else:
            idx = max_idx + 1
            ret_flg = False
# Output
print(cnt)

Submission status: Time Limit Exceeded

Solution code:


def test(x,cnt,N):
    flg = N
    for i in range(x,N):
        if l[i-1] == "B" and l[i] == "W":
          l[i-1] = "W"
          l[i] = "B"
          cnt = cnt + 1
          #print(l)
          flg  = i-1
          #print(flg)
          break

    #print("re",flg)
    return flg,cnt

str = input()

l = list(str)

N = len(l)

#print(N)

#print(l[4])

cnt1 = 0

k = 1

while k < N:

    k,cnt1=test(k,cnt1,N)
    if k == 0:
        k =1
    #print(k)

print(cnt1)

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

Submission status: Time Limit Exceeded

Solution code:
src = input()
count = 0
 
while True:
    if 'BW' in src :
       src = src.replace('BW', 'WB', 1)
       count += 1
    else:
        break
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
  start = 0
  end = l-1
  for i in range(start, end):
    if slist[i:i+2] == ['B','W']:
      slist[i:i+2] = ['W','B']
      n += 1
      j = 1
      end = i
    start += 1

print(n)

Submission status: Time Limit Exceeded

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

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

print(n)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
count = [];
while('BW'in S):
  count.append(S.count('BW'));
  S = S.replace('BW','WB');
print(sum(count))

Submission status: Time Limit Exceeded

Solution code:
import re
S = str(input())
count = 0;
while('BW'in S):
  count=count+S.count('BW');
  S = re.sub('BW','WB',S);
print(count)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
c=i=0
while i<len(s)-1:
	t,u=s[i],s[i+1]
	if t>=u:i+=1
	else:
		t,u=u,t
		c+=1
		if i>1:i-=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#文字列と文字列の長さ取得、文字列をリスト化
S = input()
N = len(S)
S = list(S)

#文字列に"BW"が含まれていないかのチェック
i=0
count = 0
while(i<N):
	#iがリストの最後に到達するとbreak
	if(i==N-1):
		break
	else:
		#i番目が"B"でi+1番目が"W"のとき置き換え、置き換えた回数を数える。
		if(S[i] == 'B' and S[i+1] == 'W'):
			S[i] = 'W'
			S[i+1] = 'B'
			count = count + 1
			i = -1
	i = i + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

s = input()
s_bin =[]
for i in s:
  if i =='B':
    s_bin.append(1)
  else:
    s_bin.append(0)

renum = 0
old = 0

while(True):
  for i in range(len(s)-1):
      if s_bin[i]==1 and s_bin[i+1]==0:
        s_bin[i] = 0
        s_bin[i+1] = 1
        renum += 1
  if renum == old:
    break
  else:
    old = renum
    
print(renum)

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_len = int(len(s))
count = 0
n = int(s_len*(s_len+1)/4)
for _ in range(n):
  num = s.count('BW')
  if num == 0:
    break
  s = s.replace('BW','WB')
  count += num
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_len = int(len(s))
count = 0
n = int(s_len*(s_len+1)/2)
for _ in range(n):
  num = s.count('BW')
  if num == 0:
    break
  s = s.replace('BW','WB')
  count += num
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0
for index, value in enumerate(S):
    if value == 'W':
        count += S[0:index].count('B')

print(count)

Submission status: Time Limit Exceeded

Solution code:
def changeStr(in_str, tgt_idx):
    work_str = ""

    # Left
    if tgt_idx != 0:
        work_str = in_str[:tgt_idx]

    # Target
    if in_str[tgt_idx] == "W":
        work_str = work_str + "BW"
    else:
        work_str = work_str + "WB"
    
    # Right
    if tgt_idx < len(in_str) -2:
        work_str = work_str + in_str[tgt_idx+2:]
    
    return work_str

# Input
s = input()

idx = 0
sav_idx = -1
cnt = 0
while idx < len(s)-1:

    if idx == sav_idx:
        idx += 1
    # BW or WB
    if (s[idx] == "B" and s[idx+1] == "W") or (s[idx] == "W" and s[idx+1] == "B"):
        s = changeStr(s, idx)

        cnt += 1
        sav_idx = idx
        idx -= 1
        if idx < 0:
            idx = 0

    # BB or WW
    else:
        idx += 1
# Output
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
src = input()
count = 0
 
for  i in range(200000):
    if 'BW' in src :
       count += len(re.findall('BW', src))
       src = src.replace('BW', 'WB')
    else:
        break
print( count )

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

#S = 'BWBWBW'
S = input()
N = len(S)

buf = []
for s in S:
  if s == 'B':
    buf.append(0)
  else:
    buf.append(1)

count = 0
flag = True
#print(buf)

while flag:
  for i in range(N-1):
    if buf[i] == 0 and buf[i+1] == 1:
      buf[i] = 1
      buf[i+1] = 0
      #print(buf)
      count += 1
      break
  else:
    flag = False

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

def bubble_sort(arr):
    counter = 0
    change = True
    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
        if change == 0: break
    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 = 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:i+2] == ['B','W']:
      slist[i:i+2] = ['W','B']
      n += 1
      j += 1

print(n)

Submission status: Time Limit Exceeded

Solution code:
import re
src = input()
count = 0

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

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
c = 0
for l in range(len(s)-1, 0, -1):
  for i in range(l):
    if s[i] < s[i+1]:
      s[i], s[i+1] = s[i+1], s[i]
      c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
s = input()
count = 0
num = 1
for _ in range(math.factorial(len(s))):
  num = s.count('BW')
  if num == 0:
    break
  s = s.replace('BW','WB')
  count += num
  
print(count)