Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

def main():
    N, Ma, Mb = map(int, input().split())
    a = [None] * N
    b = [None] * N
    c = [None] * N
    for i in range(N):
        a[i], b[i], c[i] = map(int, input().split())

    INF = 10**12
    dp = [[INF] * 401 for _ in range(401)]
    dp[0][0] = 0

    for i in range(N):
        for j in range(400,-1,-1):# 後ろから更新すること
            for k in range(400,-1,-1):
                if j - a[i] >= 0 and k - b[i] >= 0:
                    dp[j][k] = min(dp[j][k], dp[j-a[i]][k-b[i]]+c[i])
    
    ans = INF
    for j in range(400):
        for k in range(400):
            if j*Mb == k*Ma != 0:
                ans = min(ans,dp[j][k])
    print(ans) if ans < INF else print(-1)

if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3

def main():
    N, Ma, Mb = map(int, input().split())
    a = [None] * N
    b = [None] * N
    c = [None] * N
    for i in range(N):
        a[i], b[i], c[i] = map(int, input().split())

    INF = 10**12
    dp = [[[INF] * 401 for _ in range(401)] for _ in range(N+1)]
    dp[0][0][0] = 0

    for i in range(N):
        for j in range(400,-1,-1):# 後ろから更新すること
            for k in range(400,-1,-1):
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])
                if j - a[i] >= 0 and k - b[i] >= 0:
                    dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j-a[i]][k-b[i]]+c[i])
    
    ans = INF
    for j in range(400):
        for k in range(400):
            if j*Mb == k*Ma != 0:
                ans = min(ans,dp[N][j][k])
    print(ans) if ans < INF else print(-1)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [None] * N
B = [None] * N
for i in range(N):
  A[i],B[i] = map(int, input().split())
  
ans = 0
for i in range(N):
  p = A[N-1-i] % B[N-1-i]
  if p != 0:
    for j in range(N-i):
      A[j] += B[N-1-i] - p
    ans += B[N-1-i] - p
print(ans)

Fixed submission:
N = int(input())
A = [None] * N
B = [None] * N
for i in range(N):
  A[i],B[i] = map(int, input().split())
  
ans = 0
for i in range(N):
  p = (A[N-1-i] + ans) % B[N-1-i]
  ans += (B[N-1-i] - p) % B[N-1-i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
import copy

H, W, K = map(int, input().split())
if K > W:
    exit(print(0))

# 現在の盤面を生成する
c = [[] for _ in range(W)]
for i in range(H):
    S = input()
    for j in range(W):
        c[j].append(int(S[j]))

for j in range(W):
    c[j] = c[j][::-1]
# print(c)

# 連鎖消滅後の得点を計算する
def cal_score(c,score,loop):
    # 消滅
    nextc = []
    for j in range(W):
        num0 = c[j].count(0)
        tmp = [*filter(lambda x: x>0,c[j])]
        nextc.append(tmp+[0]*num0)

    # print(nextc)

    # 連鎖
    res = 0# 追加得点
    for i in range(H):
        j = 0
        while j < W:
            seq = 1
            while j<W-1 and nextc[j][i] == nextc[j+1][i] > 0:
                seq += 1
                j += 1
            if seq >= K:
                res += seq * nextc[j][i]
                for k in range(j-seq+1,j+1):
                    nextc[k][i] = 0
            j += 1
    # print(nextc,res)
    if res == 0:
        return score
    else:
        return cal_score(nextc,score+res*pow(2,loop),loop+1)
    

ans = 0
for p in range(H):
    for q in range(W):
        # p = 0
        # q = 2
        cc = copy.deepcopy(c)
        cc[q][p] = 0
        # print(p,q)
        z = cal_score(cc,0,0)
        # print(z)
        ans = max(ans, z)
print(ans)

Fixed submission:
#!/usr/bin/env python3
import copy

H, W, K = map(int, input().split())
if K > W:
    exit(print(0))

# 現在の盤面を生成する
c = [[] for _ in range(W)]
for i in range(H):
    S = input()
    for j in range(W):
        c[j].append(int(S[j]))

for j in range(W):
    c[j] = c[j][::-1]

# 連鎖消滅後の得点を計算する
def cal_score(c,score,loop):
    # 消滅
    nextc = []
    for j in range(W):
        num0 = c[j].count(0)
        tmp = [*filter(lambda x: x>0,c[j])]
        nextc.append(tmp+[0]*num0)

    # 連鎖
    res = 0# 追加得点
    for i in range(H):
        j = 0
        while j < W:
            seq = 1
            while j<W-1 and nextc[j][i] == nextc[j+1][i] > 0:
                seq += 1
                j += 1
            if seq >= K:
                res += seq * nextc[j][i]
                for k in range(j-seq+1,j+1):
                    nextc[k][i] = 0
            j += 1
    if res == 0:
        return score
    else:
        return cal_score(nextc,score+res*pow(2,loop),loop+1)
    

ans = 0
for p in range(H):
    for q in range(W):
        cc = copy.deepcopy(c)
        cc[q][p] = 0
        z = cal_score(cc,0,0)
        ans = max(ans, z)
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input.split())
print('Yes')if sum(a,b,c) == max(a,b,c)*2 else print('No')

Fixed submission:
a,b,c=map(int,input().split())
print('Yes')if a+b+c == max(a,b,c)*2 else print('No')
Buggy python submission (verdict: Runtime Error):
S = input()
a,b= S.find('C'),S.find('F')
print('Yes') if a>0 and b>0 and> a<b else print('No')

Fixed submission:
S = input()
a= S.find('C')
b= S.find('F',a+1)
print('Yes') if a>=0 and b>=0 and a<b else print('No')
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import math

def main():
    N = int(input())
    T, A = map(int, input().split())
    for _ in range(N-1):
        t, a = map(int, input().split())
        tmpT, tmpA = t,a
        while 1:
            if T <= tmpT and A <= tmpA:
                T,A = tmpT, tmpA
                break
            else:
                tmpT += t
                tmpA += a
    print(T+A)

if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
import math

def main():
    N = int(input())
    T, A = map(int, input().split())
    for _ in range(N-1):
        t, a = map(int, input().split())
        # 桁が大きいとfloatの誤差が生じて正しく判定できない
        # 負の数にして切り捨てにすればceilと同じ挙動になる
        x = max(-(-T//t), -(-A//a))
        T = t*x
        A = a*x
    print(T+A)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
s = input()
print(S[:4]+' '+S[4:])

Fixed submission:
S = input()
print(S[:4]+' '+S[4:])
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3


def main():
    N, A = map(int, input().split())
    x = list(map(int, input().split()))
    X = 50
    dp = [[[0]*(N*X +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*X+1):
                if s >= x[j-1] and k >= 1:
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]
                else:# x[j]を選ぶと合計sにできない
                    dp[j][k][s] = dp[j-1][k][s]
    ans = 0
    for i in range(N):
        ans += dp[N][i+1][(i+1)*A]
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3


def main():
    N, A = map(int, input().split())
    x = list(map(int, input().split()))
    X = 50
    dp = [[[0]*(N*X +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*X+1):
                if s >= x[j-1] and k >= 1:
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]
                else:# x[j]を選ぶと合計sにできない
                    dp[j][k][s] = dp[j-1][k][s]
    ans = 0
    for i in range(N):
        ans += dp[N][i+1][(i+1)*A]
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3


def main():
    N, A = map(int, input().split())
    x = list(map(int, input().split()))
    X = max(x)
    dp = [[[0]*(N*X +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*X+1):
                if s >= x[j-1] and k >= 1:
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]
                else:# x[j]を選ぶと合計sにできない
                    dp[j][k][s] = dp[j-1][k][s]
    ans = 0
    for i in range(N):
        ans += dp[N][i+1][(i+1)*A]
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3


def main():
    N, A = map(int, input().split())
    x = list(map(int, input().split()))
    X = 50
    dp = [[[0]*(N*X +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*X+1):
                if s >= x[j-1] and k >= 1:
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]
                else:# x[j]を選ぶと合計sにできない
                    dp[j][k][s] = dp[j-1][k][s]
    ans = 0
    for i in range(N):
        ans += dp[N][i+1][(i+1)*A]
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
print(sum(l[:k])

Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
print(sum(l[:k]))

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
print(sum(l[:k])

Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
print(sum(l[:k]))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=1
t=0
path=[]
s=set()
cycle=[]
while(c<=k):
    c+=1
    if a[t] in s:
        #print(path.index(a[t]),a[t])
        cycle=path[path.index(a[t]):]
        k-=c-1
        break
    path.append(a[t])
    s.add(a[t])
    t=a[t]-1
    #print(path,c)
#print(cycle)
print(cycle[k%len(cycle)])
    

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=2
t=0
path=[]
s=set()
cycle=[]
while(c<=k):
    if a[t] in s:
        #print(path.index(a[t]),a[t])
        cycle=path[path.index(a[t]):]
        k-=c-1
        break
    path.append(a[t])
    s.add(a[t])
    t=a[t]-1
    c+=1
if cycle==[]:
    print(a[t])
else:
    print(cycle[k%len(cycle)])
Buggy python submission (verdict: Time Limit Exceeded):
def check(s):
    n=1
    for i in range(1,int(s**0.5)+1):
        if s%i==0:
            n=i
    return n
s=int(input())
a=check(s)
b=s//a
print(0,0,a,0,0,b)

Fixed submission:
import math 
s=int(input())
if s<=10**9:
    print(0,0,1,0,0,s)
else:
    b=int(math.ceil(s/10**9))
    a=10**9*b-s
    print(0,0,10**9,1,a,b)
Buggy python submission (verdict: Runtime Error):
def maxreturn(t,n,a):
    ma=[0]*3
    b=[0]*n
    if t==n-1:
        for i in range(3):
           ma[i]=a[n-1][i]
    else:
      b=list(maxreturn(t+1,n,a))
      for i in range(3):
        for j in range(3):
            if i!=j:
                ma[i]=max(ma[i],a[t][i]+b[j])
                
    return ma
n=int(input())
a=[[0]*3]*n
for i in range(n):
    a[i]=list(map(int,input().split()))
ma=maxreturn(0,n,a)
print(max(ma))

Fixed submission:
n=int(input())
f=[0]*n
a=list(map(int,input().split()))
f[0]=0
f[1]=abs(a[0]-a[1])
for i in range(2,n):
    a1=abs(a[i]-a[i-2])
    b=abs(a[i]-a[i-1])
    f[i]=min((f[i-2]+a1),(f[i-1]+b))
print(f[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
import fractions
import bisect
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

N行M列の初期化
dp = [[INF] * M for i in range(N)]

'''


H, N = map(int, input().split())
A = []
B = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    A.append(x1)
    B.append(y1)


dp = [[INF] * (H+10) for i in range(N)] # 魔法iまでを使って体力をj減らすのに必要な最小のコスト

for hp in range(H+10):
    dp[0][hp] = ((hp//A[0]) + int(hp%A[0] != 0))*B[0]

for magic in range(1, N):
    for hp in range(H+10):

        if hp-A[magic] >= 0:
            dp[magic][hp] = min(dp[magic-1][hp], dp[magic][hp-A[magic]] + B[magic])
        else:
            dp[magic][hp] = min(dp[magic-1][hp], B[magic])


print(dp[N-1][H])

Fixed submission:
import sys
import math
import fractions
import bisect
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

N行M列の初期化
dp = [[INF] * M for i in range(N)]

'''


H, N = map(int, input().split())
A = []
B = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    A.append(x1)
    B.append(y1)


dp = [[INF] * (H+10) for i in range(N)] # 魔法iまでを使って体力をj減らすのに必要な最小のコスト

for hp in range(H+10):
    dp[0][hp] = ((hp//A[0]) + int(hp%A[0] != 0))*B[0]

for magic in range(1, N):
    for hp in range(H+10):

        if hp-A[magic] >= 0:
            dp[magic][hp] = min(dp[magic-1][hp], dp[magic][hp-A[magic]] + B[magic])
        else:
            dp[magic][hp] = min(dp[magic-1][hp], B[magic])


print(dp[N-1][H])
Buggy python submission (verdict: Runtime Error):

A = int(input())
P = int(input())

ans = (A*3+P)//2

print(ans)


Fixed submission:
A, P = (int(x) for x in input().split())
print((3*A + P) // 2)

Buggy python submission (verdict: Runtime Error):

A = int(input())
P = int(input())

ans = (A*3+P)//2

print(ans)


Fixed submission:
A, P = (int(x) for x in input().split())
print((3*A + P) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(4100000)
import math
import fractions
import bisect

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり
x = []
y = []
for i in range(5):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

'''


N, M = map(int, input().split())

ans = 0
for i in range(1, M//N+1):

    if M < i*N:
        break

    if (M - i*N) % i == 0:
        ans = i



print(int(ans))

Fixed submission:
import sys
sys.setrecursionlimit(4100000)
import math
import fractions
import bisect

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行ありl
x = []
y = []
for i in range(5):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

'''


N, M = map(int, input().split())

ans = 0
for i in range(1, int(math.sqrt(M))+1):

    if M < i*N:
        break

    if M % i == 0:
        if M >= (M//i)*N:
            ans = M//i
            break

        ans = i



print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
import fractions
import bisect
import queue
import heapq
from collections import deque
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり整数
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

N行M列の初期化
dp = [[INF] * M for i in range(N)]

'''


X, Y = map(int, input().split())
if X%Y == 0:
    print(-1)
for i in range(int(1e9)):
    if X*i % Y:
        print(X*i)
        sys.exit()

Fixed submission:
import sys
import math
import fractions
import bisect
import queue
import heapq
from collections import deque
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり整数
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

N行M列の初期化
dp = [[INF] * M for i in range(N)]

'''


X, Y = map(int, input().split())
if X%Y == 0:
    print(-1)
else:
    print(X)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
for i in range(n):
  a = i + 1
  for j in range(n):
    b = j + 1
    c = n - a * b
    if c <= 0:
      break
    ans += 1
print(ans)

Fixed submission:
import math
n = int(input())
ans = 0
for i in range(n):
  a = i + 1
  b = 1
  c = n - a * b
  ans += math.ceil(c / a)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
s = int(input())
p = s // 3
q = s % 3
ans = 0
if s < 3:
  ans = 0
else:
  if q == 0:
    ans += 1
  elif q == 1:
    ans += p
  elif q == 2:
    ans += p + math.factorial(p) // (math.factorial(p - 2) * math.factorial(2))
  for i in range(1, p):
    ans += math.factorial((s - 3 * (p - i)) + (p - i - 1)) // (math.factorial((s - 3 * (p - i))) * math.factorial(p - i - 1))
ans = ans % (10 ** 9 + 7)
print(ans)

Fixed submission:
import math
s = int(input())
ans = 0
if s < 3:
  ans = 0
else:
  p = s // 3
  q = s % 3
  if q == 0:
    ans += 1
  elif q == 1:
    ans += p
  elif q == 2:
    if p == 1:
      ans += 1
    else:
      ans += p + math.factorial(p) // (math.factorial(p - 2) * math.factorial(2))
  for i in range(1, p):
    ans += math.factorial((s - 3 * (p - i)) + (p - i - 1)) // (math.factorial((s - 3 * (p - i))) * math.factorial(p - i - 1))
ans = ans % (10 ** 9 + 7)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
c = input()
c = list(c)
arr = []
for i in range(n + 1):
  a =  c[:i].count('W')
  b = c[i:].count('R')
  arr.append(max(a, b))
ans = min(arr)
print(ans)

Fixed submission:
n = int(input())
c = input()
c = list(c)
arr = []
a = 0
b = c.count('R')
arr.append(max(a, b))
for i in range(n):
  if c[i] == 'W':
    a += 1
  elif c[i] == 'R':
    b -= 1
  arr.append(max(a, b))
ans = min(arr)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
c = input()
arr = []
for i in range(n + 1):
  a =  c[:i].count('W')
  b = c[i:].count('R')
  arr.append(max(a, b))
ans = min(arr)
print(ans)

Fixed submission:
n = int(input())
c = input()
c = list(c)
arr = []
a = 0
b = c.count('R')
arr.append(max(a, b))
for i in range(n):
  if c[i] == 'W':
    a += 1
  elif c[i] == 'R':
    b -= 1
  arr.append(max(a, b))
ans = min(arr)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
c = input()
c = list(c)
f = 0
ans = 0
while f == 0:
  if 'R' in c and 'W' in c:
    r = len(c) - c[::-1].index('R') - 1
    w = c.index('W')
    c[r] = 'W'
    c[w] = 'R'
    ans += 1
    for i, e in enumerate(c):
      if e == 'R':
        c[i] = ''
      else:
        c.remove('')
        break
  else:
    f = 1
    break
print(ans)

Fixed submission:
n = int(input())
c = input()
c = list(c)
arr = []
a = 0
b = c.count('R')
arr.append(max(a, b))
for i in range(n):
  if c[i] == 'W':
    a += 1
  elif c[i] == 'R':
    b -= 1
  arr.append(max(a, b))
ans = min(arr)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = [0] * 10000
for i in range(1,101):
  for j in range(1,101):
    for k in range(1,101):
      v = i*i+j*j+k*k+i*j+j*k+k*i
      if v<10050:
        ans[v]+=1
for i in range(n):
  print(ans[i+1])

Fixed submission:
n = int(input())
ans = [0] * 10050
for i in range(1,105):
  for j in range(1,105):
    for k in range(1,105):
      v = i*i+j*j+k*k+i*j+j*k+k*i
      if v<10050:
        ans[v]+=1
for i in range(n):
  print(ans[i+1])
Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = 0
sum_a = [0]
for i in range(n):
  if t + a[i] <= k:
    t += a[i]
    sum_a.append(t)
  else:
    break
sum_b = [0]
t = 0
for i in range(m):
  if t + b[i] <= k:
    t += b[i]
    sum_b.append(t)
  else:
    break

ans = []
for i in range(len(sum_a)):
  for j in range(len(sum_b)):
    if sum_a[i] + sum_b[len(sum_b) - j - 1] <= k:
      ans.append(i + len(sum_b) - j - 1)
      break
print(max(ans))

Fixed submission:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = 0
sum_a = [0]
for i in range(n):
  if t + a[i] <= k:
    t += a[i]
    sum_a.append(t)
  else:
    break
sum_b = [0]
t = 0
for i in range(m):
  if t + b[i] <= k:
    t += b[i]
    sum_b.append(t)
  else:
    break
ans = []
j = 0
for i in range(len(sum_a)):
  while sum_a[i] + sum_b[len(sum_b) - j - 1] > k:
    j += 1
  ans.append(i + len(sum_b) - j - 1)
print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = 0
sum_a = [0]
for i in range(n):
  if t + a[i] <= k:
    t += a[i]
    sum_a.append(t)
  else:
    break
sum_b = [0]
t = 0
for i in range(m):
  if t + b[i] <= k:
    t += b[i]
    sum_b.append(t)
  else:
    break
ans = []
for i in range(len(sum_a)):
  for j in range(len(sum_b)):
    if sum_a[i] + sum_b[j] <= k:
      ans.append(i + j)
print(max(ans))

Fixed submission:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = 0
sum_a = [0]
for i in range(n):
  if t + a[i] <= k:
    t += a[i]
    sum_a.append(t)
  else:
    break
sum_b = [0]
t = 0
for i in range(m):
  if t + b[i] <= k:
    t += b[i]
    sum_b.append(t)
  else:
    break
ans = []
j = 0
for i in range(len(sum_a)):
  while sum_a[i] + sum_b[len(sum_b) - j - 1] > k:
    j += 1
  ans.append(i + len(sum_b) - j - 1)
print(max(ans))
Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
p = list(map(int, input().split()))
a = 0
ans = ''
p.sort()
print(p)
while ans == '':
  if len(p) == 0:
    ans = x
  elif x - a not in p:
    ans = x - a
  elif x + a not in p:
    ans = x + a
  else:
    a += 1
print(ans)

Fixed submission:
l = list(map(int, input().split()))
print(l.index(0) + 1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
  ans *= a[i]
if ans > 10 ** 18:
  ans = -1
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = a[0]
if 0 in a:
  ans = 0
else:
  for i in range(1, n):
    if ans < 10 ** 18:
      ans *= a[i]
    else:
      break
if ans > 10 ** 18:
  ans = -1
print(ans)