Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = []
for i in range(n):
    s.append(sorted(input()))
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        if s[i] == s[j]:
            ans += 1
print(ans)

Fixed submission:
n = int(input())
s = sorted([sorted(input()) for i in range(n)])
a = []
last = s[0]
count = 1
for i in range(1, n):
    if s[i] == last:
        count += 1
    else:
        a.append(count)
        count = 1
    last = s[i]
a.append(count)
ans = 0
for i in a:
    if i > 1:
        ans += i * (i - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [sorted(input()) for i in range(n)]
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        if s[i] == s[j]:
            ans += 1
print(ans)

Fixed submission:
n = int(input())
s = sorted([sorted(input()) for i in range(n)])
a = []
last = s[0]
count = 1
for i in range(1, n):
    if s[i] == last:
        count += 1
    else:
        a.append(count)
        count = 1
    last = s[i]
a.append(count)
ans = 0
for i in a:
    if i > 1:
        ans += i * (i - 1) // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
odd = [0] * n
even = [1] * n
count = 1
loop = 0
for i in range(1, n):
    if s[i] == s[i - 1]:
        count += 1
    else:
        loop = max(loop, count)
        count = 1
loop = max(loop, count)
for i in range(1, loop + 1):
    if i % 2:
        for j in range(n):
            if s[j] == "R":
                odd[j + 1] += even[j]
            else:
                odd[j - 1] += even[j]
            if i != loop:
                even[j] = 0
    else:
        for j in range(n):
            if s[j] == "R":
                even[j + 1] += odd[j]
            else:
                even[j - 1] += odd[j]
            odd[j] = 0
print(" ".join(map(str, even)))

Fixed submission:
s = input()
n = len(s)
count_R = 0
count_L = 0
ans = [0] * n
for i in range(n):
    if s[i] == "R":
        if count_L:
            su = count_R + count_L
            if su % 2:
                if count_L % 2:
                    ans[sakai] = su // 2 + 1
                    ans[sakai - 1] = su // 2
                else:
                    ans[sakai] = su // 2
                    ans[sakai - 1] = su // 2 + 1
            else:
                ans[sakai] = su // 2
                ans[sakai - 1] = su // 2
            count_R = 0
            count_L = 0
        count_R += 1
    else:
        if s[i - 1] == "R":
            sakai = i
        count_L += 1
if count_L:
    su = count_R + count_L
    if su % 2:
        if count_L % 2:
            ans[sakai] = su // 2 + 1
            ans[sakai - 1] = su // 2
        else:
            ans[sakai] = su // 2
            ans[sakai - 1] = su // 2 + 1
    else:
        ans[sakai] = su // 2
        ans[sakai - 1] = su // 2
    count_R = 0
    count_L = 0
print(" ".join(map(str, ans)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n - 1, -1, -1):
    count = 0
    for j in b:
        if j % (i + 1) == 0:
            count += 1
    if count % 2 != a[i]:
        b.append(i + 1)
print(len(b))
print(" ".join(list(map(str, b))))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = set()
for i in range(n - 1, -1, -1):
    count = 0
    c = i + 1
    while c < 200000:
        if c in b:
            count += 1
        c += (i + 1)
    if count % 2 != a[i]:
        b.add(i + 1)
print(len(b))
print(" ".join(list(map(str, b))))
Buggy python submission (verdict: Runtime Error):
import math

def nCr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, k = map(int, input().split())
r = n - k
mod = 10 ** 9 + 7
for i in range(1, k + 1):
    if i == 1 or i == k:
        print(nCr(r + 1, i) % mod)
    else:
        print(nCr(r + 1, i) * (k - 1) % mod)

Fixed submission:
import math

def nCr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, k = map(int, input().split())
r = n - k
mod = 10 ** 9 + 7
for i in range(1, k + 1):
    if i > r + 1:
        print(0)
    else:
        if i == 1 or i == k:
            print(nCr(r + 1, i) % mod)
        else:
            print(nCr(r + 1, i) * (nCr(k - 1, i - 1)) % mod)
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
L = list(map(int, input().split()))
if sum(L) < x:
    print(n + 1)
else:
    i = 0
    d = 0
    while d <= x:
        d += L[i]
        i += 1
    print(i)

Fixed submission:
n, x = map(int, input().split())
L = list(map(int, input().split()))
if sum(L) <= x:
    print(n + 1)
else:
    i = 0
    d = 0
    while d <= x:
        d += L[i]
        i += 1
    print(i)

Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
L = list(map(int, input().split()))
i = 0
d = 0
while d <= x:
    d += L[i]
    i += 1
print(i)

Fixed submission:
n, x = map(int, input().split())
L = list(map(int, input().split()))
if sum(L) <= x:
    print(n + 1)
else:
    i = 0
    d = 0
    while d <= x:
        d += L[i]
        i += 1
    print(i)
Buggy python submission (verdict: Runtime Error):
import math

def nCr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, m = map(int, input().split())
a = [int(input()) for i in range(m)]
b = []
for i in range(m):
    if i == 0:
        b.append(a[i] - 1)
    else:
        b.append(a[i] - a[i - 1] - 2)
b.append(n - a[-1] - 1)
if -1 in b:
    print(0)
    exit()
c = set(b)
d = {}
for i in c:
    k = 0
    s = 1
    while i - k > k:
        s += nCr(i - k, k)
        k += 1
    d[i] = s
ans = 1
for i in b:
    ans *= d[i] % (10 ** 9 + 7)
print(ans % (10 ** 9 + 7))

Fixed submission:
from functools import lru_cache
import sys

sys.setrecursionlimit(1000000)

mod = 10 ** 9 + 7

@lru_cache(maxsize=1000000)
def saiki(i):
    if ok[i]:
        if i == 0:
            return 1
        if i == 1:
            return 1
        return saiki(i - 1) % mod + saiki(i - 2) % mod
    else:
        return 0


n, m = map(int, input().split())
a = [int(input()) for i in range(m)]
ok = [True] * (n + 1)
for i in a:
    ok[i] = False
print(saiki(n) % mod)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
    b, c = map(int, input().split())
    a += [c] * b
print(sum(sorted(a, reverse=True)[:n]))

Fixed submission:
from operator import itemgetter
import bisect

n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
bc = sorted([list(map(int, input().split())) for i in range(m)], key=itemgetter(1), reverse=True)
bi = [bisect.bisect_left(a, bc[i][1]) for i in range(m)]
ans = 0
did = 0
for i in range(m):
    if bi[i] - did <= 0:
        continue
    if bi[i] - did > bc[i][0]:
        ans += bc[i][0] * bc[i][1]
        did += bc[i][0]
    else:
        ans += (bi[i] - did) * bc[i][1]
        did += (bi[i] - did)
print(sum(a[did:]) + ans)

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

n, m = map(int, input().split())
a = list(map(int, input().split()))
ac = collections.Counter(a)
for i in range(m):
    b, c = map(int, input().split())
    x = sorted(ac.items())
    j = 0
    while b:
        y = x[j]
        if y[0] < c:
            if y[1] < b:
                ac[c] += y[1]
                del ac[y[0]]
                b -= y[1]
            else:
                ac[c] += b
                ac[y[0]] -= b
                b = 0
        else:
            break
        j += 1
ans = 0
for k, v in ac.items():
    ans += k * v
print(ans)

Fixed submission:
from operator import itemgetter
import bisect

n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
bc = sorted([list(map(int, input().split())) for i in range(m)], key=itemgetter(1), reverse=True)
bi = [bisect.bisect_left(a, bc[i][1]) for i in range(m)]
ans = 0
did = 0
for i in range(m):
    if bi[i] - did <= 0:
        continue
    if bi[i] - did > bc[i][0]:
        ans += bc[i][0] * bc[i][1]
        did += bc[i][0]
    else:
        ans += (bi[i] - did) * bc[i][1]
        did += (bi[i] - did)
print(sum(a[did:]) + ans)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

def dijkstra(graph, node, start):
    dist = [float("inf") for _ in range(node)]

    dist[start] = 0
    q = []
    heapq.heappush(q, (0, start))

    while q:
        cost, cur_node = heapq.heappop(q)

        if dist[cur_node] < cost:
            continue

        for nex_cost, nex_node in graph[cur_node]:
            dist_cand = dist[cur_node] + nex_cost
            if dist_cand < dist[nex_node]:
                dist[nex_node] = dist_cand
                heapq.heappush(q, (dist[nex_node], nex_node))

    return dist


n = int(input())
adj = [[] for _ in range(n)]
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    adj[a].append((c, b))
    adj[b].append((c, a))
shortest = []
for i in range(n):
    print(dijkstra(adj, n, i)[0] % 2)

Fixed submission:
import heapq

def dijkstra(graph, node, start):
    dist = [float("inf") for _ in range(node)]

    dist[start] = 0
    q = []
    heapq.heappush(q, (0, start))

    while q:
        cost, cur_node = heapq.heappop(q)

        if dist[cur_node] < cost:
            continue

        for nex_cost, nex_node in graph[cur_node]:
            dist_cand = dist[cur_node] + nex_cost
            if dist_cand < dist[nex_node]:
                dist[nex_node] = dist_cand
                heapq.heappush(q, (dist[nex_node], nex_node))

    return dist


n = int(input())
adj = [[] for _ in range(n)]
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    adj[a].append((c, b))
    adj[b].append((c, a))
shortest = dijkstra(adj, n, 0)
for i in shortest:
    print(i % 2)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, n = map(int, input().split())
ans = 0
for r in range(n // R + 1):
    for g in range((n - r) // G + 1):
        if (n - r * R - g * G) % B == 0:
            b = (n - r * R - g * G) / B
            if b >= 0:
                ans += 1
print(ans)

Fixed submission:
R, G, B, n = map(int, input().split())
ans = 0
for r in range(n // R + 1):
    for g in range((n - r) // G + 1):
        if (n - r * R - g * G) % B == 0:
            b = (n - r * R - g * G) / B
            if b >= 0:
                ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
for i in range(n + 1):
    for j in itertools.combinations(range(n), i):
        x = 0
        y = 0
        for z in j:
            x += v[z]
            y += c[z]
        ans = max(ans, x - y)
print(ans)

Fixed submission:
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
vc = sorted([(v[i] - c[i]) for i in range(n)], reverse=True)
ans = 0
for i in vc:
    if i > 0:
        ans += i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce

def gcd_list(n):
    return reduce(fractions.gcd, n)


n = int(input())
a = list(map(int, input().split()))

ans = max(gcd_list(a[1:]), gcd_list(a[:n - 1]))
for i in range(1, n - 1):
    ans = max(ans, fractions.gcd(gcd_list(a[:i]), gcd_list(a[i + 1:])))

print(ans)

Fixed submission:
import fractions

n = int(input())
a = list(map(int, input().split()))

l = [a[0]]
for i in range(n - 1):
    l.append(fractions.gcd(l[i], a[i + 1]))

r = [a[-1]]
for i in range(2, n + 1):
    r.append(fractions.gcd(r[i - 2], a[-i]))
r.reverse()

ans = r[1]
for i in range(n - 2):
    ans = max(ans, fractions.gcd(l[i], r[i + 2]))
ans = max(ans, l[-2])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)

from functools import reduce
def gcd_list(n):
    return reduce(gcd, n)

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans = max(ans, gcd_list(a[:i] + a[i + 1:]))
print(ans)


Fixed submission:
import fractions

n = int(input())
a = list(map(int, input().split()))

l = [a[0]]
for i in range(n - 1):
    l.append(fractions.gcd(l[i], a[i + 1]))

r = [a[-1]]
for i in range(2, n + 1):
    r.append(fractions.gcd(r[i - 2], a[-i]))
r.reverse()

ans = r[1]
for i in range(n - 2):
    ans = max(ans, fractions.gcd(l[i], r[i + 2]))
ans = max(ans, l[-2])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)

from functools import reduce
def gcd_list(n):
    return reduce(gcd, n)

from functools import lru_cache

@lru_cache(maxsize=10000)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans = max(ans, gcd_list(a[:i] + a[i + 1:]))
print(ans)

Fixed submission:
import fractions

n = int(input())
a = list(map(int, input().split()))

l = [a[0]]
for i in range(n - 1):
    l.append(fractions.gcd(l[i], a[i + 1]))

r = [a[-1]]
for i in range(2, n + 1):
    r.append(fractions.gcd(r[i - 2], a[-i]))
r.reverse()

ans = r[1]
for i in range(n - 2):
    ans = max(ans, fractions.gcd(l[i], r[i + 2]))
ans = max(ans, l[-2])
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
if s.count("1") == n or s.count("0") == n:
    print(n)
    exit()
renzoku = []
count = 0
flag = 0
for i in range(n):
    if s[i] == "1":
        if flag:
            count += 1
        else:
            renzoku.append(count)
            count = 1
        flag = 1
    else:
        if flag:
            renzoku.append(count)
            count = 1
        else:
            count += 1
        flag = 0
renzoku.append(count)
renzoku_t = [0]
for i in range(len(renzoku)):
    renzoku_t.append(renzoku[i] + renzoku_t[i])
ans = 0
if s[0] == "0":
    ans = renzoku_t[0 + k + k] - renzoku_t[0]
for i in range(1, len(renzoku) - k - k + 1, 2):
    if i == 0 or i == len(renzoku) - k - k:
        ans = max(ans, renzoku_t[i + k + k] - renzoku_t[i])
    else:
        ans = max(ans, renzoku_t[i + k + k + 1] - renzoku_t[i])
print(ans)

Fixed submission:
n, k = map(int, input().split())
s = input()
if s.count("1") == n or s.count("0") == n:
    print(n)
    exit()
zero = 0
flag = 0
for i in s:
    if i == "0":
        flag = 1
    else:
        if flag:
            zero += 1
        flag = 0
if flag:
    zero += 1
k = min(zero, k)
renzoku = []
count = 0
flag = 0
for i in range(n):
    if s[i] == "1":
        if flag:
            count += 1
        else:
            renzoku.append(count)
            count = 1
        flag = 1
    else:
        if flag:
            renzoku.append(count)
            count = 1
        else:
            count += 1
        flag = 0
renzoku.append(count)
renzoku_t = [0]
for i in range(len(renzoku)):
    renzoku_t.append(renzoku[i] + renzoku_t[i])
ans = 0
if k == zero:
    print(n)
    exit()
if s[0] == "0":
    ans = renzoku_t[0 + k + k] - renzoku_t[0]
for i in range(1, len(renzoku) - k - k + 1, 2):
    if i == 0 or i == len(renzoku) - k - k:
        ans = max(ans, renzoku_t[i + k + k] - renzoku_t[i])
    else:
        ans = max(ans, renzoku_t[i + k + k + 1] - renzoku_t[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
e = []
for i in a:
    for j in b:
        e.append(i + j)
e = sorted(e, reverse=True)[:k]
ans = []
for i in e:
    for j in c:
        ans.append(i + j)
ans = sorted(ans, reverse=True)[:k]
for i in ans:
    print(i)

Fixed submission:
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
e = []
for i in a:
    for j in b:
        e.append(i + j)
e = sorted(e, reverse=True)[:k]
ans = []
for i in e:
    for j in c:
        ans.append(i + j)
ans = sorted(ans, reverse=True)[:k]
for i in ans:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n, q = map(int, input().split())
s = input()
index = []
for i in range(n):
    if s[i:i + 2] == "AC":
        index.append(i)
for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 2
    bl = bisect.bisect_left(index, l)
    br = bisect.bisect_left(index, r)
    if r in set(index):
        print(br - bl + 1)
    else:
        print(br - bl)

Fixed submission:
n, q = map(int, input().split())
s = input()
ac = []
last = False
for i in range(n):
    if last and s[i] == "C":
        last = False
        ac.append(1)
    else:
        if s[i] == "A":
            last = True
        else:
            last = False
        ac.append(0)
ac_t = [0]
for i in range(n):
    ac_t.append(ac[i] + ac_t[i])
for i in range(q):
    l, r = map(int, input().split())
    print(ac_t[r] - ac_t[l])

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

n, q = map(int, input().split())
s = input()
index = []
for i in range(n):
    if s[i:i + 2] == "AC":
        index.append(i)
for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 2
    bl = bisect.bisect_left(index, l)
    br = bisect.bisect_left(index, r)
    if r in index:
        print(br - bl + 1)
    else:
        print(br - bl)

Fixed submission:
n, q = map(int, input().split())
s = input()
ac = []
last = False
for i in range(n):
    if last and s[i] == "C":
        last = False
        ac.append(1)
    else:
        if s[i] == "A":
            last = True
        else:
            last = False
        ac.append(0)
ac_t = [0]
for i in range(n):
    ac_t.append(ac[i] + ac_t[i])
for i in range(q):
    l, r = map(int, input().split())
    print(ac_t[r] - ac_t[l])
Buggy python submission (verdict: Runtime Error):
s = input()
r = s.count(”0”)
print(min(r, len(s) - r) * 2)

Fixed submission:
s = input()
count_1 = 0
count_0 = 0
ans = 0
for i in range(len(s)):
    if s[i] == "1":
        if count_0:
            ans += 2
            count_0 -= 1
        else:
            count_1 += 1
    else:
        if count_1:
            ans += 2
            count_1 -= 1
        else:
            count_0 += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if(s.compareTo("2019/04/30") <= 0){
            System.out.println("Heisei");
        } else {
            System.out.println("TBD");
        }
    }
}


Fixed submission:
s = input()
s = list(map(int, s.split("/")))
if s[0] <= 2019 and s[1] <= 4 and s[2] <= 30:
    print("Heisei")
else:
    print("TBD")
Buggy python submission (verdict: Runtime Error):
import bisect
import itertools

n, a, b, c = map(int, input().split())
l = sorted([int(input()) for i in range(n)])
ABC = [a, b, c]
ans = float("inf")

def dfs(i, abc):
    global ans
    sum_a = 0
    l1 = l[:]
    if i == 3:
        for k in itertools.permutations([0, 1, 2], 3):
            for j in k:
                index = bisect.bisect_left(l1, ABC[j])
                if abc[j] == 0:
                    if index < len(l1):
                        sum_a += l1[index] - ABC[j]
                        l1.remove(l1[index])
                    else:
                        sum_a += float("inf")
                elif abc[j] == 1:
                    if index > 0:
                        sum_a += ABC[j] - l1[index - 1]
                        l1.remove(l1[index - 1])
                    else:
                        sum_a += float("inf")
                else:
                    sum_ = float("inf")
                    for x in range(2, len(l1) + 1):
                        for y in itertools.combinations(l1, x):
                            if sum_ > abs(sum(y) - ABC[j]):
                                sum_ = abs(sum(y) - ABC[j]) + (x - 1) * 10
                                l2 = l1[:]
                                for z in y:
                                    l2.remove(z)
                    l1 = l2[:]
                    sum_a += sum_
            ans = min(ans, sum_a)
        return 0
    dfs(i + 1, abc[:i] + [abc[i]] + abc[i + 1:])
    dfs(i + 1, abc[:i] + [abc[i] + 1] + abc[i + 1:])
    dfs(i + 1, abc[:i] + [abc[i] + 2] + abc[i + 1:])

dfs(0, [0, 0, 0])
print(ans)

Fixed submission:
def dfs(i, A, B, C):
    global ans
    if i == n:
        if A and B and C:
            s = 0
            ABC = [A, B, C]
            for i in range(3):
                s += (len(ABC[i]) - 1) * 10 + abs(sum(ABC[i]) - abc[i])
            ans = min(ans, s)
    else:
        dfs(i + 1, A + [l[i]], B, C)
        dfs(i + 1, A, B + [l[i]], C)
        dfs(i + 1, A, B, C + [l[i]])
        dfs(i + 1, A, B, C)

n, a, b, c = map(int, input().split())
l = [int(input()) for i in range(n)]
abc = [a, b, c]
ans = float("inf")
dfs(0, [], [], [])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, q = map(int, input().split())
s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]
for i in range(q):
    W = []
    Z = []
    ans = float("inf")
    x = int(input())
    for S in s:
        for T in t:
            W.append(min(abs(x - S), abs(x - T)) + abs(S - T))
        Z.append(min(W))
    print(min(Z))

Fixed submission:
import bisect

a, b, q = map(int, input().split())
s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]
for i in range(q):
    ans = float("inf")
    x = int(input())
    index_s = bisect.bisect_left(s, x)
    index_t = bisect.bisect_left(t, x)
    if index_s > 0:
        s_m = s[index_s - 1]
        if index_t > 0:
            t_m = t[index_t - 1]
            ans = min(ans, x - min(s_m, t_m))
        if index_t < b:
            t_p = t[index_t]
            ans = min(ans, t_p * 2 - x - s_m)
            ans = min(ans, x + t_p - s_m * 2)
    if index_s < a:
        s_p = s[index_s]
        if index_t > 0:
            t_m = t[index_t - 1]
            ans = min(ans, s_p * 2 - x - t_m)
            ans = min(ans, x + s_p - t_m * 2)
        if index_t < b:
            t_p = t[index_t]
            ans = min(ans, max(s_p, t_p) - x)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ans = 0
for i in range(len(s)):
    if s[i] == "W":
        ans += s[:i].count("B")
print(ans)

Fixed submission:
s = input()
ans = 0
count = 0
for i in range(len(s)):
    if s[i] == "W":
        ans += i - count
        count += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = sorted([int(input()) for i in range(n)])
ans = float("inf")
for i in range(n - k + 1):
    use = h[i:i + k]
    ans = min(ans, h[i + k - 1] - h[i])
print(ans)

Fixed submission:
n, k = map(int, input().split())
h = sorted([int(input()) for i in range(n)])
ans = float("inf")
for i in range(n - k + 1):
    ans = min(ans, h[i + k - 1] - h[i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = sorted([int(input()) for i in range(n)])
ans = float("inf")
for i in range(n - k + 1):
    use = h[i:i + k]
    ans = min(ans, use[-1] - use[0])
print(ans)

Fixed submission:
n, k = map(int, input().split())
h = sorted([int(input()) for i in range(n)])
ans = float("inf")
for i in range(n - k + 1):
    ans = min(ans, h[i + k - 1] - h[i])
print(ans)