Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy

inData = input().split(' ')
mseCnt = int(inData[0])
mustCnt = int(inData[1])
neDanList = []
mseJ = {}
byCnt = 0
byMany = 0
for i in range(0, mseCnt):
    inData2 = input().split(' ')
    if inData[0] in mseJ:
        mseJ[inData2[0]] = mseJ[inData[0]] + int(inData2[1])
    else:
        mseJ[inData2[0]] = int(inData2[1])
    neDanList.append(inData2[0])

neDanList = list(set(neDanList))
neDanList = sorted(neDanList)

for i in range(0, mseCnt):
    for j in range(0, int(mseJ[str(neDanList[i])])):
        if byCnt == mustCnt:
            break
        else:
            byCnt += 1
            byMany += int(neDanList[i])
    if byCnt == mustCnt:
        break

print(byMany)

Fixed submission:
N, M = map(int, input().split())
mseList = [list(map(int, input().split())) for i in range(0, N)]
mseList = sorted(mseList, key=lambda x:x[0])
total = 0
for i, k in mseList:
    if k < M:
        total += i * k
        M -= k
    else:
        total += i * M
        break
print(total)

Buggy python submission (verdict: Runtime Error):
inData = input().split(' ')
mseCnt = int(inData[0])
mustCnt = int(inData[1])
neDanList = []
mseJ = {}
byCnt = 0
byMany = 0
for i in range(0, mseCnt):
    inData2 = input().split(' ')
    moji = int(inData2[0])
    mseJ[inData2[0]] = int(inData2[1])
    neDanList.append(inData2[0])

mseJ = sorted(mseJ.items())
neDanList = sorted(neDanList)

for i in range(0, mseCnt):
    for j in range(0, int(mseJ[i][1])):
        if byCnt == mustCnt:
            break
        else:
            byCnt += 1
            byMany += int(neDanList[i])
    if byCnt == mustCnt:
        break

print(byMany)

Fixed submission:
N, M = map(int, input().split())
mseList = [list(map(int, input().split())) for i in range(0, N)]
mseList = sorted(mseList, key=lambda x:x[0])
total = 0
for i, k in mseList:
    if k < M:
        total += i * k
        M -= k
    else:
        total += i * M
        break
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())
ans = 0
for i in range(A, B + 1, 2):
    ans = (ans ^ i)
    if B >= i + 1:
        ans = (ans ^ i + 1)
print(ans)

Fixed submission:
A, B = map(int, input().split())

def F(v):
    tmp = v // 2
    amari = v % 2
    ans = 0
    if tmp % 2 == 0:
        if amari != 0:
            ans = v - 1
    else:
        if amari != 0:
            ans = 1 ^ (v - 1)
        else:
            ans = 1
    return ans

ansA = F(A)
ansB = F(B + 1)
print(ansA ^ ansB)
Buggy python submission (verdict: Runtime Error):
MOD = 10 ** 5
n, m = map(int, input().split())
kyori = [int(input()) for _ in range(n - 1)]
a = [int(input()) for _ in range(m)]
rui = [0] * n
for i in range(n - 1):
    rui[i + 1] = rui[i] + kyori[i]

ans = 0
tmp = 0
for i in range(m):
    ans += abs(rui[tmp] - rui[tmp + a[i]])
    tmp += a[i]

print(ans % MOD)

Fixed submission:
inData = input().split(' ')

ans = 0
count = 0
maxCount = int(inData[2])
many = int(inData[1])
nedan = int(inData[0])

for i in range(0, maxCount):
    if nedan <= many:
        if count < maxCount:
            ans += 1
            many -= nedan
        else:
            break
    else:
        break

print(ans)

Buggy python submission (verdict: Runtime Error):
MOD = 10 ** 5
n, m = map(int, input().split())
kyori = [int(input()) for _ in range(n - 1)]
a = [int(input()) for _ in range(m)]
rui = [0] * n
for i in range(n - 1):
    rui[i + 1] = rui[i] + kyori[i]

ans = 0
tmp = 0
for i in range(m):
    ans += abs(rui[tmp] - rui[tmp + a[i]]) % MOD
    tmp += a[i]

print(ans % MOD)

Fixed submission:
inData = input().split(' ')

ans = 0
count = 0
maxCount = int(inData[2])
many = int(inData[1])
nedan = int(inData[0])

for i in range(0, maxCount):
    if nedan <= many:
        if count < maxCount:
            ans += 1
            many -= nedan
        else:
            break
    else:
        break

print(ans)

Buggy python submission (verdict: Runtime Error):
MOD = 10 ** 5
n, m = map(int, input().split())
kyori = [int(input()) for _ in range(n - 1)]
a = [int(input()) for _ in range(m)]
rui = [0] * n
for i in range(n - 1):
    rui[i + 1] = rui[i] + kyori[i]

ans = 0
tmp = 0
for i in range(m):
    ans += abs(rui[tmp] - rui[tmp + a[i]]) % MOD
    tmp += a[i]

print(ans % MOD)

Fixed submission:
inData = input().split(' ')

ans = 0
count = 0
maxCount = int(inData[2])
many = int(inData[1])
nedan = int(inData[0])

for i in range(0, maxCount):
    if nedan <= many:
        if count < maxCount:
            ans += 1
            many -= nedan
        else:
            break
    else:
        break

print(ans)

Buggy python submission (verdict: Runtime Error):
MOD = 10 ** 5
n, m = map(int, input().split())
kyori = [int(input()) for _ in range(n - 1)]
a = [int(input()) for _ in range(m)]
rui = [0] * n
for i in range(n - 1):
    rui[i + 1] = rui[i] + kyori[i]

ans = 0
tmp = 0
for i in range(m):
    ans += abs(rui[tmp] - rui[tmp + a[i]])
    tmp += a[i] % MOD

print(ans % MOD)

Fixed submission:
inData = input().split(' ')

ans = 0
count = 0
maxCount = int(inData[2])
many = int(inData[1])
nedan = int(inData[0])

for i in range(0, maxCount):
    if nedan <= many:
        if count < maxCount:
            ans += 1
            many -= nedan
        else:
            break
    else:
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
inData = str(input())
ansList = []
dataLen = len(inData)
rpLen = len(inData)
for i in range(0, dataLen):
    for j in range(1, rpLen + 1):
        if inData[-j] != inData[-j - 1]:
            ansList.append(inData[-j])
            ansList.append(inData[-j - 1])
            tmp1 = str(inData[0:-j - 1])
            tmp2 = ''
            if -j + 1 != 0:
                tmp2 = str(inData[-j + 1:])
            reData = tmp1 + tmp2
            if reData == '[]':
                inData = '[]'
            else:
                inData = reData
            break
        else:
            if rpLen == j + 1:
                break
    if inData == '[]':
        break
    rpLen = len(inData)
    if rpLen < 2:
        break

print(len(ansList))


Fixed submission:
inData = str(input())
ansList = []
dataLen = len(inData)
zeroCnt = 0
oneCnt = 0
for i in range(0, dataLen):
    if inData[i] == '0':
        zeroCnt += 1
    else:
        oneCnt += 1

print(2 * min([zeroCnt, oneCnt]))
Buggy python submission (verdict: Runtime Error):
inputData = input().split(' ')
ans = 0

if int(inputData[1]) % input(inputData[0]) ==0:
    ans = int(inputData[0]) + int(inputData[1])
else:
    ans = int(inputData[1]) - int(inputData[0])
print(ans)

Fixed submission:
inputData = input().split(' ')
ans = 0

if int(inputData[1]) % int(inputData[0]) ==0:
    ans = int(inputData[0]) + int(inputData[1])
else:
    ans = int(inputData[1]) - int(inputData[0])
print(ans)

Buggy python submission (verdict: Runtime Error):
inputData1 = int(input())
inputData2 = int(input())
ans = 0
if inputData2 % inputData1 ==0:
    ans = inputData1 + inputData2
else:
    ans = inputData2 - inputData1
print(ans)

Fixed submission:
inputData = input().split(' ')
ans = 0

if int(inputData[1]) % int(inputData[0]) ==0:
    ans = int(inputData[0]) + int(inputData[1])
else:
    ans = int(inputData[1]) - int(inputData[0])
print(ans)

Buggy python submission (verdict: Runtime Error):
inputData1 = int(input())
inputData2 = int(input())
ans = 0
if inputData2 % inputData1 ==0:
    ans = inputData1 + inputData2
else:
    ans = inputData2 - inputData1
print(ans)

Fixed submission:
inputData = input().split(' ')
ans = 0

if int(inputData[1]) % int(inputData[0]) ==0:
    ans = int(inputData[0]) + int(inputData[1])
else:
    ans = int(inputData[1]) - int(inputData[0])
print(ans)

Buggy python submission (verdict: Runtime Error):
inputData1 = int(input())
inputData2 = int(input())
ans = 0
if inputData2 % inputData1 ==0:
    ans = inputData1 + inputData2
else:
    ans = inputData2 - inputData1
print(ans)

Fixed submission:
inputData = input().split(' ')
ans = 0

if int(inputData[1]) % int(inputData[0]) ==0:
    ans = int(inputData[0]) + int(inputData[1])
else:
    ans = int(inputData[1]) - int(inputData[0])
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
kLst = [list(map(str, input().split())) for i in range(N)]

ansLst = ['0'] * M
for i in range(1, len(kLst[0])):
    ansLst[i] = kLst[0][i]
for i in range(N):
    del kLst[i][0]
ansLst = list(set(ansLst))
ansLst.remove('0')

for i in range(1, N):
    for j in ansLst:
        if kLst[i].count(j) == 0:
            ansLst.remove(j)
print(len(ansLst))

Fixed submission:
N, M = map(int, input().split())
kLst = [list(map(int, input().split())) for i in range(N)]

ansLst = [0] * M
for i in range(N):
    for j in range(1, len(kLst[i])):
        ansLst[kLst[i][j] - 1] += 1

ansCnt = 0
for i in ansLst:
    if i == N:
        ansCnt += 1

print(ansCnt)
Buggy python submission (verdict: Runtime Error):
import math
def yuk(a, b):
    ans = int(a / b)
    amari = a % b
    if amari != 0:
        ans = yuk(b, amari)
    else:
        ans = b
    return ans


N = int(input())
alst = list(map(int, input().split()))
ans = alst[0]
for i in range(1, N):
    if ans > alst[i]:
        ans = math.gcd(ans, alst[i])
    else:
        ans = math.gcd(alst[i], ans)
print(ans)

Fixed submission:
def yuk(a, b):
    ans = int(a / b)
    amari = a % b
    if amari != 0:
        ans = yuk(b, amari)
    else:
        ans = b
    return ans

N = int(input())
alst = list(map(int, input().split()))
ans = alst[0]
for i in range(1, N):
    if ans > alst[i]:
        ans = yuk(ans, alst[i])
    else:
        ans = yuk(alst[i], ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
X = list(map(int, input().split()))
t = sorted(X, reverse=True)
h = [0] * M
for i in range(1, M):
    h[i] = abs(t[i - 1] - t[i])

for i in range(N - 1):
    tmp = h.index(max(h))
    h[tmp] = 0
print(sum(h))

Fixed submission:
N, M = map(int, input().split())
X = list(map(int, input().split()))
t = sorted(X, reverse=True)
h = [0] * M
for i in range(1, M):
    h[i] = abs(t[i - 1] - t[i])

tmp = sorted(h, reverse=True)
print(sum(tmp[N - 1:]))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
X = list(map(int, input().split()))
t = sorted(X, reverse=True)
h = [0] * M
for i in range(1, M):
    h[i] = abs(t[i - 1] - t[i])

for i in range(N - 1):
    tmp = h.index(max(h))
    h[tmp] = 0
print(sum(h))

Fixed submission:
N, M = map(int, input().split())
X = list(map(int, input().split()))
t = sorted(X, reverse=True)
h = [0] * M
for i in range(1, M):
    h[i] = abs(t[i - 1] - t[i])

tmp = sorted(h, reverse=True)
print(sum(tmp[N - 1:]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
h = list(map(int, input().split()))
cnt = 0
start = 0
end = 0
while True:
    for i in range(N):
        if h[i] != 0:
            start = i
            break

    end = N
    for i in range(start + 1, N):
        if h[i] == 0:
            end = i
            break

    for i in range(start, end):
        h[i] = h[i] - 1

    cnt += 1
    start = 0
    end = 0
    if sum(h) == 0:
        break

print(cnt)

Fixed submission:
import sys

N = int(input())
h = list(map(int, input().split()))
cnt = 0
start = 0
end = 0
if sum(h) == 0:
    print(0)
    sys.exit()

while True:
    for i in range(N):
        if h[i] != 0:
            start = i
            break

    end = N
    for i in range(start + 1, N):
        if h[i] == 0:
            end = i
            break

    for i in range(start, end):
        if h[i] != 0:
            h[i] = h[i] - 1

    cnt += 1
    start = 0
    end = 0
    if sum(h) == 0:
        break

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
h = list(map(int, input().split()))
cnt = 0
start = 0
end = 0
while True:
    for i in range(N):
        if h[i] != 0:
            start = i
            break

    end = N
    for i in range(start + 1, N):
        if h[i] == 0:
            end = i
            break

    for i in range(start, end):
        h[i] = h[i] - 1

    cnt += 1
    start = 0
    end = 0
    if sum(h) == 0:
        break

print(cnt)

Fixed submission:
import sys

N = int(input())
h = list(map(int, input().split()))
cnt = 0
start = 0
end = 0
if sum(h) == 0:
    print(0)
    sys.exit()

while True:
    for i in range(N):
        if h[i] != 0:
            start = i
            break

    end = N
    for i in range(start + 1, N):
        if h[i] == 0:
            end = i
            break

    for i in range(start, end):
        if h[i] != 0:
            h[i] = h[i] - 1

    cnt += 1
    start = 0
    end = 0
    if sum(h) == 0:
        break

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
INF = 10 ** 9
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [INF] * N
dp[0] = 0
for i in range(1, N):
    for j in range(K):
        if i + j < N:
            dp[i + j] = min(dp[i + j], dp[i - 1] + abs(h[i - 1] - h[i + j]))

print(dp[N - 1])

Fixed submission:
N, K = map(int, input().split())
hList = list(map(int, input().split()))
ans = 0
dp = [0] * N
dp[0] = 0

for i in range(1, N):
    minT = 1000000000
    for j in range(i - 1, i - K - 1, -1):
        tmp = dp[j] + abs(hList[j] - hList[i])
        minT = min(minT, tmp)
        if j == 0:
            break
    dp[i] = minT

print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
hList = list(map(int, input().split()))
ans = 0
dp = [0] * N
dp[0] = 0

for i in range(1, N):
    minT = 1000000000
    for j in range(i - 1, i - K - 1, -1):
        tmp = dp[j] + abs(hList[j] - hList[i])
        minT = min(minT, tmp)
        if j == 0:
            break
    dp[i] = minT

print(dp[N - 1])

Fixed submission:
N, K = map(int, input().split())
hList = list(map(int, input().split()))
ans = 0
dp = [0] * N
dp[0] = 0

for i in range(1, N):
    minT = 1000000000
    for j in range(i - 1, i - K - 1, -1):
        tmp = dp[j] + abs(hList[j] - hList[i])
        minT = min(minT, tmp)
        if j == 0:
            break
    dp[i] = minT

print(dp[N - 1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for j in range(W + 1):
        if j - wv[i][0] >= 0:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1])
        else:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

print(dp[N][W])

Fixed submission:
N, W = map(int, input().split())
w = [list(map(int, input().split())) for _ in range(N)]
dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]

for i in range(N):
    for j in range(W + 1):
        if j - w[i][0] >= 0:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i][0]] + w[i][1])

        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

print(dp[N][W])

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
w = [list(map(int, input().split())) for _ in range(N)]
dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]

for i in range(N):
    for j in range(W + 1):
        if j - w[i][0] >= 0:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i][0]] + w[i][1])

        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

print(dp[N][W])

Fixed submission:
N, W = map(int, input().split())
w = [list(map(int, input().split())) for _ in range(N)]
dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]

for i in range(N):
    for j in range(W + 1):
        if j - w[i][0] >= 0:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i][0]] + w[i][1])

        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

print(dp[N][W])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
INF = 10 ** 9 + 7
wvLst = [list(map(int, input().split())) for _ in range(N)]
dp = [[INF for i in range(10 ** 5 + 1)] for _ in range(N + 1)]

dp[0][0] = 0
for i in range(N):
    for j in range(10 ** 5 + 1):
        if j - wvLst[i][1] >= 0:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - wvLst[i][1]] + wvLst[i][0])
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
ans = 0
for i in range(10 ** 5 + 1):
    if dp[N][i] <= W:
        ans = i

print(ans)

Fixed submission:
N, W = map(int, input().split())
INF = 10 ** 9 + 7
wvLst = [list(map(int, input().split())) for _ in range(N)]
dp = [[INF for i in range(10 ** 5 + 1)] for _ in range(N + 1)]

dp[0][0] = 0
for i in range(N):
    for j in range(10 ** 5 + 1):
        if j - wvLst[i][1] >= 0:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - wvLst[i][1]] + wvLst[i][0])
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
ans = 0
for i in range(10 ** 5 + 1):
    if dp[N][i] <= W:
        ans = i

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
n = len(s)
m = len(t)
dp = [[0 for _ in range(len(s) + 1)] for _ in range(len(t) + 1)]

for i in range(len(t)):
    for j in range(len(s)):
        if t[i] == s[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        else:
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])
cnt = dp[m][n]
ans = ''
while n > 0 and m > 0:
    if dp[m][n] == dp[m][n - 1]:
        n -= 1
    elif dp[m][n] == dp[m - 1][n]:
        m -= 1
    else:
        ans = s[n - 1] + ans
        n -= 1
        m -= 1

print(ans)

Fixed submission:
def solve(n, m, s, t):
    dp = [[0 for i in range(m + 1)] for _ in range(n + 1)]
    for i in range(n):
        for j in range(m):
            if s[i] == t[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])

    ans = ''
    while n > 0 and m > 0:
        if dp[n][m] == dp[n - 1][m]:
            n -= 1
        elif dp[n][m] == dp[n][m - 1]:
            m -= 1
        else:
            ans = s[n - 1] + ans
            n -= 1
            m -= 1
    print(ans)
    return

s = input()
t = input()

solve(len(s), len(t), s, t)

Buggy python submission (verdict: Time Limit Exceeded):
def solve(n, m, s, t):
    dp = [[0 for i in range(m + 1)] for _ in range(n + 1)]
    for i in range(n):
        for j in range(m):
            if s[i] == t[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])

    ans = ''
    while n > 0 and m > 0:
        if dp[n][m] == dp[n - 1][m]:
            n -= 1
        elif dp[n][m] == dp[n][m - 1]:
            m -= 1
        else:
            ans = s[n - 1] + ans
            n -= 1
            m -= 1
    print(ans)
    return

s = input()
t = input()

solve(len(s), len(t), s, t)

Fixed submission:
def solve(n, m, s, t):
    dp = [[0 for i in range(m + 1)] for _ in range(n + 1)]
    for i in range(n):
        for j in range(m):
            if s[i] == t[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])

    ans = ''
    while n > 0 and m > 0:
        if dp[n][m] == dp[n - 1][m]:
            n -= 1
        elif dp[n][m] == dp[n][m - 1]:
            m -= 1
        else:
            ans = s[n - 1] + ans
            n -= 1
            m -= 1
    print(ans)
    return

s = input()
t = input()

solve(len(s), len(t), s, t)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
p = list(map(float, input().split()))

dp = [[0] * (N + 1) for _ in range(N + 1)]
dp[0][0] = 1

for i in range(N):
    for j in range(i + 1):
        dp[i + 1][j + 1] += dp[i][j] * p[i]
        dp[i + 1][j] += dp[i][j] * (1 - p[i])
ans = 0
for i in range(N // 2 + 1, N + 1):
    ans += dp[N][i]

print(ans)

Fixed submission:
N = int(input())
p = list(map(float, input().split()))

dp = [[0] * (N + 1) for _ in range(N + 1)]
dp[0][0] = 1

for i in range(N):
    for j in range(i + 1):
        dp[i + 1][j + 1] += dp[i][j] * p[i]
        dp[i + 1][j] += dp[i][j] * (1 - p[i])
ans = 0
for i in range(N // 2 + 1, N + 1):
    ans += dp[N][i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C = map(int, input().split())
jyotai = 0
ans = 0
while True:
    if A == 0 and B == 0 and jyotai == 1:
        break
    if B == 0 and C == 0:
        break

    if jyotai == 0:
        if C != 0:
            ans += 1
            C -= 1
            jyotai += 1
        else:
            ans += 1
            B -= 1
            jyotai -= 1

    else:
        if B != 0:
            ans += 1
            B -= 1
        else:
            A -= 1
        jyotai -= 1

print(ans)

Fixed submission:
A, B, C = map(int, input().split())
ans = 2 * B
C -= B
if A >= C:
    ans += C
else:
    ans += A + 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
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)

Fixed submission:
S = input()
B = S.count('B')
W = S.count('W')
es = 'W' * W + 'B'* B
bf = es.find('B')
blst = [0] * B
for i in range(B):
    blst[i] = bf + i
slst = [0] * B
bindex = 0
for i in range(len(S)):
    if S[i] == 'B':
        slst[bindex] = i
        bindex += 1

ans = 0
for i in range(B):
    ans += blst[i] - slst[i]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
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)

Fixed submission:
S = input()
B = S.count('B')
W = S.count('W')
es = 'W' * W + 'B'* B
bf = es.find('B')
blst = [0] * B
for i in range(B):
    blst[i] = bf + i
slst = [0] * B
bindex = 0
for i in range(len(S)):
    if S[i] == 'B':
        slst[bindex] = i
        bindex += 1

ans = 0
for i in range(B):
    ans += blst[i] - slst[i]

print(ans)