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

nmax = 0

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] + a[i] > K:
        j -= 1
    ans = max(ans, i+j)

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

sum_a = [0]
sum_b = [0]

for i in range(n):
    sum_a.append(sum_a[i] + a[i])
for j in range(m):
    sum_b.append(sum_b[j] + b[j])

temp = 0
j = m
ans = 0
for i in range(n+1):
    if sum_a[i] > k:
        temp = i -1
        if temp > ans:
            ans = temp
        break
    else:
        while k - sum_a[i] < sum_b[j]:
            j -= 1
        temp = i + j
        if temp > ans:
            ans = temp
            
print(temp)

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

sum_a = [0]
sum_b = [0]

for i in range(n):
    sum_a.append(sum_a[i] + a[i])
for j in range(m):
    sum_b.append(sum_b[j] + b[j])

temp = 0
j = m
ans = 0
for i in range(n+1):
    if sum_a[i] > k:
        temp = i -1
        if temp > ans:
            ans = temp
        break
    else:
        while k - sum_a[i] < sum_b[j]:
            j -= 1
        temp = i + j
        if temp > ans:
            ans = temp
            
print(ans)
Buggy code:
n, m, p = list(map(int, input().split()))
# a = list(map(int, input().split()))
#
#  abc = [int(input()) for i in range(5)]
# a = int(input())
# w = list(map(int, input().split()))
# n, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# q = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
# bc = [list(map(int, input().split())) for i in range(q)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
arui = [0]
for i in range(n):
    arui.append(arui[i]+a[i])

brui = [0]
for i in range(m):
    brui.append(brui[i]+b[i])

ans = 0
for i in range(1, n+1):
    if arui[i] > p:
        break
    bmax = p-arui[i]
    for j in range(m, -1, -1):
        # print(arui[i])
        if bmax >= brui[j]:
            if ans <= i+j:
                ans = i+j
                break

print(arui)
print(brui)
print(ans)


Fixed code:
n, m, p = list(map(int, input().split()))
# a = list(map(int, input().split()))
#
#  abc = [int(input()) for i in range(5)]
# a = int(input())
# w = list(map(int, input().split()))
# n, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# q = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
# bc = [list(map(int, input().split())) for i in range(q)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
arui = [0]
for i in range(n):
    arui.append(arui[i]+a[i])

brui = [0]
for i in range(m):
    brui.append(brui[i]+b[i])

ans = 0
j = m
for i in range(n+1):
    if arui[i] > p:
        break
    bmax = p-arui[i]
    while brui[j] > bmax:
        j -= 1
    if ans <= i+j:
        ans = i+j


print(ans)
Buggy code:
import sys
readline = sys.stdin.readline

N,M,K = map(int,readline().split())

A = [0] + list(map(int,readline().split()))
B = [0] + list(map(int,readline().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]
  
import bisect

ans = 0
for i in range(len(A)):
  rest = K - A[i]
  if rest <= 0:
    if ans < i:
      ans = i
    continue
  b_read = bisect.bisect_right(B, rest)
  if ans < i + b_read - 1:
    ans = i + b_read - 1
    
print(ans)

Fixed code:
import sys
readline = sys.stdin.readline

N,M,K = map(int,readline().split())

A = [0] + list(map(int,readline().split()))
B = [0] + list(map(int,readline().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]
  
import bisect

ans = 0
for i in range(len(A)):
  rest = K - A[i]
  if rest < 0:
    continue
  if ans < i:
    ans = i
  b_read = bisect.bisect_right(B, rest)
  if ans < i + b_read - 1:
    ans = i + b_read - 1
    
print(ans)
Buggy code:
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

sumA = []
sumB = []
tmp = 0
answer = 0
st = 1

for i in range(N):
    tmp = tmp + A[i]
    sumA.append(tmp)

tmp = 0
for i in range(M):
    tmp = tmp + B[i]
    sumB.append(tmp)

for i in range(N, 0, -1):
    booktmp = 0

    for j in range(st , M + 1):

        if sumA[i-1] + sumB[j-1] <= K:
            booktmp = i + j
            st = st + 1
        else:
            st = st - 1
            break
    answer = max(answer, booktmp)


print(answer)




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

sumA = [0]
sumB = [0]
tmp = 0
answer = 0
st = 0

for i in range(N):
    tmp = tmp + A[i]
    sumA.append(tmp)

tmp = 0
for i in range(M):
    tmp = tmp + B[i]
    sumB.append(tmp)

for i in range(N, -1, -1):
    booktmp = 0

    for j in range(st, M + 1):

        if sumA[i] + sumB[j] <= K:
            booktmp = i + j
        else:
            st = j
            break
    answer = max(answer, booktmp)
    if j == M:
        break


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

b_sum = 0
for i in range(M):
    b_sum += B[i]
    if b_sum > K:
        b_sum -= B[i]
        j = i - 1
        break
result = j + 1

a_sum = 0
for i in range(N):
    a_sum += A[i]
    if a_sum > K:
        break
    while a_sum + b_sum > K:
        b_sum -= B[j]
        j -= 1
    result = max(result, (i + 1) + (j + 1))
print(result)


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

b_sum = 0
for i in range(M):
    b_sum += B[i]
    if b_sum > K:
        b_sum -= B[i]
        j = i - 1
        break
else:
    j = M - 1
result = j + 1

a_sum = 0
for i in range(N):
    a_sum += A[i]
    if a_sum > K:
        break
    while a_sum + b_sum > K:
        b_sum -= B[j]
        j -= 1
    result = max(result, (i + 1) + (j + 1))
print(result)
Buggy code:
from itertools import accumulate
from bisect import bisect_left

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

a = [0] + list(accumulate(A))
b = [0] + list(accumulate(B))

result = 0
for i in range(N):
    t = K - a[i]
    if t < 0:
        break
    j = bisect_left(b, t)
    if b[j] == t:
        result = max(result, i + j + 1)
    else:
        result = max(result, i + j)
print(result)


Fixed code:
from itertools import accumulate
from bisect import bisect_left

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

result = 0
j = bisect_left(b, K)
if j == M:
  result = M
elif b[j] == K:
    result = j + 1
else:
    result = j
for i in range(N):
    t = K - a[i]
    if t < 0:
        break
    j = bisect_left(b, t)
    if j == M:
        result = max(result, i + 1 + M)
    elif b[j] == t:
        result = max(result, i + 1 + j + 1)
    else:
        result = max(result, i + 1 + j)
print(result)
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 = m

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 itertools

numOfA,numOfB,target = map(int, input().split())

timetoreadA = list(map(int,input().split()))
timetoreadB = list(map(int,input().split()))

timetoreadAacc = list(itertools.accumulate(timetoreadA))

booknumonlyA = 0
totaltime = 0
for time in timetoreadAacc:
	if target < time:
		break
	booknumonlyA += 1
	totaltime = time

bookreadA = booknumonlyA
bookread = [bookreadA]

for posB in range(numOfB):
	bookreadB = posB + 1
	newtime = totaltime + timetoreadB[posB]
	if newtime <= target:
		bookread.append(bookreadA + bookreadB)
		totaltime = newtime
	else:
		while newtime > target and bookreadA > 0:
			bookreadA -= 1
			newtime = newtime - timetoreadA[bookreadA]

		if newtime <= target:
			bookread.append(bookreadA + bookreadB)

		totaltime = newtime

print(bookread)

Fixed code:
import itertools

numOfA,numOfB,target = map(int, input().split())

timetoreadA = list(map(int,input().split()))
timetoreadB = list(map(int,input().split()))

timetoreadAacc = list(itertools.accumulate(timetoreadA))

booknumonlyA = 0
totaltime = 0
for time in timetoreadAacc:
	if target < time:
		break
	booknumonlyA += 1
	totaltime = time

bookreadA = booknumonlyA
bookread = [bookreadA]

for posB in range(numOfB):
	bookreadB = posB + 1
	newtime = totaltime + timetoreadB[posB]
	if newtime <= target:
		bookread.append(bookreadA + bookreadB)
		totaltime = newtime
	else:
		while newtime > target and bookreadA > 0:
			bookreadA -= 1
			newtime = newtime - timetoreadA[bookreadA]

		if newtime <= target:
			bookread.append(bookreadA + bookreadB)

		totaltime = newtime

print(max(bookread))
Buggy code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n -= -1
m -= -1
a.insert(0, 0)
b.insert(0, 0)
for i in range(1, n): a[i] += a[i - 1]
for i in range(1, m): b[i] += b[i - 1]
ans = 0
for i in range(n):
    lo, hi = 0, m - 1
    tmp = a[i]
    while hi - lo > 1:
        mid = lo + (hi - lo) // 2
        if tmp + b[mid] > k: hi = mid - 1
        else: lo = mid
    if tmp + b[hi] <= k: lo = hi
    ans = max(ans, i + lo)
print(ans)

Fixed code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n -= -1
m -= -1
a.insert(0, 0)
b.insert(0, 0)
for i in range(1, n): a[i] += a[i - 1]
for i in range(1, m): b[i] += b[i - 1]
ans = 0
for i in range(n):
    if a[i] > k: break
    lo, hi = 0, m - 1
    tmp = a[i]
    while hi - lo > 1:
        mid = lo + (hi - lo) // 2
        if tmp + b[mid] > k: hi = mid - 1
        else: lo = mid
    if tmp + b[hi] <= k: lo = hi
    ans = max(ans, i + lo)
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(n):
    b.append(b[i] + B[i])

ans, j = 0, m
for i in range(n+1):
    if a[i] > k:
        break
    while [b] > 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())
times_a = list(map(int, input().split()))
times_b = list(map(int, input().split()))
read_time = 0
read_time_a = [0]
read_time_b = [0]
for i in range(len(times_a)):
    read_time_a.append(read_time_a[i]+times_a[i])
for i in range(len(times_b)):
    read_time_b.append(read_time_b[i]+times_b[i])
count = 0
for i in range(N+1):
    t = read_time_a[i]
    l = 0
    r = len(read_time_b)
    while l + 1 < r:
        c = (l + r) // 2
        if t + read_time_b[c] <= K:
            l = c
        else:
            r = c
    if read_time_a[i] + read_time_b[l] <= K:
        ans = max(ans, i + l)
print(ans)


Fixed code:
N, M, K = map(int, input().split())
times_a = list(map(int, input().split()))
times_b = list(map(int, input().split()))
read_time = 0
read_time_a = [0]
read_time_b = [0]
for i in range(N):
    read_time_a.append(read_time_a[i]+times_a[i])
for i in range(M):
    read_time_b.append(read_time_b[i]+times_b[i])

ans = 0
for i in range(N+1):
    t = read_time_a[i]
    l = 0
    r = len(read_time_b)
    while l + 1 < r:
        c = (l + r) // 2
        if t + read_time_b[c] <= K:
            l = c
        else:
            r = c
    if read_time_a[i] + read_time_b[l] <= K:
        ans = max(ans, i + l)
print(ans)
Buggy code:

if __name__ == "__main__":
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    ans, j = 0, M
    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])
    for i in range(N+1):
        if a[i] > K:
            break
        else:
            if a[i] + b[j] > K:
                j -= 1
        ans = max(ans, i+j)
    print(ans)

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

    ans, j = 0, M
    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])
    for i in range(N+1):
        if a[i] > K:
            break
        else:
            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 = [0] + list(map(int,input().split()))
B = [0] + list(map(int,input().split()))
 
for i in range(2,n):
    A[i] += A[i-1]
for i in range(1,m):
    B[i] += B[i-1]
j = m
ans = 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:
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(2,n+1):
    A[i] += A[i-1]
for i in range(2,m+1):
    B[i] += B[i-1]

j = m
ans = 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)
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_stack=deque([])
now=0
mn=0
j=0
flag=True
for i in a:
  mn+=i
  if mn>k:
    mn-=i
    flag=None
    break
  else:
    now+=1
    a_stack.append(i)
if flag:
  for i in b:
    mn+=i
    if mn>k:
      mn-=i
      flag=None
      break
    else:
      now+=1
      j+=1
ans=now
while a_stack:
  if j>=m:
    break
  else:
    q=a_stack.pop()
    mn-=q
    now-=1
    while k-mn>0:
      mn+=b[j]
      now+=1
      j+=1
      if k-mn<0:
        now-=1
        mn-=b[j]
        j-=1
      if j==m:
        break
    ans=max(now,ans)
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_stack=deque([])
now=0
mn=0
j=0
for i in a:
  mn+=i
  if mn>k:
    mn-=i
    break
  else:
    now+=1
    a_stack.append(i)
for i in b:
  mn+=i
  if mn>k:
    mn-=i
    break
  else:
    now+=1
    j+=1
    if j==m:
      print(now)
      exit()
ans=now
while a_stack:
  if j>=m:
    break
  else:
    q=a_stack.pop()
    mn-=q
    now-=1
    while k-mn>0:
      mn+=b[j]
      now+=1
      if k-mn<0:
        now-=1
        mn-=b[j]
        break
      j+=1
      if j==m:
        break
    ans=max(now,ans)
print(ans)
Buggy code:
n, m, k = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in 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])


# print(a)
# print(b)


ans = 0

for i_n in range(n + 1):
    if a[i_n] > k:
        break

    for j_n in range(m + 1):
        if a[i_n] + b[j_n] < k:
            ans = max(ans, i_n + j_n)

print(ans)


Fixed code:
n, m, k = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in 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])


# print(a)
# print(b)

j_n = m
ans = 0

for i_n in range(len(a)):
    if a[i_n] > k:
        break

    while b[j_n] > k - a[i_n]:
        j_n -= 1

    ans = max(ans, i_n + j_n)

print(ans)
Buggy code:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
#from heapq import heappop, heappush
#from collections import OrderedDict, defaultdict
#import math
#from itertools import product, accumulate, combinations, product
import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
#import numba

def run():
    N, M, K = map(int, sysread().split())
    A = list(map(int, sysread().split()))
    B = list(map(int, sysread().split()))

    A_sum = [0]
    for a in A:
        A_sum.append(A_sum[-1] + a)
    B_sum = [0]
    for b in B:
        B_sum.append(B_sum[-1] + b)
    #print(A_sum, B_sum)

    max_val = 0
    for i, a in enumerate(A_sum):
        idx = bisect.bisect_left(B_sum, K-a)
        if idx < len(B_sum) and B_sum[idx] == K-a:
            idx+=1
        max_val = max(max_val, idx+i-1)
        #print(i, idx)
    print(max_val)



    ret = 0
    time = 0


if __name__ == "__main__":
    run()

Fixed code:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
#from heapq import heappop, heappush
#from collections import OrderedDict, defaultdict
#import math
#from itertools import product, accumulate, combinations, product
import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
#import numba

def run():
    N, M, K = map(int, sysread().split())
    A = list(map(int, sysread().split()))
    B = list(map(int, sysread().split()))

    A_sum = [0]
    for a in A:
        A_sum.append(A_sum[-1] + a)
    B_sum = [0]
    for b in B:
        B_sum.append(B_sum[-1] + b)
    #print(A_sum, B_sum)

    max_val = 0
    for i, a in enumerate(A_sum):
        if a > K:
            max_val = max(i-1, max_val)
            break
        idx = bisect.bisect_left(B_sum, K-a)
        if idx < len(B_sum) and B_sum[idx] == K-a:
            idx += 1
        max_val = max(max_val, idx+i-1)
        #print(i, idx)
    print(max_val)



if __name__ == "__main__":
    run()
Buggy code:
from itertools import accumulate
import bisect
n, m, k = map(int,input().split())
a_lst = [0] + list(accumulate(list(map(int,input().split()))))
b_lst = list(accumulate(list(map(int,input().split()))))

ans = 0
for i in range(n+1):
    cnt = i
    num = k - a_lst[i]
    if num < 0:
        continue
    b_yomeru = bisect.bisect_left(b_lst,num)
    cnt += b_yomeru
    if ans < cnt:
        ans = cnt

print(ans)

Fixed code:
from itertools import accumulate
import bisect
n, m, k = map(int,input().split())
a_lst = [0] + list(accumulate(list(map(int,input().split()))))
b_lst = list(accumulate(list(map(int,input().split()))))

ans = 0
for i in range(n+1):
    cnt = i
    num = k - a_lst[i]
    if num < 0:
        continue
    b_yomeru = bisect.bisect_right(b_lst,num)
    cnt += b_yomeru
    if ans < cnt:
        ans = cnt

print(ans)
Buggy code:
from itertools import accumulate

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

acc1 = list(accumulate(A))
acc2 = list(accumulate(B))

def is_ok(a, b):
    if acc1[a] + acc2[b] <= K:  return 1
    return 0

def binary_search(i, left, right):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(i, mid):  right = mid
        else:  left = mid
    return right

ans = 0
for i in range(N):
    ret = binary_search(i, M, -1)
    if ret == -1:  
      if acc1[i] <= K:  ans = max(i + 1, ans)
    else:
      ans = max(ans,  i + ret + 2)
      
acc1, acc2 = acc2, acc1
      
for i in range(N):
    ret = binary_search(i, M, -1)
    if ret == -1:  
      if acc1[i] <= K:  ans = max(i + 1, ans)
    else:
      ans = max(ans,  i + ret + 2)
      
print(ans)

Fixed code:
from itertools import accumulate

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

acc1 = list(accumulate(A))
acc2 = list(accumulate(B))

def is_ok(a, b):
    if acc1[a] + acc2[b] <= K:  return 1
    return 0

def binary_search(i, left, right):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(i, mid):  right = mid
        else:  left = mid
    return right

ans = 0
for i in range(N):
    ret = binary_search(i, M, -1)
    if ret == -1:  
      if acc1[i] <= K:  ans = max(i + 1, ans)
    else:
      ans = max(ans,  i + ret + 2)
      
acc1, acc2 = acc2, acc1
N, M = M, N
      
for i in range(N):
    ret = binary_search(i, M, -1)
    if ret == -1:  
      if acc1[i] <= K:  ans = max(i + 1, ans)
    else:
      ans = max(ans,  i + ret + 2)
      
print(ans)
Buggy code:
def main():
    n, m, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    maxv = 0
    acum = [0] * (n + 1)
    bcum = [0] * (m + 1)
    for i in range(n):
        acum[i + 1] = acum[i] + a[i]
    for i in range(m):
        bcum[i + 1] = bcum[i] + b[i]

    for i in range(n + 1):
        if acum[i] > k:
            continue
        maxv = max(maxv, i + bisect_right(bcum, k - acum[i]) - 1)
    print(maxv)

if __name__ == '__main__':
    main()

Fixed code:
from bisect import bisect_right

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

    maxv = 0
    acum = [0] * (n + 1)
    bcum = [0] * (m + 1)
    for i in range(n):
        acum[i + 1] = acum[i] + a[i]
    for i in range(m):
        bcum[i + 1] = bcum[i] + b[i]

    for i in range(n + 1):
        if acum[i] > k:
            continue
        maxv = max(maxv, i + bisect_right(bcum, k - acum[i]) - 1)
    print(maxv)

if __name__ == '__main__':
    main()
Buggy code:
from bisect import bisect_right
from numpy import cumsum
from sys import stdin
input=stdin.readline
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=numpy.cumsum(a)
b=numpy.cumsum(b)
ans=0
for i in range(len(a)):
  x=k-a[i]
  y=bisect.bisect_right(b,x)
  if ans<y+i+1:
    ans=y+i+1
print(ans)

Fixed code:
from bisect import bisect_right
from numpy import cumsum
from sys import stdin
input=stdin.readline
n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))
a=cumsum(a)
b=cumsum(b)
ans=0
for i in range(len(a)):
  x=k-a[i]
  if x>=0:
    y=bisect_right(b,x)
    if ans<y+i:
      ans=y+i
  else:
    break
print(ans)