Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def main():
    from bisect import bisect_left
    import sys
    input = sys.stdin.buffer.readline
    def dist(x, s, t):
        if s < x and t < x:
            return x - min(s, t)
        elif s > x and t > x:
            return max(s, t) - x
        else:
            if (ds := abs(x - s)) <= (dt := abs(x - t)):
                return 2 * ds + dt
            else:
                return ds + 2 * dt
    def near(A, x):
        if (i := bisect_left(A, x)) == 0:
            return [A[0], ]
        elif 0 < i < a:
            return [A[i - 1], A[i]]
        else:
            return [A[-1], ]
    a, b, q = map(int, input().split())
    S = [int(input()) for _ in range(a)]
    T = [int(input()) for _ in range(b)]
    for _ in range(q):
        x = int(input())
        ans = 100000000000
        for s in near(S, x):
            for t in near(T, x):
                ans = min(ans, dist(x, s, t))
        print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from bisect import bisect_left
    import sys
    input = sys.stdin.buffer.readline
    def dist(x, s, t):
        if s < x and t < x:
            return x - min(s, t)
        elif s > x and t > x:
            return max(s, t) - x
        else:
            if (ds := abs(x - s)) <= (dt := abs(x - t)):
                return 2 * ds + dt
            else:
                return ds + 2 * dt
    def near(A, x):
        if (i := bisect_left(A, x)) == 0:
            return [A[0], ]
        elif 0 < i < len(A):
            return [A[i - 1], A[i]]
        else:
            return [A[-1], ]
    a, b, q = map(int, input().split())
    S = [int(input()) for _ in range(a)]
    T = [int(input()) for _ in range(b)]
    for _ in range(q):
        x = int(input())
        ans = 100000000000
        for s in near(S, x):
            for t in near(T, x):
                ans = min(ans, dist(x, s, t))
        print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [0] * n
dp[0] = 0
for i in range(1, n):
    dp[i] = min([dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, min(i, k) + 1)])
print(dp[n - 1])


Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [0] * n
dp[0] = 0
for i in range(1, n):
    dp[i] = min([dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, min(i, k) + 1)])
print(dp[n - 1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [0] * n
dp[0] = 0
for i in range(1, n):
    dp[i] = min([dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, min(i, k) + 1)])
print(dp[n - 1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [0] * n
dp[0] = 0
for i in range(1, n):
    dp[i] = min([dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, min(i, k) + 1)])
print(dp[n - 1])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
H = np.array([list(map(int, input().split())) for _ in range(n)], dtype = np.int)
dp = np.zeros((n, 3), dtype = np.int)
dp[0] = H[0]
def except_ind(num):
    ind = np.ones((3, ), dtype = bool)
    ind[num] = False
    return ind
for i in range(1, n):
    for j in range(3):
        dp[i][j] = np.max(dp[i - 1][except_ind(j)]) + H[i][j]
print(np.max(dp[n - 1]))


Fixed submission:
n = int(input())
H = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * 3 for _ in range(n)]
dp[0] = H[0]
for i in range(1, n):
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + H[i][0]
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + H[i][1]
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + H[i][2]
print(max(dp[n - 1]))

Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
H = np.array([list(map(int, input().split())) for _ in range(n)], dtype = np.int)
dp = np.zeros((n, 3), dtype = np.int)
dp[0] = H[0]
def except_ind(num):
    ind = np.ones((3, ), dtype = bool)
    ind[num] = False
    return ind
for i in range(1, n):
    for j in range(3):
        dp[i][j] = np.max(dp[i - 1][except_ind(j)]) + H[i][j]
print(np.max(dp[n - 1]))

Fixed submission:
n = int(input())
H = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * 3 for _ in range(n)]
dp[0] = H[0]
for i in range(1, n):
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + H[i][0]
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + H[i][1]
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + H[i][2]
print(max(dp[n - 1]))
Buggy python submission (verdict: Time Limit Exceeded):
n, W = list(map(int, input().split()))
dp = [[0] * (W + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
    w, v = list(map(int, input().split()))
    for j in range(W + 1):
        if w > j:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = max(dp[i - 1][j - w] + v, dp[i - 1][j])
print(dp[n][W])


Fixed submission:
n, W = list(map(int, input().split()))
dp = [[0] * (W + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
    w, v = list(map(int, input().split()))
    for j in range(W + 1):
        if w > j:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = max(dp[i - 1][j - w] + v, dp[i - 1][j])
print(dp[n][W])
Buggy python submission (verdict: Runtime Error):
from itertools import product
def main():
    n = int(input())
    A = []
    for _ in range(n):
        A.append(list(map(int, input().split())))
    for a in A:
        if a[2] != 0:
            t = a
            break
    for x, y in product(range(0, 101), repeat = 2):
        H = t[2] + abs(t[0] - x) + abs(t[1] - y)
        for a in A:
            if a[2] == 0 and H < abs(a[0] - x) + abs(a[1] - y):
                break
            elif a[2] == 0:
                continue
            elif a[2] != 0 and a[2] == H - abs(a[0] - x) - abs(a[1] - y):
                continue
            elif a[2] != H - abs(a[0] - x) - abs(a[1] - y):
                break
        else:
            ansx, ansy = x, y
            break
    H = t[2] + abs(t[0] - ansx) + abs(t[1] - ansy)
    print('{} {} {}'.format(ansx, ansy, H))



if __name__ == '__main__':
    main()


Fixed submission:
from itertools import product
def main():
    n = int(input())
    A = []
    for _ in range(n):
        A.append(list(map(int, input().split())))
    for a in A:
        if a[2] > 0:
            t = a
            break
    for x, y in product(range(0, 101), repeat = 2):
        H = t[2] + abs(t[0] - x) + abs(t[1] - y)
        for a in A:
            if a[2] == 0 and H > abs(a[0] - x) + abs(a[1] - y):
                break
            elif a[2] != 0 and a[2] != H - abs(a[0] - x) - abs(a[1] - y):
                break
        else:
            ansx, ansy = x, y
            break
    H = t[2] + abs(t[0] - ansx) + abs(t[1] - ansy)
    print('{} {} {}'.format(ansx, ansy, H))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    a, b = map(int, inptut().split())
    print((a - 1) * (b - 1))

if __name__ == '__main__':
    main()


Fixed submission:
a, b = list(map(int, input().split()))
print((a - 1) * (b - 1))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
ans = 1e+6
for n in range(N):
    score = len([x for x in S[:n] if x == 'W']) + len([x for x in S[n + 1:] if x == 'E'])
    ans = min(ans, score)
print(ans)

Fixed submission:
N = int(input())
S =input()
wn = [0] * (N + 1)
en = [0] * (N + 1)
for i in range(1, N + 1):
    if S[i - 1] == 'W':
        wn[i] = wn[i - 1] + 1
        en[i] = en[i - 1]
    else:
        wn[i] = wn[i - 1]
        en[i] = en[i - 1] + 1
ans = [wn[i] + en[N] - en[i + 1] for i in range(N)]
print(min(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
ans = 1e+6
for n in range(N):
    score = len(list(filter(lambda x: x == 'W', S[:n]))) + len(list(filter(lambda x: x == 'E', S[n + 1:])))
    ans = min(ans, score)
print(ans)

Fixed submission:
N = int(input())
S =input()
wn = [0] * (N + 1)
en = [0] * (N + 1)
for i in range(1, N + 1):
    if S[i - 1] == 'W':
        wn[i] = wn[i - 1] + 1
        en[i] = en[i - 1]
    else:
        wn[i] = wn[i - 1]
        en[i] = en[i - 1] + 1
ans = [wn[i] + en[N] - en[i + 1] for i in range(N)]
print(min(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
X = list(map(int, input().split()))
xs = sorted(X)
x0, x1 = xs[n // 2 - 1:n // 2 + 1]
[print(x1) if xs.index(x) <= n // 2 - 1 else print(x0) for x in X]

Fixed submission:
n = int(input())
X = list(map(int, input().split()))
x0, x1 = sorted(X)[n // 2 - 1:n // 2 + 1]
[print(x1) if x <= x0 else print(x0) for x in X]
Buggy python submission (verdict: Runtime Error):
def main():
    import math
    def generate_primes(num):
        if num == 1: return []
        primes = list(range(2, num + 1))
        i, p = 0, 1
        while p <= math.sqrt(num):
            if primes[i] != 0:
                p = primes[i]
                primes = [prime if (prime % p != 0 or prime == p) else 0 for prime in primes]
            i += 1
        return set([p for p in primes if p != 0])

    primes = generate_primes(100000)
    ans = [0] * 50000
    for j in range(1, 50000):
        i = 2 * j - 1
        if i in primes and (i + 1) / 2 in primes:
            ans[j] = ans[j - 1] + 1
        else:
            ans[j] = ans[j - 1]
    q = int(input())
    for _ in range(q):
        l, r = list(map(lambda x: (int(x) + 1) // 2, input().split()))
        print(ans[r] - ans[l - 1])


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import math
    def generate_primes(num):
        if num == 1: return []
        primes = list(range(2, num + 1))
        i, p = 0, 1
        while p <= math.sqrt(num):
            if primes[i] != 0:
                p = primes[i]
                primes = [prime if (prime % p != 0 or prime == p) else 0 for prime in primes]
            i += 1
        return set([p for p in primes if p != 0])

    primes = generate_primes(100000)
    ans = [0] * 50001
    for j in range(1, 50001):
        i = 2 * j - 1
        if i in primes and (i + 1) // 2 in primes:
            ans[j] = ans[j - 1] + 1
        else:
            ans[j] = ans[j - 1]
    q = int(input())
    for _ in range(q):
        l, r = list(map(lambda x: (int(x) + 1) // 2, input().split()))
        print(ans[r] - ans[l - 1])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
s = list(input())
t = list(input())
s_uni = sorted([ord(i) for i in s])
t_uni = sorted([ord(i) for i in t], reverse = True)
for i in range(len(s)):
    if s_uni[i] < t_uni[i]:
        print('Yes')
        exit()
    elif s_uni[i] == t_uni[i]:
        continue
    else:
        print('No')
        exit()
if len(s) < len(t):
    print('Yes')
else:
    print('No')

Fixed submission:
s = list(input())
t = list(input())
s_uni = sorted([ord(i) for i in s])
t_uni = sorted([ord(i) for i in t], reverse = True)
for i in range(min(len(s), len(t))):
    if s_uni[i] < t_uni[i]:
        print('Yes')
        exit()
    elif s_uni[i] == t_uni[i]:
        continue
    else:
        print('No')
        exit()
if len(s) < len(t):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
x, y = list(input())
if x < y:
    print('<')
elif x == y:
    print('=')
else:
    print('>')

Fixed submission:
x, y = input().split()
if x < y:
    print('<')
elif x == y:
    print('=')
else:
    print('>')
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_right
def main():
    n = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))
    AB = [0] * n
    BC = [0] * n
    for i in range(n):
        AB[i] = n - bisect_right(B, A[i])
        BC[i] = n - bisect_right(C, B[i])
    ans = 0
    for ab in AB:
        if ab != 0:
            ans += sum(BC[-ab:])
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
from bisect import bisect_right, bisect_left
def main():
    n = int(input())
    A = sorted(list(map(int, input().split())))
    B = list(map(int, input().split()))
    C = sorted(list(map(int, input().split())))
    ans = 0
    for b in B:
        ans += bisect_left(A, b) * (n - bisect_right(C, b))
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
ans = 1
for i in sorted(set(A)):
    for j in range(-1, 2):
        ans = max(ans, sum([i + j - 1 <= a <= i + j + 1 for a in A]))
print(ans)

Fixed submission:
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = 1
for c in C.keys():
    for i in range(-1, 2):
        j = c + i
        ans = max(ans, sum([C[j - 1], C[j], C[j + 1]]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def main():
    n = int(input())
    G = [[] for _ in range(n)]
    D = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        G[a].append(b)
        D[a].append(c)
        G[b].append(a)
        D[b].append(c)
    q, k = list(map(int, input().split()))
    k -= 1
    stack = deque([k, ])
    ans = [-1] * n
    ans[k] = 0
    while stack:
        x = stack.popleft()
        for dx, l in zip(G[x], D[x]):
            if ans[dx] == -1:
                ans[dx] = ans[x] + l
                stack.appendleft(dx)
    for _ in range(q):
        x, y = list(map(lambda x: int(x) - 1, input().split()))
        print(ans[x] + ans[y])

if __name__ == '__main__':
    main()


Fixed submission:
from collections import deque
import sys
def input():
    return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    G = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        G[a].append([b, c])
        G[b].append([a, c])
    q, k = list(map(int, input().split()))
    k -= 1
    stack = deque([k, ])
    ans = [-1] * n
    ans[k] = 0
    while stack:
        x = stack.popleft()
        for (dx, l) in G[x]:
            if ans[dx] == -1:
                ans[dx] = ans[x] + l
                stack.appendleft(dx)
    for _ in range(q):
        x, y = list(map(lambda x: int(x) - 1, input().split()))
        print(ans[x] + ans[y])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    def flatten_list(l):
        for el in l:
            if isinstance(el, list):
                yield from flatten_list(el)
            else:
                yield el
    H, W = list(map(int, input().split()))
    n = int(input())
    A = list(map(int, input().split()))
    ans = []
    for i, a in enumerate(A):
        ans .append([str(i + 1)] * a)
    ans = list(flatten_list(ans))
    ans = [ans[i:i + W] if i // W % 2 == 0 else ans[i + W - 1:i - 1:-1] for i in range(0, len(ans), W)]
    [print(' '.join(a)) for a in ans]



if __name__ == '__main__':
    main()


Fixed submission:
def main():
    def flatten_list(l):
        for el in l:
            if isinstance(el, list):
                yield from flatten_list(el)
            else:
                yield el
    H, W = list(map(int, input().split()))
    n = int(input())
    A = list(map(int, input().split()))
    ans = []
    for i, a in enumerate(A):
        ans .append([str(i + 1)] * a)
    ans = list(flatten_list(ans))
    ans = [ans[i:i + W] if i // W % 2 == 0 else ans[i + W - 1:i - 1:-1] for i in range(0, len(ans), W)]
    [print(' '.join(a)) for a in ans]

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(input()) for _ in range(N)]
a = [0] + a
hist = [1, ]
count = 0
i = 1
while i != 2:
    i = a[i]
    count  += 1
    if i in hist:
        count = -1
        break
    hist.append(i)
print(count)

Fixed submission:
N = int(input())
a = [int(input()) for _ in range(N)]
a = [0] + a
count = 0
i = 1
while i != 2:
    j = i
    i = a[i]
    a[j] = -1
    count  += 1
    if i == -1:
        count = -1
        break
print(count)
Buggy python submission (verdict: Runtime Error):
n = list(input())
n = int(''.join(n))
if n % 4 == 0:
    print('YES')
else:
    print('NO')


Fixed submission:
n = input().split()
n = int(''.join(n))
if n % 4 == 0:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
a = list(map(int, input().split()))
a = [i for i in a if i != 1 else 14]
if a[0] > a[1]:
    print('Alice')
elif a[0] == a[1]:
    print('Draw')
else:
    print('Bob')

Fixed submission:
a = list(map(int, input().split()))
a = [i if i != 1 else 14 for i in a]
if a[0] > a[1]:
    print('Alice')
elif a[0] == a[1]:
    print('Draw')
else:
    print('Bob')
Buggy python submission (verdict: Runtime Error):
def main():
    S = list(input())
    k = int(input())
    ans = []
    for s in S:
        if k == 0:
            break
        if s != 'a' and ord(s) >= 123 - k:
            ans.append('a')
            k -= 123 - ord(s)
        else:
            ans.append(s)
    if k > 0:
        ans[-1] = chr(ord(ans[-1]) + k)
    print(''.join(ans))



if __name__ == '__main__':
    main()


Fixed submission:
def main():
    s = input()
    print(s[:4] + ' ' + s[4:])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    S = list(input())
    k = int(input())
    ans = []
    for s in S:
        if k == 0:
            break
        if s != 'a' and ord(s) >= 123 - k:
            ans.append('a')
            k -= 123 - ord(s)
        else:
            ans.append(s)
    if k > 0:
        ans[-1] = chr(ord(ans[-1]) + k)
    print(''.join(ans))



if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = list(input())
    k = int(input())
    ans = []
    for s in S:
        if s != 'a' and ord(s) >= 123 - k:
            ans.append('a')
            k -= 123 - ord(s)
        else:
            ans.append(s)
    if k > 0:
        ans[-1] = chr((ord(ans[-1]) + k - 97) % 26 + 97)
    print(''.join(ans))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    S = list(input())
    k = int(input())
    ans = []
    for s in S:
        if k == 0:
            break
        if ord(s) >= 123 - k:
            ans.append('a')
            k -= 123 - ord(s)
        else:
            ans.append(s)
    if k > 0:
        ans[-1] = chr(ord(ans[-1]) + k)
    print(''.join(ans))



if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = list(input())
    k = int(input())
    ans = []
    for s in S:
        if s != 'a' and ord(s) >= 123 - k:
            ans.append('a')
            k -= 123 - ord(s)
        else:
            ans.append(s)
    if k > 0:
        ans[-1] = chr((ord(ans[-1]) + k - 97) % 26 + 97)
    print(''.join(ans))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
a, b, h = list(map(int, input().split()))
print((a + b) * h // 2)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())
print((a + b) * h // 2)
Buggy python submission (verdict: Runtime Error):
def main():
    n, a = list(map(int, input().split()))
    X = list(map(lambda x: int(x) - a, input().split()))
    m = sum([x for x in X if x < 0])
    p = sum([x for x in X if x > 0])
    if p == m == 0:
        print(pow(2, n) - 1)
        exit()
    dp = [[0] * (p - m + 1) for  _ in range(n + 1)]
    dp[0][1 - m] = 1
    for i in range(1, n + 1):
        for j in range(p - m + 1):
            if 0 <= j - X[i - 1] < p - m + 1:
                dp[i][j] = dp[i - 1][j] + dp[i - 1][j - X[i - 1]]
            else:
                dp[i][j] = dp[i - 1][j]
    print(dp[n][1 - m] - 1)

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, a = list(map(int, input().split()))
    X = list(map(lambda x: int(x) - a, input().split()))
    b = max(max([x for x in X]) + a, a)
    dp = [[0] * (2 * b * n + 1) for  _ in range(n + 1)]
    dp[0][b * n] = 1
    for i in range(1, n + 1):
        for j in range(2 * b * n + 1):
            if 0 <= j - X[i - 1] < 2 * b * n:
                dp[i][j] = dp[i - 1][j] + dp[i - 1][j - X[i - 1]]
            else:
                dp[i][j] = dp[i - 1][j]
    print(dp[n][b * n] - 1)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
A=[[int(i) for i in input().split()] for _ in range(3)]
N=int(input())
for _ in range(N):
    b=int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                A[i][j]=-1
flag=False
for h in range(3):
    cnt=0
    for w in range(3):
        if A[h][w]==-1:
            cnt+=1
    if cnt==3:
        flag=True
for w in range(3):
    cnt=0
    for h in range(3):
        if A[h][w]==-1:
            cnt+=1
    if cnt==3:
        flag=True
cnt=0
if A[d][d]==-1:
    cnt+=1
if cnt==3:
    flag=True
cnt=0
if A[d][-d]==-1:
    cnt+=1
if cnt==3:
    flag=True
print('Yes' if flag else 'No')


Fixed submission:
A=[[int(i) for i in input().split()] for _ in range(3)]
N=int(input())
for _ in range(N):
    b=int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                A[i][j]=-1
flag=False
for h in range(3):
    cnt=0
    for w in range(3):
        if A[h][w]==-1:
            cnt+=1
    if cnt==3:
        flag=True
for w in range(3):
    cnt=0
    for h in range(3):
        if A[h][w]==-1:
            cnt+=1
    if cnt==3:
        flag=True
cnt=0
for d in range(3):
    if A[d][d]==-1:
        cnt+=1
if cnt==3:
    flag=True
cnt=0
for d in range(3):
    if A[d][2-d]==-1:
        cnt+=1
if cnt==3:
    flag=True
print('Yes' if flag else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
H,N=map(int,input().split())
dp = [10**10]*(H+1)
dp[0]=0
for _ in range(N):
    A,B=map(int,input().split())
    for idx in range(H):
        nidx = min(idx+A,H)
        dp[nidx]=min(dp[nidx],dp[idx]+B)
print(dp[-1])


Fixed submission:
H,N=map(int,input().split())
dp = [10**10]*(H+1)
dp[0]=0
for _ in range(N):
    A,B=map(int,input().split())
    for idx in range(H):
        nidx = min(idx+A,H)
        dp[nidx]=min(dp[nidx],dp[idx]+B)
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
from math import gcd
N=int(input())
A=[int(i) for i in input().split()]

for i in range(N-1):
    A[-1]=gcd(A[-1],A[i])
print(A[-1])


Fixed submission:
from fractions import gcd
N=int(input())
A=[int(i) for i in input().split()]

for i in range(N-1):
    A[-1]=gcd(A[-1],A[i])
print(A[-1])
Buggy python submission (verdict: Runtime Error):
#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

int N;
vector<ll> A, B;
vector<pair<ll, ll>> diff;

//���C���֐�
int main()
{
	cin >> N;
	A.resize(N);
	B.resize(N);
	diff.resize(N);
	REP(i, N)cin >> A[i] >> B[i];
	REP(i, N)diff[i] = make_pair(A[i] + B[i], i);
	sort(diff.begin(), diff.end());
	reverse(diff.begin(), diff.end());

	ll tak = 0, ao = 0;
	REP(i, N)
	{
		auto p = diff[i];
		if(i % 2 == 0)tak += A[p.second];
		else ao += B[p.second];
	}
	cout << tak - ao << endl;
	//cerr << tak << " " << ao << endl;

	cin >> N;
	return 0;
}


Fixed submission:
print(-sum([v[k%2]*(k%2*2-1)for k,v in enumerate(sorted([[int(j) for j in input().split()] for i in range(int(input()))],key=lambda x:-x[0]-x[1]))]))