Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
to = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    to[a].append([b, c])
    to[b].append([a, c])

Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(Q)]

dist = [0] * N

def dfs(v, pv, dis):
    for i in to[v]:
        if i[0] != pv:
            dfs(i[0], v, dis+i[1])
    dist[v] = dis

dfs(K-1, -1, 0)

for q in xy:
    print(dist[q[0]-1] + dist[q[1]-1])


Fixed submission:
import sys
sys.setrecursionlimit(10**9)
N = int(input())
to = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    to[a].append([b, c])
    to[b].append([a, c])

Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(Q)]

dist = [0] * N

def dfs(v, pv, dis):
    for i in to[v]:
        if i[0] != pv:
            dfs(i[0], v, dis+i[1])
    dist[v] = dis

dfs(K-1, -1, 0)

for x, y in xy:
    print(dist[x-1] + dist[y-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ab = [sorted(list(map(int, input().split()))) for _ in range(M)]
judge = False
m = []
for i, (a, b) in enumerate(ab):
    if a == 1:
        m.append(b)

for i, (a, b) in enumerate(ab):
    if a in m and b == N:
        judge = True
        break

if judge:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Fixed submission:
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    edge[a].append(b)
    edge[b].append(a)

ans = {True: "POSSIBLE",
    False: "IMPOSSIBLE"}

print(ans[len(set(edge[0]) & set(edge[-1])) > 0])
Buggy python submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

# いずれか2つの数字のGCDが1 必ずTrue
# いずれか2つの数字のGCDが2 かつ Ai - K % 2 == 0 のものが存在する場合 True
# いずれか2つのGCDが計算できれば、答えが導けるが、いずれか2つの組み合わせはA * (A-1) // 2通りあるから間に合わない
# 累積GCDで1になる → どうにかこうにか1にできる
# 累積GCDで2になる → どの組み合わせをとっても2にしかならない


def main():
    ma = max(A)
    if ma < K:
        return False
    if K in A:
        return True
    gcd = A[0]
    for a in A:
        gcd = math.gcd(gcd, a)
    for a in A:
        if (a-K) % gcd == 0:
            return True
    return False
    

if main():
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Fixed submission:
def gcd(x, y):
    '''
    最大公約数の計算
    '''
    if y == 0:
        return x
    return gcd(y, x % y)
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

# いずれか2つの数字のGCDが1 必ずTrue
# いずれか2つの数字のGCDが2 かつ Ai - K % 2 == 0 のものが存在する場合 True
# いずれか2つのGCDが計算できれば、答えが導けるが、いずれか2つの組み合わせはA * (A-1) // 2通りあるから間に合わない
# 累積GCDで1になる → どうにかこうにか1にできる
# 累積GCDで2になる → どの組み合わせをとっても2にしかならない


def main():
    ma = max(A)
    if ma < K:
        return False
    if K in A:
        return True
    g = A[0]
    for a in A:
        g = gcd(g, a)
    for a in A:
        if (a-K) % g == 0:
            return True
    return False


if main():
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]
res = []
for i in range(1,len(a)):
    res.append(abs(sum(a[:i])-sum(a[i:])))

print(min(res))


Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]

l = [0] * (N+1)
r = [0] * (N+1)

for i in range(N):
    l[i+1] = l[i] + a[i]

for i in range(N-1,-1,-1):
    r[i] = r[i+1] + a[i]

res = []

for i in range(1,len(l)-1):
    res.append(abs(l[i]-r[i]))

print(min(res))

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(i) for i in input().split()]
res = []
for i in range(1,len(a)):
    res.append(abs(a[:i+1]-a[i:]))

print(min(res))


Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]

l = [0] * (N+1)
r = [0] * (N+1)

for i in range(N):
    l[i+1] = l[i] + a[i]

for i in range(N-1,-1,-1):
    r[i] = r[i+1] + a[i]

res = []

for i in range(1,len(l)-1):
    res.append(abs(l[i]-r[i]))

print(min(res))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ret = []

for i in range(N):
    if i % 2 == 0:
        ret.append(A[i])
    else:
        ret.insert(0, A[i])

if N % 2 == 1:
    ret.reverse()

print(*ret)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ret = []

for i in range(N):
    if i % 2 == 0:
        ret.append(A[i])
ret.reverse()
for i in range(N):
    if i % 2 == 1:
        ret.append(A[i])

if N % 2 == 0:
    ret.reverse()

print(*ret)
Buggy python submission (verdict: Runtime Error):
n=int(input())
mod=10**9+7

def prime_factorization(n):
    '''
    素因数分解を求める

    Parameters:
    n : int
        求める数
    
    Returns:
    r : list
        素因数分解の結果
    '''
    r=[1]*(n+1)
    for i in range(1,n+1):
        for j in range(2,i+1):
            while i % j == 0:
                r[j] += 1
                i //= j
    
    return r

r = prime_factorization(N)
ans = 1
for i in r:
    ans *= i
    ans %= mod

print(ans)


Fixed submission:
N=int(input())
mod=10**9+7

def prime_factorization(n):
    '''
    素因数分解を求める

    Parameters:
    n : int
        求める数
    
    Returns:
    r : list
        素因数分解の結果
    '''
    r=[1]*(n+1)
    for i in range(1,n+1):
        for j in range(2,i+1):
            while i % j == 0:
                r[j] += 1
                i //= j
    
    return r

r = prime_factorization(N)
ans = 1
for i in r:
    ans *= i
    ans %= mod

print(ans)
Buggy python submission (verdict: Runtime Error):
S = list(input())
L = len(S)
K = int(input())
idx = 0
while K > 0:
    # aまでの必要な回数
    if S[idx] == "a" and idx < L-1:
        idx += 1
        continue
    k = 123 - ord(S[idx])
    if k > K:
        if idx < L-1:
            # aまで操作できないのに、操作すると辞書順でより後ろの文字列になってしまうので、次の文字へ
            idx += 1
        else:
            # 一番後ろの場合
            t = chr(ord(S[idx])+(K%26))
            S[idx] = t
            K = 0
    else:
        K -= k
        S[idx] = "a"
        idx += 1

print("".join(S))


Fixed submission:
S = list(input())
L = len(S)
K = int(input())
idx = 0
while K > 0:
    # aまでの必要な回数
    if S[idx] == "a" and idx < L-1:
        idx += 1
        continue
        
    k = 123 - ord(S[idx])
    if k > K:
        if idx < L-1:
            # aまで操作できないのに、操作すると辞書順でより後ろの文字列になってしまうので、次の文字へ
            idx += 1
        else:
            # 一番後ろの場合
            t = chr(ord(S[idx])+(K%26))
            S[idx] = t
            K = 0
    else:
        K -= k
        S[idx] = "a"
        if idx < L-1:
            idx += 1

print("".join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
L = len(S)
K = int(input())
idx = 0
while K > 0:
    # aまでの必要な回数
    k = 123 - ord(S[idx])
    if k > K:
        if idx < L-1:
            # aまで操作できないのに、操作すると辞書順でより後ろの文字列になってしまうので、次の文字へ
            idx += 1
        else:
            # 一番後ろの場合
            t = chr(ord(S[idx])+(K%26))
            S[idx] = t
            K = 0
    else:
        if S[idx] != "a":
            K -= k
        S[idx] = "a"
        if idx < L-1:
            idx += 1

print("".join(S))


Fixed submission:
S = list(input())
L = len(S)
K = int(input())
idx = 0
while K > 0:
    # aまでの必要な回数
    if S[idx] == "a" and idx < L-1:
        idx += 1
        continue
        
    k = 123 - ord(S[idx])
    if k > K:
        if idx < L-1:
            # aまで操作できないのに、操作すると辞書順でより後ろの文字列になってしまうので、次の文字へ
            idx += 1
        else:
            # 一番後ろの場合
            t = chr(ord(S[idx])+(K%26))
            S[idx] = t
            K = 0
    else:
        K -= k
        S[idx] = "a"
        if idx < L-1:
            idx += 1

print("".join(S))

Buggy python submission (verdict: Runtime Error):
S = list(input())
L = len(S)
K = int(input())
idx = 0
while K > 0:
    # aまでの必要な回数
    k = 123 - ord(S[idx])
    if k > K:
        if idx < L-1:
            idx += 1
        else:
            t = chr(ord(S[idx])+(K%26))
            S[idx] = t
            K = 0
    else:
        K -= k
        S[idx] = "a"
        idx += 1

print("".join(S))


Fixed submission:
S = list(input())
L = len(S)
K = int(input())
idx = 0
while K > 0:
    # aまでの必要な回数
    if S[idx] == "a" and idx < L-1:
        idx += 1
        continue
        
    k = 123 - ord(S[idx])
    if k > K:
        if idx < L-1:
            # aまで操作できないのに、操作すると辞書順でより後ろの文字列になってしまうので、次の文字へ
            idx += 1
        else:
            # 一番後ろの場合
            t = chr(ord(S[idx])+(K%26))
            S[idx] = t
            K = 0
    else:
        K -= k
        S[idx] = "a"
        if idx < L-1:
            idx += 1

print("".join(S))
Buggy python submission (verdict: Runtime Error):
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for(int i = 0; i < (int)n; ++i)
int main()
{
    int N, M;
    scanf("%d %d", &N, &M);
    int a[N], b[N];
    REP(i, N) scanf("%d %d", &a[i], &b[i]);
    int c[M], d[M];
    REP(i, M) scanf("%d %d", &c[i], &d[i]);
    REP(i, N) {
        int res = -1;
        int dis = 1e9;
        REP(j, M) {
            int tmp = abs(c[j] - a[i]) + abs(d[j] - b[i]);
            if(tmp < dis) dis = tmp, res = j + 1;
        }
        printf("%d\n", res);
    }
    return 0;
}

Fixed submission:
#!/usr/bin/python3
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)


def main():
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(n)]
    cd = [list(map(int, input().split())) for _ in range(m)]

    for a, b in ab:
        arr = []
        for c, d in cd:
            arr.append(abs(a-c) + abs(b-d))
        print(arr.index(min(arr)) + 1)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
    ll N;
    cin >> N;
    int res = 30;
    for(ll i = 1; i*i <= N; ++i) {
        if(N%i) continue;
        ll j = N/i;
        int cnt = 0;
        while(j > 0) ++cnt, j /= 10;
        res = min(res, cnt);
    }
    cout << res << endl;
    return 0;
}

Fixed submission:
import sys
input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

def main():
    N = int(input())
    a = make_divisors(N)
    a.sort()
    ans = 10
    for i in a:
        ans = min(ans, len(str(max(i, N/i))))
    
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
in = input()
key = "keyence"
for i in range(len(in)):
  for j in range(i, len(in)):
    if (in[i:j] == key):
      print("YES")
      exit()
print("NO")


Fixed submission:
a = input()
key = "keyence"
for i in range(len(a)):
  for j in range(i, len(a)):
    if (a[:i] + a[j:] == key):
      print("YES")
      exit(0)
print("NO")

Buggy python submission (verdict: Runtime Error):
in = input()
key = "keyence"
for i in range(len(in)):
  for j in range(i, len(in)):
    if (in[i:j] == key):
      print("YES")
      exit
print("NO")


Fixed submission:
a = input()
key = "keyence"
for i in range(len(a)):
  for j in range(i, len(a)):
    if (a[:i] + a[j:] == key):
      print("YES")
      exit(0)
print("NO")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = map(int, input().split())
print(sum(a)-len(a))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
print(sum(a)-len(a))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i+1
b = sorted(a)
center1 = b[n//2+1]
center2 = 0
if not n == 1:
    center2 = b[n//2]
buf1 = 0
buf2 = 0
for i in range(n):
    buf1 += abs(b[i]-center1)
    buf2 += abs(b[i]-center2)
print(int(min(buf1, buf2)))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i+1
b = sorted(a)
center1 = b[n//2]
center2 = 0
if not n == 1:
    center2 = b[n//2+1]
buf1 = 0
buf2 = 0
for i in range(n):
    buf1 += abs(b[i]-center1)
    buf2 += abs(b[i]-center2)
print(int(min(buf1, buf2)))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i+1
b = sorted(a)
center1 = b[n//2+1]
center2 = b[n//2]
buf1 = 0
buf2 = 0
for i in range(n):
    buf1 += abs(b[i]-center1)
    buf2 += abs(b[i]-center2)
print(int(min(buf1, buf2)))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i+1
b = sorted(a)
center1 = b[n//2]
center2 = 0
if not n == 1:
    center2 = b[n//2+1]
buf1 = 0
buf2 = 0
for i in range(n):
    buf1 += abs(b[i]-center1)
    buf2 += abs(b[i]-center2)
print(int(min(buf1, buf2)))
Buggy python submission (verdict: Runtime Error):
a = input();
if (a[0] == a[1] & a[1] == a[2]) print('Yes')
elif (a[1] == a[2] & a[2] == a[3]) print('Yes')
else print('No')


Fixed submission:
a = input();
if ((a[0] == a[1]) & (a[1] == a[2])) : print('Yes')
elif ((a[1] == a[2]) & (a[2] == a[3])) : print('Yes')
else : print('No')
Buggy python submission (verdict: Runtime Error):
a, b, c = int(input().split)
if a == c : print(b)
elif a == b : print(c)
else : print(a)


Fixed submission:
a, b, c = input().split()
if a == c : print(b)
elif a == b : print(c)
else : print(a)
Buggy python submission (verdict: Runtime Error):
n, k = int(input()), int(input())
a = map(int, input().split())
sum = 0
for x in a :
  sum += min(x, abs(k-x)) * 2
print(sum)


Fixed submission:
print(int(input())**2-int(input()))
Buggy python submission (verdict: Runtime Error):
n, k = int(input()), int(input())
a = map(int, input().split())
sum = 0
for x in a :
  sum += min(a, abs(k-a)) * 2
print(sum)


Fixed submission:
n, k = int(input()), int(input())
a = map(int, input().split())
sum = 0
for x in a :
  sum += min(x, abs(k-x)) * 2
print(sum)
Buggy python submission (verdict: Runtime Error):
if (n = input().split())[0] == n[2] : print('Yes')
else : print('No')


Fixed submission:
n = input()
if n[0] == n[2] : print('Yes')
else : print('No')
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
row = [0 for i in range(101)]
for i in range(a, b+1) : row[i] += 1
for i in range(c, d+1) : row[i] += 1
if row.count(2) == 0 : print(0)
else : print(raw.count(2)-1)


Fixed submission:
a, b, c, d = map(int, input().split())
row = [0 for i in range(101)]
for i in range(a, b+1) : row[i] += 1
for i in range(c, d+1) : row[i] += 1
if row.count(2) == 0 : print(0)
else : print(row.count(2)-1)

Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
row = [i for i in range(101)]
row[a-1:b] += 1
row[c-1:d] += 1
print(row.count(0))


Fixed submission:
a, b, c, d = map(int, input().split())
row = [0 for i in range(101)]
for i in range(a, b+1) : row[i] += 1
for i in range(c, d+1) : row[i] += 1
if row.count(2) == 0 : print(0)
else : print(row.count(2)-1)
Buggy python submission (verdict: Runtime Error):
s = input()
print(f'{s[0]}{s.len()-2}{s[-1]}')


Fixed submission:
s = input()
print(s[0], end='')
print(len(s)-2, end='')
print(s[-1])
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
l = sort(list(map(int, input().split())), reverse=True)
print(sum(l[:k]))


Fixed submission:
n, k = map(int, input().split())
l = sorted(list(map(int, input().split())), reverse=True)
print(sum(l[:k]))
Buggy python submission (verdict: Runtime Error):
x, a, b = map(int. input().split())
if (b <= a) : print('delicious')
elif (x >= b-a) : print('safe')
else : print('dangerous')


Fixed submission:
x, a, b = map(int, input().split())
if (b <= a) : print('delicious')
elif (x >= b-a) : print('safe')
else : print('dangerous')
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
if (a < b) print(0)
else print(b*(n-1)+a-a*(n-1)-b+1)


Fixed submission:
n, a, b = map(int, input().split())
if (a > b) : print(0)
elif (n == 1) :
  if (a == b) : print(1)
  else : print(0)
else : print((b-a)*(n-2)+1)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a == b : print('Draw')
else :
  if min(a, b) == 1 : flag = True
  if a < b :
    if flag : print('Alice')
    else : print('Bob')
  else :
    if flag : print('Bob')
    else : print('Alice')


Fixed submission:
a, b = map(int, input().split())
if a == b : print('Draw')
else :
  flag = False
  if min(a, b) == 1 : flag = True
  if a < b :
    if flag : print('Alice')
    else : print('Bob')
  else :
    if flag : print('Bob')
    else : print('Alice')

Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a == b : print('Draw')
else :
  if min(a, b) == 1 : flag = TRUE
  if a < b :
    if flag : print('Alice')
    else : print('Bob')
  else :
    if flag : print('Bob')
    else : print('Alice')


Fixed submission:
a, b = map(int, input().split())
if a == b : print('Draw')
else :
  flag = False
  if min(a, b) == 1 : flag = True
  if a < b :
    if flag : print('Alice')
    else : print('Bob')
  else :
    if flag : print('Bob')
    else : print('Alice')
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
print(n*((n-1)**(k-1)))


Fixed submission:
a = set(list(map(int, input().split())))
print(len(a))
Buggy python submission (verdict: Runtime Error):
l, n = map(int, input().split())
a = [input() for _ in range(n)]
a = sorted(a)
ans = ""
for s in a:
  ans += s
print(ans)


Fixed submission:
n, l = map(int, input().split())
a = [input() for _ in range(n)]
a = sorted(a)
ans = ""
for s in a:
  ans += s
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,k = map(int,input().split())
    a = []
    for _ in range(n):
        a.append(int(input()))
    DP = [[] for _ in range(n)]
    DP[1].append(0)
    M = 1
    for i in range(1,n):
        m = M
        flg = 0
        while m>0:
            for p in DP[m]:
                if abs(a[i]-a[p])<=k:
                    DP[m+1].append(i)
                    flg = 1
                    if m+1>M:
                        M=m+1
                    break
            if flg==1:
                break
            m -= 1
        if flg==0:
            DP[1].append(i)
    print(M)

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n,k = map(int,input().split())
    a = []
    for _ in range(n):
        a.append(int(input()))
    DP = [[] for _ in range(n)]
    DP[1].append(0)
    M = 1
    for i in range(1,n):
        m = M
        flg = 0
        while m>0:
            for p in DP[m]:
                if abs(a[i]-a[p])<=k:
                    DP[m+1].append(i)
                    flg = 1
                    if m+1>M:
                        M=m+1
                    break
            if flg==1:
                break
            m -= 1
        if flg==0:
            DP[1].append(i)
    print(M)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    import math
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    def f(a,l):
        ans = 0
        for i in range(len(a)):
            ans += math.ceil(a[i]/l)-1
        return ans
    l,r = 1,max(a)
    while (r+l)//2!=r and (r+l)//2!=l:
        if f(a,(l+r)//2)>k:
            l = (l+r)//2
        elif f(a,(l+r)//2)<k:
            r = (l+r)//2
        else:
            break
    while True:
        if f(a,r)<=k:
            r -= 1
        else:
            print(r+1)
            return

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    import math
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    def f(a,l):
        ans = 0
        for i in range(len(a)):
            ans += math.ceil(a[i]/l)-1
        return ans
    l,r = 1,max(a)
    while r-l>1:
        mid = (l+r)//2
        g = f(a,mid)
        if g>k:
            l = mid+1
        else:
            r = mid
    if f(a,l)<=k:
        print(l)
    else:
        print(r)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    import math
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    def f(a,l):
        ans = 0
        for i in range(len(a)):
            ans += math.ceil(a[i]/l)-1
        return ans
    l,r = 1,max(a)
    while r-l>1:
        if f(a,(l+r)//2)>k:
            l = (l+r)//2
        else:
            r = (l+r)//2
    while True:
        if f(a,r)<=k:
            r -= 1
        else:
            print(r+1)
            return

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    import math
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    def f(a,l):
        ans = 0
        for i in range(len(a)):
            ans += math.ceil(a[i]/l)-1
        return ans
    l,r = 1,max(a)
    while r-l>1:
        mid = (l+r)//2
        g = f(a,mid)
        if g>k:
            l = mid+1
        else:
            r = mid
    if f(a,l)<=k:
        print(l)
    else:
        print(r)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    ans = 0
    for i in range(n+1):
        ans_ = 0
        cost = sum(a[0:i])
        k_ = k-cost
        if k_<0:
            break
        ans_ = i
        for j in range(m):
            k_ = k_-b[j]
            if k_<0:
                break
            ans_ += 1
        if ans_ > ans:
            ans = ans_
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    import bisect
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    A,B = [0],[0]
    for i in range(n):
        A.append(A[i]+a[i])
    for i in range(m):
        B.append(B[i]+b[i])
    ans = 0
    for i in range(n+1):
        cost = A[i]
        c = i
        if cost > k:
            continue
        cost = k-cost
        c += bisect.bisect_right(B,cost)-1
        if c>ans:
            ans = c
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    n_ = int(n**0.5)
    ans = [2 for i in range(n)]
    ans[0] = 1
    for i in range(2,n_+1):
        for j in range(i+1,n+1):
            if j%i==0:
                if j==i*i:
                    ans[j-1]+=1
                elif j> i*i:
                    ans[j-1]+=2
    s=0
    for i in range(n):
        s += (i+1)*ans[i]
    print(s)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    ans = 0
    for i in range(1,n+1):
        s = n//i * (1+n//i) * i/2
        ans += s
    print(int(ans))

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    ans = []
    while n>26:
        p = n//26
        k = n-26*p
        ans.append(k)
        n = p
    ans.append(n)
    ans = ans[::-1]
    b = []
    for a in ans:
        if int(a)==0:
            t = b.pop(-1)
            if t=='a':
                s = 'z'
            else:
                s = chr(ord(t)-1)
            b.append(s+'z')
        else:
            b.append(chr(96+int(a)))
    print(''.join(b))

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    ans = []
    while n>25:
        p = n//26
        k = n-26*p
        if k==0:
            ans.append(26)
            n = p-1
        else:
            ans.append(k)
            n = p
    if n!=0:
        ans.append(n)
    ans = ans[::-1]
    b = []
    for i in range(len(ans)):
        b.append(chr(96+ans[i]))

    print(''.join(b))

if __name__ == "__main__":
    main()