Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n == 1:
  print("Hello World")
  
else:
	a=int(input())
	b=int(input())
    print(a+b)

Fixed submission:
n=int(input())
if n==1:
  print('Hello World')
else:
    print(int(input())+int(input()))

Buggy python submission (verdict: Runtime Error):
n=int(input())
if n==1:
  print("Hello World")
a=int(input())
b=int(input())
else:
  print(a+b)

Fixed submission:
n=int(input())
if n==1:
  print('Hello World')
else:
    print(int(input())+int(input()))

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=int(input())
b=int(input())
if n==1:
  print("Hello World")
else:
  print(a+b)


Fixed submission:
n=int(input())
if n==1:
  print('Hello World')
else:
    print(int(input())+int(input()))

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=int(input())
b=int(input())
if n==1:
  print("Hello World")
else:
  print(a+b)

Fixed submission:
n=int(input())
if n==1:
  print('Hello World')
else:
    print(int(input())+int(input()))
Buggy python submission (verdict: Runtime Error):
a=input()
if a < 1000:
  print("ABC")
else:
  print("ABD")


Fixed submission:
a=int(input())
if a < 1000:
  print("ABC")
else:
  print("ABD")
Buggy python submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
if a>c or a+b<x:
  print("No")
else:
  print("Yes")


Fixed submission:
a,b,x=map(int,input().split())
if a<=x<=a+b:
	print("YES")
else:
	print("NO")
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
if a==b==c or b==c==d:
  print("Yes")
else:
  print("No")

Fixed submission:
a,b,c,d=input()
if a==b==c or b==c==d:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
x,y=map(int,input().split())
if x>y:
  print(">")
elif x<y:
  print("<")
else:
  print("=")

Fixed submission:
x,y=map(str,input().split())
if ord(x)>ord(y):
  print(">")
elif ord(x)<ord(y):
  print("<")
else:
  print("=")
Buggy python submission (verdict: Runtime Error):
r=int(input())
g=int(input())
print(2*b-a)

Fixed submission:
r=int(input())
g=int(input())
print(2*g-r)
Buggy python submission (verdict: Runtime Error):
n=input()
m=n[::-1]
if n=m:
  print("Yes")
else:
  print("No")

Fixed submission:
n=input()
m=n[::-1]
if n==m:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
n=input()
print(reverse[::-1])


Fixed submission:
n=input()
m=n[::-1]
if n==m:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
n=input()
print(reverse(n))

Fixed submission:
n=input()
m=n[::-1]
if n==m:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print(a[0].upper()+b[0].upper()+c[0].upper())

Fixed submission:
a,b,c=map(str,input().split())
print(a[0].upper()+b[0].upper()+c[0].upper())
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
  print(a+b%24)

Fixed submission:
a,b=map(int,input().split())
print((a+b)%24)
Buggy python submission (verdict: Runtime Error):
a,b=map(str,input().split())
if a=="H" and b="H" or a=="D" and b="D":
  print("H")
elif a=="H" and b="D" or a=="D" and b="H":
  print("D")


Fixed submission:
a,b=map(str,input().split())
if a==b:
  print("H")
else:
  print("D")

Buggy python submission (verdict: Runtime Error):
a,b=map(str,input().split())
if a=="H" and b="H" or a=="D" and b="D":
  print("H")
else:
  print("D")

Fixed submission:
a,b=map(str,input().split())
if a==b:
  print("H")
else:
  print("D")
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int.input().split())
total=a+b+c
if total%2==0:
  print("Yes")
else:
  print("No")

Fixed submission:
a,b,c = map(int, input().split())
if max(a,b,c)*2==a+b+c:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
total=a+b+c
if total%2=0:
  print("Yes")
else:
  print("No")

Fixed submission:
a,b,c = map(int, input().split())
if max(a,b,c)*2==a+b+c:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if a==b==c:
  print(1)
elif a=!b=!=!c:
  print(3)
else:
  print(2)

Fixed submission:
abc=list(map(int,input().split()))

print(len(set(abc)))
Buggy python submission (verdict: Time Limit Exceeded):
import math


a, b, x = map(int, input().split())
eps = 10 ** -6
r = 90 * 10 ** 6
h1 = x / a ** 2
if h1 >= b / 2:
    for e in range(0, r):
        th = e * eps * (math.pi / 180)
        c = b - h1 - (a / 2 * math.tan(th))
        if c <= 0:
            break
    print(e * eps)
else:
    h2 = x / (a * b)
    for e in range(0, r):
        th = e * eps * (math.pi / 180)
        c = 2 * h2 - (b * math.tan(th))
        if c <= 0:
            break
    print(90 - e * eps)

Fixed submission:
import math


a, b, x = map(int, input().split())
r = 180 / math.pi
h = x / a ** 2
c = h * 2 - b
d = 2 * x / (a * b)
if h >= b / 2:
    th = math.atan((h - c) / (a / 2)) * r
else:
    th = ((math.pi / 2) - math.atan((d / b))) * r
print(th)

Buggy python submission (verdict: Runtime Error):
a, b, x = map(int, input().split())
r = 180 / math.pi
h = x / a ** 2
c = h * 2 - b
d = 2 * x / (a * b)
if h >= b / 2:
    th = math.atan((h - c) / (a / 2)) * r
else:
    th = ((math.pi / 2) - math.atan((d / b))) * r
print(th)

Fixed submission:
import math


a, b, x = map(int, input().split())
r = 180 / math.pi
h = x / a ** 2
c = h * 2 - b
d = 2 * x / (a * b)
if h >= b / 2:
    th = math.atan((h - c) / (a / 2)) * r
else:
    th = ((math.pi / 2) - math.atan((d / b))) * r
print(th)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l, r = -1, 10 ** 12


def func(x):
    k = 0  # 修行回数初期化
    for a, f in zip(A, F): # O(N)
        if a <= x // f:  # (Ai-Ki)*Fi<=x Ki=0なら次 (a*f<=xの変形)
            continue
        k += a - x // f
        # else (Ai-Ki)*Fi<=x を満たすようにKiを設定。つまり修行回数にKiを加算。
    if k <= K:
        return 1
    return 0


while (r - l > 1): # O(logx)
    mid = (l + r) // 2
    if func(mid):
        r = mid
    else:
        l = mid


print(r)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l, r = -1, 10 ** 12


def func(x):  # a, x, kは全て整数ということに注意(//またはint())
    k = 0  # 修行回数初期化
    for a, f in zip(A, F):  # O(N)
        e = x // f
        if a <= e:  # (Ai-Ki)*Fi<=x Ki=0なら次 (a*f<=xの変形)
            continue
        k += a - e
        # else (Ai-Ki)*Fi<=x を満たすようにKiを設定。つまり修行回数にKiを加算。
    if k <= K:
        return 1
    return 0


while (r - l > 1):  # O(logx)
    mid = (l + r) // 2
    if func(mid):
        r = mid
    else:
        l = mid


print(r)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
AF = [A[i] * F[i] for i in range(N)]
for _ in range(K):
    j = AF.index(max(AF))
    A[j] -= 1
    AF[j] = A[j] * F[j]
print(max(AF))

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l, r = -1, 10 ** 12


def func(x):  # a, x, kは全て整数ということに注意(//またはint())
    k = 0  # 修行回数初期化
    for a, f in zip(A, F):  # O(N)
        e = x // f
        if a <= e:  # (Ai-Ki)*Fi<=x Ki=0なら次 (a*f<=xの変形)
            continue
        k += a - e
        # else (Ai-Ki)*Fi<=x を満たすようにKiを設定。つまり修行回数にKiを加算。
    if k <= K:
        return 1
    return 0


while (r - l > 1):  # O(logx)
    mid = (l + r) // 2
    if func(mid):
        r = mid
    else:
        l = mid


print(r)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
AF = [A[i] * F[i] for i in range(N)]
for _ in range(K):
    j = AF.index(max(AF))
    A[j] -= 1
    AF[j] = A[j] * F[j]
print(max(AF))

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l, r = -1, 10 ** 12


def func(x):  # a, x, kは全て整数ということに注意(//またはint())
    k = 0  # 修行回数初期化
    for a, f in zip(A, F):  # O(N)
        e = x // f
        if a <= e:  # (Ai-Ki)*Fi<=x Ki=0なら次 (a*f<=xの変形)
            continue
        k += a - e
        # else (Ai-Ki)*Fi<=x を満たすようにKiを設定。つまり修行回数にKiを加算。
    if k <= K:
        return 1
    return 0


while (r - l > 1):  # O(logx)
    mid = (l + r) // 2
    if func(mid):
        r = mid
    else:
        l = mid


print(r)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
Lb = L[::-1]
ans = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L[i + 1:]):
        c = l1 - l2
        p = max(0, len(L) - (i + j + 2) - bisect.bisect_right(Lb, c))
        ans += p
print(ans)

Fixed submission:
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
Lb = L[::-1]
ans = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L[i + 1:]):
        c = l1 - l2
        p = max(0, len(L) - (i + j + 2) - bisect.bisect_right(Lb, c))
        ans += p
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
ans = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L[i + 1:]):
        for k, l3 in enumerate(L[i + j + 2:]):
            if (l1 < l2 + l3) and (l2 < l3 + l1) and (l3 < l1 + l2):
                ans += 1
            else:
                break
print(ans)

Fixed submission:
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
Lb = L[::-1]
ans = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L[i + 1:]):
        c = l1 - l2
        p = max(0, len(L) - (i + j + 2) - bisect.bisect_right(Lb, c))
        ans += p
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math


def cf(x, y):
    table = [1]
    for i in range(2, min(x, y) + 1):
        if x % i == 0 and y % i == 0:
            table.append(i)
    return table


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


def is_pn(x):
    if x == 2:
        return 1
    if x % 2 == 0:
        return 0
    m = math.floor(math.sqrt(x))
    for p in pn_list:
        if x % p == 0:
            return 0
        if p > m:
            break
    return 1


A, B = map(int, input().split())
table = cf(A, B)
pn_list = primes(table[-1])
ans = 0
for i in table:
    ans += is_pn(i)
print(ans)

Fixed submission:
def prime_factorize(n):
    table = [1]
    while n % 2 == 0:
        table.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            table.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        table.append(n)
    return table


A, B = map(int, input().split())
a = set(prime_factorize(A))
b = set(prime_factorize(B))
ans = 0
for ap in a:
    if ap in b:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
for m in range(M):
    A[0] = A[0] // 2
    for i in range(N - 1):
        if A[i] < A[i + 1]:
            A[i], A[i + 1] = A[i + 1], A[i]
        else:
            break
print(sum(A))

Fixed submission:
def funcD():
    import heapq
    N, M = map(int, input().split())
    A = list(map(lambda x: -1 * int(x), input().split()))
    A.sort(reverse=True)
    heapq.heapify(A)
    for m in range(M):
        a = -(-heapq.heappop(A) // 2)
        heapq.heappush(A, a)
    print(-sum(A))


funcD()

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
for m in range(M):
    A[0] = A[0] // 2
    A.sort(reverse=True)
print(sum(A))

Fixed submission:
def funcD():
    import heapq
    N, M = map(int, input().split())
    A = list(map(lambda x: -1 * int(x), input().split()))
    A.sort(reverse=True)
    heapq.heapify(A)
    for m in range(M):
        a = -(-heapq.heappop(A) // 2)
        heapq.heappush(A, a)
    print(-sum(A))


funcD()
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
memo = [0] * M
for _ in range(N):
    a, b = map(int, input().split())
    if M < a:
        continue
    memo[a] = max(b, memo[a])
ans = sum(memo)
print(ans)

Fixed submission:
import bisect


N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1], reverse=True)
memo = [x for x in range(N)]
ans = 0
for a, b in AB:
    if M < a:
        continue
    Ma = M - a
    i = bisect.bisect_right(memo, Ma)
    if i > 0:
        del memo[i - 1]
        ans += b
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1], reverse=True)
memo = [0] * min(N, M)
ans = 0
for a, b in AB:
    Ma = max(M - a + 1, 0)
    for i in range(Ma, 0, -1):
        if memo[i - 1] == 0:
            memo[i - 1] = 1
            ans += b
            break
print(ans)

Fixed submission:
import bisect


N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1], reverse=True)
memo = [x for x in range(N)]
ans = 0
for a, b in AB:
    if M < a:
        continue
    Ma = M - a
    i = bisect.bisect_right(memo, Ma)
    if i > 0:
        del memo[i - 1]
        ans += b
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1], reverse=True)
memo = [0] * N
ans = 0
for a, b in AB:
    Ma = M - a + 1
    if 0 in memo[:Ma]:
        i = bisect.bisect_right(memo[:Ma], 0) - 1
        memo[i] = 1
        ans += b
print(ans)

Fixed submission:
import bisect


N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1], reverse=True)
memo = [x for x in range(N)]
ans = 0
for a, b in AB:
    if M < a:
        continue
    Ma = M - a
    i = bisect.bisect_right(memo, Ma)
    if i > 0:
        del memo[i - 1]
        ans += b
print(ans)
Buggy python submission (verdict: Runtime Error):
N = input()
n = len(list(N))
d_list = [9, 900, 90000]
if n >= 5:
  ans = 90909
elif n >= 4:
  ans = 909
elif n >= 3:
  ans = 9 + N % 1000
elif n >= 2:
  ans = 9
else:
  ans = N % 10
print(ans)

Fixed submission:
N = int(input())
n = len(list(str(N)))
if n >= 6:
  ans = 90909
elif n >= 5:
  ans = 909 + (N - 9999)
elif n >= 4:
  ans = 909
elif n >= 3:
  ans = 9 + (N - 99)
elif n >= 2:
  ans = 9
else:
  ans = N
print(ans)

Buggy python submission (verdict: Runtime Error):
N = input()
n = len(list(n))
d_list = [9, 900, 90000]
if n >= 5:
  ans = 90909
elif n >= 4:
  ans = 909
elif n >= 3:
  ans = 9 + N % 1000
elif n >= 2:
  ans = 9
else:
  ans = N % 10
print(ans)

Fixed submission:
N = int(input())
n = len(list(str(N)))
if n >= 6:
  ans = 90909
elif n >= 5:
  ans = 909 + (N - 9999)
elif n >= 4:
  ans = 909
elif n >= 3:
  ans = 9 + (N - 99)
elif n >= 2:
  ans = 9
else:
  ans = N
print(ans)
Buggy python submission (verdict: Runtime Error):
L, R = map(int, input().split())
l = L % 2019
r = R % 2019
ans = 10 ** 12
if l > r:
    ans = 0
else:
    for i in range(l, r + 1):
        for j in range(i + 1, r + 1):
            ans = min(ans, i * j % 2019)
print(ans)

Fixed submission:
N, A, B = map(int, input().split())
ans = min(N * A, B)
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())
AC = (A - 1) // C
AD = (A - 1) // D
BC = B // C
BD = B // D
BCD = B // lcm(C, D)
ACD = (A - 1) // lcm(C, D)
tmp = (BC + BD) - (AC + AD) - (BCD - ACD)
ans = (B - A + 1) - tmp
print(ans)

Fixed submission:
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A, B, C, D = map(int, input().split())
AC = (A - 1) // C
AD = (A - 1) // D
BC = B // C
BD = B // D
BCD = B // lcm(C, D)
ACD = (A - 1) // lcm(C, D)
tmp = (BC + BD) - (AC + AD) - (BCD - ACD)
ans = (B - A + 1) - tmp
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
ans = N - K
ans += 1 if k == 1 else 0
print(ans)

Fixed submission:
N, K = map(int, input().split())
ans = N % K
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
memo = {}
pq = []
for i in range(N-1):
    for j in range(i+1,N):
        pq.append([xy[j][0]-xy[i][0], xy[j][1]-xy[i][1]])
for p, q in pq:
    index = str(p) + str(q)
    if index in memo:
        memo[index] += 1
    else:
        memo[index] = 1
print(N-max(memo.values()))

Fixed submission:
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
x, y = [], []
for i, j in xy:
    x += [i]
    y += [j]
ans = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p = x[j] - x[i]
        q = y[j] - y[i]
        c = 0
        for k in range(N):
            for l in range(N):
                if k == l:
                    continue
                if (x[k] - x[l]) == p and (y[k] - y[l]) == q:
                    c += 1
        ans = max(ans, c)
if N != 1:
    print(N-ans)
else:
    print('1')

Buggy python submission (verdict: Runtime Error):
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
xy.sort()
deff_xy = []
memo = {}
for i in range(N-1):
    x = str(xy[i+1][0]-xy[i][0])
    y = str(xy[i+1][1]-xy[i][1])
    deff_xy = ('').join([x, y])
    if deff_xy in memo:
        memo[deff_xy] += 1
    else:
        memo[deff_xy] = 1
print(N-max(memo.values()))

Fixed submission:
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
x, y = [], []
for i, j in xy:
    x += [i]
    y += [j]
ans = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p = x[j] - x[i]
        q = y[j] - y[i]
        c = 0
        for k in range(N):
            for l in range(N):
                if k == l:
                    continue
                if (x[k] - x[l]) == p and (y[k] - y[l]) == q:
                    c += 1
        ans = max(ans, c)
if N != 1:
    print(N-ans)
else:
    print('1')

Buggy python submission (verdict: Runtime Error):
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
xy.sort()
deff_xy = []
memo = {}
for i in range(N-1):
    x = str(xy[i+1][0]-xy[i][0])
    y = str(xy[i+1][1]-xy[i][1])
    deff_xy = ('').join([x, y])
    if deff_xy in memo:
        memo[deff_xy] += 1
    else:
        memo[deff_xy] = 1
print(max(memo.values()))


Fixed submission:
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
x, y = [], []
for i, j in xy:
    x += [i]
    y += [j]
ans = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p = x[j] - x[i]
        q = y[j] - y[i]
        c = 0
        for k in range(N):
            for l in range(N):
                if k == l:
                    continue
                if (x[k] - x[l]) == p and (y[k] - y[l]) == q:
                    c += 1
        ans = max(ans, c)
if N != 1:
    print(N-ans)
else:
    print('1')
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
AM = A.pop(0)
xy = []
if AM > 0 and A[-1] >= 0:
    p = 1
elif AM <= 0 and A[-1] < 0:
    p = 2
else:
    p = 3
if p == 1:
    while(len(A)>1):
        x = A.pop(-1)
        y = A.pop(0)
        xy.append([x, y])
        A.append(x-y)
    xy.append([AM, A[0]])
    ans = AM - A[0]
if p == 2:
    while(len(A)>1):
        x = AM
        y = A.pop(-1)
        xy.append([x, y])
        AM -= y
    xy.append([AM, A[0]])
    ans = AM - A[0]
if p == 3:
    while(len(A)>1):
        y = A.pop(0)
        if y >= 0:
            x = A.pop(-1)
            xy.append([x, y])
            xy.append([x, y])
            A.append(x-y)
        else:
            x = AM
            xy.append([x, y])
            AM -= y
            xy.append([AM, A[0]])
            ans = AM - A[0]
print(ans)
for out in xy:
    print(*out)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
AM = A.pop(0)
xy = []
if AM > 0 and A[-1] >= 0:
    p = 1
elif AM <= 0 and A[-1] < 0:
    p = 2
else:
    p = 3
if p == 1:
    while(len(A)>1):
        x = A.pop(-1)
        y = A.pop(0)
        xy.append([x, y])
        A.append(x-y)
    xy.append([AM, A[0]])
    ans = AM - A[0]
if p == 2:
    while(len(A)>1):
        x = AM
        y = A.pop(-1)
        xy.append([x, y])
        AM -= y
    xy.append([AM, A[0]])
    ans = AM - A[0]
if p == 3:
    while(len(A)>1):
        y = A.pop(0)
        if y >= 0:
            x = A.pop(-1)
            xy.append([x, y])
            A.append(x-y)
        else:
            x = AM
            xy.append([x, y])
            AM -= y
    xy.append([AM, A[0]])
    ans = AM - A[0]
print(ans)
for out in xy:
    print(*out)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
sl = list(s)
ls = range(len(s) - 1)
loop = 1
c = 0
while (loop):
    loop = 0
    for i in ls:
        if sl[i:i + 3] == ['A', 'B', 'C']:
            sl[i] = 'B'
            sl[i + 1] = 'C'
            sl[i + 2] = 'A'
            c += 1
            loop = 1
print(c)

Fixed submission:
def b():
    import re
    s = input()
    s = re.sub(r'BC', 'D', s)
    ls = range(len(s))
    ac, c = 0, 0
    for i in ls:
        if s[i] == 'A':
            ac += 1
        elif s[i] == 'D':
            c += ac
        else:
            ac = 0
    return c


ans = b()
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
A.sort()
BC.sort(key=lambda x: - x[1])
tmp = []
for B, C in BC:
    tmp += [C] * B
    if len(tmp) >= N:
        break
for i in range(N):
    if A[i] < tmp[i]:
        A[i] = tmp[i]
    else:
        break
print(sum(A))

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
A.sort()
BC.sort(key=lambda x: - x[1])
tmp = []
for B, C in BC:
    tmp += [C] * B
    if len(tmp) >= N:
        break
if len(tmp) < N:
    n = len(tmp)
else:
    n = N
for i in range(n):
    if A[i] < tmp[i]:
        A[i] = tmp[i]
    else:
        break
print(sum(A))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
A.sort()
BC.sort(key=lambda x: -x[1])
i = 0
for B, C in BC:
    for _ in range(B):
        if C >= A[i]:
            A[i] = C
            i += 1
            if i == N - 1:
                break
    if i == N - 1:
        break
print(sum(A))

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
A.sort()
BC.sort(key=lambda x: - x[1])
tmp = []
for B, C in BC:
    tmp += [C] * B
    if len(tmp) >= N:
        break
if len(tmp) < N:
    n = len(tmp)
else:
    n = N
for i in range(n):
    if A[i] < tmp[i]:
        A[i] = tmp[i]
    else:
        break
print(sum(A))