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: Accepted

Solution code:
#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        print(*args,  file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit
    
 
#print(N)
S = input()
r = 0
tb = 0
for c in S:
    if c== 'B':
        tb+=1
    else:
        r += tb

print(r)

Submission status: Accepted

Solution code:
S = input()
sumW = 0
total = 0
for i in reversed(range(len(S))):
    if S[i] == "W":
        sumW += 1
    elif S[i] == "B":
        total += sumW
print(total)

Submission status: Accepted

Solution code:
s = raw_input().strip()
ans = x = 0
for i, c in enumerate(s):
    if c == 'W':
        ans += i - x
        x += 1
print ans

Submission status: Accepted

Solution code:
s = reversed(input())
stack = 0
ans = 0
for i in s:
    if i == 'W':
        stack += 1
    else:
        ans += stack
print(ans)

Submission status: Accepted

Solution code:
S = input()

cnt_b = 0
ans = 0
for s in S:
    if s == 'B':
        cnt_b += 1
    else:
        ans += cnt_b
print(ans)

Submission status: Accepted

Solution code:
S = input()
numB = 0
ans = 0
for c in S:
  if c == 'B':
    numB += 1
  else:
    ans += numB
print(ans)

Submission status: Accepted

Solution code:
s = input()

cou = 0
ans = 0
for i in s:
    if i == 'B':
        cou += 1
    else:
        ans += cou
print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
cnt = 0
for i, c in enumerate(S[::-1]):
    if c=="B":
        ans += i - cnt
        cnt += 1
print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
ans = 0
cur = N-1
for i in range(N-1, -1, -1):
    if S[i] == 'B':
        ans += cur - i
        cur -= 1
print(ans)

Submission status: Accepted

Solution code:
# A
S_list = list(input())

res = 0
cnt = 0

for s in S_list:
    if s == "B":
        cnt += 1
    else:
        res += cnt

print(res)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N = input()

num_B = 0
ans = 0
for i in N:
    if i == 'W':
        ans += num_B
    else:
        num_B += 1

print(ans)

Submission status: Accepted

Solution code:
S=input()
N=len(S)
t=0
ans=0
for i in range(N-1,-1,-1):
    if S[i]=='W':
        t+=1
    else:
        ans+=t
print(ans)

Submission status: Accepted

Solution code:
#N = int(input())
#a = [int(i) for i in input().split()]
#s = [[int(j) for j in input().split()] for i in range(N)]

s=input()
res=0
cnt=0
for i in range(len(s)):
    if s[i]=='W':
        res+=(i-cnt)
        cnt+=1
print(res)

Submission status: Accepted

Solution code:
s = input()

cnt = 0
res = 0

for c in s:
    if c == 'B':
        cnt += 1
    if c == 'W':
        res += cnt

print(res)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
ans = 0
b = 0
for c in s:
    if c == 'W':
        ans += b
    elif c == 'B':
        b += 1
print(ans)

Submission status: Accepted

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

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

S = raw_input()[::-1]

ans = 0
cnt = 0
for c in S:
    if c == 'W':
        cnt += 1
    else:
        ans += cnt

print ans

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
S = list(input())

loop_idx = 0
loop_len = -(-len(S)//2)
cnt = 0

if len(S) == 1:
    pass
else:
    while loop_idx < loop_len:
        while True:
            if S[0] == "W":
                S.pop(0)
            else:
                break
        while True:
            if S[-1] == "B":
                S.pop(-1)
            else:
                break
        for i in range(len(S)-1,0,-1):
            if S[i]=="W" and S[i-1] == "B":
                cnt += 1
                S[i],S[i-1] = "B","W"
        loop_idx += 1
        #print(S)
print(cnt)

Submission status: Runtime Error

Solution code:
othello = input()
bef = 0
sumall = 0
sumelse = 0

for i in range(len(othello)):
    sumall += i
    if(othello[i] == 'B'):
        bef += i
        count += 1

count = 0
for i in range(len(othello)-count):
    sumelse += i

aft = sumall - sumelse

print(aft - bef)

Submission status: Runtime Error

Solution code:
S = input()
W = []

for i, s enumerate(S):
  if s == 'W':
    W.append(i)

idx = 0
ans = 0
for w in W:
  ans += w-idx
  idx += 1

print(ans)

Submission status: Runtime Error

Solution code:
S = input()

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

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
sum = [0] * (n + 1)
sum[0] = (s[0] == 'B')
for i in range(1 , n):
	sum[i] = sum[i-1] + (s[i] == 'B')
ans = 0
for i in range(n, -1 ,-1):
	if s[i] == 'W':
		ans += sum[i]
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
sum = [0] * (n + 1)
sum[0] = (s[0] == 'B')
for i in range(1 , n):
	sum[i] = sum[i-1] + (s[i] == 'B')
ans = 0
for i in range(n, -1 ,-1):
	print(i)
	if s[i] == 'W':
		ans += sum[i]
print(ans)

Submission status: Runtime Error

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

i = 0
for i in range(l)
    for j in range(l-1):
        if s[j] =="B" and s[j+1] == "W":
            cnt += 1
            s[j],s[j+1] = s[j+1],s[j]
            break
        break
print(cnt)

Submission status: Runtime Error

Solution code:
s = input()

cw = 0
ans = 0
for i in range(n):
  if s[i] == 'W':
    ans += i-cw
    cw += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
s = list(input())
ls = len(s)
ss = sorted(s, reverse=True)
cnt = [0, 0]
ans = 0
w = 0
while ss[w] == "W":
    w += 1

for i in range(ls):
    if s[i] == "B":
        ans += w + cnt[0] - i
    else:
        ans += i - cnt[1]
    cnt[s[i] != "B"] += 1

print(ans//2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
def main():
    S = list(input())
    state = 0
    CNT = 0
    while(state != 1):
    # for x in range(50):
        first_W = 0
        for i in range(len(S)):
            if state == 0:
                if S[i] == 'B':
                    B_cnt = 1
                    state = 1
                else:
                    first_W += 1
            elif state == 1:
                if S[i] == 'B':
                    B_cnt += 1
                else:
                    W_cnt = 1
                    state = 2
            elif state == 2:
                if S[i] == 'W':
                    W_cnt += 1
                else:
                    state = 0
                    break
        # print(state)
        if state == 2:
            state = 0
            S = ['W']*(W_cnt+first_W) + ['B']*B_cnt
        else:
            CNT += W_cnt*B_cnt
            S = ['W']*(W_cnt+first_W) + ['B']*B_cnt + S[i:]
        # print(S)
    print(CNT)
        
if __name__ == '__main__':
    main()

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

Submission status: Runtime Error

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


def calc_rle_l(s):
    now_c = s[0]
    count = 1
    res = []
    for i in range(1, len(s)):
        if now_c == s[i]:  # 同じ文字が続く
            count += 1
        else:  # 手前まで続いた文字を集計
            res.append([now_c, count])
            now_c = s[i]
            count = 1
    res.append([now_c, count])  # 最後に続く文字
    return res


s = S()
if len(set(s)) < 2:  # B か W しかない
    print(0)
    sys.exit()

rle = calc_rle_l(s)
# print(rle)
if rle[0][1] == 'W':
    rle = rle[1:]
if rle[-1][1] == 'B':
    rle = rle[:-1]
ans = 0
for i in range(0, len(rle), 2):
    ans += rle[i][1] * rle[i + 1][1]
    if i + 2 < len(rle):
        rle[i + 2][1] += rle[i][1]
print(ans)

Submission status: Runtime Error

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


def calc_rle_l(s):
    now_c = s[0]
    count = 1
    res = []
    for i in range(1, len(s)):
        if now_c == s[i]:  # 同じ文字が続く
            count += 1
        else:  # 手前まで続いた文字を集計
            res.append([now_c, count])
            now_c = s[i]
            count = 1
    res.append([now_c, count])  # 最後に続く文字
    return res


s = S()
if len(set(s)) < 2:  # B か W しかない
    print(0)
    sys.exit()

rle = calc_rle_l(s)
# print(rle)
if rle[0][1] == 'W':
    rle = rle[1:]
if rle[-1] == 'B':
    rle = rle[:-1]
ans = 0
for i in range(0, len(rle), 2):
    ans += rle[i][1] * rle[i + 1][1]
    if i + 2 < len(rle):
        rle[i + 2][1] += rle[i][1]
print(ans)

Submission status: Runtime Error

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


def calc_rle(s):
    tmp, count, ans = s[0], 1, ""
    for i in range(1, len(s)):
        if tmp == s[i]:
            count += 1
        else:
            ans += tmp + str(count)
            tmp = s[i]
            count = 1
    ans += tmp + str(count)
    return ans


s = S()
if len(set(s)) < 2:  # B か W しかない
    print(0)
    sys.exit()

rle = calc_rle(s)

if rle[0] == 'W':
    rle = rle[2:]
if len(rle) // 2 >= 2 and rle[-2] == 'B':
    rle = rle[:-2]
# print(rle)
rle = [[rle[i], eval(rle[i+1])] for i in range(0, len(rle), 2)]
# print(rle)
ans = 0
for i in range(0, len(rle), 2):
    # print(rle[i], rle[i+1])
    ans += rle[i][1] * rle[i + 1][1]
    if i + 2 < len(rle):
        rle[i + 2][1] += rle[i][1]
    # print(f'{ans=}')
print(ans)

Submission status: Runtime Error

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


def calc_rle(s):
    tmp, count, ans = s[0], 1, ""
    for i in range(1, len(s)):
        if tmp == s[i]:
            count += 1
        else:
            ans += tmp + str(count)
            tmp = s[i]
            count = 1
    ans += tmp + str(count)
    return ans


s = S()
rle = calc_rle(s)
if 'W' not in s or 'B' not in s:
    print(0)
    sys.exit()
# print(rle)
if rle[0] == 'W':
    rle = rle[2:]
if len(rle) // 2 >= 2 and rle[-2] == 'B':
    rle = rle[:-2]
# print(rle)
rle = [[rle[i], eval(rle[i+1])] for i in range(0, len(rle), 2)]
# print(rle)
ans = 0
for i in range(0, len(rle), 2):
    # print(rle[i], rle[i+1])
    ans += rle[i][1] * rle[i + 1][1]
    if i + 2 < len(rle):
        rle[i + 2][1] += rle[i][1]
    # print(f'{ans=}')
print(ans)

Submission status: Runtime Error

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


def calc_rle(s):
    tmp, count, ans = s[0], 1, ""
    for i in range(1, len(s)):
        if tmp == s[i]:
            count += 1
        else:
            ans += tmp + str(count)
            tmp = s[i]
            count = 1
    ans += tmp + str(count)
    return ans


s = S()
rle = calc_rle(s)
if rle[0] == 'W':
    rle = rle[2:]
if len(rle)  >= 4 and rle[-2] == 'B':
    rle = rle[:-2]
rle = [[rle[i], eval(rle[i+1])] for i in range(0, len(rle), 2)]
ans = 0
for i in range(0, len(rle), 2):
    ans += rle[i][1] * rle[i + 1][1]
    if i + 2 < len(rle):
        rle[i + 2][1] += rle[i][1]
print(ans)

Submission status: Runtime Error

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


def calc_rle(s):
    tmp, count, ans = s[0], 1, ""
    for i in range(1, len(s)):
        if tmp == s[i]:
            count += 1
        else:
            ans += tmp + str(count)
            tmp = s[i]
            count = 1
    ans += tmp + str(count)
    return ans


s = S()
rle = calc_rle(s)
if rle[0] == 'W':
    rle = rle[2:]
if rle[-2] == 'B':
    rle = rle[:-2]
# print(rle)
rle = [[rle[i], eval(rle[i+1])] for i in range(0, len(rle), 2)]
# print(rle)
ans = 0
for i in range(0, len(rle), 2):
    # print(rle[i], rle[i+1])
    ans += rle[i][1] * rle[i + 1][1]
    if i + 2 < len(rle):
        rle[i + 2][1] += rle[i][1]
    # print(f'{ans=}')
print(ans)

Submission status: Runtime Error

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


def calc_rle(s):
    tmp, count, ans = s[0], 1, ""
    for i in range(1, len(s)):
        if tmp == s[i]:
            count += 1
        else:
            ans += tmp + str(count)
            tmp = s[i]
            count = 1
    ans += tmp + str(count)
    return ans


s = S()
rle = calc_rle(s)
print(rle)
if rle[0] == 'W':
    rle = rle[2:]
if rle[-2] == 'B':
    rle = rle[:-2]
# print(rle)
rle = [[rle[i], eval(rle[i+1])] for i in range(0, len(rle), 2)]
# print(rle)
ans = 0
for i in range(0, len(rle), 2):
    # print(rle[i], rle[i+1])
    ans += rle[i][1] * rle[i + 1][1]
    if i + 2 < len(rle):
        rle[i + 2][1] += rle[i][1]
    # print(f'{ans=}')
print(ans)

Submission status: Runtime Error

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

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

print(cnt)

Submission status: Runtime Error

Solution code:
s = input()
 
n = len(s)
 
ans = 0
 
cunt = 0
 
for i in range(n):
    if s[i] == "B":
        cnt += 1
    else:
        ans += cunt
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import permutations
N = int(input())

val = []
for _ in range(N):
    val.append(int(input()))
ans = 10**10
for i in permutations(val):
    for j in range(1, N):
        ans = min(max(sum(i[:j]), sum(i[j:])), ans)
if N == 1:
    print(val[0])
else:
    print(ans)

Submission status: Runtime Error

Solution code:
s=input()
c=0
a=0
for i in s:
  if i=='B':
    c+=1
  else:
    a+=c
print(ans)

Submission status: Runtime Error

Solution code:
s = input()

def fact(n):
    if n > 1:
        return n * fact(n-1)
    else:
        return 1

print(fact(s.count("B")))

Submission status: Runtime Error

Solution code:
N=input()
count=0
if N.count('BW')==0:
    print(0)
    exit

temp_count=1

while tempcount==0:
    count+=N.count('BW')
    newN=N.replace('BW','WB')
    temp_count=newN.count('BW')
    N=newN

print(count)

Submission status: Runtime Error

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

total=0
while s.index("B")<s.index("W"):
    b=s.index("B")
    w=s.index("W",b)
    total+=w-b
    s[b]="W"
    s[w]="B"
print(total)

Submission status: Runtime Error

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
        # print(S)
        j = 1
        while True:
            if S[i-j] == 'B':
                S[i-j] = 'W'
                S[i-j+1] = 'B'
                cnt += 1
                j += 1
                # print(S)
            else :
                break
            
print(cnt)

Submission status: Runtime Error

Solution code:
from functools import lru_cache
import numpy as np
S = np.array(list(map(str, input().rstrip())))

S[np.where(S=="W")] = 1
S[np.where(S=="B")] = 0
S = S.astype(int)

@lru_cache(maxsize=None)
def sum_n(n):
    if n<=1:
        return 1
    return (sum_n(n-1) + n)

goal = sum_n(S.sum())

now = (np.where(S==1)[0]+1).sum()

print(now - goal)

Submission status: Runtime Error

Solution code:
a=list(input())
i=0
result=0
while len(a)>i:
  if a[i]=='B' and a[i+1]=='W':
    i=0
    result=result+1
  else :
    i++
print(result)

Submission status: Runtime Error

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    s = IS()
    c = s.split('B')
    if s.index('W') != 0:
        c = c[1:]
    c = c[::-1]
    cnt_w = [len(ci) for ci in c]
    acc_w = acc(cnt_w)
    print(sum(acc_w))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
BWBWBW

Submission status: Runtime Error

Solution code:
s = input()
ans = 0

def reverse(s,i):
  if s[i] == 'B' and s[i+1] == 'W':
	s[i] = 'W'
	s[i+1] = 'B'
    ans += 1
  
while True:
  s = ans
  for i in range(len(s) - 1):
    reverse(s,i)
  if s == ans:
    print(ans)
    break

Submission status: Runtime Error

Solution code:
s = input()
ans = 0

def reverse(s,i):
  if s[i] == 'B' and s[i+1] == 'B':
	s[i] = 'W'
	s[i+1] = 'B'
    ans += 1
  
while True:
  s = ans
  for i in range(len(s) - 1):
    reverse(s,i)
  if s == ans:
    print(ans)
    break

Submission status: Runtime Error

Solution code:
import collections
S=list(input())
c=collections.Counter(S)
n=c["W"]
s=0
i=0
while "B" in S[0:n]:
  if S[i]=="B" and S[i+1]=="W":
    S[i]="W" and S[i+1]="B"
    s+=1
    i=i
  else:
    i+=1
print(s)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline


def read():
    S = list(input().strip())
    return S,

def solve(S):
    N = len(S)
    count = 0
    l = 0
    r = N-1
    while S[r] != 'W':
        r-=1
    s = list()
    c = 0
    for i in range(r, -1, -1):
        d = r - i
        if S[i] == 'B':
            s.append(d - c)
            c += 1
    return sum(s)

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Runtime Error

Solution code:
s = input()
n  =len(s)
res = 0
ans = 0
for i in range(n):
    if s[i] == 'B':
        res+=1AC
    else:
        ans+=res


print(ans)

Submission status: Runtime Error

Solution code:
/*test*/
#include<bits/stdc++.h>

using namespace std;

int main() {
    int i = 0,b = 0, bko = 0, sum = 0;
    string s;
    cin >> s;
    for (i = 0; i < s.size(); i++) {
        if (s[i] == 'B') {
            b += bko;
            bko += 1;
            sum += s.size() - 1 - i;
        }
    }
    cout << sum - b << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
def ans():
    global cnt, s, l
    if s.count("BW") == 0:
        return None
    for i in range(s.count("BW")):
        print(s)
        cnt += 1
        l.pop(s.index("BW") + 1)
        l[s.index("BW"):s.index("BW") + 1] = ["W", "B"]
        s = "".join(l)
    ans()
s = input()
l = list(s)
cnt = 0
ans()
print(cnt)

Submission status: Runtime Error

Solution code:
s = input()
s = [str(s[i]) for i in range(len(s))]
ans = 0
for i in range(n-1):
  p, q = s[i], s[i+1]
  if p != "B" or q != "W":
    continue
  ans += 1
  s[i], s[i+1] = "W", "B"
  if i == 0:
    continue
  if s[i-1] == "B":
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline

    _ = int(input())
    A = [int(i) for i in input().split()]

    ans = 0
    c = Counter(A)
    B = sorted(c.keys(), reverse=True)

    for b in B:
        if c[b] == 0:
            continue
        a = (2 ** b.bit_length()) - b
        if a == b:
            cur = c[b]//2
        else:
            if a in c.keys():
                cur = min(c[a], c[b])
            else:
                cur = 0
        ans += cur
        # c[b] -= cur
        c[a] -= cur

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
    N=int(input())
    lis=list(map(int,input().split()))
    lis.sort()
    sum=0
    while(len(lis)>1):
        v=lis.pop()
        k=1
        while k<=v:
            k*=2
        m=k-v
        if m in lis:
            sum+=1
            lis.remove(m)

    print(sum)

Submission status: Runtime Error

Solution code:
print(TODO)

Submission status: Runtime Error

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

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

print(count * 2)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define BITF(n, i) (((n) >> i) & 1)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPI(i, x) for (int i = 1; i <= x; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define REPZ(i, x) for (int i = 0; i <= x; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORI(i, m, n) for (int i = m; i <= n; i++)
using namespace std;
#define PRINTARR(x, y)                                     \
  cerr << #x << "=\n";                                     \
  for (auto itr = x; itr != y; itr++) cerr << *itr << " "; \
  cerr << endl;
#define PRINTARR2(x, i0, i1)                                       \
  cerr << #x << "=\n";                                             \
  for (int ii0 = 0; ii0 < i0; ii0++) {                             \
    for (int ii1 = 0; ii1 < i1; ii1++) cerr << x[ii0][ii1] << " "; \
    cerr << endl;                                                  \
  }
#define DUMPOUT cerr
// vector
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  REP(i, (int)vec.size())
  os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
  os << "}";
  return os;
}
// map
template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  FORA(itr, map_var) {
    os << *itr;
    itr++;
    if (itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  FORA(itr, set_var) {
    os << *itr;
    itr++;
    if (itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if (sizeof...(Tail) > 0) DUMPOUT << ", ";
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define DUMP(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define DUMP(...)
#endif
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF0 = 1061109567, INF = INF0 * INF0;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define MAXN
//----//
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string S;
  cin >> S;
  int ans = 0, cnt = 0;
  FORA(e, S) {
    cnt += e == 'B';
    if (e == 'W') ans += cnt;
  }
  print(ans);
}

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
cnt=0
for i in range(n):
  if s[i]=='W':
    cnt+=1
ans=0
for i in range(n):
  if s[i]=='W':
    cnt--
  else:
    ans+=cnt
print(ans)

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
    S = input()
    ans = 0
    bcount = 0
    for i in range(len(S)):
        if S[i] == 'B':
            bcount += 1
        else:
            ans += bcount
​
    print(ans)

Submission status: Runtime Error

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(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: Runtime Error

Solution code:

###template###
import sys
def input(): return sys.stdin.readline().rstrip()
import heapq
INF = float("inf")
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###


S = ii()

prev = 0
sum = 0
for c in S:
  if c == 'B':
    prev += 1
  else:
    sum += prev
    
print(sum)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main() {
    string s;
    cin>>s;
    long long int ans = 0;
    long long int temp = 0;
    for(long long int i = 0;i<s.length();i++){
        if(s[i] == 'B'){
            temp++;
        } else {
            ans += temp;
        }
    }
    cout<<ans<<endl;
}

Submission status: Runtime Error

Solution code:
S = input()

B_num = S.count("B")
W_num = S.count("W")

B_start = W_num # 一番左のBがいていいindex

res = 0
for i in range(B_start + 1):
    if S[i] == "B":
        res += B_start - i
        B_start += 1
        while(B_start < len(S) and S[B_start] == "B"):
            B_start += 1

print(res)

Submission status: Runtime Error

Solution code:
a,b,s=0,input(),0
for i in range(len(s)):a+=i*(s[i]=="W");b+=1
print(a-((b*(b-1))//2))

Submission status: Runtime Error

Solution code:
s = input()

if s[0]=="W":
    l = [1]
else:
    l = [0,1]

for i in range(1,len(s)):
    if s[i]==s[i-1]:
        l[-1]+=1
    else:
        l.append(1)

rightw = sum(l[2::2])

ans = 0

for i in range(len(l)//2):
    ans += l[2*i+1]*rightw
    if i!=len(s)//2-1:
        rightw -= l[2*i+2]

print(ans)