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

Fixed submission:
N, A = map(int, input().split())
X = list(map(int, input().split()))
L = max(X)
L = max(L, A)

dp = [[[0 for _ in range((N+1)*(L+1))] for _ in range(N+1)] for _ in range(N+1)]
dp[0][0][0] = 1

for j in range(1, N+1):
    for k in range(N+1):
        for s in range((N+1)*(L+1)):
            if s < X[j-1]:
                dp[j][k][s] = dp[j-1][k][s]
            if k >= 1 and s >= X[j-1]:
                dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-X[j-1]]
ans = 0
for k in range(1, N+1):
    ans += dp[N][k][k*A]
print(ans)

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

L = max(A)*N
dp = [[0 for _ in range(L+1)] for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    a = A[i]
    for j in reversed(range(N)):
        for l in range(L+1):
            if l < a: continue
            dp[j+1][l] += dp[j][l-a]

ans = 0
for j in range(N):
    ans += dp[j+1][(j+1)*K]
print(ans)
Problem p04016 (python)

Fixed submission:
import math

N = int(input())
S = int(input())
L = N-S

def search(b, n=N):
    ans = 0
    while n >= b:
        ans += n%b
        n //= b
    ans += n
    return ans


def main():

    if L < 0:
        print(-1)
    elif L == 0:
        print(N+1)
    else:
        P = []
        for l in range(1, int(math.sqrt(L))+2):
            if L%l == 0:
                P.append(l+1)
                P.append(L//l+1)
        P.sort()

        ans = -1
        for p in P:
            if p == 1: continue
            S0 = search(p)
            if S == S0:
                ans = p
                break

        print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
S = int(input())
L = N-S

def search(b, n=N):
    ans = 0
    while n >= b:
        ans += n%b
        n //= b
    ans += n
    return ans
s
if L < 0:
    print(-1)
elif L == 0:
    print(1)
else:
    P = []
    for l in range(1, int(math.sqrt(L))+1):
        if L%l == 0:
            P.append(l+1)
            P.append(L//l+1)
    P.sort()

    ans = -1
    for p in P:
        S0 = search(p)
        if S == S0:
            ans = p
            break

    print(ans)
Problem p02613 (python)

Fixed submission:
import sys
from collections import defaultdict

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
dic = defaultdict(int)
for i in range(n):
    dic[ns()] += 1
for w in ("AC", "WA", "TLE", "RE"):
    print(f"{w} x {dic[w]}")

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
dic = defaultdict(int)
for i in range(n):
    dic[ns()] += 1
for w in ("AC", "WA", "TLE", "RE"):
    print(f"{w} x {dic[w]}")
Problem p02698 (python)

Fixed submission:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
g = []
for i in range(n):
    g.append([])
for i in range(n-1):
    x, y = na()
    g[x-1].append(y-1)
    g[y-1].append(x-1)

sys.setrecursionlimit(230000)
import bisect
def dfs(cur, pre, g, lis, la, anss, a):
    ind = bisect.bisect_left(la, a[cur], 0, lis+1)
    old = la[ind]
    la[ind] = a[cur]
    nlis = lis + 1 if ind == lis + 1 else lis
    anss[cur] = nlis

    for e in g[cur]:
        if e == pre: continue
        dfs(e, cur, g, nlis, la, anss, a)

    la[ind] = old

anss = [0] * n
la = [999999999999] * (n+2)
la[0] = 0
dfs(0, -1, g, 0, la, anss, a)
for v in anss:
    print(v)

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
g = []
for i in range(n):
    g.append([])
for i in range(n-1):
    x, y = na()
    g[x-1].append(y-1)
    g[y-1].append(x-1)

sys.setrecursionlimit(300000)
import bisect
def dfs(cur, pre, g, lis, la, anss, a):
    ind = bisect.bisect_left(la, a[cur])
    old = la[ind]
    la[ind] = a[cur]
    nlis = lis + 1 if ind == lis + 1 else lis
    anss[cur] = nlis

    for e in g[cur]:
        if e == pre: continue
        dfs(e, cur, g, nlis, la, anss, a)

    la[ind] = old

anss = [0] * n
la = [99999999] * (n+1)
la[0] = 0
dfs(0, -1, g, 0, la, anss, a)
for v in anss:
    print(v)

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
g = []
for i in range(n):
    g.append([])
for i in range(n-1):
    x, y = na()
    g[x-1].append(y-1)
    g[y-1].append(x-1)

import bisect
def dfs(cur, pre, g, lis, la, anss, a):
    ind = bisect.bisect_left(la, a[cur])
    old = la[ind]
    la[ind] = a[cur]
    nlis = lis + 1 if ind == lis + 1 else lis
    anss[cur] = nlis

    for e in g[cur]:
        if e == pre: continue
        dfs(e, cur, g, nlis, la, anss, a)

    la[ind] = old

anss = [0] * n
la = [99999999] * (n+1)
la[0] = 0
dfs(0, -1, g, 0, la, anss, a)
for v in anss:
    print(v)
Problem p02720 (python)

Fixed submission:
import sys
import itertools

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

K = ni() - 1

for le in range(1, 11):
    for h in range(1, 10):
        for a in itertools.product((-1, 0, 1), repeat=le-1):
            cur = h
            ok = True
            for u in a:
                cur += u
                if cur > 9 or cur < 0:
                    ok = False
                    break
            if ok:
                if K == 0:
                    ret = [h] + [_ + h for _ in itertools.accumulate(a)]
                    print("".join(map(str, ret)))
                    sys.exit(0)
                K -= 1

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

K = ni() - 1

for le in range(1, 11):
    for h in range(1, 10):
        for a in itertools.product((-1, 0, 1), repeat=le-1):
            cur = h
            ok = True
            for u in a:
                cur += u
                if cur > 9 or cur < 0:
                    ok = False
                    break
            if ok:
                if K == 0:
                    ret = [h] + [_ + h for _ in itertools.accumulate(a)]
                    print("".join(map(str, ret)))
                    sys.exit(0)
                K -= 1
Problem p02770 (python)

Fixed submission:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

K, Q = na()
d = na()

for z in range(Q):
    n, x, m = na()

    n -= 1

    rem = n%K
    pre = m-1
    x %= m
    ans = 0
    for i in range(rem):
        pre = x
        x = (x + d[i]) % m
        if pre < x:
            ans += 1

    lpre = 0
    turn = 0
    # print(d[rem:] +  d[:rem])
    for v in d[rem:] + d[:rem]:
        cur = (lpre + v) % m
        if lpre < cur:
            turn += 1
        lpre = cur
    my = turn*m - lpre
    # print(turn, m, my, n//K, x)
    ans += (my * (n//K) + m-x-1) // m - (m-x-1)//m
    print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

K, Q = na()
d = na()

u = [0] * (K+1)
for i in range(1, K+1):
    u[i] = u[i - 1] + d[i%K]

import math
# count ax < k (mod p), 0 <= x < n
def countle(l, r, a, n, p):
    if l == r:
        return 0
    s = min(n, int(math.sqrt(n)*3))
    # s = int(math.sqrt(n))
    comb = [a*i % p for i in range(s)]
    comb.sort()

    ret = 0
    b = -a * s % p
    for u in range(n//s):
        # print(u, l, r)
        num = bisect.bisect_left(comb, r) - bisect.bisect_left(comb, l)
        if r < l:
            num += s
        ret += num

        l -= b
        r -= b
        if l < 0:
            l += p
        if r < 0:
            r += p

    if l < r:
        for i in range(n//s*s, n):
            if l <= a * i % p < r:
                ret += 1
    else:
        for i in range(n // s * s, n):
            if a * i % p < r or l <= a * i % p:
                ret += 1
    return ret

# 2 3 5 7
# 0 2 3 5: 3
# 2 4 5 0: 2
# 4 6 0 2: 2
# 6 1 2 4

# a+k < b+k (mod p)
# a < bなら、k in [-a,p-1-b]
# a > bなら、k in [p-a, p-1-b]
# [-a,-1-b][-b, ...]
# a = bなら無
for z in range(Q):
    n, x, m = na()

    # d0 = x
    # ex = 0
    # for i in range(n-1):
    #     d1 = d0 + d[i%K]
    #     if d0 % m < d1 % m:
    #         ex += 1
    #     d0 = d1

    n -= 1

    rem = n%K
    pre = m-1
    x %= m
    ans = 0
    for i in range(rem):
        pre = x
        x = (x + d[i]) % m
        if pre < x:
            ans += 1
    # print(x, n, K, rem, ans)

    l = [0]
    # print(d[rem:] +  d[:rem])
    for v in d[rem:] + d[:rem]:
        l.append((l[-1] + v) % m)
    # print(l)
    turn = 0
    for i in range(len(l)-1):
        # if m-l[i+1] > m-1-l[i]
        if l[i] < l[i+1]:
            turn += 1
    last = m-1-l[-1]
    if x == (x+last+1) % m:
        turn += 1
    # print(ans, turn, last, -x%m, (-x+last+1)%m, l[-1], n//K)
    le = countle(-x%m, (-x+last+1)%m, l[-1], n//K, m)
    # print(le)
    ans += le*turn + (n//K-le)*(turn-1)
    print(ans)
    # assert ans == ex

    # x = turn - (start > last ? 1 : 0)
Problem p02920 (python)

Fixed submission:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
a.sort(reverse=True)

done = [False] * (1<<n)
b = [a[0]]
done[0] = True
for d in range(n):
    j = 0
    for i in range(1<<d):
        while j < 1<<n and (done[j] or b[i] <= a[j]):
            j += 1
        if j == 1<<n:
            print("No")
            sys.exit(0)
        b.append(a[j])
        done[j] = True
    b.sort(reverse=True)
print("Yes")

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
a.sort(reverse=True)

for d in range(n):
    for i in range(1<<d):
        if a[i] <= a[i+(1<<i)]:
            print("No")
            sys.exit(0)
print("Yes")
Problem p02934 (python)

Fixed submission:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()

s = 0
for i in range(n):
    s += 1/a[i]
print("{:.14f}".format(1/s))

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()

s = 0
for i in range(n):
    s += 1/a[i]
print(f"{1/s:.14f}")
Problem p02936 (python)

Fixed submission:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, q = na()
g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = na()
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

ps = [0] * n
for i in range(q):
    p, x = na()
    p -= 1
    ps[p] += x

stack = [0] * (n+1)
inds = [0] * (n+1)

sp = 0
stack[sp] = 0
sp += 1

while sp > 0:
    cur = stack[sp-1]
    if inds[sp-1] == len(g[cur]):
        sp -= 1
        continue
    if inds[sp-1] == 0 and sp > 1:
        ps[cur] += ps[stack[sp-2]]
    if sp == 1 or stack[sp-2] != g[cur][inds[sp-1]]:
        stack[sp] = g[cur][inds[sp-1]]
        inds[sp] = 0
        inds[sp-1] += 1
        sp += 1
        continue
    inds[sp - 1] += 1

print(" ".join(map(str, ps)))

Buggy submission (verdict: Runtime Error):
import sys
# sys.setrecursionlimit(200005)

# はぁー・・

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, q = na()
g = []
for i in range(n):
    g.append([])
for i in range(n-1):
    a, b = na()
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

ps = [0] * n
for i in range(q):
    p, x = na()
    p -= 1
    ps[p] += x

ans = [0] * n

def dfs(cur, pre, g, curv):
    global ps, ans
    curv += ps[cur]
    ans[cur] = curv
    for e in g[cur]:
        if e == pre: continue
        dfs(e, cur, g, curv)

dfs(0, -1, g, 0)

print(" ".join(map(str, ans)))
Problem p02961 (python)

Fixed submission:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

k = ni()
x, y = na()

def go(x, y, k):
    if (x+y) % 2 != 0 and k % 2 == 0:
        return None
    if x < 0:
        res = go(-x, y, k)
        for u in res:
            u[0] = -u[0]
        return res
    if y < 0:
        res = go(x, -y, k)
        for u in res:
            u[1] = -u[1]
        return res

    ops = []
    while x+y >= 2*k and x >= k:
        ops.append([k, 0])
        x -= k
    while x + y >= 2 * k and y >= k:
        ops.append([0, k])
        y -= k
    if (x+y) % k == 0:
        while x >= k:
            ops.append([k, 0])
            x -= k
        while y >= k:
            ops.append([0, k])
            y -= k
        if x > 0 and y > 0:
            ops.append([x, y])
        return ops

    if (x+y) % 2 == 0:
        mid = (x + y) // 2
        if mid <= x:
            ops.append([mid, -(k-mid)])
            ops.append([x-mid, y+(k - mid)])
        else:
            ops.append([x+(k-mid), mid-x])
            ops.append([-(k-mid), y-(mid-x)])
        return ops

    if x >= k:
        ops.append([k, 0])
        res = go(x-k, y, k)
        ops.extend(res)
        return ops

    ops.append([x, k-x])
    res = go(0, y-(k-x), k)
    ops.extend(res)
    return ops

res = go(x, y, k)
if not res:
    print(-1)
    sys.exit(0)

print(len(res))
cx, cy = 0, 0
for o in res:
    cx += o[0]
    cy += o[1]
    print(cx, cy)

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

k = ni()
x, y = na()

def go(x, y, k):
    if x < 0:
        res = go(-x, y, k)
        for u in res:
            u[0] = -u[0]
        return res
    if y < 0:
        res = go(x, -y, k)
        for u in res:
            u[1] = -u[1]
        return res

    if (x+y) % 2 == 1 and k % 2 == 0:
        return None

    ops = []
    while x+y >= 2*k and x >= k:
        ops.append([k, 0])
        x -= k
    while x + y >= 2 * k and y >= k:
        ops.append([0, k])
        y -= k
    if (x+y) % k == 0:
        while x >= k:
            ops.append([k, 0])
            x -= k
        while y >= k:
            ops.append([0, k])
            y -= k
        if x > 0 and y > 0:
            ops.append([x, y])
        return ops

    if (x+y) % 2 == 0:
        mid = (x + y) // 2
        if mid <= x:
            ops.append([mid, -(k-mid)])
            ops.append([x-mid, y+(k - mid)])
        else:
            ops.append([x+(k-mid), mid-x])
            ops.append([-(k-mid), y-(mid-x)])
        return ops

    if x >= k:
        ops.append([k, 0])
        res = go(x-k, y, k)
        ops.extend(res)
        return ops

    ops.append([x, k-x])
    res = go(0, y-(k-x), k)
    ops.extend(res)
    return ops

res = go(x, y, k)
if not res:
    print(-1)
    sys.exit(0)

print(len(res))
cx, cy = 0, 0
for o in res:
    cx += o[0]
    cy += o[1]
    print(cx, cy)
Problem p02991 (python)

Fixed submission:
import sys
from queue import Queue

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
g = []
for i in range(n):
    g.append([])
for i in range(m):
    u, v = na()
    g[u-1].append(v-1)

s, t = na()
s -= 1;
t -= 1

ds = [[9999999999] * n for i in range(3)]
ds[0][s] = 0

q = Queue()
q.put((0, s))
while not q.empty():
    r, cur = q.get_nowait()
    nr = (r+1) % 3
    for e in g[cur]:
        # print(nr, e)
        if ds[nr][e] > ds[r][cur] + 1:
            ds[nr][e] = ds[r][cur] + 1
            q.put((nr, e))
if ds[0][t] < 99999999:
    print(ds[0][t]//3)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
g = []
for i in range(n):
    g.append([])
for i in range(m):
    u, v = na()
    g[u-1].append(v-1)

s, t = na()
s -= 1;
t -= 1

ds = [[9999999999] * n for i in range(3)]
ds[0][s] = 0

q = Queue()
q.put((0, s))
while not q.empty():
    r, cur = q.get_nowait()
    nr = (r+1) % 3
    for e in g[cur]:
        # print(nr, e)
        if ds[nr][e] > ds[r][cur] + 1:
            ds[nr][e] = ds[r][cur] + 1
            q.put((nr, e))
if ds[0][t] >= 0:
    print(ds[0][t]//3)
else:
    print(-1)
Problem p02995 (python)

Fixed submission:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

a, b, c, d = na()

def gcd(a, b):
    while b > 0:
        c = a % b
        a = b
        b = c
    return a

def cou(b, c, d):
    g = gcd(c, d)
    return b - b//c - b//d + b//(c//g*d)

print(cou(b, c, d) - cou(a-1, c, d))

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

a, b, c, d = na()

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

def cou(b, c, d):
    g = gcd(c, d)
    return b - b//c - b//d + b//(c//g*d)

print(cou(b, c, d) - cou(a-1, c, d))
Problem p02997 (python)

Fixed submission:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, k = na()
# last sum
if k > (n-1)*(n-2)//2:
    print("-1")
else:
    es = []
    cur = (n-1)*(n-2)//2-k
    for c in range(2, n+1):
        for d in range(2, n+1):
            if c < d and cur > 0:
                es.append((c, d))
                cur -= 1
    for i in range(1, n):
        es.append((1, i+1))
    print(len(es))
    for e in es:
        print(e[0], e[1])

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, k = na()
# last sum
if k > (n-1)*(n-2)//2:
    print("-1")
else:
    cur = (n-1)*(n-2)//2-k
    ps = []
    for i in range(n-1, 1, -1):
        h = i*(i-1)//2
        if cur // h > 0:
            ps.append(*([i]*(cur//h)))
            cur %= h
    assert cur == 0
    es = []
    for i in range(1, n):
        es.append((1, i+1))
    c = 2
    for p in ps:
        for i in range(p):
            for j in range(p):
                if i < j:
                    es.append((c+i, c+j))
        c += p
    print(len(es))
    for e in es:
        print(e[0], e[1])
Problem p03040 (python)

Fixed submission:
import sys
import heapq

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

q = ni()

lh = []
hh = []
ln = 0
hn = 0
ls = 0
hs = 0
off = 0
for z in range(q):
    line = na()
    if line[0] == 1:
        _, a, b = line
        off += b

        if len(lh) > 0:
            mid = -lh[0]
            if a <= mid:
                heapq.heappush(lh, -a)
                ls += a
                ln += 1
            else:
                heapq.heappush(hh, a)
                hs += a
                hn += 1
        else:
            heapq.heappush(lh, -a)
            ls += a
            ln += 1

        while ln < hn:
            mx = heapq.heappop(hh)
            hs -= mx
            hn -= 1
            ls += mx
            ln += 1
            heapq.heappush(lh, -mx)

        while ln > hn + (ln+hn)%2:
            mx = -heapq.heappop(lh)
            ls -= mx
            ln -= 1
            heapq.heappush(hh, mx)
            hs += mx
            hn += 1
    else:
        lls = -lh[0]*ln - ls
        hhs = hs - (-lh[0]*hn)
        print(-lh[0], lls+hhs+off)

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

q = ni()

lh = []
hh = []
ln = 0
hn = 0
ls = 0
hs = 0
off = 0
for z in range(q):
    line = na()
    if line[0] == 1:
        _, a, b = line
        off += b

        if len(lh) > 0:
            mid = -lh[0]
            if a <= mid:
                heapq.heappush(lh, -a)
                ls += a
                ln += 1
            else:
                heapq.heappush(hh, a)
                hs += a
                hn += 1
        else:
            heapq.heappush(lh, -a)
            ls += a
            ln += 1

        while ln < hn:
            mx = heapq.heappop(hh)
            hs -= mx
            hn -= 1
            ls += mx
            ln += 1
            heapq.heappush(lh, -mx)

        while ln > hn + (ln+hn)%2:
            mx = -heapq.heappop(lh)
            ls -= mx
            ln -= 1
            heapq.heappush(hh, mx)
            hs += mx
            hn += 1
    else:
        lls = -lh[0]*ln - ls
        hhs = hs - (-lh[0]*hn)
        print(-lh[0], lls+hhs+off)
Problem p03161 (python)

Fixed submission:
from numba import jit
import math
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
@jit
def nya(N, K, h):
    S = [0] * N
    S[0] = 0
 
    for i in range(1, N):
        value = math.inf
        for step in range(1, K + 1):
            if i - step < 0:
                break
            value = min(value, S[i - step] + abs(h[i] - h[i - step]))
        S[i] = value
    return S[N-1]

print(nya(N, K, h))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
S = [0] * N

for i in range(1, N):
  S[i] = min(S[_] + abs(h[i] - h[_]) for range(max(0, i-K), i))

print(S[N-1])

Buggy submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
S = [0] * N

for i in range(1, N):
  S[i] = min(S[_] + math.abs(h[i] - h[_]) for range(max(0, i-K), i)]

print(S[N-1])

Buggy submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
S = [0] * N

for i in range(1, N):
  S[i] = min(S[_] + abs(h[i] - h[_]) for range(max(0, i-K), i)]

print(S[N-1])

Buggy submission (verdict: Runtime Error):
from numba import jit
import math
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
@jit
def nya(N, K, h):
    S = [0] * N
    S[0] = 0
 
    for i in range(1, N):
        value = math.inf
        for step in range(1, K + 1):
            if i - step < 0:
                break
            value = min(value, S[i - step] + abs(h[i] - h[i - step]))
        S[i] = value
    return S[N-1]

print(nya(N, K, h))