Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import deque

def bfs(s):
    global dist, visit
    q = deque()
    q.append(s)
    dist[s] = 0
    visit[s] = s
    x = 0
    y = deque()
    while q:
        p = q.popleft()
        for g in G[p]:
            if dist[g[0]] == a:
                dist[g[0]] = dist[p] + g[1] + x
                y.append(dist[g[0]])
                visit[g[0]] = s
                q.append(g[0])
            else:
                if not dist[g[0]] == dist[p] + g[1] + x:
                    if visit[g[0]] == s:
                        print("No")
                        exit()
                    else:
                        if x == 0:
                            x = dist[g[0]] - (dist[p] + g[1])
                            while y:
                                z = y.popleft()
                                dist[z] += x
                        else:
                            print("No")
                            exit()
                    

n, m = map(int, input().split())
G = [[] for _ in range(n + 1)]
for _ in range(m):
    l, r, d = map(int, input().split())
    G[l].append([r, d])
a = -pow(10, 9)
dist = [a] * (n + 1)
visit = [0] * (n + 1)
for i in range(1, n + 1):
    if dist[i] == a:
        bfs(i)
print("Yes")

Fixed submission:
from collections import deque

def bfs():
    visit = [0] * (n + 1)
    e = [0] * (m + 1)
    x = [0] * (n + 1)
    q = deque()
    for i in range(1, n + 1):
        if not visit[i]:
            q.append(i)
            visit[i] = 1
            while q:
                j = q.popleft()
                for g in G[j]:
                    if not e[g[2]]:
                        #print(e, visit, q, x, j)
                        e[g[2]] = 1
                        if not visit[g[0]]:
                            x[g[0]] = g[1] + x[j]
                            visit[g[0]] = 1
                            q.append(g[0])
                        else:
                            #print(x[g[0]], g[1] + x[j])
                            if not x[g[0]] == g[1] + x[j]:
                                return False
    return True

n, m = map(int, input().split())
G = [[] for _ in range(n + 1)]
for i in range(m):
    l, r, d = map(int, input().split())
    G[l].append([r, d, i])
    G[r].append([l, -d, i])
print("Yes" if bfs() else "No")
Buggy python submission (verdict: Time Limit Exceeded):
import math

n, h = map(int, input().split())
a, b = [0] * n, [0] * n
for i in range(n):
    x, y = map(int, input().split())
    a[i], b[i] = x, y
b.sort(reverse = True)
ans = 0
for i in range(n):
    if b[i] < max(a):
        break
    h -= b[i]
    ans += 1
    if h <= 0:
        break
if not h <= 0:
    ans += math.ceil(h / max(a))
print(ans)

Fixed submission:
import math

n, h = map(int, input().split())
b = [0] * n
maxa = 0
for i in range(n):
    x, y = map(int, input().split())
    maxa = max(x, maxa)
    b[i] = y
b.sort(reverse = True)
ans = 0
for i in range(n):
    if b[i] < maxa:
        break
    h -= b[i]
    ans += 1
    if h <= 0:
        break
if not h <= 0:
    ans += math.ceil(h / maxa)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math

n, h = map(int, input().split())
a, b = [0] * n, [0] * n
for i in range(n):
    x, y = map(int, input().split())
    a[i], b[i] = x, y
b.sort(reverse = True)
ans = 0
for i in range(n):
    if b[i] < max(a):
        break
    h -= b[i]
    ans += 1
    if h <= 0:
        break
if not h <= 0:
    ans += math.ceil(h / max(a))
print(ans)

Fixed submission:
import math

n, h = map(int, input().split())
b = [0] * n
maxa = 0
for i in range(n):
    x, y = map(int, input().split())
    maxa = max(x, maxa)
    b[i] = y
b.sort(reverse = True)
ans = 0
for i in range(n):
    if b[i] < maxa:
        break
    h -= b[i]
    ans += 1
    if h <= 0:
        break
if not h <= 0:
    ans += math.ceil(h / maxa)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(0, n):
    t = 0
    m = i
    if i != n - 1:
        t = s[i][0] + s[i][1]
        m += 1
    while True:
        if m == n - 1:
            break
        while True:
            if (t - s[m][1]) % s[m][2] == 0 and t < s[m][1]:
                t = s[m][1]
            if (t - s[m][1]) % s[m][2] == 0 and t >= s[m][1]:
                break
            t += 1
        t += s[m][0]
        m += 1
    print(t)

Fixed submission:
n = int(input())
s = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(0, n):
    t = 0
    m = i
    if i != n - 1:
        t = s[i][0] + s[i][1]
        m += 1
    while True:
        if m == n - 1:
            break
        while True:
            if (t - s[m][1]) % s[m][2] == 0 and t < s[m][1]:
                t = s[m][1]
            if (t - s[m][1]) % s[m][2] == 0 and t >= s[m][1]:
                break
            t += 1
        t += s[m][0]
        m += 1
    print(t)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(0, n):
    t = 0
    m = i
    if i != n - 1:
        t = s[i][0] + s[i][1]
        m += 1
    while True:
        if m == n - 1:
            break
        while True:
            if (t - s[m][1]) % s[m][2] == 0 and t >= s[m][1]:
                break
            t += 1
        t += s[m][0]
        m += 1
    print(t)

Fixed submission:
n = int(input())
s = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(0, n):
    t = 0
    m = i
    if i != n - 1:
        t = s[i][0] + s[i][1]
        m += 1
    while True:
        if m == n - 1:
            break
        while True:
            if (t - s[m][1]) % s[m][2] == 0 and t < s[m][1]:
                t = s[m][1]
            if (t - s[m][1]) % s[m][2] == 0 and t >= s[m][1]:
                break
            t += 1
        t += s[m][0]
        m += 1
    print(t)
Buggy python submission (verdict: Runtime Error):
s = list(input())
t = list(input())
ans = [-1, -1]
if len(t) <= len(s):
    for i in range(len(s) - len(t) + 1):
        c = 1
        for j in range(len(t)):
            if s[i + j] != "?" and t[j] != s[i + j]:
                c = 0
                break
        if c == 1:
            ans = [i, i + len(t)]

if ans != [-1, -1]:
    k = []
    for i in range(len(s)):
        if ans[0] <= i <= ans[1]:
            k.append(t[i - ans[0]])
        else:
            if s[i] == "?":
                k.append("a")
            else:
                k.append(s[i])
    print("".join(k))
else:
    print("UNRESTORABLE")


Fixed submission:
s = list(input())
t = list(input())
ans = [-1, -1]
if len(t) <= len(s):
    for i in range(len(s) - len(t) + 1):
        c = 1
        for j in range(len(t)):
            if s[i + j] != "?" and t[j] != s[i + j]:
                c = 0
                break
        if c == 1:
            ans = [i, i + len(t)]

if ans != [-1, -1]:
    k = []
    for i in range(len(s)):
        if ans[0] <= i < ans[1]:
            k.append(t[i - ans[0]])
        else:
            if s[i] == "?":
                k.append("a")
            else:
                k.append(s[i])
    print("".join(k))
else:
    print("UNRESTORABLE")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
t = []
for _ in range(n):
    s = input()
    if not s in t:
        t.append(s)
    else:
        t.remove(s)
print(len(t))

Fixed submission:
n = int(input())
t = [int(input()) for _ in range(n)]
t.sort()
c = 1
ans = 0
for i in range(1, n):
    if t[i - 1] == t[i]:
        c += 1
    else:
        if c % 2 != 0:
            ans += 1
        c = 1
if c % 2 != 0:
    ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.insert(0, a[i])
if n % 2 == 1:
    b.reverse()
print(" ".join(map(str, b)))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [0] * ((n + 1) // 2)
c = [0] * (n // 2)
for i in range(n):
    if i % 2 == 0:
        b[i // 2] = a[i]
    else:
        c[i // 2] = a[i]
if n % 2 == 0:
    c.reverse()
    s = c + b
else:
    b.reverse()
    s = b + c
print(" ".join(map(str, s)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]
b = [0] * n
ans = 0
c = 0
b[0] = 1
while True:
    c = a[c] - 1
    ans += 1
    if b[c] == 1:
        ans = -1
        break
    if c == 1:
        break
print(ans)

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
b = [0] * n
ans = 0
c = 0
b[c] = 1
while True:
    c = a[c] - 1
    ans += 1
    if b[c] == 1:
        ans = -1
        break
    if c == 1:
        break
    b[c] = 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]
ans = 0
c = 0
while True:
    c = a[c] - 1
    ans += 1
    if c == 0:
        ans = -1
        break
    if c == 1:
        break
print(ans)

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
b = [0] * n
ans = 0
c = 0
b[c] = 1
while True:
    c = a[c] - 1
    ans += 1
    if b[c] == 1:
        ans = -1
        break
    if c == 1:
        break
    b[c] = 1
print(ans)
Buggy python submission (verdict: Runtime Error):
h, w, h0, w0 = map(int, input().split())
x, y = h // h0, w // w0
a1cnt = h0 * w0 - 1
a1sum, a2sum = h * w - x * y, x * y
a1 = ((pow(10, 9) - 1) // a1cnt)
a2 = -(a1 * a1cnt + 1)
asum = a1 * a1sum + a2 * a2sum
print("Yes" if asum > 0 else "No")
if asum > 0:
    for i in range(1, h + 1):
        a = [0] * w
        for j in range(1, w + 1):
            a[j - 1] = a2 if i % h0 == j % w0 == 0 else a1
        print(*a)

Fixed submission:
h, w, h0, w0 = map(int, input().split())
if h0 == w0 == 1:
    print("No")
    exit()
x, y = h // h0, w // w0
a1cnt = h0 * w0 - 1
a1sum, a2sum = h * w - x * y, x * y
a1 = ((pow(10, 9) - 1) // a1cnt)
a2 = -(a1 * a1cnt + 1)
asum = a1 * a1sum + a2 * a2sum
print("Yes" if asum > 0 else "No")
if asum > 0:
    for i in range(1, h + 1):
        a = [0] * w
        for j in range(1, w + 1):
            a[j - 1] = a2 if i % h0 == j % w0 == 0 else a1
        print(*a)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(input())
m = 0
c1, c2 = 0, 0
for i in range(n):
    if s[i] == ")":
        m += 1
        c2 = c1
    else:
        c1 += 1
j = 0
while True:
    if s[j] == "(":
        break
    j += 1
l = max((m - c2), j)
s1 = ["("] * l
for i in s:
    if i == "(":
        l += 1
    else:
        l -= 1
s2 = [")"] * l
s = s1 + s + s2
print("".join(s))

Fixed submission:
n = int(input())
s = list(input())
m = 0
l = 0
for i in range(n):
    if s[i] == ")":
        m += 1
    else:
        m -= 1
    if l < m:
        l = m
s1 = ["("] * l
for i in s:
    if i == "(":
        l += 1
    else:
        l -= 1
s2 = [")"] * l
s = s1 + s + s2
print("".join(s))

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(input())
m, l = 0, 0
c1, c2 = 0, 0
for i in range(n):
    if s[i] == ")":
        m += 1
        c3 = c1
    else:
        c1 += 1
    if s[n - i - 1] == "(":
        l += 1
        c4 = c2
    else:
        c2 += 1
s1 = ["("] * (m - c3)
s2 = [")"] * (l - c4)
s = s1 + s + s2
print("".join(s))

Fixed submission:
n = int(input())
s = list(input())
m = 0
l = 0
for i in range(n):
    if s[i] == ")":
        m += 1
    else:
        m -= 1
    if l < m:
        l = m
s1 = ["("] * l
for i in s:
    if i == "(":
        l += 1
    else:
        l -= 1
s2 = [")"] * l
s = s1 + s + s2
print("".join(s))
Buggy python submission (verdict: Runtime Error):
from collections import deque

n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n - 1):
    if a[i] != a[i + 1]:
        b.append(a[i])
if b[len(b) - 1] != a[n - 1]:
    b.append(a[n - 1])
l = len(b)
m = 0
ans = 1
for i in range(l - 1):
    if m == 0:
        if b[i] < b[i + 1]:
            m = 1
        else:
            m = -1
    elif m == 1:
        if b[i] > b[i + 1]:
            ans += 1
            m = 0
    else:
        if b[i] < b[i + 1]:
            ans += 1
            m = 0
print(ans)

Fixed submission:
from collections import deque

n = int(input())
a = list(map(int, input().split()))
b = []
if n >= 2:
    for i in range(n - 1):
        if a[i] != a[i + 1]:
            b.append(a[i])
    if b[len(b) - 1] != a[n - 1]:
        b.append(a[n - 1])
    l = len(b)
    m = 0
    ans = 1
    for i in range(l - 1):
        if m == 0:
            if b[i] < b[i + 1]:
                m = 1
            else:
                m = -1
        elif m == 1:
            if b[i] > b[i + 1]:
                ans += 1
                m = 0
        else:
            if b[i] < b[i + 1]:
                ans += 1
                m = 0
else:
    ans = 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math

def f(i):
    if i == ns:
        suma, sumb, sumcost = 0, 0, 0
        for j in range(ns):
            if s[j] == 1:
                suma += x[j][0]
                sumb += x[j][1]
                sumcost += x[j][2]
        mincost[suma][sumb] = min(mincost[suma][sumb], sumcost)
        return
    s[i] = 1
    f(i + 1)
    s[i] = 0
    f(i + 1)

def g(i):
    if i == nt:
        global ans
        suma, sumb, sumcost = 0, 0, 0
        for j in range(nt):
            if t[j] == 1:
                suma += y[j][0]
                sumb += y[j][1]
                sumcost += y[j][2]
        k = 1
        while True:
            ss, tt = k * ma - suma, k * mb - sumb
            if 0 <= ss <= l and 0 <= tt <= l:
                ans = min(ans, mincost[ss][tt] + sumcost)
            elif l < ss or l < tt:
                break
            k += 1
        return
    t[i] = 1
    g(i + 1)
    t[i] = 0
    g(i + 1)

n, ma, mb = map(int, input().split())
ns, nt = int(math.ceil(n / 2)), n // 2
l = 10 * ns
mincost = [[114514] * (l + 5) for _ in range(l + 5)]
ans = 114514
x = [list(map(int, input().split())) for _ in range(ns)]
y = [list(map(int, input().split())) for _ in range(nt)]
s = [0] * ns
t = [0] * nt
f(0)
g(0)
print(ans if not ans == 114514 else -1)

Fixed submission:
n, ma, mb = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
x.insert(0, [0, 0, 0])
inf = 114514
dp = [[[inf] * (10 * n + 1) for _ in range(10 * n + 1)] for _ in range(n + 1)]
for i in range(n + 1):
    dp[i][0][0] = 0
suma, sumb = 0, 0
for i in range(1, n + 1):
    suma += x[i][0]
    sumb += x[i][1]
    for j in range(suma + 1):
        for k in range(sumb + 1):
            dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j][k])
            if j >= x[i][0] and k >= x[i][1]:
                dp[i][j][k] = min(dp[i - 1][j][k], dp[i - 1][j - x[i][0]][k - x[i][1]] + x[i][2])
ans = 114514
for i in range(1, 10 * n + 1):
    for j in range(1, 10 * n + 1):
        if i * mb == j * ma:
            ans = min(ans, dp[n][i][j])
print(ans if not ans == 114514 else -1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
s = []
c = 0
for i in a:
    if not i in s:
        s.append(i)
    else:
        c += 1
print(n - 2 * ((c + 1) // 2))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = set(a)
print(n - 2 * ((n - len(b) + 1) // 2))
Buggy python submission (verdict: Time Limit Exceeded):
n, a = map(int, input().split())
x = list(map(int, input().split()))
s = sum(x)
dp = [[0] * (s * n + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
    dp[i][x[i - 1]] = 1
    for j in range(1, s + 1):
        dp[i][j] += dp[i - 1][j]
    for j in range(s + 1, s * n + 1):
        dp[i][j] = dp[i - 1][max(0, j - s - x[i - 1])] + dp[i - 1][j]
ans = 0
for i in range(1, n + 1):
    if i * a > s:
        print(ans)
        exit()
    ans += dp[n][i * a + (i - 1) * s]
print(ans)

Fixed submission:
n, a = map(int, input().split())
x = list(map(int, input().split()))
s = sum(x)
dp = [[0] * (s * n + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
    dp[i][x[i - 1]] = 1
    for j in range(1, s + 1):
        dp[i][j] += dp[i - 1][j]
    for j in range(s + 1, s * n + 1):
        dp[i][j] = dp[i - 1][max(0, j - s - x[i - 1])] + dp[i - 1][j]
ans = 0
for i in range(1, n + 1):
    if i * a > s:
        print(ans)
        exit()
    ans += dp[n][i * a + (i - 1) * s]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import product
input = lambda:sys.stdin.buffer.readline().rstrip()

m, n, k = map(int, input().split())
item = {}
for _ in range(k):
    i, j, v = map(int, input().split())
    i -= 1; j -= 1
    item[i, j] = v

dp = [[0] * 4 for _ in range(n)]
for i in range(m):
    ndp = [[0] * 4 for _ in range(n)]
    for j, k in product(range(n), range(4)):
        # from top
        ndp[j][0] = max(ndp[j][0], dp[j][k])
        if (i, j) in item:
            ndp[j][1] = max(ndp[j][1], dp[j][k] + item[i, j])
        # from left
        if j > 0:
            ndp[j][k] = max(ndp[j][k], ndp[j - 1][k])
            if k > 0 and (i, j) in item:
                ndp[j][k] = max(ndp[j][k], ndp[j - 1][k - 1] + item[i, j])
    dp = ndp

print(max(dp[-1]))

Fixed submission:
import sys
from itertools import product
input = lambda:sys.stdin.buffer.readline().rstrip()

m, n, k = map(int, input().split())
grid = [[0] * n for _ in range(m)]
for _ in range(k):
    i, j, v = map(int, input().split())
    i -= 1; j -= 1
    grid[i][j] = v

dp = [[0] * 4 for _ in range(n)]
for i in range(m):
    ndp = [[0] * 4 for _ in range(n)]
    for j, k in product(range(n), range(4)):
        # from top
        ndp[j][0] = max(ndp[j][0], dp[j][k])
        ndp[j][1] = max(ndp[j][1], dp[j][k] + grid[i][j])
        # from left
        if j > 0:
            ndp[j][k] = max(ndp[j][k], ndp[j - 1][k])
            if k > 0:
                ndp[j][k] = max(ndp[j][k], ndp[j - 1][k - 1] + grid[i][j])
    dp = ndp

print(max(dp[-1]))
Buggy python submission (verdict: Runtime Error):
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
mul = lambda x, y: x * y % MOD
div = lambda x, y: x * pow(y, MOD - 2, MOD) % MOD
from functools import reduce
def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(key = abs, reverse = 1)

    if all(a < 0 for a in A):
        A.sort()
        if k & 1:
            print(reduce(mul, A[-k:]))
        else:
            print(reduce(mul, A[:k]))
        return


    B = A[:k]
    C = A[k:]
    s = sum(b < 0 for b in B)
    if ~s & 1:
        print(reduce(mul, A[:k]))
        return

    res = reduce(mul, A[:k])
    p, q = max(B), min(B)
    lp, lq = max(C), min(C)
    # res * lq / p と res * lp / q
    # q * lq と p * lp のうち絶対値の大きい方
    f1 = p >= 0 and lq < 0
    f2 = lp >= 0 and q < 0

    if f1 and f2:
        if abs(q * lq) >= abs(p * lp):
            ans = div(res, p)
            ans = mul(ans, lq)
        else:
            ans = div(res, q)
            ans = mul(ans, lp)
    elif f1:
        ans = div(res, p)
        ans = mul(ans, lq)
    elif f2:
        ans = div(res, q)
        ans = mul(ans, lp)
    print(ans)
resolve()

Fixed submission:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
mul = lambda x, y : x * y % MOD
from functools import reduce
def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(key = abs, reverse = 1)

    if all(a < 0 for a in A) or n == k:
        if k & 1:
            print(reduce(mul, A[-k:]))
        else:
            print(reduce(mul, A[:k]))
        return

    pos = []
    neg = []
    for a in A:
        if a >= 0:
            pos.append(a)
        else:
            neg.append(-a)

    pos.reverse()
    neg.reverse()
    ans = 1
    if k & 1:
        ans *= pos.pop()
        k -= 1

    for _ in range(k // 2):
        if len(pos) >= 2 and len(neg) >= 2:
            a, b = pos[-2:]
            c, d = neg[-2:]
            if a * b >= c * d:
                ans *= pos.pop()
                ans *= pos.pop()
                ans %= MOD
            else:
                ans *= neg.pop()
                ans *= neg.pop()
                ans %= MOD
        elif len(pos) >= 2:
            ans *= pos.pop()
            ans *= pos.pop()
            ans %= MOD
        elif len(neg) >= 2:
            ans *= neg.pop()
            ans *= neg.pop()
            ans %= MOD
    print(ans)
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

def divisors(n):
    S, T = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            S.append(i)
            T.append(n // i)
        i += 1
    T.reverse()
    return S + T if S[-1] != T[0] else S + T[1:]

def resolve():
    n = int(input())
    print(sum(k * len(divisors(k)) for k in range(1, n + 1)))
resolve()

Fixed submission:
n = int(input())
ans = 0
for m in range(1, int(n**.5) + 1):
    ans += m * (m + (n // m)) * ((n // m) + 1 - m)
k = int(n**.5)
ans -= k * (k + 1) * (2 * k + 1) // 6

print(ans)
Buggy python submission (verdict: Runtime Error):
n = input()
ans = []
while n:
  n, r = divmod(n - 1, 26)
  ans.append(chr(ord('a') + r))
ans.reverse()
print(''.join(ans))

Fixed submission:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input()) - 1
    res = []
    while 1:
        res.append(chr(ord('a') + n % 26))
        n = n // 26 - 1
        if n == -1:
            break

    res.reverse()
    print(''.join(res))
resolve()

Buggy python submission (verdict: Runtime Error):
n = input()
ans = []
while n:
  n, r = divmod(n - 1, 26)
  ans.append(chr(ord('a') + r))
ans.reverse()
print(''.join())

Fixed submission:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input()) - 1
    res = []
    while 1:
        res.append(chr(ord('a') + n % 26))
        n = n // 26 - 1
        if n == -1:
            break

    res.reverse()
    print(''.join(res))
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    k = int(input())
    S = input()
    n = len(S)
    dp = {0 : 1}
    for _ in range(n + k):
        ndp = defaultdict(int)
        for key, val in dp.items():
            if key == n:
                ndp[key] += 26 * val
                ndp[key] %= MOD
            else:
                ndp[key + 1] += val
                ndp[key + 1] %= MOD
                ndp[key] += 25 * val
                ndp[key] %= MOD

        dp = ndp
    print(dp[n])
resolve()

Fixed submission:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

class modfact(object):
    def __init__(self, n):
        fact, invfact = [1] * (n + 1), [1] * (n + 1)
        for i in range(1, n + 1): fact[i] = i * fact[i - 1] % MOD
        invfact[n] = pow(fact[n], MOD - 2, MOD)
        for i in range(n - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD
        self._fact, self._invfact = fact, invfact

    def inv(self, n):
        return self._fact[n - 1] * self._invfact[n] % MOD

    def fact(self, n):
        return self._fact[n]

    def invfact(self, n):
        return self._invfact[n]

    def comb(self, n, k):
        if k < 0 or n < k: return 0
        return self._fact[n] * self._invfact[k] % MOD * self._invfact[n - k] % MOD

    def perm(self, n, k):
        if k < 0 or n < k: return 0
        return self._fact[n] * self._invfact[n - k] % MOD

def resolve():
    k = int(input())
    n = len(input())
    mf = modfact(n + k)
    ans = 0
    for i in range(n, n + k + 1):
        ans += mf.comb(n + k, i) * pow(25, n + k - i, MOD)
        ans %= MOD
    print(ans)
resolve()