qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ea=[0]
for i in range(n):
    ea.append(ea[i]+a[i])
eb=[0]
for i in range(m):
    eb.append(eb[i]+b[i])
tb=m
p=0
if n<m:
    ea,eb=eb,ea
    n,m=m,n
for i in range(n+1):
    while ea[i]+eb[tb]>k:
        if tb==0:
            break
        tb-=1
    if ea[i]+eb[tb]<=k:
        p=max(i+tb,p)
print(p)

Fixed code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ea=[0]
for i in range(n):
    ea.append(ea[i]+a[i])
eb=[0]
for i in range(m):
    eb.append(eb[i]+b[i])
tb=m
p=0
for i in range(n+1):
    while ea[i]+eb[tb]>k:
        if tb==0:
            break
        tb-=1
    if ea[i]+eb[tb]<=k:
        p=max(i+tb,p)
print(p)
Buggy code:
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(a[i] + A[i])

ans, j = o, M

for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)


Fixed code:
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, j = 0, M

for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
Buggy code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

for i in range(1,n): a[i]=a[i]+a[i-1]
for i in range(1,m): b[i]=b[i]+b[i-1]
j=m-1
ans=0
for i in range(n):
    if j<0: break
    while a[i]+b[j]>k and j>=0: j-=1
    ans=max(i+j+2,ans)
print(ans)

Fixed code:
n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=[0]+list(map(int,input().split()))

for i in range(1,n+1): a[i]=a[i]+a[i-1]
for i in range(1,m+1): b[i]=b[i]+b[i-1]
j=m
ans=0
for i in range(n+1):
    if j<0: break
    while a[i]+b[j]>k and j>=0: j-=1
    ans=max(i+j,ans)
print(ans)
Buggy code:
n,m,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))

import numpy as np
import bisect
a = np.cumsum(a)
b = np.cumsum(b)
ans = 0
r = m
for i in range(n+1):
  if a[i] > k:
    break
  while a[i] + b[r] > k:
    r -= 1
  ans = max(ans, i+r)
if i == 0:
  r = bisect.bisect_left(b, k)
  ans = max(ans, i+r)
print(ans)

Fixed code:
n,m,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
 
import numpy as np
a = [0] + a
b = [0] + b
sa = np.cumsum(a)
sb = np.cumsum(b)
ans = 0
r = m
for i in range(n+1):
  if sa[i] > k:
    break
  while sa[i] + sb[r] > k:
    r -= 1
  ans = max(ans, i+r)

print(ans)
Buggy code:
n,m,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
 
a = [0] * (n + 1)
b = [0] * (m + 1)
for i in range(n):
  a[i + 1] = a[i] + a[i]
for i in range(m):
  b[i + 1] = b[i] + b[i]
ans = 0
r = m
for i in range(n+1):
  if a[i] > k:
    break
  while a[i] + b[r] > k:
    r -= 1
  ans = max(ans, i+r)

print(ans)

Fixed code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0] * (n + 1)
sb = [0] * (m + 1)
for i in range(n):
  sa[i + 1] = sa[i] + a[i]
for i in range(m):
  sb[i + 1] = sb[i] + b[i]
r = m
ans = 0
for i in range(n + 1):
  if sa[i] > k:
    break
  while sa[i] + sb[r] > k:
    r -= 1
  ans = max(ans, i + r)
print(ans)
Buggy code:
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

A = [0]
B = [0]
for i in range(n):
	A.append(A[i]+a[i])
for j in range(m):
	B.append(B[j]+b[j])

print(A,B)

maxij = 0
l = m
for i in range(n+1):
	for j in range(m):
#		print(i,l,A[i],B[l],k)
		if((A[i]+B[l]) <= k):
		 	maxij=max(maxij,i+l)
#		 	print("mm",maxij)
		 	break
		else:
		 	l-=1
print(maxij)

Fixed code:
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

A = [0]
B = [0]
for i in range(n):
	A.append(A[i]+a[i])
for j in range(m):
	B.append(B[j]+b[j])

#print(A,B)

maxij = 0
l = m
for i in range(n+1):
	for j in range(m):
#		print(i,l,A[i],B[l],k)
		if(l == -1):
			break
		elif((A[i]+B[l]) <= k):
		 	maxij=max(maxij,i+l)
#		 	print("mm",maxij)
		 	break
		else:
		 	l-=1
print(maxij)
Buggy code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
for i in range(1,n):
    a[i] += a[i-1]
for i in range(1,m):
    b[i] += b[i-1]
a = [0]+a
b = [0]+b

ans = 0
ALL = 0
from bisect import bisect
for i in range(n+1):
    ALL = a[i]
    if ALL > k:
        continue
    else:idx = bisect(b,k-ALL)
    #print(i,ALL,idx)
        ans = max(ans,i+idx-1)
print(ans)

Fixed code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
for i in range(1,n):
    a[i] += a[i-1]
for i in range(1,m):
    b[i] += b[i-1]
a = [0]+a
b = [0]+b

ans = 0
ALL = 0
from bisect import bisect
for i in range(n+1):
    ALL = a[i]
    if ALL > k:
        continue
    else:
        idx = bisect(b,k-ALL)
    #print(i,ALL,idx)
        ans = max(ans,i+idx-1)
print(ans)
Buggy code:
import bisect
n, m, k = map(int, input().split())
aList = list(map(int, input().split()))
bList = list(map(int, input().split()))

cList = [0]
dList = [0]
for a in aList:
    t = a + cList[-1]
    if t <= k:
        cList.append(a + cList[-1])
    else:
        break
for b in bList:
    t = b + dList[-1]
    if t <= k:
        dList.append(b + dList[-1])
    else:
        break
cList.pop(0)
dList.pop(0)
n = len(cList)
m = len(dList)
print(cList, dList)

if len(cList) == 0:
    print(bisect.bisect_right(dList, k))
else:
    a = 0
    for i in range(0, n+1):
        if i == n:
            lim = k
        else:
            lim = k - cList[n-1-i]
        a = max(a, n - i + bisect.bisect_right(dList, lim))
    print(a)

Fixed code:
import bisect
n, m, k = map(int, input().split())
aList = list(map(int, input().split()))
bList = list(map(int, input().split()))

cList = [0]
dList = [0]
for a in aList:
    t = a + cList[-1]
    if t <= k:
        cList.append(a + cList[-1])
    else:
        break
for b in bList:
    t = b + dList[-1]
    if t <= k:
        dList.append(b + dList[-1])
    else:
        break
cList.pop(0)
dList.pop(0)
n = len(cList)
m = len(dList)

if len(cList) == 0:
    print(bisect.bisect_right(dList, k))
else:
    a = 0
    for i in range(0, n+1):
        if i == n:
            lim = k
        else:
            lim = k - cList[n-1-i]
        a = max(a, n - i + bisect.bisect_right(dList, lim))
    print(a)
Buggy code:
#C
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
for i in range(n):
    asum.append(asum[-1]+a[i])
for i in range(m):
    bsum.append(bsum[-1+b[i]])
ans=0
for i in range(n+1):
    if asum[i]>0:
        break
    while asum[i]+bsum[m]>0 and m>0:
        m-=1
    ans=(ans,i+m)
print(ans)

Fixed code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
for i in range(n):
    asum.append(asum[-1]+a[i])
for i in range(m):
    bsum.append(bsum[-1]+b[i])
ans=0
for i in range(n+1):
    if asum[i]>k:
        break
    while asum[i]+bsum[m]>k and m>0:
        m-=1
    ans=max(ans,i+m)
print(ans)
Buggy code:
from itertools import accumulate

N, M, K = map(int, input().split())
a = list(accumulate(int(i) for i in input().split(), initial=0))
b = list(accumulate(int(i) for i in input().split(), initial=0))

cnt = 0
best0 = M
for i in range(N+1):
    ai = a[i]
    for j in range(best0, -1, -1):
        bj = b[j]
        if ai + bj <= K:
            cnt = max(cnt, i + j)
            best0 = j
            break

print(cnt)

Fixed code:
from itertools import accumulate

N, M, K = map(int, input().split())
A = list(accumulate(int(i) for i in input().split()))
B = list(accumulate(int(i) for i in input().split()))

a,b = [0],[0]
for ai in A:
    a.append(ai)
for bj in B:
    b.append(bj)

cnt = 0
best0 = M
for i in range(N+1):
   ai = a[i]
   for j in range(best0, -1, -1):
       bj = b[j]
       if ai + bj <= K:
           cnt = max(cnt, i + j)
           best0 = j
           break

print(cnt)
Buggy code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

from itertools import accumulate
a = list(accumulate(a))
b = list(accumulate(b))

from collections import deque
u = deque([0])
a.append(0)

import bisect
for i in range(n+1):
    if k-a[i]>=0:
        index = bisect.bisect_left(b,k-a[i])
        u.append(index+i)
    else:
        break
print(max(u))


Fixed code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

from itertools import accumulate
a = list(accumulate(a))
b = list(accumulate(b))

from collections import deque
u = deque([0])
a.insert(0,0)

import bisect
for i in range(n+1):
    if k-a[i]>=0:
        index = bisect.bisect_right(b,k-a[i])
        u.append(index+i)
    else:
        break
print(max(u))
Buggy code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = []
b = []
p = 0
for i in range(N):
  p += A[i]
  a.append(p)
q = 0
for j in range(M):
  q += B[j]
  b.append(q)
ans = 0
j = M - 1
for i in range(N):
  while j >= 0:
    if a[i] + b[j] < K:
      ans = i + j + 2
      break
    j -= 1
  if j < 0:
    break
print(ans)

Fixed code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]
b = [0]
p = 0
for i in range(N):
  p += A[i]
  a.append(p)
q = 0
for j in range(M):
  q += B[j]
  b.append(q)
ans = 0
j = M
for i in range(N+1):
  if a[i] > K:
    break
  while a[i] + b[j] > K:
    j -= 1
  ans = max(ans, i + j)
print(ans)
Buggy code:

n,m,k = map(int,input().split())

a = list(map(int,input().split()))

b = list(map(int,input().split()))

x = [0]

y = [0]

for i in range(n):
    x.append(x[i]+a[i])

for i in range(m):
    y.append(y[i]+b[i])

ans = 0

cnt = m

for i in range(n+1):
    
    if x[i]<0:
        break
    
    while y[cnt]>k-x[i]:
        cnt -= 1
        
    ans = max(ans,cnt+i)
    
print(ans)

Fixed code:
n,m,k = map(int,input().split())

a = list(map(int,input().split()))

b = list(map(int,input().split()))

x = [0]

y = [0]

for i in range(n):
    x.append(x[i]+a[i])

for i in range(m):
    y.append(y[i]+b[i])

ans = 0

cnt = m

for i in range(n+1):
    
    if k-x[i]<0:
        break
    
    while y[cnt]>k-x[i]:
        cnt -= 1
        
    ans = max(ans,cnt+i)
    
print(ans)
Buggy code:
import sys
n,m,k=map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

ans = 1
c = [0]
d = [0]
for i in range(1,n+1):
    c.append(c[i-1] + a[i-1])
    if(c[i] > k):
        c.pop()
        break
for i in range(1,m+1):
    d.append(d[i-1] + b[i-1])
    if(d[i] > k):
        d.pop()
        break


leng = len(c)
lend = len(d)
ans = leng - 1
temp = 0
for i in range(leng):
    p = c[leng-i-1]
    t = temp
    while(t < lend and p+d[temp] <= k):
        t += 1
        if(t==lend):
            print(leng-i-2+t)
            sys.exit()
    ans = max(ans,leng-i-2+t)
    temp = t

print(ans)

Fixed code:
import sys
n,m,k=map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

ans = 1
c = [0]
d = [0]
for i in range(1,n+1):
    c.append(c[i-1] + a[i-1])
    if(c[i] > k):
        c.pop()
        break
for i in range(1,m+1):
    d.append(d[i-1] + b[i-1])
    if(d[i] > k):
        d.pop()
        break


leng = len(c)
lend = len(d)
ans = leng - 1
temp = 0
for i in range(leng):
    p = c[leng-i-1]
    t = temp
    while(t < lend and p+d[t] <= k):
        t += 1
        if(t==lend):
            print(max(ans,leng-i-2+t))
            sys.exit()
    ans = max(ans,leng-i-2+t)
    temp = t

print(ans)
Buggy code:
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import accumulate
def main():
    n, m, k = map(int,input().split())
    A = [0] + list(map(int,input().split()))
    B = [0] + list(map(int,input().split()))
    A = list(accumulate(A))
    B = list(accumulate(B))
    ans = 0
    j = m
    for i in range(n + 1):
        if A[i] > k:
            break
        while A[i] + B[j] > k:
            j -= 1
        ans = max(ans, i + j)
        print(i, j, ans)
    print(ans)


if __name__=='__main__':
    main()

Fixed code:
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import accumulate
def main():
    n, m, k = map(int,input().split())
    A = [0] + list(map(int,input().split()))
    B = [0] + list(map(int,input().split()))
    A = list(accumulate(A))
    B = list(accumulate(B))
    ans = 0
    j = m
    for i in range(n + 1):
        if A[i] > k:
            break
        while A[i] + B[j] > k:
            j -= 1
        ans = max(ans, i + j)
    print(ans)


if __name__=='__main__':
    main()
Buggy code:
import bisect
n,m,k = map(int,input().split())

a = [0 for _ in range(n)]
b = [0 for _ in range(m)]

a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]

mx = sum(a)+sum(b)

a_sum = [0 for _ in range(n)]
b_sum = [0 for _ in range(m)]

sm = 0
for i in range(n):
    sm += a[i]
    a_sum[i] = sm

sm = 0
for i in range(m):
    sm += b[i]
    b_sum[i] = sm


#print(a_sum)
def solve():
    
    caca = bisect.bisect_left(b_sum,k)
    
    for i in range(n):
        a_a = a_sum[i]
        rd = k - a_a
        if(rd < 0):
            continue

        b_b = bisect.bisect_left(b_sum,rd)
        caca_tmp = i + 1 + b_b
        caca = max(caca,caca_tmp)
        #print(i,b_b,rd)
    
    print(caca)



solve()


Fixed code:
import bisect
n,m,k = map(int,input().split())

a = [0 for _ in range(n)]
b = [0 for _ in range(m)]

a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]

mx = sum(a)+sum(b)

a_sum = [0 for _ in range(n)]
b_sum = [0 for _ in range(m)]

sm = 0
for i in range(n):
    sm += a[i]
    a_sum[i] = sm

sm = 0
for i in range(m):
    sm += b[i]
    b_sum[i] = sm


#print(a_sum)
def solve():
    if(k >= mx):
        print(n+m)
        return
    
    
    caca = bisect.bisect_right(b_sum,k)
    
    for i in range(n):
        a_a = a_sum[i]
        rd = k - a_a
        if(rd < 0):
            continue

        b_b = bisect.bisect_right(b_sum,rd)
        caca_tmp = i + 1 + b_b
        caca = max(caca,caca_tmp)
        #print(i,b_b,rd)
    
    print(caca)



solve()
Buggy code:
N, M, K = map(int, input().split())
a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))

i_l, j_l = [0], [0]

best0 = M
ans = 0

for i in range(N):
    i_l.append(i_l[i] + a_l[i])

for i in range(M):
    j_l.append(j_l[i] + b_l[i])

# for j in range(M):
#     total += b_l[j]
#     if total > K:
#         best0 = j-1
#         break
#     elif total == K:
#         best0 = j
#     else:
#         continue

for k in range(N+1):
    if i_l[i] > K:
        break
    while i_l[k] + j_l[best0] > K:
        best0 -= 1
    ans = max(ans, k+best0)
print(ans)
    

Fixed code:
N, M, K = map(int, input().split())
a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))

i_l, j_l = [0], [0]

best0 = M
ans = 0

for i in range(N):
    i_l.append(i_l[i] + a_l[i])

for i in range(M):
    j_l.append(j_l[i] + b_l[i])

# for j in range(M):
#     total += b_l[j]
#     if total > K:
#         best0 = j-1
#         break
#     elif total == K:
#         best0 = j
#     else:
#         continue

for k in range(N+1):
    if i_l[k] > K:
        break
    while i_l[k] + j_l[best0] > K:
        best0 -= 1
    ans = max(ans, k+best0)
print(ans)
Buggy code:
from itertools import accumulate
from bisect import bisect_left

n, m, k = map(int, input().split())
a = [0] + list(accumulate(list(map(int, input().split()))))
b = [0] + list(accumulate(list(map(int, input().split()))))
ans = 0

for i in range(n + 1):
    if a[i] + b[bisect_left(b, k - a[i])] <= k:
        ans = max(ans, i + bisect_left(b, k - a[i]))
    
print(ans)

Fixed code:
from itertools import accumulate
from bisect import bisect_right

n, m, k = map(int, input().split())
a = [0] + list(accumulate(list(map(int, input().split()))))
b = [0] + list(accumulate(list(map(int, input().split()))))
ans = 0

for i in range(n + 1):
    j = bisect_right(b, k - a[i])
    if a[i] + b[j - 1] <= k:
            ans = max(ans, i + (j - 1))
    
print(ans)
Buggy code:
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a_max = 0
sum = 0
for i in range(n):
  sum += A[i]
  if sum > k:
    sum -= A[i]
    break
  a_max += 1
  
ans = a_max
kotae =ans
j = 0

print(a_max, 0)
for i in range(m):
  sum += B[i]
  ans += 1
  while sum > k and j < a_max:
    sum -= A[a_max-1-j]
    ans -= 1
    j += 1
  if sum > k:
    print(kotae)
    exit()
  kotae = max(kotae, ans)
  if a_max-j == 0:
    break
  
print(kotae)
  
    
    
  

Fixed code:
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a_max = 0
sum = 0
for i in range(n):
  sum += A[i]
  if sum > k:
    sum -= A[i]
    break
  a_max += 1
  
ans = a_max
kotae =ans
j = 0


for i in range(m):
  sum += B[i]
  ans += 1
  while sum > k and j < a_max:
    sum -= A[a_max-1-j]
    ans -= 1
    j += 1
  if sum > k:
    print(kotae)
    exit()
  kotae = max(kotae, ans)

  
print(kotae)
Buggy code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

c=[0]
d=[0]

for i in range(n):
  c.append(c[-1]+a[i])
  
for j in range(m):
  d.append(d[-1]+b[j])

ans=0
for x in range(n):
  l=c[x+1]-c[x]
  B=0
  if l<=k:
    h=k-l
    mi=0
    ma=m+1
    while ma-mi>1:
      mid=(mi+ma)//2
      if d[mid]<=h:
        mi=mid
      elif d[mid]<h:
        mi=mid
    B=mi
        
  ans=max(ans,x+1+B)
    
print(ans)


Fixed code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

c=[0]
d=[0]

for i in range(n):
  c.append(c[-1]+a[i])
  
for j in range(m):
  d.append(d[-1]+b[j])

ans=0
for x in range(n+1):
  l=c[x]
  B=0
  if l<=k:
    h=k-l
    mi=0
    ma=m+1
    while ma-mi>1:
      mid=(mi+ma)//2
      if d[mid]<=h:
        mi=mid
      elif d[mid]>h:
        ma=mid
    B=mi
    
    ans=max(ans,x+B)
        
  
    
print(ans)
Buggy code:

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
'''
with open('./b20.txt') as f:
    N, M, K = map(int, f.readline().split())
    A = list(map(int, f.readline().split()))
    B = list(map(int, f.readline().split()))
'''

A_cnt = 0
B_cnt = 0
ans = 0
nowK = K
for A_idx in range(N):
    if nowK < A[A_idx]:
        break
    ans += 1
    nowK -= A[A_idx]
    A_cnt += 1
for B_idx in range(M):
    if nowK < B[B_idx]:
        break
    ans += 1
    nowK -= B[B_idx]
    B_cnt += 1
tmp_ans = ans
finish = False
for i in range(A_cnt, 0, -1):
    nowK += A[i]
    tmp_ans -= 1
    for j in range(B_cnt, M):
        if finish or nowK < B[j]:
            break
        nowK -= B[j]
        tmp_ans += 1
        if j == M - 1:
            finish = True
    B_idx = j
    ans = max(tmp_ans, ans)
print(ans)




Fixed code:

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
'''
with open('./b09.txt') as f:
    N, M, K = map(int, f.readline().split())
    A = list(map(int, f.readline().split()))
    B = list(map(int, f.readline().split()))
'''
A_cnt = 0
B_cnt = 0
ans = 0
nowK = K
for A_idx in range(N):
    if nowK < A[A_idx]:
        break
    ans += 1
    nowK -= A[A_idx]
    A_cnt += 1
for B_idx in range(M):
    if nowK < B[B_idx]:
        break
    ans += 1
    nowK -= B[B_idx]
    B_cnt += 1
tmp_ans = ans
finish = False
for i in range(A_cnt, 0, -1):
    nowK += A[i - 1]
    tmp_ans -= 1
    for j in range(B_cnt, M):
        if finish or nowK < B[j]:
            break
        nowK -= B[j]
        tmp_ans += 1
        B_cnt += 1
    ans = max(tmp_ans, ans)
print(ans)
Buggy code:
import bisect
N, M, K = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
A_cumulative_sum = [A[0]]
B_cumulative_sum = [B[0]]
for i in range(1, N):
    A_cumulative_sum.append(A[i] + A[i - 1])
for i in range(1, M):
    B_cumulative_sum.append(B[i] + B[i - 1])

for i in range(N):
    if K < A_cumulative_sum[i]:
        remaining_time = K
        idx = bisect.bisect_right(B_cumulative_sum, remaining_time)
        ans = max(ans, i + 1 + idx)
        break
    else:
        remaining_time = K - A_cumulative_sum[i]
        idx = bisect.bisect_right(B_cumulative_sum, remaining_time)
        ans = max(ans, i + 1 + idx)
        
print(ans)

Fixed code:
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
A_cumulative_sum = [0]
B_cumulative_sum = [B[0]]
for i in range(N):
    A_cumulative_sum.append(A[i] + A_cumulative_sum[i])
for i in range(1, M):
    B_cumulative_sum.append(B[i] + B_cumulative_sum[i - 1])

for i in range(N + 1):
    if K < A_cumulative_sum[i]:
        remaining_time = K
        idx = bisect.bisect_right(B_cumulative_sum, remaining_time)
        ans = max(ans, idx)
        break
    else:
        remaining_time = K - A_cumulative_sum[i]
        idx = bisect.bisect_right(B_cumulative_sum, remaining_time)
        ans = max(ans, i + idx)
print(ans)

# 113897
Buggy code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_sum = [0]
b_sum = [0]
for i in range(n):
    a_sum.append(a_sum[i] + a[i])
for i in range(m):
    b_sum.append(b_sum[j] + b[j])
    
ans, j = 0, m
for i in range(n + 1):
    if a[i] > k:
        break
    while b[i] > k - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Fixed code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_sum = [0]
b_sum = [0]
for i in range(n):
    a_sum.append(a_sum[i] + a[i])
for i in range(m):
    b_sum.append(b_sum[i] + b[i])
    
ans, j = 0, m
for i in range(n + 1):
    if a_sum[i] > k:
        break
    while b_sum[j] > k - a_sum[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
Buggy code:
from sys import stdin, stdout
input = stdin.readline
print = stdout.write
n, m, k = map(int, input().split())
a, b = [0], [0]
a += list(map(int, input().split())),
b += list(map(int, input().split())),
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]
i, j, z = 0, m, 0
while i <= n and a[i] <= k:
    while b[j] > k - a[i]:
        j -= 1
    z = max(z, i + j)
    i += 1
print(str(z))

Fixed code:
from sys import stdin, stdout
input = stdin.readline
print = stdout.write 
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]
i, j, z = 0, m, 0
while i <= n and a[i] <= k:
    while b[j] > k - a[i]:
        j -= 1
    z = max(z, i + j)
    i += 1
print(str(z))