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


def eratosthenes(n):
    sieve = [True for _ in range(n + 1)]
    sieve[0] = False
    sieve[1] = False

    def _update(p):
        if sieve[p]:
            for i in range(p * 2, n + 1, p):
                sieve[i] = False

    _update(2)
    p = 3
    while p * p <= n:
        _update(p)
        p += 2
    return sieve


n = int(input())
sieve = eratosthenes(n)
primes = [i for i in range(n + 1) if sieve[i]]
counter = collections.Counter()
for i in range(2, n + 1):
    for p in primes:
        while i % p == 0:
            counter[p] += 1
            i //= p
        if i == 1:
            break

counter2 = collections.Counter()
for i in [2, 4, 14, 24, 74]:
    for p in primes:
        if counter[p] >= i:
            counter2[i] += 1

c0 = counter2[74]
c1 = counter2[24] * (counter2[2] - 1)
c2 = counter2[14] * (counter2[4] - 1)
c3 = (counter2[4] * (counter2[4] - 1) * (counter2[2] - 2)) // 2
print(c0 + c1 + c2 + c3)

Fixed submission:
import collections


def eratosthenes(n):
    sieve = [True for _ in range(n + 1)]
    sieve[0] = False
    sieve[1] = False

    def _update(p):
        if sieve[p]:
            for i in range(p * 2, n + 1, p):
                sieve[i] = False
    if n > 1:
        _update(2)
    p = 3
    while p * p <= n:
        _update(p)
        p += 2
    return sieve


n = int(input())
sieve = eratosthenes(n)
primes = [i for i in range(n + 1) if sieve[i]]
counter = collections.Counter()
for i in range(2, n + 1):
    for p in primes:
        while i % p == 0:
            counter[p] += 1
            i //= p
        if i == 1:
            break

counter2 = collections.Counter()
for i in [2, 4, 14, 24, 74]:
    for p in primes:
        if counter[p] >= i:
            counter2[i] += 1

c0 = counter2[74]
c1 = counter2[24] * (counter2[2] - 1)
c2 = counter2[14] * (counter2[4] - 1)
c3 = (counter2[4] * (counter2[4] - 1) * (counter2[2] - 2)) // 2
print(c0 + c1 + c2 + c3)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
cities = []
for i in range(m):
    p, y = map(int, input().split())
    cities.append([p, y, i])
cities = sorted(cities, key=lambda x: (x[0], x[1]))

prev = 0
count = 0
res = []
for city in cities:
    if city[0] != prev:
        count = 0
        prev = city[0]
    count += 1
    res.append([f'{city[0]:06d}{count:06d}', city[2]])
res = sorted(res, key=lambda x: x[1])

for x in res:
    print(x[0])

Fixed submission:
n, m = map(int, input().split())
cities = []
for i in range(m):
    p, y = map(int, input().split())
    cities.append([p, y, i])
cities = sorted(cities, key=lambda x: (x[0], x[1]))

prev = 0
count = 0
res = []
for city in cities:
    if city[0] != prev:
        count = 0
        prev = city[0]
    count += 1
    res.append(['{:06d}{:06d}'.format(city[0], count), city[2]])
res = sorted(res, key=lambda x: x[1])

for x in res:
    print(x[0])
Buggy python submission (verdict: Runtime Error):
import collections
import math

MOD = 10**9 + 7


def eratosthenes(n):
    sieve = [True for _ in range(n + 1)]
    sieve[0] = False
    sieve[1] = False

    def _update(p):
        if sieve[p]:
            for i in range(p * 2, n + 1, p):
                sieve[i] = False

    if n > 1:
        _update(2)
    p = 3
    while p * p <= n:
        _update(p)
        p += 2
    return sieve


n, m = map(int, input().split())
mm = math.ceil(math.sqrt(m))
sieve = eratosthenes(mm)
primes = [i for i in range(mm) if sieve[i]]
counter = collections.Counter()
for p in primes:
    while m % p == 0:
        counter[p] += 1
        m //= p
    if m == 1:
        break
else:
    if m != 1:
        counter[m] += 1

me = max(counter.values())
factorials = [1]
for i in range(1, me + 1):
    factorials.append(factorials[-1] * i)

res = 1
for p, e in counter.items():
    for i in range(e):
        res *= e + n - 1 - i
    res //= factorials[e]
    res %= MOD
print(res)

Fixed submission:
import collections
import math

MOD = 10**9 + 7


def eratosthenes(n):
    sieve = [True for _ in range(n + 1)]
    sieve[0] = False
    sieve[1] = False

    def _update(p):
        if sieve[p]:
            for i in range(p * 2, n + 1, p):
                sieve[i] = False

    if n > 1:
        _update(2)
    p = 3
    while p * p <= n:
        _update(p)
        p += 2
    return sieve


n, m = map(int, input().split())
mm = math.ceil(math.sqrt(m))
sieve = eratosthenes(mm)
primes = [i for i in range(mm) if sieve[i]]
counter = collections.Counter()
for p in primes:
    while m % p == 0:
        counter[p] += 1
        m //= p
    if m == 1:
        break
else:
    if m != 1:
        counter[m] += 1

me = max(counter.values()) if len(counter.values()) > 0 else 0
factorials = [1]
for i in range(1, me + 1):
    factorials.append(factorials[-1] * i)

res = 1
for p, e in counter.items():
    for i in range(e):
        res *= e + n - 1 - i
    res //= factorials[e]
    res %= MOD
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
ls = list(map(int, input().split()))

res = 2 * (abs(ls[0]) + abs(ls[-1]))
for i in range(n - k + 1):
    l = ls[i:i + k]
    if l[-1] <= 0:
        res = min(res, -l[0])
    elif l[0] >= 0:
        res = min(res, l[-1])
    else:
        res = min(res, -2 * l[0] + l[-1], -l[0] + 2 * l[-1])
print(res)

Fixed submission:
n, k = map(int, input().split())
ls = list(map(int, input().split()))

res = 2 * (abs(ls[0]) + abs(ls[-1]))
for i in range(n - k + 1):
    a = ls[i]
    b = ls[i + k - 1]
    if b <= 0:
        res = min(res, -a)
    elif a >= 0:
        res = min(res, b)
    else:
        res = min(res, -2 * a + b, -a + 2 * b)
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
ls = list(map(int, input().split()))

res = 2 * (abs(ls[0]) + abs(ls[-1]))
for i in range(n - k + 1):
    l = ls[i:i + k]
    if l[-1] <= 0:
        res = min(res, -l[0])
    elif l[0] >= 0:
        res = min(res, l[-1])
    else:
        res = min(res, -2 * l[0] + l[-1], -l[0] + 2 * l[-1])
print(res)

Fixed submission:
n, k = map(int, input().split())
ls = list(map(int, input().split()))

res = 2 * (abs(ls[0]) + abs(ls[-1]))
for i in range(n - k + 1):
    a = ls[i]
    b = ls[i + k - 1]
    if b <= 0:
        res = min(res, -a)
    elif a >= 0:
        res = min(res, b)
    else:
        res = min(res, -2 * a + b, -a + 2 * b)
print(res)
Buggy python submission (verdict: Runtime Error):
s = input().strip()
k = int(input())

count = 0
for i in range(k):
    c = s[i]
    if c != '1':
        print(c)
    else:
        count += 1
else:
    print('1')

Fixed submission:
s = input().strip()
k = int(input())

count = 0
for i in range(len(s)):
    c = s[i]
    if c != '1':
        if k <= count:
            print('1')
        else:
            print(c)
        break
    else:
        count += 1
else:
    print('1')
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import sys

input = sys.stdin.readline

n, m, q = map(int, input().split())
ls = [[0] * n for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    ls[l - 1][r - l] += 1
for i in range(n):
    ls[i] = list(itertools.accumulate(ls[i]))
for _ in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    res = 0
    for i in range(min(r - l + 1, n - l)):
        res += ls[l + i][r - l - i]
    print(res)

Fixed submission:
import itertools
import sys

input = sys.stdin.readline

n, m, q = map(int, input().split())
ls = [[0] * n for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    ls[l - 1][r - l] += 1
for i in range(n):
    ls[i] = list(itertools.accumulate(ls[i]))
for _ in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    res = 0
    for i in range(r - l + 1):
        res += ls[l + i][r - l - i]
    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys

input = sys.stdin.readline

n, m, q = map(int, input().split())
ls = [[] for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    ls[l - 1].append(r - l)
for i in range(n):
    ls[i].sort()
for _ in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    res = 0
    for i in range(min(r - l + 1, n - l)):
        res += bisect.bisect(ls[l + i], r - l - i)
    print(res)

Fixed submission:
import itertools
import sys

input = sys.stdin.readline

n, m, q = map(int, input().split())
ls = [[0] * n for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    ls[l - 1][r - l] += 1
for i in range(n):
    ls[i] = list(itertools.accumulate(ls[i]))
for _ in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    res = 0
    for i in range(r - l + 1):
        res += ls[l + i][r - l - i]
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

n, m = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(m)]
heapq.heapify(ls)
res = 0
r = min([r for _, r in ls])
while True:
    res += 1
    while ls:
        ll, rr = heapq.heappop(ls)
        if ll >= r:
            heapq.heappush(ls, [ll, rr])
            break
    if len(ls) > 0:
        r = min([r for _, r in ls])
    else:
        break
print(res)

Fixed submission:
n, m = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(m)]
ls.sort()
res = 1
rmin = float('inf')
for l, r in ls:
    if l >= rmin:
        res += 1
        rmin = r
    else:
        rmin = min(rmin, r)

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

n, m = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(m)]
heapq.heapify(ls)
res = 0
r = min([r for _, r in ls])
while True:
    res += 1
    while ls:
        ll, rr = heapq.heappop(ls)
        if ll >= r:
            heapq.heappush(ls, [ll, rr])
            break
    if len(ls) > 0:
        r = min([r for _, r in ls])
    else:
        break
print(res)

Fixed submission:
n, m = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(m)]
ls.sort()
res = 1
rmin = float('inf')
for l, r in ls:
    if l >= rmin:
        res += 1
        rmin = r
    else:
        rmin = min(rmin, r)

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

n, m = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(m)]
ls2 = [[r, l] for l, r in ls]
heapq.heapify(ls)
heapq.heapify(ls2)
res = 0
while ls2:
    r, l = heapq.heappop(ls2)
    res += 1
    while ls:
        ll, rr = heapq.heappop(ls)
        if ll >= r:
            heapq.heappush(ls, [ll, rr])
            break
    ls2 = []
    for l, r in ls:
        heapq.heappush(ls2, [r, l])
print(res)

Fixed submission:
n, m = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(m)]
ls.sort()
res = 1
rmin = float('inf')
for l, r in ls:
    if l >= rmin:
        res += 1
        rmin = r
    else:
        rmin = min(rmin, r)

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ls = list(map(int, input().split()))
ls = [x - i - 1 for i, x in enumerate(ls)]
ls = [abs(x - sum(ls) // n) for x in ls]
print(sum(ls))

Fixed submission:
n = int(input())
ls = list(map(int, input().split()))
ls = sorted([x - i - 1 for i, x in enumerate(ls)])
m = ls[n // 2]
ls = [abs(x - m) for x in ls]
print(sum(ls))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n = int(input())
ls = [0] + list(map(int, input().split()))
s0 = list(itertools.accumulate(ls))
s1 = list(itertools.accumulate(ls, lambda a, b: a ^ b))
res = 0
for l in range(1, n + 1):
    for r in range(l, n + 1):
        a = s0[r] - s0[l - 1]
        b = s1[r] ^ s1[l - 1]
        if a == b:
            res += 1
print(res)

Fixed submission:
import itertools

n = int(input())
ls = [0] + list(map(int, input().split()))
s0 = list(itertools.accumulate(ls))
s1 = list(itertools.accumulate(ls, lambda a, b: a ^ b))
res = 0
left = 0
right = 1
count = 0
while left <= n:
    while left < right - 1:
        a = s0[right] - s0[left]
        b = s1[right] ^ s1[left]
        if a != b:
            left += 1
        else:
            res -= (right - left - 1) * (right - left) // 2
            break
    while right <= n + 1:
        if right == n + 1:
            break
        a = s0[right] - s0[left]
        b = s1[right] ^ s1[left]
        if a == b:
            right += 1
        else:
            break
    res += (right - left - 1) * (right - left) // 2
    if right == n + 1:
        break
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
s = input().strip()
k = int(input())
ss = []
for i in range(1, len(s) + 1):
    for j in range(len(s) + 1 - i):
        ss.append(s[j:j + i])
ss = list(set(ss))
ss.sort()
print(ss[k - 1])

Fixed submission:
s = input().strip()
k = int(input())
ss = []
n = len(s)
for i in range(n):
    for j in range(1, 6):
        if i + j <= n:
            ss.append(s[i:i + j])
ss = list(set(ss))
ss.sort()
print(ss[k - 1])
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
s = input()
ok = True
for i in range(a):
    if s[i] == '-':
        ok = False
ok = ok and s[a] == '-'
for i in range(b):
    if s[a + 2 + i] == '-':
        ok = False
if ok:
    print('Yes')
else:
    print('No')

Fixed submission:
a, b = map(int, input().split())
s = input()
ok = True
for i in range(a):
    if s[i] == '-':
        ok = False
ok = ok and s[a] == '-'
for i in range(b):
    if s[a + 1 + i] == '-':
        ok = False
if ok:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
a, b, c, d, e, f = map(int, input().split())
res = None
m = 0
for aa in range(0, f, 100 * a):
    for bb in range(0, f, 100 * b):
        w = aa + bb
        if w == 0 or aa + bb > f:
            continue
        r = f - w
        for cc in range(0, r, c):
            for dd in range(0, r, d):
                s = cc + dd
                if s + w > f or 100 * s > e * w:
                    continue
                mm = s / w
                if mm > m:
                    res = (w + s, s)
                    m = mm
print(*res)

Fixed submission:
a, b, c, d, e, f = map(int, input().split())
res = (100 * a, 0)
for aa in range(0, f + 1, 100 * a):
    for bb in range(0, f + 1, 100 * b):
        w = aa + bb
        if w == 0 or w >= f:
            continue
        r = f - w
        for cc in range(0, r + 1, c):
            for dd in range(0, r + 1, d):
                s = cc + dd
                t = w + s
                if t > f or 100 * s > e * w:
                    continue
                if s * res[0] > res[1] * t:
                    res = (t, s)
print(*res)
Buggy python submission (verdict: Time Limit Exceeded):
n, ma, mb = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
MAX_N = 10 * n + 1
dp = [[[float('inf')] * MAX_N for _ in range(MAX_N)] for _ in range(n + 1)]
dp[0][0][0] = 0

for k, (a, b, c) in enumerate(ls):
    for i in range(MAX_N):
        for j in range(MAX_N):
            dp[k + 1][i][j] = min(dp[k + 1][i][j], dp[k][i][j])
            if i + a < MAX_N and j + b < MAX_N:
                dp[k + 1][i + a][j + b] = min(dp[k][i][j] + c,
                                              dp[k][i + a][j + b])
p = min([
    dp[n][ma * i][mb * i] for i in range(1, MAX_N)
    if ma * i < MAX_N and mb * i < MAX_N
])
if p < float('inf'):
    print(p)
else:
    print(-1)

Fixed submission:
n, ma, mb = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
MAX_N = 10 * n + 1
dp = [[[float('inf')] * MAX_N for _ in range(MAX_N)] for _ in range(n + 1)]
dp[0][0][0] = 0

for k, (a, b, c) in enumerate(ls):
    for i in range(MAX_N):
        for j in range(MAX_N):
            dp[k + 1][i][j] = min(dp[k + 1][i][j], dp[k][i][j])
            if i + a < MAX_N and j + b < MAX_N:
                dp[k + 1][i + a][j + b] = min(dp[k][i][j] + c,
                                              dp[k][i + a][j + b])
p = min([
    dp[n][ma * i][mb * i] for i in range(1, MAX_N)
    if ma * i < MAX_N and mb * i < MAX_N
])
if p < float('inf'):
    print(p)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
s = input().rstrip()
res = 0
for i in range(len(s)):
    if s[i] == 'A':
        res -= i - 1
        break
for i in range(len(s)):
    if s[::-1][i] == 'Z':
        res += len(s) - 1 - i
        break
print(res)

Fixed submission:
s = input().rstrip()
ss = s[::-1]
n = len(s)
res = 0
for i in range(n):
    if s[i] == 'A':
        res -= i - 1
        break
for i in range(n):
    if ss[i] == 'Z':
        res += n - 1 - i
        break
print(res)
Buggy python submission (verdict: Runtime Error):
s = input().rstrip()
n = len(s)
res = 0
for i in range(2**(n - 1)):
    bs = bin(i)[2:].rjust(n - 1, '0')
    ss = s[0]
    for j, b in enumerate(bs, 1):
        if b == '1':
            ss += '+'
        ss += s[j]
    res += eval(ss)
print(res)

Fixed submission:
s = input().rstrip()
n = len(s)
res = 0
for i in range(2**(n - 1)):
    bs = bin(i)[2:].rjust(n - 1, '0')
    ss = s[0]
    for b, c in zip(bs, s[1:]):
        if b == '1':
            ss += '+'
        ss += c
    res += eval(ss)
print(res)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split()  ) #split()で分解したものを別々の変数に入れる

result=0

if a % b <>0:
    result += 1 

result += a // b 
print(result)

#################



Fixed submission:
a, b = map(int, input().split()  ) #split()で分解したものを別々の変数に入れる

result=0

if a % b !=0:
    result += 1 

result += a // b 
print(result)

#####################
Buggy python submission (verdict: Runtime Error):
h, n = map(int, input().split()  ) #split()で分解したものを別々の変数に入れる
l = []
for i in range(n):
    l.append(input()) 

a = sum(l)

if h > a:
    print('No')
else:
    print('Yes')

Fixed submission:
h, n = map(int, input().split()  ) #split()で分解したものを別々の変数に入れる
l = list(map(int, input().split()))  

a = sum(l)

if h > a:
    print('No')
else:
    print('Yes')

Buggy python submission (verdict: Runtime Error):
h, n = map(int, input().split()  ) #split()で分解したものを別々の変数に入れる
l = []
for i in range(n):
    l.append(input()) 

a = sum(l)

if h >= a:
    print('Yes')
else:
    print('No')

Fixed submission:
h, n = map(int, input().split()  ) #split()で分解したものを別々の変数に入れる
l = list(map(int, input().split()))  

a = sum(l)

if h > a:
    print('No')
else:
    print('Yes')
Buggy python submission (verdict: Runtime Error):
import math
from math import atan, cos, tan

a, b, x = map(int, input().split()  ) #split()で分解したものを別々の変数に入れる

result =0

if x>=a**2 * b/2:
    result = math.degrees(math.pi /2 - atan(a/ (2*(b - x/a**2))))
else:
    result = math.degrees(math.pi /2 - atan(2*x/(a*b)/b))

print(result)

Fixed submission:
import math
from math import atan, cos, tan

a, b, x = map(int, input().split()  ) #split()で分解したものを別々の変数に入れる

result =0

if x>=a**2 * b/2:
    result = math.degrees(atan((2*(b - x/a**2)/a)))
else:
    result = math.degrees(atan(a*b**2/2/x))

print(result)
Buggy python submission (verdict: Runtime Error):
import bisect
from bisect import bisect_left

n = int(input()) #n行の入力をリストに入れる
l = []
for i in range(n):
    l.append(input()) 

l.sort()
result =0
for i in range(n):
    a =l[i]
    for j in range(i+1,n-1):
        b=l[j]
        k = bisect_left(l,a+b)
        result += k-j-1

print(result)




Fixed submission:
import bisect
from bisect import bisect_left

n = int(input()) #n行の入力をリストに入れる
l = []
l = list(map(int, input().split( )))

l.sort()
result =0
for i in range(n-2):
    a =l[i]
    for j in range(i+1,n-1):
        b=l[j]
        k = bisect_left(l,a+b)
        result += k-j-1

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input()) #n行の入力をリストに入れる
l = []
for i in range(n):
    l.append(input()) 

from collections import Counter

def get_counter(s):
    return Counter(s.upper().replace(' ', ''))

def verify_anagrams(first_word, second_word):
    return get_counter(first_word) == get_counter(second_word)

count =0 
for i in range(n):
    for j in range(i+1,n):
        if verify_anagrams(l[i],l[j])==True:
            count += 1

print(count)
#print(verify_anagrams(l[0],l[2]))

Fixed submission:
from collections import Counter

n = int(input()) #n行の入力をリストに入れる
S = [''.join(sorted(input())) for i in range(n)] #inputの文字列をソートできる
counter = Counter(S) #Sの中の文字列を集計し、dict型で返せる

ans =0 
for i in counter.values():
    ans += i*(i-1)//2

print(ans)

""""
l = []
for i in range(n):
    l.append(input()) 

def get_counter(s):
    return Counter(s.upper().replace(' ', ''))

def verify_anagrams(first_word, second_word):
    return get_counter(first_word) == get_counter(second_word)

count =0 
for i in range(n):
    for j in range(i+1,n):
        if verify_anagrams(l[i],l[j])==True:
            count += 1


print(count)

#print(verify_anagrams(l[0],l[2]))
"""
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
counter=0

while S.find('W') != -1:
    for i in range(len(S)):
        if S[i]=='B':
            counter+=1
        else:
            temp = S[:i]+S[i+1:]
            S =temp
            break

print(counter)

Fixed submission:
S=input()
counter=0
result = 0

for i in range(len(S)):
    if S[i]=='B':
        counter+=1
    else:
        result +=counter

print(result)

Buggy python submission (verdict: Runtime Error):
temp=input()
S=list(temp)
counter1=0
counter2=0
counter3=0 
i=len(S)-1

while True:
    if S[i-1]=='B' and S[i]=='W':
        S[i-1]='W'
        S[i]='B'
        counter1 +=1
    i -=1
    if i ==0:
        if counter1==counter2:
            break
        counter2=counter1
        for j in range(len(S)):
            if S[j]=='W':
                counter3 =j
            j -=1
        i= counter3

print(counter1)


Fixed submission:
S=input()
counter=0
result = 0

for i in range(len(S)):
    if S[i]=='B':
        counter+=1
    else:
        result +=counter

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
temp=input()
S=list(temp)
counter1=0
counter2=0
counter3=0 
i=len(S)-1

while True:
    if S[i-1]=='B' and S[i]=='W':
        S[i-1]='W'
        S[i]='B'
        counter1 +=1
    i -=1
    if i ==0:
        if counter1==counter2:
            break
        counter2=counter1
        counter3+=1
        i=len(S) - counter3

print(counter1)

Fixed submission:
S=input()
counter=0
result = 0

for i in range(len(S)):
    if S[i]=='B':
        counter+=1
    else:
        result +=counter

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
temp=input()
S=list(temp)
counter1=0
counter2=0 
i=0
while True:
    if S[i]=='B' and S[i+1]=='W':
        S[i]='W'
        S[i+1]='B'
        counter1 +=1
    i +=1
    if i ==len(S)-1:
        if counter1==counter2:
            break
        counter2=counter1
        i=0

print(counter1)



Fixed submission:
S=input()
counter=0
result = 0

for i in range(len(S)):
    if S[i]=='B':
        counter+=1
    else:
        result +=counter

print(result)
Buggy python submission (verdict: Runtime Error):
A,B,K = input().split()
A=int(A)
B=int(B)
K=int(K)

if K==1:
    if A % 2 ==1:
        A =A-1
    A =A/2
    B=B+A

if K==2:
    if A % 2 ==1:
        A =A-1
    A =A/2
    B=B+A
    if B % 2==1:
        B=B-1
    B=B/2
    A=A+B

if K>=3:
    for i in range(1,K,2):
        if A % 2 ==1:
            A =A-1
        A =A/2
        B=B+A
        if B % 2==1:
            B=B-1
        B=B/2
        A=A+B

    if K%2==1:
        if A % 2 ==1:
            A =A-1
        A =A/2
        B=B+A


print (int(A),int(B))

Fixed submission:
A = input()
chars = list(A)

result ="0"
if len(A)==2:
    result = A
else:
    result= chars[2]+chars[1]+chars[0]

print(result)