Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
mod = 10 ** 9 + 7

def main():
    result = 1
    i = -1
    j = -1
    used_area = 0

    A.sort(reverse=True)
    B.sort(reverse=True)

    for x in range(N * M, 0, -1):
        while i < N-1:
            if A[i+1] >= x:
                i += 1
            else:
                break

        while j < M-1:
            if B[j+1] >= x:
                j += 1
            else:
                break

        marked_row = False
        marked_col = False

        count_row = A[0:i+1].count(x)
        if count_row > 1:
            return(0)
        if count_row == 1:
            usable_row = 1
            marked_row = True
        else:
            usable_row = i+1

        count_col = B[0:j+1].count(x)
        if count_col > 1:
            return(0)
        if count_col == 1:
            usable_col = 1
            marked_col = True
        else:
            usable_col = j+1

        if marked_row or marked_col:
            usable_area = usable_row * usable_col
        else:
            usable_area = usable_row * usable_col - used_area

        if usable_area <= 0:
            return(0)

        result = result * usable_area % mod
        used_area += 1

    return(result)


if __name__ == '__main__':
    print(main())


Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
mod = 10 ** 9 + 7

def main():
    result = 1
    i = -1
    j = -1
    used_area = 0

    A.sort(reverse=True)
    B.sort(reverse=True)

    for x in range(N * M, 0, -1):
        expanded_row = 0
        expanded_col = 0
        while i < N-1:
            if A[i+1] >= x:
                i += 1
                expanded_row += 1
            else:
                break

        while j < M-1:
            if B[j+1] >= x:
                j += 1
                expanded_col += 1
            else:
                break

        marked_row = False
        marked_col = False

        if expanded_row > 1:
            return(0)
        if expanded_row == 1:
            usable_row = 1
            marked_row = True
        else:
            usable_row = i+1

        if expanded_col > 1:
            return(0)
        if expanded_col == 1:
            usable_col = 1
            marked_col = True
        else:
            usable_col = j+1

        if marked_row or marked_col:
            usable_area = usable_row * usable_col
        else:
            usable_area = usable_row * usable_col - used_area

        # print('x:', x)
        # print('usable_row:', A[0:i+1])
        # print('usable_col:', B[0:j+1])
        # print('usable_area:', usable_area)

        if usable_area <= 0:
            return(0)

        result = result * usable_area % mod
        used_area += 1

    return(result)


if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

count = 0
flag = True

while flag:
    flag = False
    for i in range(len(S)-1):
        c = S.count("BW")
        count += c
        if c:
            flag = True
        S = S.replace("BW", "WB")

print(count)

Fixed submission:
S = input()

count = 0

i = 0

for j in range(len(S)):
    if S[j] == "W":
        count += j-i
        i += 1


print(count)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

count = 0
flag = True

while flag:
    flag = False
    for i in range(len(S)-1):
        if S[i:i+2] == "BW":
            S = S[:i] + "WB" + S[i+2:]
            count += 1
            flag = True

print(count)

Fixed submission:
S = input()

count = 0

i = 0

for j in range(len(S)):
    if S[j] == "W":
        count += j-i
        i += 1


print(count)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import groupby
from math import factorial


def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors


def comb(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))


N, M = map(int, input().split())
result = 1

for k, g in groupby(prime_factors(M)):
    result = result * comb(len(list(g)) + N - 1, N - 1)
    result = result % (10 ** 9 + 7)

print(result)


Fixed submission:
import operator as op
from itertools import groupby
from functools import reduce

NN = 10 ** 9 + 7


def prime_factors(n):
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            yield i
    if n > 1:
        yield n


def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom


N, M = map(int, input().split())
result = 1

for k, g in groupby(prime_factors(M)):
    result = result * ncr(len(list(g)) + N - 1, N - 1)
    if result > NN:
        result = result % NN

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys


def solve(N: int, T: "List[int]", V: "List[int]"):
    t_period = [0 for i in range(N+1)]
    for i in range(N):
        t_period[i+1] = t_period[i] + T[i]*2

    limit = [0 for t in range(t_period[N]+1)]
    for i in range(1, N):
        limit[t_period[i]] = min((V[i-1], V[i]))
    for i in range(N):
        limit[t_period[i]+1:t_period[i+1]] = [V[i]] * (t_period[i+1] - t_period[i] - 1)
    
    speed = [0 for t in range(t_period[N]+1)]

    for v in range(1, 201):
        for t in range(1, t_period[N]):
            speed[t] = min([limit[t], speed[t-1]+0.5, speed[t+1]+0.5])

    total = 0
    for t in range(t_period[N]):
        total += (speed[t] + speed[t+1]) * 0.5 * 0.5
    
    print(total)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    t = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    v = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, t, v)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, T: "List[int]", V: "List[int]"):
    t_period = [0 for i in range(N+1)]
    for i in range(N):
        t_period[i+1] = t_period[i] + T[i]*2

    limit = np.zeros((t_period[N]+1,))
    for i in range(1, N):
        limit[t_period[i]] = min((V[i-1], V[i]))
    for i in range(N):
        limit[t_period[i]+1:t_period[i+1]] = V[i]
    
    speed = np.zeros((t_period[N]+1,))

    for v in range(1, 201):
        speed[1:t_period[N]] = np.min([limit[1:t_period[N]], speed[0:t_period[N]-1]+0.5, speed[2:t_period[N]+1]+0.5], axis=0)

    total = 0
    for t in range(t_period[N]):
        total += (speed[t] + speed[t+1]) * 0.5 * 0.5
    
    print(total)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    t = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    v = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, t, v)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
p = int(input())
a = list(map(int, input().split()))
MOD = p

P = p
fact = [0] * P
fact[0] = 1
for i in range(1, P):
    fact[i] = fact[i - 1] * i
    fact[i] %= MOD

rfact = [0] * P
rfact[P - 1] = pow(fact[P - 1], MOD - 2, MOD)
for i in range(P - 2, -1, -1):
    rfact[i] = rfact[i + 1] * (i + 1)
    rfact[i] %= MOD


def comb(n, k):
    return fact[n] * rfact[n - k] * rfact[k] % MOD


b = [0] * p
for i in range(p):
    if a[i]:
        b[0] += 1
        b[0] %= MOD
        for j in range(p):
            b[j] -= comb(p - 1, j) * (-i) ** (p - 1 - j)
            b[j] %= MOD

print(*b)


Fixed submission:
import sys
input = sys.stdin.readline
p = int(input())
a = list(map(int, input().split()))
MOD = p

P = p
fact = [0] * P
fact[0] = 1
for i in range(1, P):
    fact[i] = fact[i - 1] * i
    fact[i] %= MOD

rfact = [0] * P
rfact[P - 1] = pow(fact[P - 1], MOD - 2, MOD)
for i in range(P - 2, -1, -1):
    rfact[i] = rfact[i + 1] * (i + 1)
    rfact[i] %= MOD


def comb(n, k):
    return fact[n] * rfact[n - k] * rfact[k] % MOD


b = [0] * p
for i in range(p):
    if a[i]:
        b[0] += 1
        b[0] %= MOD
        s = 1
        for j in range(p - 1, -1, -1):
            b[j] -= comb(p - 1, j) * s
            b[j] %= MOD
            s *= -i
            s %= MOD

print(*b)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import bisect_left
input = sys.stdin.readline
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

num = 0
while A:
    num += 1
    D = [A[0]]
    for i in range(len(A)):
        if A[i] > D[-1]:
            D.append(A[i])
        else:
            D[bisect_left(D, A[i])] = A[i]

    for i in range(len(D)):
        A.remove(D[i])

print(num)

Fixed submission:
from bisect import bisect_right
N = int(input())
A = []
for i in range(N):
    A.append(-int(input()))
INF = float('inf')
D = [INF] * N
for i in range(len(A)):
    D[bisect_right(D, A[i])] = A[i]

print(N - D.count(INF))
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())
D = []
for i in range(N):
    x, y = map(int, input().split())
    D.append((x, y))

d = defaultdict(int)
for i in range(N):
    for j in range(i + 1, N):
        d[(D[i][0] - D[j][0], D[i][1] - D[j][1])] += 1

print(N - max(d.values()))


Fixed submission:
N = int(input())
if N == 1:
    print(1)
    exit()
D = []
for i in range(N):
    x, y = map(int, input().split())
    D.append((x, y))
D = sorted(D)

d = set()
for i in range(N):
    for j in range(N):
        d.add((D[i][0] - D[j][0], D[i][1] - D[j][1]))


d = list(d)
num = float('inf')
for p, q in d:
    if p == 0 and q == 0:
        continue
    used = [0] * N
    prex, prey = D[0][0], D[0][1]
    used[0] = 1
    tmp = 1
    for k in range(N - 1):
        for i in range(N):
            if used[i]:
                continue
            if D[i][0] - prex == p and D[i][1] - prey == q:
                prex = D[i][0]
                prey = D[i][1]
                used[i] = 1
                break
        else:
            tmp += 1
            for i in range(N):
                if not used[i]:
                    prex = D[i][0]
                    prey = D[i][1]
                    used[i] = 1
                    break
    num = min(tmp, num)

print(num)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
V = list(map(int, input().split()))
que = []
ma = 0
for i in range(K):
    P = K - i
    for p in range(P + 1):
        q1 = []
        q2 = []
        s = 0
        for j in range(p):
            if V[j] >= 0:
                s += V[j]
            else:
                q1.append(V[j])
        if len(q1) == p:
            q1 = []
        for j in range(N - 1, N - (P - p) - 1, -1):
            if V[j] >= 0:
                s += V[j]
            else:
                q2.append(V[j])
        if len(q2) == P - p:
            q2 = []

        q = sorted(q1 + q2)
        if len(q) < i:
            t = 0
        else:
            t = sum(q[i:])
        ma = max(s + t, ma)

print(ma)


Fixed submission:
N, K = map(int, input().split())
V = list(map(int, input().split()))

ma = 0
for i in range(K):
    P = K - i
    for p in range(P + 1):
        q1 = []
        q2 = []
        s = 0
        for j in range(min(N, p)):
            if V[j] >= 0:
                s += V[j]
            else:
                q1.append(V[j])
        if len(q1) == p:
            q1 = []
        for j in range(N - 1, max(p - 1, N - (P - p) - 1), -1):
            if V[j] >= 0:
                s += V[j]
            else:
                q2.append(V[j])
        if len(q2) == P - p:
            q2 = []

        q = sorted(q1 + q2)
        if len(q) < i:
            t = 0
        else:
            t = sum(q[i:])
        ma = max(s + t, ma)

print(ma)
Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
MOD = 10 ** 9 + 7

P = 100005
fact = [0] * P
fact[0] = 1
for i in range(1, P):
    fact[i] = fact[i - 1] * i
    fact[i] %= MOD

rfact = [0] * P
rfact[P - 1] = pow(fact[P - 1], MOD - 2, MOD)
for i in range(P - 2, -1, -1):
    rfact[i] = rfact[i + 1] * (i + 1)
    rfact[i] %= MOD


def comb(n, k):
    return fact[n] * rfact[k] * rfact[n - k] % MOD


num = 0
for d in range(1, N):
    num += d * (N - d) * (M ** 2)
    num %= MOD

for d in range(1, M):
    num += d * (M - d) * (N ** 2)
    num %= MOD

num *= comb(N * M - 2, K - 2)
print(num % MOD)



Fixed submission:
N, M, K = map(int, input().split())
MOD = 10 ** 9 + 7

P = 200005
fact = [0] * P
fact[0] = 1
for i in range(1, P):
    fact[i] = fact[i - 1] * i
    fact[i] %= MOD

rfact = [0] * P
rfact[P - 1] = pow(fact[P - 1], MOD - 2, MOD)
for i in range(P - 2, -1, -1):
    rfact[i] = rfact[i + 1] * (i + 1)
    rfact[i] %= MOD


def comb(n, k):
    return fact[n] * rfact[k] * rfact[n - k] % MOD


num = 0
for d in range(1, N):
    num += d * (N - d) * (M ** 2)
    num %= MOD

for d in range(1, M):
    num += d * (M - d) * (N ** 2)
    num %= MOD

num *= comb(N * M - 2, K - 2)
print(num % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush
Q = int(input())
n, a, b = map(int, input().split())
mi = b
L = [-a]
R = [a]
num = 1
for i in range(Q - 1):
    q = list(map(int, input().split()))
    if len(q) == 3:
        if num % 2 != 0:
            l = -heappop(L)
            r = heappop(R)
            l1 = min(l, q[1])
            r1 = max(r, q[1])
            heappush(L, -l1)
            heappush(R, r1)
            mi += abs(l - q[1])
        else:
            if q[1] < -L[0]:
                heappush(L, -q[1])
                heappush(R, -L[0])
                mi -= q[1] + L[0]
            elif q[1] > R[0]:
                heappush(L, -R[0])
                heappush(R, q[1])
                mi += q[1] - R[0]
            else:
                heappush(L, -q[1])
                heappush(R, q[1])

        mi += q[2]
        num += 1
    else:
        print(-L[0], mi)


Fixed submission:
from heapq import heappop, heappush
Q = int(input())
n, a, b = map(int, input().split())
mi = b
L = [-a]
R = [a]
num = 1
for i in range(Q - 1):
    q = list(map(int, input().split()))
    if len(q) == 3:
        if num % 2 != 0:
            l = -heappop(L)
            r = heappop(R)
            l1 = min(l, q[1])
            r1 = max(r, q[1])
            heappush(L, -l1)
            heappush(R, r1)
            mi += abs(l - q[1])
        else:
            if q[1] < -L[0]:
                heappush(L, -q[1])
                heappush(R, -L[0])
                mi -= q[1] + L[0]
            elif q[1] > R[0]:
                heappush(L, -R[0])
                heappush(R, q[1])
                mi += q[1] - R[0]
            else:
                heappush(L, -q[1])
                heappush(R, q[1])

        mi += q[2]
        num += 1
    else:
        print(-L[0], mi)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
num = 0
for i in range(N + 1):
    for j in range(N + 1):
        if N - R * i - G * j < 0:
            break
        if 0 <= N - R * i - G * j and (N - R * i - G * j) % B == 0:
            num += 1

print(num)

Fixed submission:
R, G, B, N = map(int, input().split())
num = 0
for i in range(N + 1):
    if N - R * i < 0:
        break
    for j in range(N + 1):
        if N - R * i - G * j < 0:
            break
        if 0 <= N - R * i - G * j and (N - R * i - G * j) % B == 0:
            num += 1

print(num)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = 0
B = 0
BA = 0
num = 0
for i in range(N):
    k = input()
    if k[0] == 'B' and k[-1] == 'A':
        BA += 1
    elif k[0] == 'B':
        B += 1
    elif k[-1] == 'A':
        A += 1

    for j in range(N - 1):
        if k[j:j + 2] == 'AB':
            num += 1

num += max(0, BA - 1)
BA -= max(0, BA - 1)
num += min(BA, A) + min(BA, B)
A -= min(BA, A)
B -= min(BA, B)
num += min(A, B)
print(num)




Fixed submission:
N = int(input())
A = 0
B = 0
BA = 0
num = 0
for i in range(N):
    k = input()
    if k[0] == 'B' and k[-1] == 'A':
        BA += 1
    elif k[0] == 'B':
        B += 1
    elif k[-1] == 'A':
        A += 1

    for j in range(len(k) - 1):
        if k[j:j + 2] == 'AB':
            num += 1

num += max(0, BA - 1)
BA -= max(0, BA - 1)
num += min(BA, A) + min(BA, B)
A -= min(BA, A)
B -= min(BA, B)
num += min(A, B)
print(num)
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()))
AB = []
for i in A:
    for j in B:
        AB.append(i + j)
AB = sorted(AB, reverse=True)[:K]
ABC = []
for i in AB:
    for j in C:
        ABC.append(i + j)

ABC = sorted(ABC, reverse=True)[:K]
for a in ABC:
    print(a)

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()))
AB = []
for i in A:
    for j in B:
        AB.append(i + j)


AB = sorted(AB, reverse=True)[:K]
C = sorted(C, reverse=True)
ans = []
for i in C:
    for j in AB:
        ans.append(i + j)

ans = sorted(ans, reverse=True)[:K]
for i in ans:
    print(i)

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()))
AB = []
for i in A:
    for j in B:
        AB.append(i + j)


AB = sorted(AB, reverse=True)[:K]
C = sorted(C, reverse=True)
ans = []
for i in C:
    for j in AB:
        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()))
AB = []
for i in A:
    for j in B:
        AB.append(i + j)


AB = sorted(AB, reverse=True)[:K]
C = sorted(C, reverse=True)
ans = []
for i in C:
    for j in AB:
        ans.append(i + j)

ans = sorted(ans, reverse=True)[:K]
for i in ans:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
C = []
MOD = 10 ** 9 + 7
pre = -1
for i in range(n):
    a = int(input())
    if a != pre:
        C.append(a)
    pre = a

N = len(C)
dp = [0] * (N + 1)
col = {}
pre = -1
dp[0] = 1
for i in range(1, N + 1):
    if C[i - 1] not in col :
        dp[i] = dp[i - 1]
        col[C[i - 1]] = [i]
    else:
        dp[i] = dp[i - 1]
        for j in col[C[i - 1]]:
            dp[i] += dp[j - 1]
            dp[i] %= MOD
        col[C[i - 1]].append(i)

print(dp[N])


Fixed submission:
n = int(input())
C = []
MOD = 10 ** 9 + 7
pre = -1
for i in range(n):
    a = int(input())
    if a != pre:
        C.append(a)
    pre = a

N = len(C)
dp = [0] * (N + 1)
col = {}
pre = -1
dp[0] = 1
for i in range(1, N + 1):
    if C[i - 1] not in col:
        dp[i] = dp[i - 1]
        col[C[i - 1]] = dp[i]
    else:
        dp[i] = dp[i - 1]
        dp[i] += col[C[i - 1]]
        dp[i] %= MOD
        col[C[i - 1]] += dp[i - 1]

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
C = []
MOD = 10 ** 9 + 7
pre = -1
for i in range(n):
    a = int(input())
    if a != pre:
        C.append(a)
    pre = a

N = len(C)
dp = [0] * (N + 1)
col = [[] for i in range(200005)]
pre = -1
dp[0] = 1
for i in range(1, N + 1):
    if len(col[C[i - 1]]) == 0:
        dp[i] = dp[i - 1]
        col[C[i - 1]].append(i)
    else:
        dp[i] = dp[i - 1]
        for j in col[C[i - 1]]:
            dp[i] += dp[j - 1]
            dp[i] %= MOD
        col[C[i - 1]].append(i)

print(dp[N])

Fixed submission:
n = int(input())
C = []
MOD = 10 ** 9 + 7
pre = -1
for i in range(n):
    a = int(input())
    if a != pre:
        C.append(a)
    pre = a

N = len(C)
dp = [0] * (N + 1)
col = {}
pre = -1
dp[0] = 1
for i in range(1, N + 1):
    if C[i - 1] not in col:
        dp[i] = dp[i - 1]
        col[C[i - 1]] = dp[i]
    else:
        dp[i] = dp[i - 1]
        dp[i] += col[C[i - 1]]
        dp[i] %= MOD
        col[C[i - 1]] += dp[i - 1]

print(dp[N])
Buggy python submission (verdict: Runtime Error):
N = int(input())
rec = []
for i in range(N):
    a, b = map(int, input().split())
    rec.append((a, b, i))

rec1 = sorted(rec, key=lambda x: x[0] - x[1], reverse=True)
rec2 = sorted(rec, key=lambda x: x[1] - x[0], reverse=True)
used = [-1] * N
i = 0
j = 0
k = 0
num = 0
while k < N:
    if k % 2 == 0:
        while i < N and used[i] != -1:
            i += 1
        num += rec1[i][0]
        used[rec1[i][2]] = 1
        i += 1
    else:
        while j < N and used[j] != -1:
            j += 1
        num -= rec2[j][1]
        used[rec2[j][2]] = 1
        j += 1

    k += 1

print(num)

Fixed submission:
N = int(input())
rec = []
num = 0
for i in range(N):
    a, b = map(int, input().split())
    rec.append(a + b)
    num -= b

rec = sorted(rec, reverse=True)
for i in range(N):
    if i % 2 == 0:
        num += rec[i]
print(num)

Buggy python submission (verdict: Runtime Error):
N = int(input())
rec = []
for i in range(N):
    a, b = map(int, input().split())
    rec.append((a, b, i))

rec1 = sorted(rec, key=lambda x: x[0] - x[1], reverse=True)
rec2 = sorted(rec, key=lambda x: x[1] - x[0], reverse=True)
used = [-1] * N
i = 0
j = 0
k = 0
num = 0
while k < N:
    if k % 2 == 0:
        while i < N and used[i] != -1:
            i += 1
        num += rec1[i][0]
        used[rec1[i][2]] = 1
        i += 1
    else:
        while j < N and used[j] != -1:
            j += 1
        num -= rec2[i][1]
        used[rec2[i][2]] = 1
        j += 1

    k += 1

print(num)

Fixed submission:
N = int(input())
rec = []
num = 0
for i in range(N):
    a, b = map(int, input().split())
    rec.append(a + b)
    num -= b

rec = sorted(rec, reverse=True)
for i in range(N):
    if i % 2 == 0:
        num += rec[i]
print(num)

Buggy python submission (verdict: Runtime Error):
N = int(input())
rec = []
for i in range(N):
    a, b = map(int, input().split())
    rec.append((a, b, i))

rec1 = sorted(rec, key=lambda x: x[0] - x[1], reverse=True)
rec2 = sorted(rec, key=lambda x: x[1] - x[0], reverse=True)
used = [-1] * N
i = 0
j = 0
k = 0
num = 0
while k < N:
    if k % 2 == 0:
        while used[i] != -1:
            i += 1
        num += rec1[i][0]
        used[rec1[i][2]] = 1
        i += 1
    else:
        while used[j] != -1:
            j += 1
        num -= rec2[i][1]
        used[rec2[i][2]] = 1
        j += 1

    k += 1

print(num)


Fixed submission:
N = int(input())
rec = []
num = 0
for i in range(N):
    a, b = map(int, input().split())
    rec.append(a + b)
    num -= b

rec = sorted(rec, reverse=True)
for i in range(N):
    if i % 2 == 0:
        num += rec[i]
print(num)