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 = list(input())
Ans = 0
k = 1
while k == 1:
    j = 0
    ren = 0
    for i in range(len(S)-1):
        if S[i] == 'B' and S[i+1] == 'W' and ren == 0:
            S[i] = 'W'
            S[i+1] = 'B'
            Ans += 1
            ren = 1
            j = 1
        elif S[i+1] == 'W' and ren == 1:
            S[i] = 'W'
            S[i+1] = 'B'
            Ans += 1
            ren = 1
            j = 1
        else:
            ren = 0
    if j == 0:
        k = 0
print(Ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
s = [si for si in s]
ans = 0
 
while True:
  st = ans
  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
  if st == ans:
    print(ans)
    break

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
s = input()
n = len(s)
ans = 0
while True:
    finish = True
    for i in range(n - 1):
        if s[i] == "B" and s[i + 1] == "W":
            finish = False
            s = s[:i] + "WB" + s[i + 2:]
            ans += 1
    if finish:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
ans=0
flug=1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    s = list(input())

    t = ''.join(s)
    cnt = 0
    while 'BW' in t:
        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
        t = ''.join(s)

    return cnt

if __name__ == "__main__":
    print(solve())

Submission status: Time Limit Exceeded

Solution code:
S = [i for i in input()]
ans = 0
c = 0
while S[0] == 'W':
    S = S[1:]
for i,s in enumerate(S):
    if s == 'W':
        ans = ans +i -c
        c += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = [1 if i=='W' else 0 for i in input()]
ans = 0
c = 0
while S[0] == 1:
    S = S[1:]
for i,s in enumerate(S):
    if s == 1:
        ans = ans +i -c
        c += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = [i for i in input()]
ans = 0

while 'W' in n:
    #print(n)
    if n[0] =='W':
        n = n[1:]

    for i, s in enumerate(n):
        if s == 'W':
            n[i] = 'B'
            n = n[1:]
            ans += i
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = input()
ans = 0
while 'BW' in n:
    for i, s in enumerate(n):
        if s == 'W':
            n = n[:i] + 'B' + n[i+1:]
            n = n[1:]
            ans += i
            break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def myAnswer(S:list) -> int:
   N = len(S)
   counter = 0
   for i in range(N):
      for j in range(N-1,i,-1):
         if(S[j]> S[j-1]):
            S[j],S[j-1] = S[j -1],S[j]
            counter += 1
   return counter

def modelAnswer():
   tmp=1
def main():
   S = list(input())
   print(myAnswer(S[:]))
if __name__ == '__main__':
   main()

Submission status: Time Limit Exceeded

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

while 'W' in S:
    ans += S.find('W') - num
    num += 1
    S = S[:S.find('W')] + 'E' + S[S.find('W') + 1:]

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s_l = list(input())
count_tot = 0

while True:
    count = 0
    for i in range(len(s_l)-1):
        if s_l[i] == 'B' and s_l[i+1] == 'W':
            s_l[i] = 'W'
            s_l[i+1] = 'B'
            count += 1
    count_tot += count
    if count == 0:
        break

print(count_tot)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
min sec
"""
# とりあえず愚直に書いてみる。
# Bは0、Wは1にする。
# ひっくり返す順番は関係なさそうなので考えない。
def main():
    S = input()
    N = len(S)
    S_list = [0]*N
    for i in range(N):
        if S[i] == "W":
            S_list[i] = 1
    counter = 0
    while True:
        no_BW = True
        for i in range(N-1):
            if S_list[i] == 0 and S_list[i+1] == 1:
                S_list[i] = 1
                S_list[i+1] = 0
                counter += 1
                no_BW = False
        if no_BW:
            break
    print(counter)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()

ans=0

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

Submission status: Time Limit Exceeded

Solution code:
s=input()

ans=0

while(True):

    if(s.find('BW')== -1):
        break

    ind=-1
    while(True):
        ind=s.find('BW',ind+1)
        if(ind==-1):
            break
        else:
            ans+=1

    s=s.replace('BW', 'WB')
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#2
s = list(input())
flag = 1
cnt = 0
while flag :
    cant = 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]
            cnt += 1
        else:
            cant += 1
    if cant == len(s)-1:
        flag = 0
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#2
s = list(input())
flag = 1
cnt = 0
while flag :
    cant = 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]
            cnt += 1
        else:
            cant += 1
    if cant == len(s)-1:
        flag = 0
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
for i in range(len(s)):
    if "BW" in s:
        s_index = s.index("BW")
        s = list(s)
        s[s_index], s[s_index+1] = s[s_index+1], s[s_index]
        s = "".join(s)
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

cnt = 0
t = -1
while cnt != t:
    t = cnt
    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 = list(input())

cnt = 0
e = len(S)-1
i = 0
while i < e:
    if S[i] == 'B' and S[i+1] == 'W':
        S[i] = 'W'
        S[i+1] = 'B'
        cnt += 1
        i = max(i-2, -1)
    i += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0

for i in range(200000):
    cnt = s.count("BW")
    if cnt == 0:
        break
    ans += cnt
    s = s.replace("BW", "WB")

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=list(input())
cnt=0
flag=True
N=len(S)

while flag:
  for i in range(0,N-1):
    if S[i]=="B" and S[i+1]=="W":
      S[i],S[i+1]="W","B"
      cnt += 1
      break
  else:
    flag=False
    
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0
for i,c in enumerate(s):
    if c == "W":
        count += s[:i+1].count("B")

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
counter = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
ans = 0
while True:
    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
            break
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = list(input())
    ans = 0
    while True:
        for i in range(len(S)-1):
            if S[i] < S[i+1]:
                tmp = S[i+1]
                S[i+1] = S[i]
                S[i] = tmp
                ans += 1
                break
        else:
            break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans_count = 0
b_count = 0
for i in range(len(S)):
    s = S[i]
    if s=="B":
        b_count = b_count + 1
    if s=="W":
        cut_str = S[:i]
        ans_count = ans_count + b_count

print(ans_count)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(ans_count)

Submission status: Time Limit Exceeded

Solution code:
s = [s_i for s_i in input()]
i = ans = 0
while i < len(s) - 1:
    if s[i] == "B" and s[i+1] == "W":
        ans += 1
        s[i] = "W"
        s[i+1] = "B"
        if i == 0: continue
        else: i -= 1
    else: i += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = [s_i for s_i in input()]
i = ans = 0
while i < len(s) - 1:
    if s[i] == "B" and s[i+1] == "W":
        ans += 1
        s[i] = "W"
        s[i+1] = "B"
        i = 0
    else: i += 1
print(ans)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(n):
    if A[i] == 'W':
        count += A[:i].count('B')

print(count)

Submission status: Time Limit Exceeded

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

count = 0
for _ in range(n):
    a = 0
    for i in reversed(range(1, n)):
        if  A[i-1] == 'B' and A[i] == 'W':
            A[i] = 'B'
            A[i-1] = 'W'
            count += 1
            a += 1
    
    if a == 0: break

print(count)

Submission status: Time Limit Exceeded

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

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

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:
from sys import stdin

s = stdin.readline().rstrip()
li = []

for i in range(len(s)):
    if s[i] == "B":
        li.append(0)
    else:
        li.append(1)
count = 0

while True:
    flag = 0
    for i in range(len(li)-1):
        if li[i] == 0 and li[i+1] == 1:
            li[i],li[i+1] = 1,0
            flag = 1
            count += 1
    if flag == 0:
        print(count)
        exit()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def main():
    s = input()

    b = np.array([])
    cnt = 0
    for i, e in enumerate(s):
        if e == "B":
            b = np.append(b, i)
            cnt += 1

    b_fin = np.arange(len(s) - cnt, len(s))

    ans = int(np.sum(b_fin - b))

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def f(s):
    cnt = 0
    n = len(s)
    for i in range(n-1):
        if s[i] == "B" and s[i+1] == "W":
            s[i] = "W"
            s[i+1] = "B"
            cnt += 1
    return cnt

s = list(input())
ans = 0
while True:
    tmp = f(s)
    ans += tmp
    if tmp == 0:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
N = len(S)
ans = 0
num = S.count('B')
check = ['W']*(N-num) + ['B']*num

while S != check:
    for i in range(1, N):
        if S[i-1] == 'B' and S[i] == 'W':
            S[i-1], S[i] = 'W', 'B'
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    cnt = 0
    tmp = ""

    while tmp != s:
        tmp = s
        cnt += s.count("BW")
        s = s.replace("BW", "WB")

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    cnt = 0
    tmp = ""

    while tmp != s:
        tmp = s
        cnt += s.count("BW")
        s = s.replace("BW", "WB")
        if tmp == s:
            break

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    cnt = 0
    tmp = ""

    while tmp != s:
        tmp = s
        s = s.replace("BW", "WB", 1)
        if tmp == s:
            break
        cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
counter = 0
flag = False
while 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"
      counter += 1
      break
  else:
    flag = True
print(counter)

Submission status: Time Limit Exceeded

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


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    s = list(input())
    ls = len(s)
    ans = 0
    while "BW" in "".join(s):
        for i in range(ls - 1):
            if s[i] == "B" and s[i + 1] == "W":
                s[i], s[i + 1] = "W", "B"
                ans += 1
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
S=input()
 
sum=0
judge=True

i=0
while i<len(S)-1:
    if S[i:i+2]=="BW":
        S=S[:i]+"WB"+S[i+2:]
        sum+=1
        i-=2
    i=max(0,i+1)
    
print(sum)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
S=input()
 
sum=0
judge=True

i=0
while i<len(S)-1:
    if S[i:i+2]=="BW":
        S=S[:i]+"WB"+S[i+2:]
        sum+=1
        i-=2
    i=max(0,i+1)
    
print(sum)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()

sum=0
judge=True

while judge:
    judge=False
    num=S.count("BW")
    sum+=num
    S=S.replace("BW","WB")
    if num!=0:
        judge=True

print(sum)

Submission status: Time Limit Exceeded

Solution code:
def loop():
    global x
    global counter
    thisLoopTime = 0
    i=0
    while i<len(x)-1:
        if(x[i+1]==0 and x[i]==1):
            t = x[i+1]
            x[i+1]=x[i]
            x[i]=t
            thisLoopTime += 1
            counter+=1
        i+=1
    delOne()
    if(thisLoopTime==0):
        return
    else:
        loop()
def delOne():
    global x
    while True:
        if(len(x)==1):
            return
        elif(x[-1]==1):
            x.pop()
        else:
            return
j = input()
x = []
for i in j:
    if(i=="B"):
        x.append(1)
    else:
        x.append(0)
counter =0
delOne()
loop()
print(counter)

Submission status: Time Limit Exceeded

Solution code:
def loop():
    global x
    global counter
    thisLoopTime = 0
    i=0
    while i<len(x)-1:
        if(x[i+1]==0 and x[i]==1):
            t = x[i+1]
            x[i+1]=x[i]
            x[i]=t
            thisLoopTime += 1
            counter+=1
        i+=1
    if(thisLoopTime==0):
        return
    else:
        loop() 
j = input()
x = []
for i in j:
    if(i=="B"):
        x.append(1)
    else:
        x.append(0)
counter =0
loop()
print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt = 0
while s.count('BW') > 0:
    cnt += s.count('BW')
    s = s.replace('BW', 'WB')
print(cnt)

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] == "W" and S[j-1] == "B":
            S[j], S[j-1] = S[j-1], S[j]
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0
while S.find("BW") != -1:
    count += S.count("BW")
    S = S.replace("BW","WB")
print(count)

Submission status: Time Limit Exceeded

Solution code:
a=input();c=0
for i,j in enumerate(a):
	c+=(j=="B")*a[i:].count("W")
print(c)

Submission status: Time Limit Exceeded

Solution code:
s = input()
res = 0
ir_place = s.find('BW')
while ir_place != -1:
    res += 1
    s = s[:ir_place] + 'WB' + s[ir_place+2:]
    ir_place = s.find('BW')
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

S = input()
n = len(S)
ss = [s for s in S]
answer = 0
while True:
    numThis = 0
    for i in range(n-1):
        if ss[i] == 'B' and ss[i+1] == 'W':
            ss[i] = 'W'
            ss[i+1] = 'B'
            numThis += 1
    answer += numThis
    if numThis == 0:
        break
print(answer)

Submission status: Time Limit Exceeded

Solution code:
S = input()

res = S.count("BW")
is_keep_loop = res > 0
while(is_keep_loop):
    S = S.replace("BW","WB")
    tmp = S.count("BW")
    is_keep_loop =  tmp > 0
    res += tmp

print(res)

Submission status: Time Limit Exceeded

Solution code:
s=input()
cnt=0
while "BW" in s:
    s=s.replace("BW","WB",1)
    cnt+=1
    if s[0]=="W":s=s[1:]
    if s[-1]=="B":s=s[:-1]
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0

for i in range(2*10**5):
    ss = s.count('BW')
    if ss == 0:
        break
    ans += ss
    s = s.replace('BW', 'WB')
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
cnt = 0
while True:
  tmpcnt = 0
  for i in range(N-1):
    #print(S[N-2-i:N-i])
    if S[N-2-i:N-i] == 'BW':
      S = S[:N-2-i] + 'WB' + S[N-i:]
      #print(S)
      cnt += 1
      tmpcnt += 1
  if tmpcnt == 0:
    break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S=input()
ans=0
moku='W'*S.count('W')+'B'*S.count('B')

while S != moku:
    S=S.replace('BW', 'WB', 1)
    ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
i = -1
while 1:
    i += 1
#    print(s[i:i+2])
    if i >= len(s):
        break
    if s[i:i+2] == "BW":
        s = s[:i] + "WB" + s[i+2:]
        ans += 1
        i -= 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
i = -1
while 1:
    i += 1
#    print(s[i:i+2])
    if i >= len(s):
        break
    if s[i:i+2] == "BW":
        s = s[:i] + "WB" + s[i+2:]
        ans += 1
        i = -1
print(ans)

Submission status: Time Limit Exceeded

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

count = 0

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

print(count)

Submission status: Time Limit Exceeded

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

while 'W' in S:
    ind = S.index('W')
    S.pop(ind)
    ans += ind

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
S = list(input())
count = 0
flag = True

while flag == True:
    
    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
            break
        if i == len(S)-2: # 変更箇所なし
            flag = False
            break

print(count)

Submission status: Time Limit Exceeded

Solution code:
s=input()
a=[]
b=0
w=0
for i in s:
  if i =='B':
    a.append(0)
    b+=1
  else:
    a.append(1)
    w+=1
A=len(a)
cnt=0
for i in range(A-1):
  for j in range(A-1-i):
    if a[j]==0 and a[j+1]==1:
      a[j],a[j+1]=a[j+1],a[j]
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

W = [i for i, x in enumerate(S) if x == 'W']
B = [i for i, x in enumerate(S) if x == 'B']

print(sum([len([b for b in B if b < w]) for w in W]))

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
ans = 0
# print(S)
cl1 = []
cl2 = []
while True:
	for i in range(len(S)-1):
		if S[i] == 'B' and S[i+1] == 'W' and i not in cl1:
			S[i] = 'W'
			S[i+1] = 'B'
			ans += 1
			cl1.append(i)
		elif S[i] == 'W' and S[i+1] == 'B' and i not in cl1:
			S[i] = 'B'
			S[i+1] = 'W'
			ans += 1
			cl1.append(i)
		else:
			pass
		# print(S)
	if cl1 == cl2:
		break
	else:
		cl1, cl2 = cl2, cl1
		cl1 = []
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = list(input())
stack = []
count = 0
while N:
    stack.append(N.pop(0))
    i = 0
    while len(stack) >= 2:
        #print(stack, i)
        if stack[-2 - i] != stack[-1 - i]:
            count += 1
            tmp = stack[-2 - i]
            stack[-2 - i] = stack[-1 - i]
            stack[-1 - i] = tmp
            i += 1
            if i == len(stack)-1:
                break
        else:
            break
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = list(str(input()))
ans = 0
i = len(s) - 1 
while True:
    if i > len(s) - 1:
        i -= 1
    if i == 0:
        break
    if s[i] == "W" and s[i-1] == "B":
        s[i] = "B"
        s[i-1] = "W"
        ans += 1
        i += 1
    else:
        i -= 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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