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

init = 0
init2 = 0
s = 0
for i in range(n):
  if s + a[i] <= k:
    s += a[i]
    init += 1

k2 = k - s
for i in range(m):
  if s + b[i] <= k2:
    s += b[i]
    init2 += 1

max_ = init+init2
while init-1 > 0:
  s -= a[init-1]
  init -= 1
  for i in range(init2, m):
    if s + b[i] <= k:
      s += b[i]
      init2 += 1
    else:
      break
  max_ = max(max_, init+init2)
print(max_)
      

    

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

init = 0
init2 = 0
s = 0
for i in range(n):
  if s + a[i] <= k:
    s += a[i]
    init += 1
  else:
    break

for i in range(m):
  if s + b[i] <= k:
    s += b[i]
    init2 += 1
  else:
    break

max_ = init+init2

while init > 0:
  s -= a[init-1]
  init -= 1
  for i in range(init2, m):
    if s + b[i] <= k:
      s += b[i]
      init2 += 1
    else:
      break
  max_ = max(max_, init+init2)
print(max_)
Buggy code:
N, M, K = map(int, input().split(' '))
A_ls = [0] + list(map(int, input().split(' ')))
for i in range(N):
    A_ls[i + 1] += A_ls[i]
B_ls = [0] + list(map(int, input().split(' ')))
for i in range(M):
    B_ls[i + 1] = B_ls[i]

b_cnt, rst = M, 0 
for a_cnt in range(N + 1):
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K and b_cnt >= 0:
        b_cnt -= 1
    rst = max(rst, a_cnt + b_cnt)
print(rst)

Fixed code:
N, M, K = map(int, input().split(' '))
A_ls = [0] + list(map(int, input().split(' ')))
B_ls = [0] + list(map(int, input().split(' ')))

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

for i in range(1, M+1):
    B_ls[i] += B_ls[i - 1]

a_cnt, b_cnt, rst = 0, M, 0
while a_cnt < N + 1:
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K and b_cnt > 0:
        b_cnt -= 1
    rst = max(rst, a_cnt + b_cnt)
    a_cnt += 1
print(rst)
Buggy code:
N, M, K = map(int, input().split(' '))
A_ls = [0] + list(map(int, input().split(' ')))
for i in range(len(A_ls) - 1):
    A_ls[i + 1] += A_ls[i]

B_ls = [0] + list(map(int, input().split(' ')))
for i in range(len(B_ls) - 1):
    B_ls[i + 1] += B_ls[i]

b_cnt,result = M, 0
for a_cnt in range(N):
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K:
        b_cnt -= 1
    result = max(result, a_cnt + b_cnt)
print(result)

Fixed code:
N, M, K = map(int, input().split(' '))
A_ls = [0] + list(map(int, input().split(' ')))
B_ls = [0] + list(map(int, input().split(' ')))

for i in range(1, N + 1):
    A_ls[i] += A_ls[i - 1]
for i in range(1, M + 1):
    B_ls[i] += B_ls[i - 1]

b_cnt, rst = M, 0
for a_cnt in range(N + 1):
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K:
        b_cnt -= 1
    rst = max(rst, a_cnt + b_cnt)
print(rst)
Buggy code:
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A2 = [0] * (N + 1)
for i in range(1, N + 1):
  A2[i] = A2[i - 1] + A[i - 1]

B2 = [0] * (M + 1)
for i in range(1, M + 1):
  B2[i] = B2[i - 1] + B[i - 1]

#print(A2, B2)
#print(bisect.bisect_left(B2, 300))
ans = 0
for i in range(N + 1):
  time = K - A2[i]
  if time < 0:
    print(ans)
    quit()
  else:
    index = bisect.bisect_left(B2, time) - 1
    #print(index, time, B2)
    ans = max(ans, i + index)
    
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()))

A2 = [0] * (N + 1)
for i in range(1, N + 1):
  A2[i] = A2[i - 1] + A[i - 1]

B2 = [0] * (M + 1)
for i in range(1, M + 1):
  B2[i] = B2[i - 1] + B[i - 1]

#print(A2, B2)
#print(bisect.bisect_left(B2, 300))
ans = 0
for i in range(N + 1):
  time = K - A2[i]
  if time < 0:
    print(ans)
    quit()
  else:
    index = bisect.bisect_right(B2, time) - 1
    #print(index, time, B2)
    ans = max(ans, i + index)
    
print(ans)
Buggy code:
# -*- coding: utf-8 -*-
n, m, k = map(int, input().split())

alist = input().split()
blist = input().split()

print(alist)
print(blist)

work = k
acount = 0
while (acount < n) and (work >= int(alist[acount])):
    work -= int(alist[acount])
    acount += 1

maxCount = acount
bCount = 0
for num in range(0, acount):
    if (num > 1):
        work += int(alist[acount-num])

    while (bCount < m) and (work >= int(blist[bCount])):
        work -= int(blist[bCount])
        bCount += 1
    maxCount = max(maxCount, acount-num+bCount)




print(maxCount)


Fixed code:
# -*- coding: utf-8 -*-
n, m, k = map(int, input().split())

alist = input().split()
blist = input().split()

work = k
acount = 0
while (acount < n) and (work >= int(alist[acount])):
    work -= int(alist[acount])
    acount += 1

bCount = 0
work2 = work
while (bCount < m) and (work2 >= int(blist[bCount])):
        work2 -= int(blist[bCount])
        bCount += 1


maxCount = acount + bCount
bCount = 0
for num in range(0, acount):
    work += int(alist[acount-num-1])

    while (bCount < m) and (work >= int(blist[bCount])):
        work -= int(blist[bCount])
        bCount += 1
    maxCount = max(maxCount, acount-num-1+bCount)


print(maxCount)
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 = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

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

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

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

cnt = 0
b_idx = M
for i in range(N+1):
    if a[i] > K:
        break
    for j in range(b_idx, -1, -1):
        if a[i] + b[j] <= K:
            cnt = max(cnt, i+j)
            b_idx = j
            break
print(cnt)
Buggy code:
from collections import deque
import numpy as np
n,m,k = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))

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

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

Fixed code:
from collections import deque
import numpy as np
n,m,k = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))

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

x,j = 0,m
for i in range(n+1):
    if a[i]>k:
        break
    while b[j] > k-a[i]:
        j -=1
    x = max(x,i+j)
print(x)
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])
    
v,j=0,M

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

print(v)
       


Fixed code:
N, M, K = list(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:
from collections import deque
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:
from collections import deque
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()))

totalA = [0]
totalB = [0]
sumA = 0
for i in range(N):
    sumA += A[0]
    totalA.append(sumA)
sumB = 0
for i in range(M):
    sumB += B[0]
    totalB.append(sumB)

iA = N
iB = 0
countMax = 0
while iA >= 0:
    if totalA[iA] + totalB[iB] > K:
        iA -= 1
    else:
        if iB < M:
            countMax = max(countMax, iA + iB)
            iB += 1
    elif iA == N and iB == M:
        countMax = max(countMax, iA + iB)
        break

print(countMax)



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

totalA = [0]
totalB = [0]
sumA = 0
for i in range(N):
    sumA += A[i]
    totalA.append(sumA)
sumB = 0
for i in range(M):
    sumB += B[i]
    totalB.append(sumB)

iB = M
countMax = 0
for iA in range(N+1):
  if totalA[iA]>K:
    break
  else:
    while totalA[iA] + totalB[iB] > K:
      iB -= 1
  countMax = max(countMax,iA+iB)

print(countMax)
Buggy code:
N,M,K = map(int,input().split(" "))
#print(K)
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))

time_A = [0]*(N+1)
time_B = [0]*(M+1)

for i in range(N):
    time_A[i+1] = time_A[i] + A[i]
print(time_A)
for j in range(M):
    time_B[j+1] = time_B[j] + B[j]

ans = 0
l = M

for k in range(N+1):
    if time_A[k] > K:
        break
    while time_A[k] + time_B[l] > K:
        l -= 1
    ans = max(ans,k+l)

print(ans)

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

time_A = [0]*(N+1)
time_B = [0]*(M+1)

for i in range(N):
    time_A[i+1] = time_A[i] + A[i]
for j in range(M):
    time_B[j+1] = time_B[j] + B[j]

ans = 0
l = M

for k in range(N+1):
    if time_A[k] > K:
        break
    while time_A[k] + time_B[l] > K:
        l -= 1
    ans = max(ans,k+l)

print(ans)
Buggy code:
from itertools import accumulate
from bisect import *

N, M, K = [int(n) for n in input().split()]
A = [x for x in accumulate([int(n) for n in input().split()])]
B = [x for x in accumulate([int(n) for n in input().split()])]
ans = 0
a = bisect(A, K)
for i in range(a-1, -1, -1):
  b = bisect(B, K-A[i])
  ans = max(ans, i+b)
print(ans)


Fixed code:
from itertools import accumulate
from bisect import *

N, M, K = [int(n) for n in input().split()]
A = [0]+[x for x in accumulate([int(n) for n in input().split()])]
B = [0]+[x for x in accumulate([int(n) for n in input().split()])]
#print(A)
#print(B)
ans = 0
a = bisect_right(A, K)
#print(a)
for i in range(a):
  b = bisect_right(B, K-A[i])
  ans = max(ans, i+b)
#  print(ans, i, b)
print(ans-1)
Buggy code:
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

acum = [0] * (n + 1)
bcum = [0] * (m + 1)

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

for j in range(m):
    bcum[j + 1] = bcum[j] + b[j]

max_ans = 0
j = m
for i in range(n):
    if acum[i] > k:
        break
    while acum[i] + bcum[j] > k:
        j -= 1
    max_ans = max(max_ans, i + j)

print(max_ans)

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

acum = [0] * (n + 1)
bcum = [0] * (m + 1)

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

for j in range(m):
    bcum[j + 1] = bcum[j] + b[j]

max_ans = 0
j = m
for i in range(n + 1):
    if acum[i] > k:
        break
    while acum[i] + bcum[j] > k:
        j -= 1
    max_ans = max(max_ans, i + j)

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

s=0
ac=0
bc=0
max=0

for i in range(n):
  s=s+a[i]
  ac=ac+1
  if s > k:
    s=s-a[i]
    ac=ac-1
    break
for i in range(m):
  s=s+b[i]
  bc=bc+1
  if s > k:
    s=s-b[i]
    bc=bc-1
    break

max=ac+bc

flag=0
while flag==0 && ac!=0:
  ac=ac-1
  s=s-a[ac]
  while s <= k:
    bc=bc+1
    if bc > m:
      flag=1
      break
    s=s+b[bc-1]
  bc=bc-1
  if flag==0:
    s=s-b[bc-1]
  
  if max < ac+bc:
    max=ac+bc
    
print(max)

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

s=0
ac=0
bc=0
max=0

for i in range(n):
  s=s+a[i]
  ac=ac+1
  if s > k:
    s=s-a[i]
    ac=ac-1
    break
for i in range(m):
  s=s+b[i]
  bc=bc+1
  if s > k:
    s=s-b[i]
    bc=bc-1
    break

max=ac+bc

flag=0
while flag==0 and ac!=0:
  ac=ac-1
  s=s-a[ac]
  while s <= k:
    bc=bc+1
    if bc > m:
      flag=1
      break
    s=s+b[bc-1]
  bc=bc-1
  if flag==0:
    s=s-b[bc]
  
  if max < ac+bc:
    max=ac+bc
    
print(max)
Buggy code:
def abc172c_tsundoku():
    n, m, k = 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(1, n + 1):
        A[i] = A[i - 1] + a[i - 1]
        if A[i] > k:
            n = i - 1
            break
    for i in range(1, m + 1):
        B[i] = B[i - 1] + b[i - 1]
        if B[i] > k:
            m = i - 1
            break
    ans = 0
    for i in range(0, n+1):
        j = max(ans - i, 0)
        if j > m: continue
        while j < m:
            if A[i] + B[j] > k:
                j -= 1
                break
            j += 1
        ans = max(i + j, ans)
    print(ans)


abc172c_tsundoku()

Fixed code:
def abc172c_tsundoku():
    n, m, k = 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(1, n + 1):
        A[i] = A[i - 1] + a[i - 1]
        if A[i] > k:
            n = i - 1
            break
    for i in range(1, m + 1):
        B[i] = B[i - 1] + b[i - 1]
        if B[i] > k:
            m = i - 1
            break
    ans = 0
    for i in range(0, n + 1):
        j = max(ans - i, 0)
        if j > m or A[i] + B[j] > k: continue
        while j <= m:
            if A[i] + B[j] > k:
                j -= 1
                break
            j += 1
        j = min(m,j)
        ans = max(i + j, ans)
    print(ans)


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

S_A = [0] * (N + 1)
S_B = [0] * (N + 1)
for i in range(N):
  S_A[i+1] = S_A[i] + A[i]

for i in range(M):
  S_B[i+1] = S_B[i] + B[i]
  
ans = 0
a = 0
for i in range(M, -1, -1):
  s = S_B[i]
  while a<N:
    if s + S_A[a + 1]<=K:
      a += 1
    else:
      break
  ans = max(ans, i + a)
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] * (N + 1)
S_B = [0] * (M + 1)
for i in range(N):
  S_A[i+1] = S_A[i] + A[i]

for i in range(M):
  S_B[i+1] = S_B[i] + B[i]
  
ans = 0
a = 0
for i in range(M, -1, -1):
  s = S_B[i]
  if s>K:
    continue
  while a<N:
    if s + S_A[a + 1]<=K:
      a += 1
    else:
      break
  ans = max(ans, i + a)
print(ans)
Buggy code:
n, m, k = (int(x) for x in input().split())

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

K = k
ans = 0

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

while l<m and K-b[l]>=0:
    K -= b[l]
    l += 1
    ans = max(ans, l)

print(ans)

Fixed code:
n, m, k = (int(x) for x in input().split())

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

K = k
ans = 0

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

# print(ans)
# print(b[l])
# print(K)
while l<m and K-b[l]>=0:
    K -= b[l]
    l += 1
    ans = max(ans, l)

print(ans)
Buggy code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
import numpy as np
A=np.array(A).cumsum()
B=np.array(B).cumsum()
for i in range(N):
  d=K-A[i]
  if d>=0:
    for j in reversed(range(M)):
      if d>=B[j]:
        if c<i+j+2:
          c=i+j+2
        M=j+1
        break
    if d<B[0]:
      c=i+1
  else:
    for j in reverse(range(M)):
      if K-B[j]>=0:
        if c<j+1:
          c=j+1
        break
    break
print(c)

Fixed code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
k=M
import numpy as np
A=np.array(A).cumsum()
B=np.array(B).cumsum()
for i in range(N):
  d=K-A[i]
  if d<0:
    for j in reversed(range(M)):
      if K-B[j]>=0:
        if c<j+1:
          c=j+1
        break
    break
  else:
    for j in reversed(range(k)):
      if d>=B[j]:
        if c<i+j+2:
          c=i+j+2
        k=j+1
        break
    if d<B[0]:
      if c<i+1:
        c=i+1
      k=0
for j in reversed(range(M)):
  if K-B[j]>=0:
    if c<j+1:
      c=j+1
print(c)
Buggy code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sum_A = [0]
for i,a in enumerate(A, 1):
    tmp = sum_A[i-1] + a
    if tmp <= K:
        sum_A.append(tmp)
        mark_A = i
    else:
        break
    
sum_B = [0]
for i,b in enumerate(B, 1):
    tmp = sum_B[i-1] + b
    if tmp <= K:
        sum_B.append(tmp)
        mark_B = i
    else:
        break
    
ans = 0
    
for i,a in enumerate(sum_A):
    for j in range(mark_B, -1, -1):
        if a + sum_B[j] > K:
            pass
        else:
            ans = max(ans, i+j)
            break
            
print(ans)

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

sum_A = [0]
for i,a in enumerate(A, 1):
    tmp = sum_A[i-1] + a
    if tmp <= K:
        sum_A.append(tmp)
        mark_A = i
    else:
        break
    
sum_B = [0]
for i,b in enumerate(B, 1):
    tmp = sum_B[i-1] + b
    if tmp <= K:
        sum_B.append(tmp)
        mark_B = i
    else:
        break
    
ans = 0
j = len(sum_B) - 1

for i,a in enumerate(sum_A):
    while sum_B[j] > K - a:
        j -= 1
        
    ans = max(ans, i+j)
    
print(ans)
Buggy code:
# C

import itertools
import bisect

n, m, k = map(int, input().split())
a_l = [int(x) for x in input().split()]
b_l = [int(x) for x in input().split()]

cumsuma_l = list(itertools.accumulate(a_l)) 
cumsumb_l = list(itertools.accumulate(b_l))

ans = 0
for i in range(n):
    _a = cumsuma_l[i]
    if _a > k:
        break
    _tmp = k - _a
    _idx = bisect.bisect_left(cumsumb_l, _tmp)
    ans = max(ans, i + _idx + 2)
        
print(ans)

Fixed code:
# C

import itertools
import bisect

n, m, k = map(int, input().split())
a_l = [int(x) for x in input().split()]
b_l = [int(x) for x in input().split()]

cumsuma_l = list(itertools.accumulate(a_l)) 
cumsumb_l = list(itertools.accumulate(b_l))

_idx = bisect.bisect_left(cumsumb_l, k)
if _idx == m or cumsumb_l[_idx] != k:
    _idx -= 1
ans = _idx + 1
    
for i in range(n):
    _a = cumsuma_l[i]
    if _a > k:
        break
    _tmp = k - _a
    _idx = bisect.bisect_left(cumsumb_l, _tmp)
    if _idx == m or cumsumb_l[_idx] != _tmp:
        _idx -= 1
    ans = max(ans, i + _idx + 2)
        
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,0
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:
def resolve():
    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)
    
resolve()
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 i in range(m):
    b.append(b[i] + B[i])
ans = 0
j = m
for i in range(n + 1):
    if a[0] > 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]
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:
n,m,k = map(int, input().split())
ln = list(map(int, input().split()))
lm = list(map(int, input().split()))

def csum(l,ll):
    s = 0
    res = [0] * ll
    for i in range(ll):
        s += l[i]
        res[i] = s
    return res

csln = csum(ln,n)
cslm = csum(lm,m)

import numpy as np

lk = [k-x for x in csln if k-x >=0]
res = np.searchsorted(np.array(cslm), np.array(lk), side='right').
rmax = 0
for i,j in zip(range(1,len(lk)+1), res):
    rmax = max(rmax, i+j)
print(int(rmax))

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

def csum(l,ll):
    s = 0
    res = [0] * ll
    for i in range(ll):
        s += l[i]
        res[i] = s
    return res

csln = csum(ln,n)
cslm = csum(lm,m)

import numpy as np

lk = [k] + [k-x for x in csln if k-x >=0]
res = np.searchsorted(np.array(cslm), np.array(lk), side='right')
rmax = 0
for i,j in zip(range(len(lk)+1), res):
    rmax = max(rmax, i+j)
print(rmax)
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

for i in range(n-1):
    a[i+1] += a[i]
for i in range(m-1):
    b[i+1] += b[i]
for i in range(n):
    res = k - a[i]
    index = bisect.bisect_right(b, res)
    ans = max(ans, index+i+1)
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()))
a = [0]+a
b = [0]+b
ans = 0
for i in range(1, n):
    a[i+1] += a[i]
for i in range(1, m):
    b[i+1] += b[i]
for i in range(n+1):
    res = k - a[i]
    if res<0: continue
    index = bisect.bisect_right(b, res)
    ans = max(ans, index+i-1)
print(ans)