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

tmp = []
s = 0
for i in a:
    if s + i <= k:
        tmp.append(i)
        s += i
    else:
        break
a = tmp
tmp = []
s = 0
for i in b:
    if s + i <= k:
        tmp.append(i)
        s += i
    else:
        break
b = tmp
line = b[::-1] + a
print(line)
ans = 0
right = 0
sum_ = 0
for left in range(len(line)):
    while right < len(line) and sum_ + line[right] <= k:
        sum_ += line[right]
        right += 1
    l = right -left 
    if l > ans:
        ans = l

    if right == left: right += 1
    else: sum_ -= line[left]

print(ans) 

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

tmp = []
s = 0
for i in a:
    if s + i <= k:
        tmp.append(i)
        s += i
    else:
        break
a = tmp
tmp = []
s = 0
for i in b:
    if s + i <= k:
        tmp.append(i)
        s += i
    else:
        break
b = tmp
line = b[::-1] + a

ans = 0
right = 0
sum_ = 0
for left in range(len(line)):
    while right < len(line) and sum_ + line[right] <= k:
        sum_ += line[right]
        right += 1
    l = right -left 
    if l > ans:
        ans = l

    if right == left: right += 1
    else: sum_ -= line[left]

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

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

sa = [0]*(n+1)
sb = [0]*(m+1)

for i in range(n):
    sa[i+1] = sa[i]+a[i]
for i in range(m):
    sb[i+1] = sb[i]+b[i]

isb=m
ans = 0
for isa in range(n+1):
    if sa[isa]>k:
        break
    while isb>0 and sa[isa]+sb[isb]>K:
        isb-=1
    ans = max(ans, isa+isb)
    
print(ans)

Fixed code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

sa = [0]*(n+1)
sb = [0]*(m+1)

for i in range(n):
    sa[i+1] = sa[i]+a[i]
for i in range(m):
    sb[i+1] = sb[i]+b[i]

isb=m
ans = 0
for isa in range(n+1):
    if sa[isa]>k:
        break
    #while isb>0 and sa[isa]+sb[isb]>k:
    while sa[isa]+sb[isb]>k:
        isb-=1
    ans = max(ans, isa+isb)
    
print(ans)
Buggy code:
n, m, k = map(int, input().split(' '))
list_a = list(map(int, input().split(' ')))
list_b = list(map(int, input().split(' ')))
 
a_sum=[list_a[0]]
for i in range(1, n):
  a_sum.append(list_a[i]+a_sum[i-1])
  
b_sum=[list_b[0]]
for i in range(1, m):
  b_sum.append(list_b[i]+b_sum[i-1])

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

print(ans)

Fixed code:
n, m, k = map(int, input().split(' '))
list_a = list(map(int, input().split(' ')))
list_b = list(map(int, input().split(' ')))
 
a_sum=[list_a[0]]
for i in range(1, n):
  a_sum.append(list_a[i]+a_sum[i-1])
  
b_sum=[list_b[0]]
for i in range(1, m):
  b_sum.append(list_b[i]+b_sum[i-1])

  
ans=0 
if (a_sum[0]>k) and (b_sum[0]>k):
  print(0)
else:
  for j in range(m):
    if b_sum[j]<=k:
      ans=max(ans, j+1)
  j=m-1
  for i in range(n):
    if a_sum[i]<=k:
      ans=max(ans, i+1)
      while a_sum[i] + b_sum[j] > k and j>0:
        j-=1
      if a_sum[i]+b_sum[j]<=k:
        ans=max(ans, i+j+2)
  print(ans)
Buggy code:
from bisect import bisect
n, m, k = map(int, input().split())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))

list_AS = []
list_BS = []
a = 0
b = 0
for i in list_A:
    a += i
    list_AS.append(a)

for i in list_B:
    b += i
    list_BS.append(b)
ans = 0

for i in range(n):
    j = bisect(list_BS, k-list_AS[i])
    ans = max(ans, i + j + 1)


print(ans)

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

list_AS = []
list_BS = []
a = 0
b = 0
list_AS.append(0)
for i in list_A:
    a += i
    list_AS.append(a)
list_BS.append(0)
for i in list_B:
    b += i
    list_BS.append(b)
ans = 0
for i in range(n+1):
    j = bisect(list_BS, k-list_AS[i])
    if list_AS[i] + list_BS[j-1] <= k:
        ans = max(ans, i+j-1)

print(ans)
Buggy code:
import sys
import numpy as np
input = sys.stdin.readline

N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))


A_list.insert(0, 0)
B_list.insert(0, 0)
B_cumsum = np.cumsum(B_list)

time = B_cumsum[-1]
ans, j = 0, M

for i in range(N+1):
    if (time > K):
        break
    while (j > 0 and time > K):
        time -= B_list[j]
        j -= 1

    ans = max(ans, i+j)
    time += A_list[i]

print(ans)

Fixed code:

import sys
import numpy as np
input = sys.stdin.readline

N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))


A_list.insert(0, 0)
B_list.insert(0, 0)
A_cumsum = np.cumsum(A_list)
B_cumsum = np.cumsum(B_list)

time = B_cumsum[-1]
ans, j = 0, M



for i in range(N+1):
    if A_cumsum[i] > K:
        break
    while B_cumsum[j] > K - A_cumsum[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)
Buggy code:
N, M, K =  [int(x) for x in input().split()]

stackA = [int(x) for x in input().split()]
stackB = [int(x) for x in input().split()]

indexB = 0
indexA = 0

books = 0
mostBooks = 0
time = 0

for x in stackB:
    if time + x > K:
        indexB -= 1
        break

    else:
        time += x
        indexB += 1
        books += 1

indexB -= 1

mostBooks = books

for x in stackA:
    time += x
    books += 1

    while time > K and indexB >= 0:
        time -= stackB[indexB]
        indexB -= 1
        books -= 1

    if indexB < 0 and time > K:
        break

    mostBooks = max(mostBooks, books)

print(mostBooks)

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

stackA = [int(x) for x in input().split()]
stackB = [int(x) for x in input().split()]

indexB = 0
indexA = 0

books = 0
mostBooks = 0
time = 0

for x in stackB:
    if time + x > K:
        break

    else:
        time += x
        indexB += 1
        books += 1

indexB -= 1

mostBooks = books

for x in stackA:
    time += x
    books += 1

    while time > K and indexB >= 0:
        time -= stackB[indexB]
        indexB -= 1
        books -= 1

    if indexB < 0 and time > K:
        break

    mostBooks = max(mostBooks, books)

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

    AReqTime = [0]
    BReqTime = [0]

    for i in range(N):
        AReqTime.append(AReqTime[i] + A[i])
    for i in range(M):
        BReqTime.append(BReqTime[i] + B[i])

    j = M
    answer = 0

    for i in range(N):
        if(AReqTime[i] > K):
            break

        while BReqTime[j] > K - AReqTime[i]:
            j = j - 1

        answer = max(i + j, answer)

    print(answer)

if __name__ == "__main__":
    main()

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

    AReqTime = [0]
    BReqTime = [0]

    for i in range(N):
        AReqTime.append(AReqTime[i] + A[i])
    for i in range(M):
        BReqTime.append(BReqTime[i] + B[i])

    j = M
    answer = 0

    for i in range(N + 1):
        if(AReqTime[i] > K):
            break

        while BReqTime[j] > K - AReqTime[i]:
            j = j - 1

        answer = max(i + j, answer)

    print(answer)

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, 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()))
ans=0
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])
j=M
for i in range(N+1):
  if a[i]>K:
    break
  while a[i]+b[j]>K:
    j-=1
  ans=max(i+j,ans) 
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()))
ruia=[0]
ruib=[0]
mx=0
for (i,j) in zip(a,range(n)):
  ruia.append(ruia[j]+i)

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



Fixed code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ruia=[0]
ruib=[0]
mx=0
for (i,j) in zip(a,range(n)):
  ruia.append(ruia[j]+i)

for (i,j) in zip(b,range(m)):
  ruib.append(ruib[j]+i)
ans=0
for i in range(n+1):
  if ruia[i] > k:
    break
  while ruib[m] > k - ruia[i]:
    m -= 1
  ans = max(ans, i + m)
print(ans)
Buggy code:
from bisect import bisect_right

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(n):
    A.append(A[-1] + a[i])
for j in range(1, m):
    B.append(B[-1] + b[j])
    
ans = 0
for i in range(n):
    time = A[i]
    b_index = 0
    if time > k:
        break
    if k  - time > 0:
        b_index = bisect_right(B, k - time)
    ans = max(ans, i + b_index - 1)
print(ans)

Fixed code:
from bisect import bisect_right

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(n):
    A.append(A[-1] + a[i])
for j in range(m):
    B.append(B[-1] + b[j])
    
ans = 0
for i in range(n + 1):
    time = A[i]
    b_index = 0
    if time > k:
        break
    b_index = bisect_right(B, k - time)
    ans = max(ans, i + b_index - 1)
print(ans)
Buggy code:
from bisect import bisect

N, M, K = map(int, input().split())
A = [0]+list(map(int, input().split()))
B = list(map(int, input().split()))
R_B = [0]*(M+1)
i = 0
while i < M:
  R_B[i+1] = R_B[i]+B[i]
  i += 1 
ans = 0
i = 0
while i < N and K >= A[i]:
  K -= A[i]
  idx = bisect(R_B, K)
  ans = max(ans, i+idx-1)
  i += 1
print(ans)



Fixed code:
from bisect import bisect

N, M, K = map(int, input().split())
A = [0]+list(map(int, input().split()))
B = list(map(int, input().split()))
R_B = [0]*(M+1)
i = 0
while i < M:
  R_B[i+1] = R_B[i]+B[i]
  i += 1 
ans = 0
i = 0
while i <= N and K >= A[i]:
  K -= A[i]
  idx = bisect(R_B, K)
  ans = max(ans, i+idx-1)
  i += 1
print(ans)
Buggy code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m,k = na()
a = na()
b = na()
aa = [0]
bb = [0]

for i in a:
    aa.append(aa[-1]+i)
for i in b:
    bb.append(bb[-1]+i)

import bisect
ans = 0
for i in range(n+1):
    if aa[i] > k:
        break
    kk = k-aa[i]
    ans = max(ans, i+bisect.bisect_left(bb,kk))

print(ans)

Fixed code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m,k = na()
a = na()
b = na()
aa = [0]
bb = [0]

for i in a:
    aa.append(aa[-1]+i)
for i in b:
    bb.append(bb[-1]+i)

import bisect
ans = 0
for i in range(n+1):
    if aa[i] > k:
        break
    kk = k-aa[i]
    ans = max(ans, i+bisect.bisect_right(bb,kk)-1)

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

a,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:
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[-1]+A[i])
for j in range(m):
    b.append(b[-1]+B[j])
ans = 0
j = m
for i in range(n):
    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[-1]+A[i])
for j in range(m):
    b.append(b[-1]+B[j])
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 itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re



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

    A_len = len(A)
    maxB = len(B)

    Asum = [0] * (200000 + 1)

    maxA = 0

    add = 0
    for i in range(1,A_len+1):
        add += A[i-1]
        Asum[i] = add
        if add <= K:
            maxA = i + 1
        else:
            break

    ans = maxA
    prevmax = 0
    Bsum = 0
    for i in reversed(range(maxA)):
        for j in range(prevmax,maxB):
            Bsum += B[j]
            if Asum[i] + Bsum <= K:
                if ans < i + (j + 1):
                    ans = i + (j + 1)
                    prevmax = j

                if j == maxB - 1
                    print(ans)
                    exit()
            else:
                break


    print(ans)

main_sum()


Fixed code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re



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

    A_len = len(A)
    B_len = len(B)

    Asum = [0] * (A_len + 1)
    Bsum = [0] * (B_len + 1)

    maxA = len(A) + 1
    maxB = len(B) + 1

    add = 0
    for i in range(1,A_len+1):
        Asum[i] = A[i-1] + Asum[i-1]

    add = 0
    for i in range(1,B_len+1):
        Bsum[i] = B[i-1] + Bsum[i-1]

    ans = 0
    prev = 0
    for i in reversed(range(maxA)):
        for j in range(prev,maxB):
            if Asum[i] + Bsum[j] <= K:
                prev = j
                if ans < i + j:
                    ans = i + j
                if j == (maxB - 1):
                    print(ans)
                    exit()
            else:
                break

    print(ans)




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

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

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


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

a = [0]*(n+1)
b = [0]*(m+1)

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

ans = 0
best = m
for i in range(n+1):
    if k < a[i]:
        break
    for j in range(best,-1,-1):
        if b[j] <= k-a[i]:
            break
    ans = max(ans,i+j)
    best = 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()))
a,b = [0],[0]
for i in range(N):
  a.append(a[i]+A[i])
for j in range(M):
  b.append(b[j]+B[j])
ans = 0
#print(a,b,N+1)
for i in range(N+1):
  if a[i] > K:
    break
  j = 0
  while K - a[i] >= b[j]:
    if j >= M:
      break
    j = j+1
  j = j-1
  ans = max(ans,i+j)

print(ans)

Fixed code:
N,M,K = list(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 j in range(M):
  b.append(b[j]+B[j])
ans = 0
#print(a,b,N+1)
j = M
for i in range(N+1):
  if a[i] > K:
    break

  while K - a[i] < b[j]:
    j = 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+i):
        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:
from itertools import zip_longest, count, accumulate
from bisect import bisect, bisect_left

def LIST(): return list(map(int, input().split()))

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

num = 0

for i, a in enumerate(a):
    time_rest = k - a
    
    if time_rest < 0:
        continue
    
    num = max(num, i + bisect_left(b, time_rest))

print(num)

Fixed code:
from itertools import zip_longest, count, accumulate
from bisect import bisect, bisect_left
 
def LIST(): return list(map(int, input().split()))
 
n, m, k = map(int, input().split())
a = [0] + list(accumulate(LIST()))
b = list(accumulate(LIST()))
 
num = 0
 
for i, a in enumerate(a):
    time_rest = k - a
    
    if time_rest < 0:
        continue
    
    num = max(num, i + bisect(b, time_rest))
 
print(num)
Buggy code:


import sys
import math
import itertools
import collections

def solve(N,M,K,A,B):
    accumA = [0,A.pop(0)]
    accumB = [0,B.pop(0)]
    for a in A:
        accumA.append(accumA[-1] + a)
    for b in B:
        accumB.append(accumB[-1] + b)
    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)
    return ans

def main():
    N,M,K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    # solve()
    print(solve(N,M,K,A,B))

if __name__ == "__main__":
    main()




Fixed code:


import sys
import math
import itertools
import collections

def solve(N,M,K,A,B):
    accumA = [0,A.pop(0)]
    accumB = [0,B.pop(0)]
    for a in A:
        accumA.append(accumA[-1] + a)
    for b in B:
        accumB.append(accumB[-1] + b)
    ans = 0
    j = M
    for i in range(N + 1):
        if accumA[i] > K:
            break
        while accumB[j] > K - accumA[i]:
            j -= 1
        ans = max(ans,i + j)
    return ans

def main():
    N,M,K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    # solve()
    print(solve(N,M,K,A,B))

if __name__ == "__main__":
    main()
Buggy code:
n,m,k = map(int,input().split()) 
Al=list(map(int,input().split()) )
Bl=list(map(int,input().split()) )
bmax=0
A=[0]
B=[0]
for i in range(1,n+1):
    A[i] += A[i-1]+Al[i]  
for i in range(1,m+1):
    B[i] += B[i-1]+Bl[i]
    if B[i]<=k:
        bmax=i

ans=0
b=bmax
for a in range(len(A)):
    if A[a]>k:
        break
    # ans = max(ans, a+1)
    
    while A[a] + B[b] >k and b>=0:
        b -= 1
        
        
    ans = max(ans, a+b+2)
        
print(ans)


Fixed code:
n,m,k = map(int,input().split()) 
Al=list(map(int,input().split()) )
Bl=list(map(int,input().split()) )
bmax=0
A=[0]
B=[0]
for i in range(1,n+1):
    A.append(A[i-1]+Al[i-1])  
for i in range(1,m+1):
    B.append(B[i-1]+Bl[i-1])
    if B[i]<=k:
        bmax=i

ans=0
b=bmax
for a in range(len(A)):
    if A[a]>k:
        break
    # ans = max(ans, a+1)
    
    while A[a] + B[b] >k and b>=0:
        b -= 1
        
        
    ans = max(ans, a+b)
        
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 = A[0]
b = B[0]
a_lis = [a]
b_lis = [b]
for i in range(1,N):
    a += A[i]
    a_lis.append(a)
for j in range(1,M):
    b += B[j]
    b_lis.append(b)
ans = 0
for i in range(N):
    j = bisect.bisect_right(b_lis,K-a_lis[i])
    tmp_ans = i + j + 1
    if ans < tmp_ans:
        ans = tmp_ans
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 = A[0]
b = B[0]
a_lis = [0,a]
b_lis = [b]
for i in range(1,N):
    a += A[i]
    a_lis.append(a)
for j in range(1,M):
    b += B[j]
    b_lis.append(b)
ans = 0
for i in range(N+1):
    if a_lis[i] <= K:
        j = bisect.bisect_right(b_lis,K-a_lis[i])
        tmp_ans = i + j 
        if ans < tmp_ans:
            ans = tmp_ans
    else:
        break
print(ans)
Buggy code:
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_sum = [0]
B_sum = [0]
for i in range(N):
    A_sum.append(A_sum[i]+A[i])
for i in range(M):
    B_sum.append(B_sum[i]+B[i])


num = 0
J = M
for i in range(N+1):
    if A_sum[i] > K:
        break
    for j in (J,0,-1):
        if A_sum[i] + B_sum[j] <= K:
            if num < i+j:
                num = i+j
            J = j
            break

print(num)

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

A_sum = [0]
B_sum = [0]
for i in range(N):
    A_sum.append(A_sum[i]+A[i])
for i in range(M):
    B_sum.append(B_sum[i]+B[i])

num = 0
J = M
for i in range(N+1):
    if A_sum[i] > K:
        break
    for j in reversed(range(J+1)):
        if A_sum[i] + B_sum[j] <= K:
            if num < i+j:
                num = i+j
            J = j
            break

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