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()))
  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)


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]
T = 0
ans = 0

for i in range(N):
  a.append(a[i] + A[i])

for i in range(M):
  b.append(b[i] + B[i])

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:
from itertools import accumulate
from bisect import bisect_right
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = list(map(int, input().split()))
SA = list(accumulate(A))
SB = list(accumulate(B))

ans = 0
for i in range(len(SA)):
    if tmp := K-SA[i] < 0:
        break
    ans = max(ans, bisect_right(SB, tmp))
print(ans)

Fixed code:
from itertools import accumulate
from bisect import bisect_right
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = list(map(int, input().split()))
SA = list(accumulate(A))
SB = list(accumulate(B))

ans = 0
for n in range(len(SA)):
    tmp = K-SA[n]
    if tmp < 0:
        break
    m = bisect_right(SB, tmp)
    ans = max(ans, n+m)
print(ans)
Buggy code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
asum = [0]*(n+1)
bsum = [0]*(m+1)
for i in range(n):
	asum[i+1] = a[i] + asum[i]
for j in range(m): 
	bsum[i+1] = b[j] + bsum[j]
j = m
res = 0
for i in range(n+1):
	if asum[i] > k:
		break
	while asum[i] + bsum[j] > k:
		j-=1
	res = max(res,i+j)
print(res) 



Fixed code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
asum = [0]*(n+1)
bsum = [0]*(m+1)
for i in range(n):
	asum[i+1] = a[i] + asum[i]
for j in range(m): 
	bsum[j+1] = b[j] + bsum[j]
j = m
res = 0
for i in range(n+1):
	if asum[i] > k:
		break
	while asum[i] + bsum[j] > k:
		j-=1
	res = max(res,i+j)
print(res)
Buggy code:
n, m, k = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
SA, SB = [0], [0]
for i in range(n):
    SA.append(SA[i] + A[i])
for j in range(m):
    SB.append(SB[j] + B[j])
ans, tmp = 0, m
for i in range(n + 1):
    if SA[i] > k:
        break
    for j in range(tmp, 0, -1):
        if SA[i] + SB[j] <= k:
            break
    tmp = j
    ans = max(ans, i + j)
print(ans)


Fixed code:
n, m, k = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
SA, SB = [0], [0]
for i in range(n):
    SA.append(SA[i] + A[i])
for j in range(m):
    SB.append(SB[j] + B[j])
ans, tmp = 0, m
for i in range(n + 1):
    if SA[i] > k:
        break
    for j in range(tmp + 1)[::-1]:
        if SA[i] + SB[j] <= k:
            break
    ans = max(ans, i + j)
    tmp = j
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(len(a)):
  A.append(a[i] + A[i])
for i in range(len(b)):
  B.append(b[i] + B[i])

num = 0
x = m 

for i in range(len(A)+1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x )
  
print(num)




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])

num,x = 0,m

for i in range(n+1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x)
  
print(num)
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(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-=117ans=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:
import sys
n,m,k =map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

t = k
i = 0
asum = [0]* n
bsum = [0]* m
suma = 0
sumb = 0
j =0
for  i in a:
    suma += i
    asum[j]= suma
    j +=1
j =0
for  i in b:
    sumb += i
    bsum[j] = sumb
    j +=0

count = 1
ans = 1

for j in range(m + n-1):
    count = 0
    for i in range(ans):
        if asum[ans-1]+bsum[ans]<=k:
            count = 1

    if count ==1:
        ans +=1
    else:
        break
print(min(ans,m+n))

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

t = k
i = 0
asum = [0]* (n+1)
bsum = [0]* (m+1)
suma = 0
sumb = 0

for  i in range(n):
    suma += a[i]
    asum[i+1]= suma


for  i in range(m):
    sumb += b[i]
    bsum[i+1] = sumb

count = 1
ans = 0

for i in range(n+1):
    if ans < i :
        if asum[i] <= k:
            ans=i
    else:
        for j in range(ans-i,m+1,1):
            if asum[i] + bsum[j]<=k:
                if i+j>ans:
                    ans=i+j
            else:
                break

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


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

aa = [0]
bb = [0]
for i in range(n):
    aa.append(aa[-1]+a[i])
for i in range(m):
    bb.append(bb[-1]+b[i])

d = 0
ans = 0
for i in range(n, -1, -1):
    c = k - aa[i]
    if c >= 0:
        for j in range(d, m+1):
            if bb[j] <= c:
                d = j
            else:
                break
        ans = max(ans, i+d)
print(ans)
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(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)

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()))
 
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)

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=0
j=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:
import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_t, b_t = [0], [0]
for i in range(n):
    a_t.append(a_t[i] + a[i])
for i in range(m):
    b_t.append(b_t[i] + b[i])
ans = 0
j = m
for i in range(n):
    if (a[i] > k):
        break
    while(a_t[i] + b_t[j] > k):
        j -= 1
    ans = max(ans, i + j)
print(ans)



Fixed code:
import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_t, b_t = [0], [0]
for i in range(n):
    a_t.append(a_t[i] + a[i])
for i in range(m):
    b_t.append(b_t[i] + b[i])
ans = 0
j = m
for i in range(n+1):
    if (a_t[i] > k):
        break
    while(a_t[i] + b_t[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()))
A=[0]
for i in range(n):
  A.append(a[i])
B=[0]
for i in range(m):
  B.append(b[i])
ans=0
j=m
for i in range(n+1):
  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=[0]
for i in range(n):
  A.append(A[i]+a[i])
B=[0]
for i in range(m):
  B.append(B[i]+b[i])
ans=0
j=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())
INF = int(1e18)
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = A[:]
B = B[:]
i, j = 0, 0
mcnt = 0
tmp = M+1
ccnt = 0
while tmp != 0:
  ccnt += 1
  tmp //= 2
LA = [0 for _ in range(N+1)]
LB = [0 for _ in range(M+1)]
for i in range(N):
  LA[i+1] = LA[i] + A[i]
for i in range(M):
  LB[i+1] = LB[i] + B[i]
for i in range(N+1):
  l, r = 0, M+1
  d = (l + r) // 2
  if LA[i] <= K:
    if LB[M] + LA[i] <= K:
      mcnt = max(i + M, mcnt)
    else:
      for j in range(ccnt + 1):
        if LB[d] + LA[i] <= K:
          l = d
          d = (l + r) // 2
        else:
          r = d
          d = (l + r) // 2
      print(d)
      mcnt = max(i + d, mcnt)
  else:
    break
print(mcnt)

Fixed code:
N, M, K = map(int, input().split())
INF = int(1e18)
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = A[:]
B = B[:]
i, j = 0, 0
mcnt = 0
tmp = M+1
ccnt = 0
while tmp != 0:
  ccnt += 1
  tmp //= 2
LA = [0 for _ in range(N+1)]
LB = [0 for _ in range(M+1)]
for i in range(N):
  LA[i+1] = LA[i] + A[i]
for i in range(M):
  LB[i+1] = LB[i] + B[i]
for i in range(N+1):
  l, r = 0, M+1
  d = (l + r) // 2
  if LA[i] <= K:
    if LB[M] + LA[i] <= K:
      mcnt = max(i + M, mcnt)
    else:
      for j in range(ccnt + 1):
        if LB[d] + LA[i] <= K:
          l = d
          d = (l + r) // 2
        else:
          r = d
          d = (l + r) // 2
      mcnt = max(i + d, mcnt)
  else:
    break
print(mcnt)
Buggy code:
import bisect

N, M, K = map(int, input().split())
Alist = [0] + list(map(int, input().split()))
Blist = list(map(int, input().split()))

B = [Blist[0]]
for b in Blist[1:]:
    B.append(b + B[-1])

print(B)

sums = 0
ans = 0
for idx, a in enumerate(Alist):
    sums += a
    if sums > K:
        break
    k = K - sums
    tmp = bisect.bisect_right(B, k)
    ans = max(ans, idx + tmp)

print(ans)

Fixed code:
import bisect

N, M, K = map(int, input().split())
Alist = [0] + list(map(int, input().split()))
Blist = list(map(int, input().split()))

B = [Blist[0]]
for b in Blist[1:]:
    B.append(b + B[-1])


sums = 0
ans = 0
for idx, a in enumerate(Alist):
    sums += a
    if sums > K:
        break
    k = K - sums
    tmp = bisect.bisect_right(B, k)
    ans = max(ans, idx + tmp)

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()))
for i in range(1,len(A)):
    A[i]+=A[i-1]
for i in range(1,len(B)):
    B[i]+=B[i-1]
honn=0
for i in range(len(A)):
    s=K-A[i]
    a=bisect.bisect(B,s)
    print(s)
    if i+1+a>honn:
        honn=i+1+a
print(honn)

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

honn=bisect.bisect(B,K)
#print(honn)
for i in range(len(A)):
    s=K-A[i]
    if s>=0:
        
        a=bisect.bisect(B,s)
        #print(s)
        if i+1+a>honn:
            honn=i+1+a
print(honn)
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]

j,best=0,0
for j in range(M):
  if B[j] > K: break
  else:best=j+1
for i in range(N):
  if A[i]>K:break
  c = K-A[i]
  while j < M:
    if B[j]> c:break
    else: j+=1
  if j==0:break
  else:
    best=max(best,i+1+j)
print(best)





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-1]
for i in range(1,M+1):
  B[i]+=B[i-1]

best=0
j=M
for i in range(0,N+1):
  while j>0:
    if A[i]+B[j]<=K:
      break
    else: j-=1
  if A[i]+B[j]<=K:
    best=max(best,i+j)
  pass
print(best)
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(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)


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())
al=[int(i) for i in input().split()]
bl=[int(i) for i in input().split()]
for i in range(1,n):
    al[i]+=al[i-1]
for i in range(1,m):
    bl[i]+=bl[i-1]
ans=0
j=m
for i in in range(n):
    if al[i]>k:
        break
    while bl[j]>al[i]-k:
        j-=1
    ans=max(ans,i+j)
print(ans)


Fixed code:
n,m,k=map(int,input().split())
al=[int(i) for i in input().split()]
bl=[int(i) for i in input().split()]
aa,bb=[0],[0]
for i in range(n):
    aa.append(aa[i]+al[i])
for i in range(m):
    bb.append(bb[i]+bl[i])
ans=0
j=m
for i in range(n+1):
    if aa[i]>k:
        break
    while bb[j]>k-aa[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)
Buggy code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))
la = [0]
lb = [0]
mx = 0
for i in range(n): 
    la.append(la[i]+a[i])
for j in range(m):
    lb.append(lb[j]+b[j])
for l in range(len(la)):
    if la[l] > k:
        break
    cnt = l
    q = 0
    p = 0
    while la[l] + p <= k:
        q += 1
        if q == len(lb):
            cnt += len(lb)-1
            break
        p = lb[q] 
    if cnt == l:
        cnt += q - 1
    if cnt > mx:
        mx = cnt
print(mx)


Fixed code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
la = [0]
lb = [0]
mx = 0
for i in range(n): 
    if la[i] + a[i] > k:
        break
    la.append(la[i]+a[i])
for j in range(m):
    if lb[j] + b[j] > k:
        break
    lb.append(lb[j]+b[j])
now = len(lb)-1
for l in range(len(la)):
    cnt = l
    q = now
    while la[l] + lb[q] > k:
        q -= 1
    now = q
    cnt += q
    if cnt > mx:
        mx = cnt
print(mx)
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, len(A)):
    A[i] += A[i - 1]
for i in range(1, len(B)):
    B[i] += B[i - 1]
A.insert(0, 0)
B.insert(0, 0)
r = 0
for i, a in enumerate(A):
    min_idx = 0
    max_idx = len(B) - 1
    while min_idx < max_idx:
        j = (min_idx + max_idx + 1) // 2
        k = K - A[i] - B[j]
        if k < 0:
            max_idx = j - 1
        else:
            min_idx = j
    r = max(r, i + j)
print(r)

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, len(A)):
    A[i] += A[i - 1]
for i in range(1, len(B)):
    B[i] += B[i - 1]
A.insert(0, 0)
B.insert(0, 0)
r = 0
for i, a in enumerate(A):
    min_idx = 0
    max_idx = len(B) - 1
    while min_idx < max_idx:
        j = (min_idx + max_idx + 1) // 2
        k = K - A[i] - B[j]
        if k < 0:
            max_idx = j - 1
        else:
            min_idx = j
    j = min_idx
    while j + 1 < len(B) and K - A[i] - B[j + 1] >= 0:
        j += 1
    if K - A[i] - B[j] >= 0:
        r = max(r, i + j)
print(r)
Buggy code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
time_of_A = [A[0]]
for i in range(1, N):
  time_of_A.append(time_of_A[i-1]+A[i])
B = list(map(int, input().split()))
time_of_B = [B[0]]
for i in range(1, M):
  time_of_B.append(time_of_B[i-1]+B[i])

book = []
for i in range(N):
  if time_of_A[i] <= K:
    book.append(i+1)

start = M-1
for i in range(N):
  j = start
  time = 10 ** 9 + 1
  while time > K and j >= 0:
    time = time_of_A[i] + time_of_B[j]
    j -= 1
  if time <= K:
    book.append(i+j+3)
    j +=1
    start = j
  else:
    break
print(max(book))

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

book = [0]
for i in range(N):
  if time_of_A[i] <= K:
    book.append(i+1)
for i in range(M):
  if time_of_B[i] <= K:
    book.append(i+1)


start = M-1
for i in range(N):
  j = start
  time = 10 ** 9 + 1
  while time > K and j >= 0:
    time = time_of_A[i] + time_of_B[j]
    j -= 1
  if time <= K:
    book.append(i+j+3)
    j +=1
    start = j
  else:
    break
print(max(book))
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[1])
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)

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 = 0
j = 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:
def bisect(x):
    l,r=-1,M+1
    while(r-l>1):
        mid=(l+r)//2
        if cumB[mid]>=x:
            r=mid
        else:
            l=mid
    return l

N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cumB=[0]*(M+1)
for i in range(M):
    cumB[i+1]=cumB[i]+B[i]
c=0
ans=0
for i in range(N):
    c+=A[i]
    if c>K:
        break
    r=K-c
    b=bisect(r+1)
    ans=max(ans,i+1+b)
    print(b)
print(ans)

Fixed code:
def bisect(x):
    l,r=-1,M+1
    while(r-l>1):
        mid=(l+r)//2
        if cumB[mid]>=x:
            r=mid
        else:
            l=mid
    return l

N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cumB=[0]*(M+1)
for i in range(M):
    cumB[i+1]=cumB[i]+B[i]
c=0
ans=0
for i in range(N+1):
    if c>K:
        break
    r=K-c
    b=bisect(r+1)
    ans=max(ans,i+b)
    if i!=N:
        c+=A[i]
print(ans)
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(B[i] + b[i])

print(A)
print(B)
    
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)

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:
import bisect
from itertools import accumulate

N , M , K = map(int , input().split())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
a.insert(0,0)

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


Fixed code:
import bisect
from itertools import accumulate

N , M , K = map(int , input().split())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
a.insert(0,0)

ans = 0
for i in range(N + 1):
    if a[i] > K:
        break
    ans = max(ans , i + bisect.bisect_right(b, K - a[i]))
print(ans)
Buggy code:
N,M,K=map(int,input().split())
A =list(map(int,input().split()))
B =list(map(int,input().split()))
Sum = 0
Al = [0]
Bl = [0]
for i in range(N):
    Sum += A[i]
    Al.append(Sum)
Sum = 0
for j in range(M):
    Sum += B[i]
    Bl.append(Sum)
ans, j = 0, M
for i in range(N+1):
    if Al[i] > K:
        break
    while Bl[j] > K - Al[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()))
Sum = 0
Al = [0]
Bl = [0]
for i in range(N):
    Sum += A[i]
    Al.append(Sum)
Sum = 0
for j in range(M):
    Sum += B[j]
    Bl.append(Sum)
ans, j = 0, M
for i in range(N+1):
    if Al[i] > K:
        break
    while Bl[j] > K - Al[i]:
        j -= 1
    ans = max(ans,i+j)
print(ans)
Buggy code:
N,M,K = map(int, input().split())
A = map(int, input().split())
B = map(int, input().split())

sa = [0]
for i, val in enumerate(A):
  sa.append(sa[i] + val)

sb = [0]
for i, val in enumerate(B):
  sb.append(sb[i] + val)

max_num = 0
ind_max = M
for i in range(N+1):
  if(sa[i]>K):
    break
  for k in range(ind_max):
    if(sb[M-k]<=K-sa[i]):
      break
    ind_max -= 1
  
  max_num = max(max_num,i+M-k)

      
      
print(max_num)

Fixed code:
N,M,K = map(int, input().split())
A = map(int, input().split())
B = map(int, input().split())

sa = [0]
for i, val in enumerate(A):
  sa.append(sa[i] + val)

sb = [0]
for i, val in enumerate(B):
  sb.append(sb[i] + val)

max_num = 0
ind_max = M
for i in range(N+1):
  if(sa[i]>K):
    break
  c = 0
  for k in range(ind_max+1):
    if(sb[ind_max-k]<=K-sa[i]):
      break
    c += 1
  ind_max -= c
  max_num = max(max_num,i+ind_max)

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

s_a = [0]
s_b = [0]
for i in range(n):
    s_a.append(s_a[i] + a[i])
for i in range(m):
    s_b.append(s_b[i] + b[i])

ans = 0
ok = m
for i in range(n+1):
    for j in range(ok+1)[::-1]:
        if s_a[i] + s_b[j] <= k:
            ans = max(ans, i+j)
            tmp = j
    ok = tmp

print(ans)

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

s_a = [0]
s_b = [0]
for i in range(n):
    s_a.append(s_a[i] + a[i])
for i in range(m):
    s_b.append(s_b[i] + b[i])

ans = 0
tmp = m
for i in range(n+1):
    for j in range(tmp+1)[::-1]:
        if s_a[i] + s_b[j] <= k:
            ans = max(ans, i+j)
            tmp = j
            break
print(ans)