qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * (n + 1)
d = [0] * (m + 1)

for i in range(n):
  c[i+1] = c[i]+a[i]
for i in range(m):
  d[i+1] = d[i]+b[i]
  
cnt = 0
  
for i in range(n+1):
  e = bisect.bisect_right(d, k-c[i])
  if cnt < i + e -1:
    cnt =  i + e -1
print(cnt)

Fixed code:
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * (n + 1)
d = [0] * (m + 1)

for i in range(n):
  c[i+1] = c[i]+a[i]
for i in range(m):
  d[i+1] = d[i]+b[i]
  
cnt = 0
  
for i in range(n+1):
  if c[i] > k:
    continue
  e = bisect.bisect_right(d, k-c[i])
  if cnt < i + e -1:
    cnt =  i + e -1
print(cnt)
Buggy code:
from itertools import accumulate
from bisect import bisect_right
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
sum_a = list(accumulate(a))
b = list(map(int,input().split()))
sum_b = list(accumulate(b))
ma = 0
print(sum_a,sum_b)
for i in range(len(sum_a)):
    x = sum_a[i]
    if k<x:
      break
    k -= x
    index = bisect_right(sum_b,k)
    ma = max(i+1+index,ma)
    k += x
  #  print(x,k,index,ma)
print(ma)
    

Fixed code:
from itertools import accumulate
from bisect import bisect_right
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
sum_a = [0]+list(accumulate(a))
b = list(map(int,input().split()))
sum_b = list(accumulate(b))
ma = 0
#print(sum_a,sum_b)
for i in range(len(sum_a)):
    x = sum_a[i]
    if k<x:
      index = bisect_right(sum_b,k)
      ma = max(index,ma)
    else:
      k -= x
      index = bisect_right(sum_b,k)
      ma = max(i+index,ma)
      k += x
    #  print(x,k,index,ma)
print(ma)
Buggy code:
n,m,k = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))

from itertools import accumulate
sum_a_list = list(accumulate([0] + a_list))
sum_b_list = list(accumulate([0] + b_list))

ans = 0
b_idx = 0
for a_idx in range(n+1):
    if sum_a_list[a_idx] > k:
        continue

    time_rest = k - sum_a_list[a_idx]
    b_idx = bisect.bisect_left(sum_b_list,time_rest)
    
    ans = max(ans, a_idx + b_idx)
        
print(ans)

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

from itertools import accumulate
sum_a_list = list(accumulate([0] + a_list))
sum_b_list = list(accumulate([0] + b_list))

ans = 0
b_idx = m
for a_idx in range(n+1):
    if sum_a_list[a_idx] > k:
        continue
 
    while sum_a_list[a_idx] + sum_b_list[b_idx] > k:
        b_idx -= 1
    
    ans = max(ans, a_idx + b_idx)
        
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];ans=0;j=m
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
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 a:
  A.append(i+A[-1])
for i in b:
  B.append(i+B[-1])
  
ans,j = 0,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)
Buggy code:
import bisect
import numpy

n, m, k = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))

cost_a = numpy.insert(numpy.cumsum(a), 0, 0)
cost_b = numpy.insert(numpy.cumsum(b), 0, 0)

left_max = bisect.bisect_left(cost_a, k) + 1
right_max = bisect.bisect_left(cost_b, k) + 1

ans = 0
j = right_max - 1
for i in range(left_max):
    for j in range(j , -1, -1):
        if cost_a[i] + cost_b[j] <= k:
            ans  = i + j if ans < i + j else ans
            break
print(ans)

Fixed code:

import bisect
import numpy

n, m, k = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))

cost_a = numpy.insert(numpy.cumsum(a), 0, 0)
cost_b = numpy.insert(numpy.cumsum(b), 0, 0)

ans = 0
j =  len(cost_b) -1
for i in range(len(cost_a)):
    for j in range(j, -1, -1):
        if cost_a[i] + cost_b[j] <= k:
            ans  = i + j if ans < i + j else ans
            break
print(ans)
Buggy code:
from itertools import accumulate

N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
cumsum_A, cumsum_B = [0] + list(accumulate(A)), [0] + list(accumulate(B))
ans = 0
j = M
for i in range(N+1):
    if cumsum_A[i] > K: break
    while cumsum_A[i] + cumsum_B[j] >= K: j -= 1
    ans = max(ans, i + j)
print(ans)

Fixed code:
from itertools import accumulate

N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
cumsum_A, cumsum_B = [0] + list(accumulate(A)), [0] + list(accumulate(B))
ans = 0
j = M
for i in range(N+1):
    if cumsum_A[i] > K: break
    while cumsum_A[i] + cumsum_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()))
a.insert(0,0)
b.insert(0,0)
j=1
while j<=m and b[j]+b[j-1]<=k:
  b[j]+=b[j-1]
  j+=1
  

j-=1
books=j
i=1
while i<n:
  while j>0 and a[i]+b[j]>k:
    j-=1
  if(j>=0) and a[i]+b[j]<=k:
    books=max(books,j+i)
    a[i]+=a[i-1]
  else:
    break
print(books)
  

Fixed code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.insert(0,0)
b.insert(0,0)
j=1
while j<=m and b[j]+b[j-1]<=k:
  b[j]+=b[j-1]
  j+=1
  

j-=1
books=j
#print(books,b)

i=1
while i<n+1:
  a[i]+=a[i-1]
  while j>=0 and a[i]+b[j]>k:
    j-=1
  if(j!=-1) and a[i]+b[j]<=k:
    books=max(books,j+i)
    
    
    i+=1
    #print(books,b[:j+1],a[:i])
  else:
    break
print(books)
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_acc=list(accumulate(a))
b_acc=list(accumulate(b))

cnt=0

import bisect
for i in range(n):
    nokori=k-a_acc[i]
    if nokori<b[0]:
        break
    b_i=bisect.bisect_right(b_acc,nokori)
    cnt=max(cnt,(i+1)+b_i)
    print(nokori,i,b_i)

print(cnt)


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_acc=list(accumulate(a))
b_acc=list(accumulate(b))
a_acc.insert(0,0)
b_acc.insert(0,0)

cnt=0

import bisect
for i in range(n+1):
    nokori=k-a_acc[i]
    if nokori<0:
        break
    b_i=bisect.bisect_right(b_acc,nokori)-1
    cnt=max(cnt,i+b_i)
    # print(nokori,i,b_i)

print(cnt)
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 = [int(i) for i in input().split()]
B = [int(j) for j in 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:
from bisect import bisect_right
from itertools import accumulate

N, M, K = [int(x) for x in input().split()]

a_book = [0] + list(accumulate([int(x) for x in input().split()]))
b_book = [0] + list(accumulate([int(x) for x in input().split()]))

check = {}

max_books = 0

for i, a in enumerate(a_book):
    b_pos = bisect_right(b_book, K - a)

    if max_books < b_pos - 1 + i:
        max_books = b_pos - 1 + i

print(max_books)


Fixed code:
from bisect import bisect_right
from itertools import accumulate

N, M, K = [int(x) for x in input().split()]

a_book = [0] + list(accumulate([int(x) for x in input().split()]))
b_book = [0] + list(accumulate([int(x) for x in input().split()]))

check = {}

max_books = 0

for i, a in enumerate(a_book):
    if a > K:
        break

    b_pos = bisect_right(b_book, K - a)

    if max_books < b_pos - 1 + i:
        max_books = b_pos - 1 + i

print(max_books)
Buggy code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
import bisect

def main():
    N, M, K = map(int, input().split())
    A_lsit = list(map(int, input().split()))
    B_lsit = list(map(int, input().split()))

    A_sum_list = [0] + A_lsit[:]
    for i in range(1, N+1):
        A_sum_list[i] = A_sum_list[i-1] + A_lsit[i-1]
    B_sum_list = [0] + B_lsit[:]
    for i in range(1, M+1):
        B_sum_list[i] = B_sum_list[i-1] + B_lsit[i-1]
    #print(A_sum_list)
    #print(B_sum_list)

    max_book_number = 0
    for i in range(N):
        book_number_A = i
        book_number_B = bisect.bisect_right(B_sum_list, K-A_sum_list[i]) - 1
        max_book_number = max(
            max_book_number,
            book_number_A + book_number_B
        )
        #print(book_number_A, book_number_B, book_number_A + book_number_B)
    print(max_book_number)

if __name__ == "__main__":
    main()



Fixed code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
import bisect

def main():
    N, M, K = map(int, input().split())
    A_lsit = list(map(int, input().split()))
    B_lsit = list(map(int, input().split()))

    A_sum_list = [0] + A_lsit[:]
    for i in range(1, N+1):
        A_sum_list[i] = A_sum_list[i-1] + A_lsit[i-1]
    B_sum_list = [0] + B_lsit[:]
    for i in range(1, M+1):
        B_sum_list[i] = B_sum_list[i-1] + B_lsit[i-1]
    #print(A_sum_list)
    #print(B_sum_list)

    max_book_number = 0
    for i in range(N+1):
        if A_sum_list[i] <= K:
            book_number_A = i
            book_number_B = bisect.bisect_right(B_sum_list, K-A_sum_list[i]) - 1
            max_book_number = max(
                max_book_number,
                book_number_A + book_number_B
            )
            #print(book_number_A, book_number_B, book_number_A + book_number_B)
    print(max_book_number)

if __name__ == "__main__":
    main()
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, 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]
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())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
asum = [0]
bsum = [0]

for i in range(len(aa)):
    asum.append(asum[i]+aa[i])
for i in range(len(bb)):
    bsum.append(bsum[i]+bb[i])

j = len(bsum)-1
ans = 0
for i in range(len(asum)):
    while j > 0:
        if k > asum[i] + bsum[j]:
            ans = max(ans, i+j)
            break
        else:
            j -= 1


print(ans)


Fixed code:
n, m, k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
asum = [0]
bsum = [0]

for i in range(len(aa)):
    asum.append(asum[i]+aa[i])
for i in range(len(bb)):
    bsum.append(bsum[i]+bb[i])

j = len(bsum)-1
ans = 0
for i in range(len(asum)):
    while j >= 0:
        if k >= asum[i] + bsum[j]:
            ans = max(ans, i+j)
            break
        else:
            j -= 1


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

A_cum = [0]
B_cum = [0]

for i in range(n):
  A_cum.append(A_cum[i]+A[i])
  
for i in range(m):
  B_cum.append(B_cum[i]+B[i])
    
ans = 0  
for i in range(n):
  rest = k-A_cum[i]
  if rest<=0:
    continue
  ans = max(ans, bisect.bisect_left(B_cum, rest)+i)
  
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_cum = [0]
B_cum = [0]

for i in range(n):
  A_cum.append(A_cum[i]+A[i])
  
for i in range(m):
  B_cum.append(B_cum[i]+B[i])

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

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])
  b.append(b[i] + B[i])

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, 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()))
i=0
j=0
count=0
ans=0
for i in range(1,n):
  A[i]=A[i]+A[i-1]


for j in range(1,m):
  B[i]=B[i]+B[i-1]


a_cnt=0
b_cnt=m
for a_cnt in range(n+1):
  if A[a_cnt]>k:
    continue
  #print('A',A[a_cnt])
  b_cnt=0
  while A[a_cnt]+B[b_cnt]>k:
    #print('B',B[b_cnt+1])
    b_cnt-=1 
  ans=max(ans,a_cnt+b_cnt)
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()))

ans=0
for i in range(1,n+1):
  A[i]+=A[i-1]


for j in range(1,m+1):
  B[j]+=B[j-1]


b_cnt=m
for a_cnt in range(n+1):
  if A[a_cnt]>k:
    continue
  while A[a_cnt]+B[b_cnt]>k:
    b_cnt-=1 

  ans=max(ans,a_cnt+b_cnt)
print(ans)
Buggy code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
from bisect import bisect
def main():
    n, m, k = map(int, input().split())
    a = tuple(map(int, input().split()))
    b = tuple(map(int, input().split()))

    aa = tuple(accumulate(a))
    ba = tuple(accumulate(b))
    r = 0
    for i1, aae in enumerate(aa):
        if aae > k:
            break
        else:
            time_remain = k - aae
            b_num = bisect(ba, time_remain)
            if pos:
                rtmp = i1 + 1 + b_num
            else:
                rtmp = i1 + 1
            r = max(r, rtmp)
    print(r)

if __name__ == '__main__':
    main()

Fixed code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
from bisect import bisect
def main():
    n, m, k = map(int, input().split())
    a = tuple(map(int, input().split()))
    b = tuple(map(int, input().split()))

    aa = [0] + list(accumulate(a))
    ba = [0] + list(accumulate(b))
    r = 0
    for i1, aae in enumerate(aa):
        if aae > k:
            break
        else:
            time_remain = k - aae
            b_num = bisect(ba, time_remain)
            r = max(r, i1 + b_num - 1)
    print(r)

if __name__ == '__main__':
    main()
Buggy code:
import bisect

n, m, k = map(int, input().split())
a, b = [0], [0]
for i, (a_, b_) in enumerate(zip(input().split(), input().split())):
    a.append(a[i] + int(a_))
    b.append(b[i] + int(b_))

res = 0
a_ = 0
for i in range(n+1):
    if a[i] > k:
        break
    j = bisect.bisect(b, k-a[i]) - 1
    res = max(res, i+j)

print(res)


Fixed code:
import bisect

n, m, k = map(int, input().split())
a, b = [0], [0]
for i, x in enumerate(input().split()):
    a.append(a[i] + int(x))
for i, x in enumerate(input().split()):
    b.append(b[i] + int(x))

res = 0
a_ = 0
for i in range(n+1):
    if a[i] > k:
        break
    j = bisect.bisect(b, k-a[i]) - 1
    res = max(res, i+j)

print(res)
Buggy code:
import bisect

n, m, k = map(int, input().split())
a = [0] + [int(x) for x in input().split()]
b = [0]
for x in input().split():
    b.append(b[-1] + int(x))

res = 0
a_ = 0
for i in range(n+1):
    a_ += a[i]
    b_max = k - a_
    b_num = bisect.bisect(b, b_max) - 1
    res = max(res, i + b_num)

print(res)


Fixed code:
import bisect

n, m, k = map(int, input().split())
a = [0] + [int(x) for x in input().split()]
b = [0]
for x in input().split():
    b.append(b[-1] + int(x))

res = 0
a_ = 0
for i in range(n+1):
    a_ += a[i]
    if a_ > k:
        break
    b_max = k - a_
    b_num = bisect.bisect(b, b_max) - 1
    res = max(res, i + b_num)

print(res)
Buggy code:
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)
X = 0
Y = 0
cnt = 0
for n in range(N):
    a[n+1] = a[n] + A[n]
for n in range(M):
    b[n+1] = b[n] + B[n]
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]*(N+1)
b = [0]*(M+1)
for n in range(N):
    a[n+1] = a[n] + A[n]
for n in range(M):
    b[n+1] = b[n] + B[n]
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:
if __name__ == '__main__':
    N, M, K = map(int, input().split()) 
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    acc_A = []
    acc_B = []
    acc_A.append(0)
    acc_B.append(0)
    
    sum_a = 0
    sum_b = 0

    for a in A:
        sum_a += a
        acc_A.append(sum_a)

    for b in B:
        sum_b += b
        acc_B.append(sum_b)

    large_ar = []
    small_ar = []

    if N > M:
        large_ar = acc_A
        small_ar = acc_B
    else:
        large_ar = acc_B
        small_ar = acc_A
    
    ans = 0
    for i in range(len(small_ar)):
        for j in range(ans-i-1, len(large_ar)):
            if large_ar[j] + small_ar[i] <= K:
                ans = max(ans, i+j)
            else: break
    print(ans)

Fixed code:
if __name__ == '__main__':
    N, M, K = map(int, input().split()) 
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    acc_A = []
    acc_B = []
    acc_A.append(0)
    acc_B.append(0)
    
    sum_a = 0
    sum_b = 0

    for a in A:
        sum_a += a
        acc_A.append(sum_a)

    for b in B:
        sum_b += b
        acc_B.append(sum_b)

    large_ar = []
    small_ar = []

    if N > M:
        large_ar = acc_A
        small_ar = acc_B
    else:
        large_ar = acc_B
        small_ar = acc_A
    
    ans = 0
    for i in range(len(small_ar)):
        for j in range(ans-i+1, len(large_ar)):
            if large_ar[j] + small_ar[i] <= K:
                ans = max(ans, i+j)
            else: break
    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.appned(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])

ans, j = 0, M
for i in range(len(A)):
  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]
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=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))

from itertools import accumulate
from collections import deque
A=deque(list(accumulate(A)))
B=deque(list(accumulate(B)))
A.appendleft(0)
B.appendleft(0)
ans1=0
for i in range(N+1):
    if A[i]>K:
        ans1=i
        break
else:
    ans1=N
ans2=0
ans3=0
for i in range(ans1):
    if ans1==1:
        while i+ans2<=M and A[ans1-i-1]+B[i+ans2]<=K:
            ans2+=1
        ans3=max(ans3,ans1+ans2-1)
    else:
        while i+ans2<=M and A[ans1-i]+B[i+ans2]<=K:
            ans2+=1
        ans3=max(ans3,ans1+ans2-1)
print(ans3)

Fixed code:

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

from itertools import accumulate
from collections import deque
A=deque(list(accumulate(A)))
B=deque(list(accumulate(B)))
A.appendleft(0)
B.appendleft(0)
ans1=0
for i in range(N+1):
    if A[i]>K:
        ans1=i-1
        break
else:
    ans1=N
ans2=0
ans3=0
# print(ans1)
for i in range(ans1+1):
#     print(i)
    while i+ans2<=M and A[ans1-i]+B[i+ans2]<=K:
        ans2+=1
#         print(ans1,ans2,i)
    ans3=max(ans3,ans1+ans2-1)
print(ans3)
Buggy code:
import itertools
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

sa = list(itertools.accumulate(a))
sb = list(itertools.accumulate(b))

max = 0

for i in range(n + 1):
    j = m -1
    while j > 0:
        if (sa[i] + sb[j] <= k):
            if i + j > max:
                max = i + j
            break
        else:
            j -= 1
print(max)

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

sa = list(itertools.accumulate(a))
sb = list(itertools.accumulate(b))

output = 0
j = m
for i in range(n + 1):
    if sa[i] > k:
        break
    while sa[i] + sb[j] > k:
        j -= 1
    if output < i + j:
        output = i + j
print(output)
Buggy code:
    N,M,K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
     
    Asum = [0]
    Bsum = [0]
    atemp = 0
    btemp = 0
    for i in range(N):
        atemp += A[i]
        Asum.append(atemp)
    for i in range(M):
        btemp += B[i]
        Bsum.append(btemp)
     
    ans = 0
    j = M
    for i in range(N+1):
        if Asum[i] > K:
            break
        while Asum[i] + Bsum[j] > K:
            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()))

Asum = [0]
Bsum = [0]
atemp = 0
btemp = 0
for i in range(N):
    atemp += A[i]
    Asum.append(atemp)
for i in range(M):
    btemp += B[i]
    Bsum.append(btemp)

ans = 0
j = M
for i in range(N+1):
    if Asum[i] > K:
        break
    while Asum[i] + Bsum[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]
b=[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])


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

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


print(ans)