Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02714 (python)

Fixed submission:
from numpy import prod
N = int(input())
S = input()
appearances = {"R": 0, "G": 0, "B": 0}
for c in S:
    appearances[c] += 1
print(prod(list(appearances.values())) - sum(sum(len(set(S[start] + S[start + step] + S[start + step * 2])) == 3 for start in range(N - step * 2)) for step in range(1, N // 2 + 1)))

Buggy submission (verdict: Runtime Error):
from numpy import prod
N = int(input())
S = input()
appearances = {"R": 0, "G": 0, "B": 0}
for c in S:
    appearances[c] += 1
print(prod(list(appearances.values())) - sum(sum(len(set(S[start] + S[start + step] + S[start + step * 2])) == 3 for start in range(N - step * 2)) for step in range(1, N // 2 + 1)))

Buggy submission (verdict: Runtime Error):
def diff_is_unequal(a, b, c):
    s, m, l = sorted([a, b, c])
    return (m - s) != (l - m)

input()
indices = dict()
for idx, c in enumerate(input()):
    indices[c] = indices.get(c, []) + [idx]

print(sum(diff_is_unequal(r, g, b) for b in indices["B"] for g in indices["G"] for r in indices["R"]))
Problem p02720 (python)

Fixed submission:
K = int(input())
if K < 13:
    print(K)
    quit()

now = list(range(1, 10))

count = 9
while True:
    nxt = []
    for l in now:
        tail = l % 10
        for t in range(max(0, tail - 1), min(10, tail + 2)):
            nxt.append(l * 10 + t)
            count += 1
            if count == K:
                print(l * 10 + t)
                quit()
    now = nxt

Buggy submission (verdict: Runtime Error):
K = int(input())
if K < 13:
    print(K)
    quit()

now = [*range(1, 10)]

count = 9
while True:
    nxt = []
    for l in now:
        tail = l % 10
        for t in range(max(0, tail - 1), min(10, tail + 2)):
            nxt.append(l * 10 + t)
            count += 1
            if count == K:
                print(l * 10 + t)
                quit()
    now = nxt
Problem p02722 (python)

Fixed submission:
import numpy as np

def divisors(N):
    return sorted(sum((list({n, N // n}) for n in range(1, int(N ** 0.5) + 1) if not N % n), []))

def prime_factorize_dict(n):
    d = dict()
    while not n & 1:
        d[2] = d.get(2, 0) + 1
        n >>= 1
    f = 3
    while f * f <= n:
        if not n % f:
            d[f] = d.get(f, 0) + 1
            n //= f
        else:
            f += 2
    if n != 1:
        d[n] = d.get(n, 0) + 1
    return d

N = int(input())
count = 0
for n in divisors(N)[1:]:
    M = N
    while not M % n:
        M //= n
    count += M % n == 1
fact_Nm1 = np.array(list(prime_factorize_dict(N - 1).values()), dtype=np.int32)
print(count + np.prod(fact_Nm1 + 1) - 1)

Buggy submission (verdict: Runtime Error):
import numpy as np

def divisors(N):
    return sorted(sum(([*{n, N // n}] for n in range(1, int(N ** 0.5) + 1) if not N % n), []))

def prime_factorize_dict(n):
    d = dict()
    while not n & 1:
        d[2] = d.get(2, 0) + 1
        n >>= 1
    f = 3
    while f * f <= n:
        if not n % f:
            d[f] = d.get(f, 0) + 1
            n //= f
        else:
            f += 2
    if n != 1:
        d[n] = d.get(n, 0) + 1
    return d

N = int(input())
count = 0
for n in divisors(N)[1:]:
    M = N
    while not M % n:
        M //= n
    count += M % n == 1
fact_Nm1 = np.array(list(prime_factorize_dict(N - 1).values()), dtype=np.int32)
print(count + np.prod(fact_Nm1 + 1) - 1)
Problem p02732 (python)

Fixed submission:
from collections import Counter
from scipy.misc import comb
import numpy as np
N = int(input())
A = list(map(int, input().split()))

total = 0
answers = np.array([0] * (N + 1))
for number, appearance in Counter(A).items():
    flat = comb(appearance, 2, exact=True)
    minus_one = comb(appearance - 1, 2, exact=True)
    total += flat
    answers[number] = minus_one - flat
answers += total

print(*answers[A], sep="\n")

Buggy submission (verdict: Runtime Error):

from collections import Counter
from scipy.special import comb
import numpy as np
N = int(input())
A = list(map(int, input().split()))

total = 0
answers = np.array([0] * (N + 1))
for number, appearance in Counter(A).items():
    flat = comb(appearance, 2, exact=True)
    minus_one = comb(appearance - 1, 2, exact=True)
    total += flat
    answers[number] = minus_one - flat
answers += total

print(*answers[A], sep="\n")
Problem p02761 (python)

Fixed submission:
N, M = map(int, input().split())
ans = [None] * N
for _ in range(M):
    s, c = map(int, input().split())
    if ans[s - 1] in [None, c]:
        ans[s - 1] = c
    else:
        print(-1)
        quit()

ans = "".join(map(lambda pair :str(pair[1]) if pair[1] != None else "0" if pair[0] or N == 1 else "1", enumerate(ans)))
if N > 1 and ans[0] == "0":
    print(-1)
    quit()

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
ans = [None] * N
for _ in range(M):
    s, c = map(int, input().split())
    if ans[s - 1] in [None, c]:
        ans[s - 1] = c
    else:
        print(-1)
        quit()

ans = "".join(map(lambda i, n :str(n) if n else "0" if i else "1", enumerate(ans)))
if N > 1 and ans[0] == "0":
    print(-1)
    quit()

print(ans)
Problem p02765 (python)

Fixed submission:
N, R = map(int, input().split())
print(R + max(0, 100 * (10 - N)))

Buggy submission (verdict: Runtime Error):
from math import log, ceil
print(ceil(int(log(*map(int, input().split())) - 0.001) + 0.001))
Problem p02802 (python)

Fixed submission:
N, M = map(int, input().split())
accepted = [0] * N
penalties = [0] * N
for _ in range(M):
    p, ac = input().split()
    p, ac = int(p) - 1, ac == "AC"
    accepted[p] |= ac
    penalties[p] += not accepted[p]
print(sum(accepted), sum(p for ac, p in zip(accepted, penalties) if ac))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
accepted = [0] * N
penalties = [0] * N
for _ in range(M):
    p, ac = input().split()
    p, ac = int(p), ac == "AC"
    accepted[p] |= ac
    penalties[p] += not accepted[p]
print(sum(accepted), sum(p for ac, p in zip(accepted, penalties) if ac))
Problem p02803 (python)

Fixed submission:
import numpy as np
from scipy.sparse import csgraph
H, W = map(int, input().split())
maze = "".join(input() for _ in range(H))
array = np.zeros((H * W, H * W), dtype=np.bool)
for n in range(H * W):
    if maze[n] == "#":
        continue
    r, c = divmod(n, W)
    if c and maze[n - 1] == ".":
        array[n][n - 1] = 1
    if c != W - 1 and maze[n + 1] == ".":
        array[n][n + 1] = 1
    if r and maze[n - W] == ".":
        array[n][n - W] = 1
    if r != H - 1 and maze[n + W] == ".":
        array[n][n + W] = 1
dist = csgraph.shortest_path(array, directed=False)
print(int(dist[dist < 401].max()))

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse import csgraph
H, W = map(int, input().split())
maze = np.array([c == "." for c in "".join(input() for _ in range(H))], dtype=np.bool)
array = np.zeros((H * W, H * W), dtype=np.bool)
N = np.arange(H * W)
R, C = np.divmod(N, W)
c_i = N[maze[N] & (C > 0) & maze[N - 1]]
r_i = N[maze[N] & (R > 0) & maze[N - W]]
array[c_i, c_i - 1] = 1
array[c_i - 1, c_i] = 1
array[r_i, r_i - W] = 1
array[r_i - W, r_i] = 1
dist = csgraph.shortest_path(array)
print(int(dist[dist < 401].max()))

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse import csr_matrix, csgraph
H, W = map(int, input().split())
maze = "".join(input() for _ in range(H))
array = np.zeros((H * W, H * W), dtype=np.bool)
for n in range(H * W):
    if maze[n] == "#":
        continue
    r, c = divmod(n, W)
    if c and maze[n - 1] == ".":
        array[n][n - 1] = 1
    if c != W - 1 and maze[n + 1] == ".":
        array[n][n + 1] = 1
    if r and maze[n - W] == ".":
        array[n][n - W] = 1
    if r != H - 1 and maze[n + W] == ".":
        array[n][n + W] = 1
dist = csgraph.shortest_path(csr_matrix(array, dtype=np.bool, shape=(H * W, H * W)), directed=False)
print(int(dist[dist < 401].max()))

Buggy submission (verdict: Runtime Error):
from scipy.sparse import csr_matrix, csgraph
H, W = map(int, input().split())
maze = "".join(input() for _ in range(H))
data = []
row = []
column = []
for n in range(H * W):
    if maze[n] == "#":
        continue
    r, c = divmod(n, W)
    if c and maze[n - 1] == ".":
        data.append(1)
        row.append(n)
        column.append(n - 1)
    if c != W - 1 and maze[n + 1] == ".":
        data.append(1)
        row.append(n)
        column.append(n + 1)
    if r and maze[n - W] == ".":
        data.append(1)
        row.append(n)
        column.append(n - W)
    if r != H - 1 and maze[n + W] == ".":
        data.append(1)
        row.append(n)
        column.append(n + W)
dist = csgraph.shortest_path(csr_matrix((data, (row, column)), dtype="i8", shape=(H * W, H * W)), directed=False)
print(int(dist[dist < 401].max()))
Problem p02839 (python)

Fixed submission:
R, C = map(int, input().split())

A = [list(map(int, input().split())) for _ in range(R)]
B = [list(map(int, input().split())) for _ in range(R)]

dp = [0] * C
dp[0] = s = 1 << 6400

for row_a, row_b in zip(A, B):
    for i, (a, b) in enumerate(zip(row_a, row_b)):
        d = abs(a - b)
        if i > 0:
            dp[i] |= dp[i - 1]
        dp[i] = (dp[i] << d) | (dp[i] >> d)

g = dp[-1]
for i in range(6401):
    if g & (s << i) or g & (s >> i):
        print(i)
        quit()

Buggy submission (verdict: Runtime Error):
R, C = map(int, input().split())

A = [list(map(int, input().split())) for _ in range(R)]
B = [list(map(int, input().split())) for _ in range(R)]

dp = [0] * R
dp[0] = s = 1 << 6400

for row_a, row_b in zip(A, B):
    for i, (a, b) in enumerate(zip(row_a, row_b)):
        d = abs(a - b)
        if i > 0:
            dp[i] |= dp[i - 1]
        dp[i] = (dp[i] << d) | (dp[i] >> d)

g = dp[-1]
for i in range(6401):
    if g & (s << i) or g & (s >> i):
        print(i)
        quit()

Buggy submission (verdict: Runtime Error):
R, C = map(int, input().split())

A = [list(map(int, input().split())) for _ in range(R)]
B = [list(map(int, input().split())) for _ in range(R)]

dp = [0] * R
dp[0] = s = 1 << 6400

for row_a, row_b in zip(A, B):
    for i, (a, b) in enumerate(zip(row_a, row_b)):
        d = abs(a - b)
        if i > 0:
            dp[i] |= dp[i - 1]
        dp[i] <<= d
        dp[i] >>= d

g = dp[-1]
for i in range(6401):
    if g & (s << i) or g & (s >> i):
        print(i)
        quit()

Buggy submission (verdict: Runtime Error):
r, c = map(int, input().split())

A = [list(map(int, input().split())) for _ in range(r)]
B = [list(map(int, input().split())) for _ in range(r)]

dp_table = [[[False] * 6400 for _2 in range(c)] for _1 in range(r)]

dp_table[0][0][abs(A[0][0] - B[0][0])] = True

for i in range(1, r):
    temp = A[i][0] - B[i][0]
    up_list = dp_table[i - 1][0]
    for idx, up in enumerate(up_list):
        if up:
            dp_table[i][0][abs(idx + temp)] = True
            dp_table[i][0][abs(idx - temp)] = True

for j in range(1, c):
    temp = A[0][j] - B[0][j]
    left_list = dp_table[0][j]
    for idx, left in enumerate(left_list):
        if left:
            dp_table[0][j][abs(idx + temp)] = True
            dp_table[0][j][abs(idx - temp)] = True

for i in range(1, r):
    for j in range(1, c):
        temp = A[i][j] - B[i][j]
        up_list = dp_table[i - 1][j]
        for idx, up in enumerate(up_list):
            if up:
                dp_table[i][j][abs(idx + temp)] = True
                dp_table[i][j][abs(idx - temp)] = True
        left_list = dp_table[i][j - 1]
        for idx, left in enumerate(left_list):
            if left:
                dp_table[i][j][abs(idx + temp)] = True
                dp_table[i][j][abs(idx - temp)] = True

print(dp_table[r - 1][c - 1].index(True))
Problem p02861 (python)

Fixed submission:
from itertools import combinations
dist = lambda p1, p2: ((p2[0] - p1[0]) ** 2 + (p2[1] - p1[1]) ** 2) ** (1 / 2)

N = int(input())
P = (tuple(map(int, input().split())) for _ in range(N))

distances = (dist(*combination) for combination in combinations(P, 2))
total_distance = tuple(sum(distance) for distance in combinations(distances, N - 1))
print(sum(total_distance) / len(total_distance))

Buggy submission (verdict: Runtime Error):
from statistics import mean
from itertools import combinations
dist = lambda p1, p2: ((p2[0] - p1[0]) ** 2 + (p2[1] - p1[1]) ** 2) ** (1 / 2)

N = int(input())
P = (tuple(map(int, input().split())) for _ in range(N))

distances = (dist(*combination) for combination in combinations(P, 2))
total_distance = (sum(distance) for distance in combinations(distances, N - 1))
print(mean(total_distance))
Problem p02882 (python)

Fixed submission:
from math import atan, degrees
a, b, x = map(int, input().split())
print(degrees(atan(2 * (a ** 2 * b - x) / a ** 3)) if x >= a ** 2 * b / 2 else degrees(atan(a * b ** 2 / x / 2)))

Buggy submission (verdict: Runtime Error):
print(degrees(atan(2 * (a ** 2 * b - x) / a ** 3)) if x >= a ** 2 * b / 2 else degrees(atan(a * b ** 2 / x / 2)))
Problem p02888 (python)

Fixed submission:
from bisect import bisect
N = int(input())
sides = sorted(map(int, input().split()))

ans = 0
for i in range(1, N - 1):
    for j in range(i + 1, N + 1):
        ans += N - j - bisect(sides, sides[-i] - sides[-j], hi=N-j)
print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect
N = int(input())
sides = sorted(map(int, input().split()))
print(sum(N - j - bisect(sides, sides[-i] - sides[-j], hi=N-j) for j in range(i + 1, N + 1) for i in range(1, N - 1)))
Problem p02936 (python)

Fixed submission:
from collections import deque
def dfs(graph, N, start, points):
    visited = [0] * N
    visited[start] = 1
    stack = deque([(start, points[start])])
    ret = [0] * N
    while stack:
        edge, point = stack.pop()
        ret[edge] = point
        for e in graph[edge]:
            if not visited[e]:
                visited[e] = 1
                stack.append((e, point + points[e]))
    return ret

N, Q = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(lambda n: int(n) - 1, input().split())
    graph[a].append(b)
    graph[b].append(a)
points = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    points[p - 1] += x
print(*dfs(graph, N, 0, points))

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]
visited = [0] * N
children = [0] * N
count = 0
order = [0] * N
def dfs_recursive(edge):
    global count
    visited[edge] = 1
    order[edge] = count
    count += 1
    child = edge
    for e in graph[edge]:
        if not visited[e]:
            child = dfs_recursive(e)
    children[edge] = child
    return child
for _ in range(N - 1):
    a, b = map(lambda n: int(n) - 1, input().split())
    graph[a].append(b)
    graph[b].append(a)
dfs_recursive(0)
imos = [0] * (N + 1)
for _ in range(Q):
    p, x = map(int, input().split())
    root = p - 1
    root_idx = order[root]
    child = children[root]
    child_idx = order[child]
    imos[root_idx] += x
    imos[child_idx + 1] -= x
ans = list(accumulate(imos))
ans.pop()
print(*ans)
Problem p02972 (python)

Fixed submission:
N = int(input())
A = reversed(tuple(enumerate(map(int, input().split()), 1)))

boxes = [0] * (N + 1)
ans = []

for n, digit in A:
    put = sum(d for d in boxes[n::n]) & 1 != digit
    if put:
        boxes[n] = 1
        ans.append(n)

print(len(ans))
if ans:
    print(*ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
boxes = [0] * (N + 1)
ans = tuple(n for n, digit in reversed(tuple(enumerate(map(int, input().split()), 1))) if (sum(d for d in boxes[n::n]) & 1 != digit and (boxes.__setitem__(n, 1) or 1)))
print(f"{len(ans)}\n", *ans)
Problem p03059 (python)

Fixed submission:
l = list(map(int, input().split()))
print((l[2] // l[0]) * l[1], "")

Buggy submission (verdict: Runtime Error):
input()
A = list(set(map(int, input().split()))
N = len(A)

def gcd(x, y):
  while y != 0:
    x, y = y, x%y
  return x


if N <= 2:
  print(max(A))
else:
  max = 0
  for i in range(N):
    temp = A.pop(0)
    ans = gcd(A[0], A[1])
    for j in A[1:]:
      ans = gcd(ans, j)
    if max < ans:
      max = ans
    A.append(temp)
  print(max)

Buggy submission (verdict: Runtime Error):
input()
A = list(map(int, input().split()))
N = len(A)

def gcd(x, y):
  while y != 0:
    x, y = y, x%y
  return x


if N <= 2:
  print(max(A))
else:
  max = 0
  for i in range(N):
    temp = A.pop(0)
    ans = gcd(A[0], A[1])
    for j in A[1:]:
      ans = gcd(ans, j)
    if max < ans:
      max = ans
    A.append(temp)
  print(max)
Problem p03061 (python)

Fixed submission:
from fractions import gcd

n = int(input())
list_ = list(map(int, input().strip().split()))

gcd_from_left = [0]
gcd_from_right = [0]
for i in range(n):
    gcd_from_left.append(gcd(gcd_from_left[i], list_[i]))
    gcd_from_right.append(gcd(gcd_from_right[i], list_[-(i + 1)]))

gcd_from_left.insert(0, 0)
gcd_from_right.insert(0, 0)
gcd_from_right.reverse()

print(max(gcd(gcd_from_left[i], gcd_from_right[i]) for i in range(n + 2)))

Buggy submission (verdict: Runtime Error):
from math import gcd
class SegmentTree(object):
    def __init__(self, sequence, function, identity):
        N = len(sequence)
        self.length = (1 << (N - 1)).bit_length()
        self.data = [identity] * (self.length << 1)
        self.function = function
        self.identity = identity
        for i in range(N):
            self.data[i + self.length - 1] = sequence[i]
        for i in range(self.length - 2, -1, -1) :
            self.data[i] = self.function(self.data[(i << 1) + 1], self.data[(i << 1) + 2])

    def update(self, idx, x):
        idx += self.length - 1
        self.data[idx] = x
        while idx:
            idx = (idx - 1) >> 1
            self.data[idx] = self.function(self.data[(idx << 1) + 1], self.data[(idx << 1) + 2])

    def query(self, p, q):
        if q <= p:
            return self.identity
        p += self.length - 1
        q += self.length - 2
        res = self.identity
        while q - p > 1:
            if not p & 1:
                res = self.function(res, self.data[p])
            if q & 1:
                res = self.function(res, self.data[q])
                q -= 1
            p >>= 1
            q = (q - 1) >> 1
        return self.function(res, self.data[p]) if p == q else self.function(self.function(res, self.data[p]), self.data[q])

N, *A = map(int, open(0).read().split())
seg_tree = SegmentTree(A, gcd, 0)
ans = 0
for i in range(N):
    seg_tree.update(i, 0)
    ans = max(ans, seg_tree.query(0, N))
    seg_tree.update(i, A[i])
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
array = np.array(list(map(int, input().strip().split())))

print(max([np.gcd.reduce(array[[i for i in range(n) if i != j]]) for j in range(n)]))

Buggy submission (verdict: Runtime Error):
input()
A = list(set(map(int, input().split())))
N = len(A)

def gcd(x, y):
  while y != 0:
    x, y = y, x%y
  return x

max = 0

if N <= 2:
  print(max(A))
else:
  for i in range(N):
    temp = A.pop(0)
    ans = gcd(A[0], A[1])
    for j in A[1:]:
      ans = gcd(ans, j)
    if max < ans:
      max = ans
    A.append(temp)
  print(max)

Buggy submission (verdict: Runtime Error):
input()
A = list(set(map(int, input().split())))
N = len(A)

def gcd(x, y):
  while y != 0:
    x, y = y, x%y
  return x

max = 0

for i in range(N):
  temp = A.pop(0)
  ans = gcd(A[0], A[1])
  for j in A[1:]:
    ans = gcd(ans, j)
  if max < ans:
    max = ans
  A.append(temp)
print(max)
Problem p03074 (python)

Fixed submission:
_, K = map(int, input().split())
S = input()

offset = int(S[0]) == (K & 1)
runs = []

prev = S[0]
run = 0
for c in S:
    if c != prev:
        runs.append(run)
        run = 0
    prev = c
    run += 1
runs.append(run)

L = len(runs)
candidates = []

prev = sum(runs[max(0, offset - K): min(L, offset + K + 1)])
candidates.append(prev)

for i in range(offset + 2, L, 2):
    now = prev
    old_left = i - 2 - K
    new_right = i + K
    if old_left >= 0:
        now -= runs[old_left]
    if old_left + 1 >= 0:
        now -= runs[old_left + 1]
    if new_right - 1 < L:
        now += runs[new_right - 1]
    if new_right < L:
        now += runs[new_right]
    prev = now
    candidates.append(prev)

print(max(candidates))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()

parity = []
runlength = []

prev = S[0]
run = 0
for c in S:
    if c != prev:
        parity.append(bool(int(prev)))
        runlength.append(run)
        run = 0
    prev = c
    run += 1
parity.append(bool(int(prev)))
runlength.append(run)

if parity.count(False) <= K:
    print(N)
    quit()

argmax = 0
maximum = 0

L = len(parity)
for i in range(L):
    total = sum(runlength[max(0, i - 1): min(L, i + 2)])
    if not parity[i] and total > maximum:
        argmax = i
        maximum = total

while True:
    parity[argmax] = True
    runlength[argmax] = maximum
    del parity[argmax + 1]
    del parity[argmax - 1]
    del runlength[argmax + 1]
    del runlength[argmax - 1]

    K -= 1
    if not K:
        print(maximum)
        break

    L = len(parity)
    maximum = 0
    for i in [argmax - 2, argmax]:
        total = sum(runlength[max(0, i - 1): min(L, i + 2)])
        if total > maximum:
            argmax = i
            maximum = total
Problem p03076 (python)

Fixed submission:
dishes = [int(input()) for _ in range(5)]
tuple_ = tuple(n for n in map(lambda num: num % 10, dishes) if n)
print(sum(map(lambda num: num + 10 * (num % 10 != 0) - (num % 10), dishes)) + min(tuple_ if tuple_ else (10,)) - 10)

Buggy submission (verdict: Runtime Error):
dishes = [int(input()) for _ in range(5)]
print(sum(map(lambda num: num + 10 * (num % 10 != 0) - (num % 10), dishes)) + min(n for n in map(lambda num: num % 10, dishes) if n) - 10)
Problem p03103 (python)

Fixed submission:
M, N = map(int, input().split())
COST, STOCK = range(2)
energy_drinks = sorted((tuple(map(int, input().split())) for _ in range(M)), key=lambda tuple_: tuple_[COST])

cost = 0
for energy_drink in energy_drinks:
    buy = min(energy_drink[STOCK], N)
    N -= buy
    cost += buy * energy_drink[COST]
print(cost)

Buggy submission (verdict: Runtime Error):
M, N = map(int, input().split())
COST, STOCK = range(2)
energy_drinks = sorted((tuple(map(int, input().split())) for _ in range(N)), key=lambda tuple_: tuple_[COST])

cost = 0
for energy_drink in energy_drinks:
    buy = min(energy_drink[STOCK], N)
    N -= buy
    cost += buy * energy_drink[COST]
print(cost)