Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, a, b, k = map(int, input().split())

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
    
def mod_inv(a, mod):
    return (pow(a,mod-2,mod))

def mod_combination(n, k, mod):
    return (fact[n]*mod_inv(fact[k], mod)*mod_inv(fact[n-k], mod)) % mod

mod = 998244353
fact = [1] + [0] * n
for i in range(n):
    fact[i+1] = (fact[i] * (i+1)) % mod

ans = 0
for x in range(n+1):
    if (k-x*a) % b == 0:
        y = (k-x*a)//b
        if y >= 0:
            ans += mod_combination(n, x, mod) * mod_combination(n, y, mod)
            ans %= mod

    
print(ans)


Fixed submission:
def sum_digit(n):
    ret = 0
    while n>0:
        ret += n % 10
        n //= 10
    return ret

N = int(input())

mi = 999999999
for a in range(1, N):
    b = N - a
    mi = min(mi, sum_digit(a)+sum_digit(b))

print(mi)

Buggy python submission (verdict: Runtime Error):
n, a, b, k = map(int, input().split())

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
    
def mod_inv(a, mod):
    return (pow(a,mod-2,mod))

def mod_combination(n, k, mod):
    return (fact[n]*mod_inv(fact[k], mod)*mod_inv(fact[n-k], mod)) % mod

g = gcd(k, gcd(a, b))
a //= g
b //= g
k //= g

mod = 998244353
fact = [1] + [0] * n
for i in range(n):
    fact[i+1] = (fact[i] * (i+1)) % mod
if a < b:
    tmp = a
    a = b
    b = tmp

ans = 0
for x in range(n+1):
    if (k-x*a) % b == 0:
        y = (k-x*a)//b
        if y >= 0:
            ans += mod_combination(n, x, mod) * mod_combination(n, y, mod)
            ans %= mod

    
print(ans)


Fixed submission:
def sum_digit(n):
    ret = 0
    while n>0:
        ret += n % 10
        n //= 10
    return ret

N = int(input())

mi = 999999999
for a in range(1, N):
    b = N - a
    mi = min(mi, sum_digit(a)+sum_digit(b))

print(mi)

Buggy python submission (verdict: Runtime Error):
n, a, b, k = map(int, input().split())

if False:
    n = 4
    a = 1
    b = 2
    k = 5

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
    
def mod_inv(a, mod):
    return (pow(a,mod-2,mod))

def mod_combination(n, k, mod):
    return fact[n]*mod_inv(fact[k], mod)*mod_inv(fact[n-k], mod) % mod

mod = 998244353
fact = [1] + [0] * n
for i in range(n):
    fact[i+1] = (fact[i] * (i+1)) % mod
# print(fact)
if a < b:
    tmp = a
    a = b
    b = tmp

ans = 0
# print("n, a, b =", n, a, b)
# print((k-b*n)//a, k//a+1)
for x in range(max(-int(-(k-b*n)//a),0), k//a+1):
    if (k-x*a) % b == 0:
        y = (k-x*a)//b
        
        # print("n, x, y, mod", n, x, y, mod)
        # print(mod_combination(n, x, mod))
        # print(mod_combination(n, y, mod))
        
        ans += mod_combination(n, x, mod) * mod_combination(n, y, mod)
        ans %= mod
    
print(ans)


Fixed submission:
def sum_digit(n):
    ret = 0
    while n>0:
        ret += n % 10
        n //= 10
    return ret

N = int(input())

mi = 999999999
for a in range(1, N):
    b = N - a
    mi = min(mi, sum_digit(a)+sum_digit(b))

print(mi)
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int().input())
if abs(a-c) <= d or (abs(a-b)<= d and abs(b-c)<=d):
  print("Yes")
else:
  print("No")

Fixed submission:
a, b, c, d = map(int, input().split())
if abs(a-c) <= d or (abs(a-b)<= d and abs(b-c)<=d):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
f

Fixed submission:
a,b,x=map(int,input().split());print("YNEOS"[x-a not in range(b+1)::2])
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())
[print(i) for i in range(A, B+1) if i-A <= K-1 or B-i <= K-1]

Fixed submission:
A, B, K = map(int, input().split())
for a in sorted(list(set([i for i in range(A, min(A + K, B+1))]) | set([i for i in range(max(A, B-K+1), B+1)]))):
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
A6 = []
A2 = []
A3 = []
for i in range(2, 30001):
    if i % 6 == 0:
        A6.append(i)
    elif i % 2 == 0:
        A2.append(i)
    elif i % 3 == 0:
        A3.append(i)

N = int(input())
if N <= 4:
    print(*[[2, 5, 63], [2, 5, 20, 63]][N-3])
else:
    S = A2[:2] + A3[:2]
    A2, A3 = A2[2:], A3[2:]
    N -= 4
    while N >= 2:
        if len(A2) >= 2:
            S.append(A2.pop())
            S.append(A2.pop())
            N -= 2
        elif len(A3) >= 2:
            S.append(A3.pop())
            S.append(A3.pop())
            N -= 2
    while N:
        S.append(A6.pop())
        N -= 1
    print(*S)

Fixed submission:
A6 = []
A2 = []
A3 = []
for i in range(2, 30001)[::-1]:
    if i % 6 == 0:
        A6.append(i)
    elif i % 2 == 0:
        A2.append(i)
    elif i % 3 == 0:
        A3.append(i)

N = int(input())
if N <= 4:
    print(*[[2, 5, 63], [2, 5, 20, 63]][N-3])
else:
    S = []
    S.append(A2.pop())
    S.append(A2.pop())
    S.append(A3.pop())
    S.append(A3.pop())
    N -= 4
    while N >= 2:
        if len(A2) >= 2:
            S.append(A2.pop())
            S.append(A2.pop())
            N -= 2
        elif len(A3) >= 2:
            S.append(A3.pop())
            S.append(A3.pop())
            N -= 2
        else:
            break
    while N:
        S.append(A6.pop())
        N -= 1
    print(*S)

Buggy python submission (verdict: Time Limit Exceeded):
A6 = []
A2 = []
A3 = []
for i in range(2, 30001):
    if i % 6 == 0:
        A6.append(i)
    elif i % 2 == 0:
        A2.append(i)
    elif i % 3 == 0:
        A3.append(i)

N = int(input())
if N <= 4:
    print(*[[2, 5, 63], [2, 5, 20, 63]][N-3])
else:
    S = A2[:2] + A3[:2]
    A2, A3 = A2[2:], A3[2:]
    N -= 4
    while N >= 2:
        if len(A2) >= 2:
            S.append(A2.pop())
            S.append(A2.pop())
            N -= 2
        elif len(A3) >= 2:
            S.append(A3.pop())
            S.append(A3.pop())
            N -= 2
    while N:
        S.append(A6.pop())
        N -= 1
    print(*S)

Fixed submission:
A6 = []
A2 = []
A3 = []
for i in range(2, 30001)[::-1]:
    if i % 6 == 0:
        A6.append(i)
    elif i % 2 == 0:
        A2.append(i)
    elif i % 3 == 0:
        A3.append(i)

N = int(input())
if N <= 4:
    print(*[[2, 5, 63], [2, 5, 20, 63]][N-3])
else:
    S = []
    S.append(A2.pop())
    S.append(A2.pop())
    S.append(A3.pop())
    S.append(A3.pop())
    N -= 4
    while N >= 2:
        if len(A2) >= 2:
            S.append(A2.pop())
            S.append(A2.pop())
            N -= 2
        elif len(A3) >= 2:
            S.append(A3.pop())
            S.append(A3.pop())
            N -= 2
        else:
            break
    while N:
        S.append(A6.pop())
        N -= 1
    print(*S)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
P = [i for i in range(N)]
D = [0] * N
C = [1] * N

def par(a):
    if a == P[a]:
        return a
    p = par(P[a])
    d = D[P[a]]
    P[a] = p
    D[a] += d
    return p

def dist(a, b):
    pa = par(a)
    pb = par(b)
    if pa == pb:
        return D[b] - D[a]
    return 1 << 30

def unite(a, b, d):
    if par(a) == par(b):
        return
    if C[P[a]] < C[P[b]]:
        a, b = b, a
    D[P[b]] = D[a] + d - D[b]
    P[P[b]] = P[a]

for _ in range(M):
    l, r, d = map(int, input().split())
    l, r = l-1, r-1
    dd = dist(l, r)
    if dd == 1<<30:
        unite(l, r, d)
    else:
        if d != dd:
            print("No")
            break
else:
    print("Yes")

Fixed submission:
N, M = map(int, input().split())
P = [i for i in range(N)]
D = [0] * N
C = [1] * N

def par(a):
    if a == P[a]:
        return a
    p = par(P[a])
    d = D[P[a]]
    P[a] = p
    D[a] += d
    return p

def dist(a, b):
    pa = par(a)
    pb = par(b)
    if pa == pb:
        return D[b] - D[a]
    return 1 << 30

def unite(a, b, d):
    if par(a) == par(b):
        return
    if C[P[a]] < C[P[b]]:
        a, b, d = b, a, -d
    C[P[a]] += C[P[b]]
    D[P[b]] = D[a] + d - D[b]
    P[P[b]] = P[a]

for _ in range(M):
    l, r, d = map(int, input().split())
    l, r = l-1, r-1
    dd = dist(l, r)
    if dd == 1<<30:
        unite(l, r, d)
    else:
        if d != dd:
            print("No")
            break
else:
    print("Yes")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
P = [i for i in range(N)]
D = [0] * N

def par(a):
    if a == P[a]:
        return a
    p = par(P[a])
    d = D[P[a]]
    P[a] = p
    D[a] += d
    return p

def dist(a, b):
    pa = par(a)
    pb = par(b)
    if pa == pb:
        return D[b] - D[a]
    return 1 << 30

def unite(a, b, d):
    if par(a) == par(b):
        return
    D[P[b]] = D[a] + d - D[b]
    P[P[b]] = P[a]

for _ in range(M):
    l, r, d = map(int, input().split())
    l, r = l-1, r-1
    dd = dist(l, r)
    if dd == 1<<30:
        unite(l, r, d)
    else:
        if d != dd:
            print("No")
            break
else:
    print("Yes")

Fixed submission:
N, M = map(int, input().split())
P = [i for i in range(N)]
D = [0] * N
C = [1] * N

def par(a):
    if a == P[a]:
        return a
    p = par(P[a])
    d = D[P[a]]
    P[a] = p
    D[a] += d
    return p

def dist(a, b):
    pa = par(a)
    pb = par(b)
    if pa == pb:
        return D[b] - D[a]
    return 1 << 30

def unite(a, b, d):
    if par(a) == par(b):
        return
    if C[P[a]] < C[P[b]]:
        a, b, d = b, a, -d
    C[P[a]] += C[P[b]]
    D[P[b]] = D[a] + d - D[b]
    P[P[b]] = P[a]

for _ in range(M):
    l, r, d = map(int, input().split())
    l, r = l-1, r-1
    dd = dist(l, r)
    if dd == 1<<30:
        unite(l, r, d)
    else:
        if d != dd:
            print("No")
            break
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
 = input()
t = s[len(s)//2]
j = len(s)//2
i = len(s)-j-1
ans = j
while i >= 0:
    if s[i] != t or s[j] != t:
        break
    ans += 1
    i -= 1
    j += 1

print(ans)

Fixed submission:
s = input()
t = s[len(s)//2]
j = len(s)//2
i = len(s)-j-1
ans = j
while i >= 0:
    if s[i] != t or s[j] != t:
        break
    ans += 1
    i -= 1
    j += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import counter as C
print(9)

Fixed submission:
from collections import Counter as C
N = int(input())
A = [int(a) for a in input().split()]
X = C(A)
ans = 0
for x in X:
    ans += X[x] if X[x] < x else X[x] - x
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
def calc(n):
    if n % 2:
        return 0
    else:
        return a(n//2) + 1

A = [int(a) for a in input().split()]
mi = 9999
for a in A:
    mi = min(mi, calc(a))
print(a)



Fixed submission:
N = int(input())
def calc(n):
    if n % 2:
        return 0
    else:
        return calc(n//2) + 1

A = [int(a) for a in input().split()]
mi = 9999
for a in A:
    mi = min(mi, calc(a))
print(mi)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
if N == 1:
    for _ in range(Q):
        v, w = map(int, input().split())
        print(min(v, w))
else:
    L = [1]
    aa = 1
    def ch(k):
        return (k-2)//N+1
    
    def chh(a, b):
        if a == b:
            return a
        
        if a > b:
            a, b = b, a
        
        return chh(a, ch(b))
        
    for _ in range(Q):
        v, w = map(int, input().split())
        print(chh(v, w))


Fixed submission:
N, Q = map(int, input().split())
if N == 1:
    for _ in range(Q):
        v, w = map(int, input().split())
        print(min(v, w))
else:
    L = [1]
    aa = 1
    def ch(k):
        return (k-2)//N+1
    
    def chh(a, b):
        if a == b:
            return a
        
        if a > b:
            a, b = b, a
        
        return chh(a, ch(b))
        
    for _ in range(Q):
        v, w = map(int, input().split())
        print(chh(v, w))
Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
import sys
sys.setrecursionlimit(1000000)

N, Z, W = map(int, input().split())
A = [int(a) for a in input().split()]

@lru_cache(maxsize=None)
def X(i, y):
    return max([Y(j+1, A[j]) for j in range(i, N-1)] + [abs(A[N-1] - y)])

@lru_cache(maxsize=None)
def Y(i, x):
    return min([X(j+1, A[j]) for j in range(i, N-1)] + [abs(A[N-1] - x)])

print(X(0, W))

Fixed submission:
from functools import lru_cache
import sys
sys.setrecursionlimit(1000000)

N, Z, W = map(int, input().split())
A = [int(a) for a in input().split()]

@lru_cache(maxsize=None)
def X(i, y):
    return max([Y(j+1, A[j]) for j in range(i, N-1)] + [abs(A[N-1] - y)])

@lru_cache(maxsize=None)
def Y(i, x):
    return min([X(j+1, A[j]) for j in range(i, N-1)] + [abs(A[N-1] - x)])

print(X(0, W))
Buggy python submission (verdict: Time Limit Exceeded):
import time
n = int(input())
sTime = time.time()

def sum_digit(n):
    s = 0
    while n>0:
        s += n%10
        n //= 10
    return s


mi = n
t = 0
for i in range(1, 10**n):
    mi = min(mi, sum_digit(n*i))
    t = time.time() - sTime
    if t > 2.7:
        break
        
print(mi)

Fixed submission:
n = int(input())

while n % 2 == 0:
    n //= 2
while n % 5 == 0:
    n //= 5
if n == 1:
    print(1)
else:
    X = [n for i in range(n)]
    
    j = 1
    s = 1
    post = []
    m = 0
    while True:
        s *= 10
        s %= n
        post.append(s)
        X[s] = min(j, X[s])
        m += 1
        if s == 1:
            break
    ans = 0
    while True:
        if ans > 0:
            break
        pre = post
        post = []
        j += 1
        for p in pre:
            pp = (p + 1) % n
            if pp == 0:
                X[0] = j
                ans = j
                break
            if X[pp] == n:
                for i in range(m):
                    post.append(pp)
                    X[pp] = j
                    pp *= 10
                    pp %= n
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import time
n = int(input())
sTime = time.time()

def sum_digit(n):
    s = 0
    while n>0:
        s += n%10
        n //= 10
    return s


mi = n
t = 0
for i in range(1, 10**n):
    mi = min(mi, sum_digit(n*i))
    t = time.time() - sTime
    if t > 2.9:
        break
        
print(mi)

Fixed submission:
n = int(input())

while n % 2 == 0:
    n //= 2
while n % 5 == 0:
    n //= 5
if n == 1:
    print(1)
else:
    X = [n for i in range(n)]
    
    j = 1
    s = 1
    post = []
    m = 0
    while True:
        s *= 10
        s %= n
        post.append(s)
        X[s] = min(j, X[s])
        m += 1
        if s == 1:
            break
    ans = 0
    while True:
        if ans > 0:
            break
        pre = post
        post = []
        j += 1
        for p in pre:
            pp = (p + 1) % n
            if pp == 0:
                X[0] = j
                ans = j
                break
            if X[pp] == n:
                for i in range(m):
                    post.append(pp)
                    X[pp] = j
                    pp *= 10
                    pp %= n
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
X = []
Y = []
XY = []
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    XY.append((x, y))

X = sorted(X)
Y = sorted(Y)
mi = 1<<200
for i in range(N):
    for j in range(i+1, N):
        for k in range(N):
            for l in range(k+1, N):
                s = 0
                for x, y in XY:
                    if X[i] <= x <= X[j] and Y[k] <= y <= Y[l]:
                        s += 1
                if s >= K:
                    mi = min(mi, (X[j] - X[i]) * (Y[l] - Y[k]))

print(mi)


Fixed submission:
N, K = map(int, input().split())
X = []
Y = []
XY = []
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    XY.append((x, y))

X = sorted(X)
Y = sorted(Y)
mi = 1<<200
for i in range(N):
    for j in range(i+1, N):
        for k in range(N):
            for l in range(k+1, N):
                s = 0
                for x, y in XY:
                    if X[i] <= x <= X[j] and Y[k] <= y <= Y[l]:
                        s += 1
                if s >= K:
                    mi = min(mi, (X[j] - X[i]) * (Y[l] - Y[k]))

print(mi)
Buggy python submission (verdict: Runtime Error):
input()
D = {}
for a in [int(a) for a in input().split()]:
    if a not in D: D[i] = 0
    D[a] += 1

input()
for a in [int(a) for a in input().split()]:
    if a not in D: D[i] = 0
    D[a] -= 1

for a in D:
    if D[a] < 0:
        print("NO")
        break
else:
    print("YES")


Fixed submission:
input()
D = {}
for a in [int(a) for a in input().split()]:
    if a not in D: D[a] = 0
    D[a] += 1

input()
for a in [int(a) for a in input().split()]:
    if a not in D: D[a] = 0
    D[a] -= 1

for a in D:
    if D[a] < 0:
        print("NO")
        break
else:
    print("YES")

Buggy python submission (verdict: Runtime Error):
input()
D = {}
for a in [int(a) for a in input().split()]:
    if a not in D: D[i] = 0
    D[i] += 1

input()
for a in [int(a) for a in input().split()]:
    if a not in D: D[i] = 0
    D[i] -= 1

for a in D:
    if D[a] < 0:
        print("NO")
        break
else:
    print("YES")

Fixed submission:
input()
D = {}
for a in [int(a) for a in input().split()]:
    if a not in D: D[a] = 0
    D[a] += 1

input()
for a in [int(a) for a in input().split()]:
    if a not in D: D[a] = 0
    D[a] -= 1

for a in D:
    if D[a] < 0:
        print("NO")
        break
else:
    print("YES")
Buggy python submission (verdict: Runtime Error):
K = int(input())
N = 50
s = N * (N-1) // 2
A = [a + i + (1 if i >= N-b else 0) for i in range(N)]
print(N)
print(*A)


Fixed submission:
K = int(input())
N = 50
s = N * (N-1) // 2
a = K // N
b = K % N
A = [a + i + (1 if i >= N-b else 0) for i in range(N)]
print(len(A))
print(*A)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter as C
N, M = map(int, input().split())
A = [[int(a)-1 for a in input().split()] for _ in range(N)]
X = [1] * M
mi = 1 << 100
for i in range(M):
    c = C([min([(j, A[i][j]) for j in range(M) if X[A[i][j]]])[1] for i in range(N)])
    a = max([(c[a], a) for a in c])[1]
    mi = min(mi, c[a])
    X[a] -= 1
print(mi)

Fixed submission:
from collections import Counter as C
N, M = map(int, input().split())
A = [[int(a)-1 for a in input().split()] for _ in range(N)]
X = [1] * M
mi = 1 << 100
for i in range(M):
    c = C([min([(j, A[i][j]) for j in range(M) if X[A[i][j]]])[1] for i in range(N)])
    a = max([(c[a], a) for a in c])[1]
    mi = min(mi, c[a])
    X[a] -= 1
print(mi)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
def acc(X): return list(accumulate(X))

N, M = map(int, input().split())
A = [int(a)-1 for a in input().split()]

X = [0] * M # 1,1,1,...
Y = [0] * M # 1,2,3,...

def tri(l, r, a = 1):
    if l < M:
        Y[l] += a
    if r + 1 < M:
        Y[r+1] -= a
        X[r+1] -= (r-l+1) * a

def box(l, r, a = 1):
    if l < M:
        X[l] += a
    if r + 1< M:
        X[r+1] -= a
    
def calc(a, b):
    if a <= b - 2:
        tri(a+2, b)
    elif a > b and a <= b + M - 2:
        tri(a+1, M-1)
        tri(0, b)
        box(0, b, b-a-1)

ans = 0
for i in range(1, N):
    ans += (A[i] - A[i-1]) % M
    calc(A[i-1], A[i])

Y = acc(Y)
X = [X[i] + Y[i] for i in range(N)]
X = acc(X)

ans -= max(X)
print(ans)

Fixed submission:
from itertools import accumulate
def acc(X): return list(accumulate(X))

N, M = map(int, input().split())
A = [int(a)-1 for a in input().split()]

X = [0] * M # 1,1,1,...
Y = [0] * M # 1,2,3,...

def tri(l, r, a = 1):
    if l < M:
        Y[l] += a
    if r + 1 < M:
        Y[r+1] -= a
        X[r+1] -= (r-l+1) * a

def box(l, r, a = 1):
    if l < M:
        X[l] += a
    if r + 1< M:
        X[r+1] -= a
    
def calc(a, b):
    if a <= b - 2:
        tri(a+2, b)
    elif a > b and a <= b + M - 2:
        tri(a+2, M-1)
        tri(0, b)
        box(0, b, -a+M-2)
        
    # print(a, b, X, Y, rev())

def rev():
    ret = acc(Y)
    ret = [X[i] + ret[i] for i in range(M)]
    return acc(ret)
    
ans = 0
for i in range(1, N):
    ans += (A[i] - A[i-1]) % M
    calc(A[i-1], A[i])

X = rev()
# print(X)
ans -= max(X)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
E1 = [[] for _ in range(N)]
E2 = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    E1[a-1].append((b-1, -c))
    E2[b-1].append((a-1, -c))

def bellman_ford(n, E, s=0):
    D = [1<<100] * n
    D[s] = 0
    f = 1
    k = 0
    while f:
        f = 0
        for i in range(n):
            for j, c in E[i]:
                if D[i] < 1<<100 and D[j] > D[i] + c:
                    D[j] = D[i] + c
                    f = 1
                    if k == N-1 and j == N-1: return (1, [])
        k += 1
    return (0, D)

b, d = bellman_ford(N, E1)
if b:
    print("inf")
else:
    print(-d[-1])


Fixed submission:
from collections import deque
N, M = map(int, input().split())
E1 = [[] for _ in range(N)]
E2 = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    E1[a-1].append((b-1, -c))
    E2[b-1].append((a-1, -c))

def BFS(n, E, i0=0):
    Q = deque([i0])
    D = [-1] * n
    D[i0] = 0
    while Q:
        x = Q.popleft()
        for c, w in E[x]:
            if D[c] == -1:
                D[c] = D[x] + 1
                Q.append(c)
    return D

def bellman_ford(n, E, s=0):
    D = [1<<100] * n
    D[s] = 0
    f = 1
    while f:
        f = 0
        for i in range(n):
            if not B[i]: continue
            for j, c in E[i]:
                if not B[j]: continue
                if D[i] < 1<<100 and D[j] > D[i] + c:
                    D[j] = D[i] + c
                    f = 1
    return D

def bellman_ford_check(n, E, s=0):
    D = [0] * n
    for k in range(n):
        for i in range(n):
            if not B[i]: continue
            for j, c in E[i]:
                if not B[j]: continue
                if D[j] > D[i] + c:
                    D[j] = D[i] + c
                    if k == n-1: return 1
    return 0

B1 = BFS(N, E1, 0)
B2 = BFS(N, E2, N-1)
B = [0 if B1[i] < 0 or B2[i] < 0 else 1 for i in range(N)]

if bellman_ford_check(N, E1):
    print("inf")
else:
    D = bellman_ford(N, E1)
    print(-D[-1])
Buggy python submission (verdict: Runtime Error):
def calc(n, k):
  if k>100:
    print(1/0)
  # print(n, k)
  if n<=0:
    return []
  i = 0
  while (1<<(i+1)) -1 <= n:
    i += 1
  return [str(k)] * (i+1) + calc(n-((1<<i) - 1), k+1)

a=calc(int(input()), 1)
if len(a)>200:
  print(1/0)
print(len(a))
print(" ".join(a))

Fixed submission:
fact = [1]
for i in range(1, 101):
    fact.append(fact[-1]*i)
    
def C(a, b):
    return fact[a]//(fact[b]*fact[a-b])

def sC(a, b):
    ret = 0
    for i in range(min(b, a-b) + 1):
        ret += C(b, i) * C(a - b, i)
    return ret

def calc(n, k):
    if n<=0:
        return []
    i = 0
    while (1<<(i+1)) -1 <= n:
        i += 1
        
    ret = [str(k)] * (i+1)
    rem = n-((1<<i) - 1)
    kk = k + 1
    i += 1
    j = i // 2
    
    while j > 0:
        while True:
            tmp = sC(i, j)
            if tmp <= rem:
                ret.insert(j, str(kk))
                ret.append(str(kk))
                kk += 1
                rem -= tmp

            else:
                break
                
        j -= 1
        
    return ret + calc(rem, kk)

N = int(input())

X = calc(N, 1)
print(len(X))
print(" ".join(X))