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()))
arui = [0] * (N + 1)
brui = [0] * (M + 1)
for i in range(N):
    arui.append(a[i] + arui[i])
for i in range(M):
    brui.append(b[i] + brui[i])

ans = 0
for i in range(N + 1):
    if arui[i] > K:
        break
    bcnt = M
    while brui[bcnt] + arui[i] > K:
        bcnt -= 1
    ans = max(ans, i + bcnt)

print(ans)

Fixed code:
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arui = [0] * (N + 1)
brui = [0] * (M + 1)
for i in range(N):
    arui[i + 1] = a[i] + arui[i]
for i in range(M):
    brui[i + 1] = b[i] + brui[i]


ans, j = 0, M
for i in range(N + 1):
    if arui[i] > K:
        break
    while brui[j] > K - arui[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[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])
    
c=0
idx=m

for i in range(n+1):
    while 1:
        if idx<0:
            break
        if a[i]+b[idx]>k:
            print(a[i]+b[idx])
            idx-=1
            continue
        else:
            c=max(i+idx,c)
            break
else:
    print(c)

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])
    
c=0
idx=m

for i in range(n+1):
    while 1:
        if idx<0:
            break
        if a[i]+b[idx]>k:
            idx-=1
            continue
        else:
            c=max(i+idx,c)
            break
else:
    print(c)
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 = [0] + list(accumulate(a))
B = [0] + list(accumulate(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)

print(ans)

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 = [0] + list(accumulate(a))
B = [0] + list(accumulate(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)

print(ans)
Buggy code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from bisect import bisect
n,k,m = map(int,readline().split())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]

aa = [0]*(n+1)
bb = [0]*(k+1)
for i in range(n):
  aa[i+1] = aa[i]+a[i]
for i in range(k):
  bb[i+1] = bb[i]+b[i]
  
ans = 0
for num,i in enumerate(bb):
  M = m-i
  ind = bisect(aa,M)
  ans = max(ans,num+ind-1)
  
print(ans)

Fixed code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from bisect import bisect_right
n,k,m = map(int,readline().split())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]

aa = [0]*(n+1)
bb = [0]*(k+1)
for i in range(n):
  aa[i+1] = aa[i]+a[i]
for i in range(k):
  bb[i+1] = bb[i]+b[i]
  
ans = 0
for num,i in enumerate(bb):
  M = m-i
  if M >= 0:
    ind = bisect_right(aa,M)
    ans = max(ans,num+ind-1)
  
print(ans)
Buggy code:
import itertools

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

sumA = list(itertools.accumulate(A))
sumB = list(itertools.accumulate(B))
ans=0
j=M-1
for i in range(N):
    if sumA[i]>K and i>0:
        break
    while K<sumA[i]+sumB[j] and j>=0:
        j-=1
    ans=max(ans,i+j+2)
print(ans)

Fixed code:
import itertools

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

sumA = list(itertools.accumulate(A))
sumB = list(itertools.accumulate(B))
j=M-1
while K<sumB[j] and j>=0:
    j-=1
ans=j+1
for i in range(N):
    if sumA[i]>K:
        break
    while K<sumA[i]+sumB[j] and j>=0:
        j-=1
    ans=max(ans,i+j+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=[0]+A
B=[0]+B

from itertools import accumulate

AA=list(accumulate(A))
BB=list(accumulate(B))



print(AA)
print(BB)

timer=0
count=0
a,b=0,0

import bisect
for i in range(N+1):
    a=i
    b=bisect.bisect_right(BB,K-AA[i])-1
    if b==-1:
        continue
    count=max(count,a+b)
    #print(a,b,count,AA[a]+BB[b])
print(count)



Fixed code:
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

from itertools import accumulate

AA=list(accumulate(A))
BB=list(accumulate(B))
count=0
a,b=0,0

import bisect
for i in range(N+1):
    a=i
    b=bisect.bisect_right(BB,K-AA[i])-1
    if b==-1:
        continue
    count=max(count,a+b)
print(count)
Buggy code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

p, q = [0], [0]
for i in range(n):
	p.append(p[i] + a[i])
for i in range(m):
	q.append(q[i] + b[i])

j, ans = m, 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 = list(map(int, input().split()))
b = list(map(int, input().split()))

p, q = [0], [0]
for i in range(n):
	p.append(p[i] + a[i])
for i in range(m):
	q.append(q[i] + b[i])

j, ans = m, 0
for i in range(n+1):
	if p[i] > k:
		break

	while q[j] > k - p[i]:
		j -= 1

	ans = max(ans, i+j)

print(ans)
Buggy code:
import numpy

n,m,k = map(int,input().split())
li_a = list(map(int,input().split()))
li_b = list(map(int,input().split()))

li_A = numpy.cumsum(li_a)
li_B = numpy.cumsum(li_b)

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

Fixed code:
import numpy

n,m,k = map(int,input().split())
li_a = list(map(int,input().split()))
li_b = list(map(int,input().split()))

li_A = [0] + list(numpy.cumsum(li_a))
li_B = [0] + list(numpy.cumsum(li_b))

ans, j = 0,m
for i in range(n+1):
    if li_A[i] > k:
        break
    while li_B[j] + li_A[i]> k:
        j -= 1
    ans = max(ans, i + j)
print(ans)
Buggy code:
# -*- coding: utf-8 -*-
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

ans=0
T=0
for i in range(N):
    T+=A[i]
    if T > K:
        T-=A[i]
        ans-=1
        break
    else:
        ans+=1
R=[]
R.append(ans)
n=ans
m=0
while(1):
    while(1):
        if m>=M: break
        T+=B[m]
        
        if T > K:
            T-=B[m]
            break
        else:
            ans+=1
            R.append(ans)
            m+=1
            
    n-=1
    if n<0: break
    T-=A[n]
    ans-=1
    

print(max(R))

Fixed code:
# -*- coding: utf-8 -*-
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

ans=0
T=0
for i in range(N):
    T+=A[i]
    if T > K:
        T-=A[i]
        break
    else:
        ans+=1
R=[]
R.append(ans)
n=ans
m=0
while(1):
    while(1):
        if m>=M: break
        T+=B[m]
        
        if T > K:
            T-=B[m]
            break
        else:
            ans+=1
            R.append(ans)
            m+=1
            
    n-=1
    if n<0: break
    T-=A[n]
    ans-=1
    

print(max(R))
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 = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ai = -1
bi = -1
answer = 0
t_sum = 0
if sum(a) + sum(b) <= k:
    print(n + m)
elif sum(a) <= k:
    t_sum = sum(a)
    ai = n-1
    while True:
        bi += 1
        if t_sum + b[bi] > k:
            break
        t_sum += b[bi] 
    bi -= 1
    answer = ai + bi + 2
    while ai >= 0:
        t_sum -= a[ai]
        ai -= 1
        while bi <= m:
            bi += 1
            if t_sum + b[bi] > k:
                break
            t_sum += b[bi]
        bi -= 1
        if ai + bi +2 > answer:
            answer = ai + bi +2
    print(answer)
else:
    for i in range(n):
        t_sum += a[i]
        if t_sum > k:
            ai = i-1
            break
    while True:
        bi += 1
        if t_sum + b[bi] > k:
            break
        t_sum += b[bi] 
    bi -= 1
    answer = ai + bi + 2
    while ai >= 0:
        t_sum -= a[ai]
        ai -= 1
        while bi <= m:
            bi += 1
            if t_sum + b[bi] > k:
                break
            t_sum += b[bi]
        bi -= 1
        if ai + bi +2 > answer:
            answer = ai + bi +2
    print(answer)

Fixed code:
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ai = -1
bi = -1
answer = 0
t_sum = 0
if sum(a) + sum(b) <= k:
    print(n + m)
elif sum(a) <= k:
    t_sum = sum(a)
    ai = n-1
    while True:
        bi += 1
        if bi == m:
            break
        if t_sum + b[bi] > k:
            break
        t_sum += b[bi] 
    bi -= 1
    answer = ai + bi + 2
    while ai >= 0:
        t_sum -= a[ai]
        ai -= 1
        while bi <= m-1:
            bi += 1
            if bi == m:
                break
            if t_sum + b[bi] > k:
                break
            t_sum += b[bi]
        bi -= 1
        if ai + bi +2 > answer:
            answer = ai + bi +2
    print(answer)
else:
    while True:
        ai += 1
        if t_sum + a[ai] > k:
            break
        t_sum += a[ai]
    ai -= 1
    while True:
        bi += 1
        if bi == m:
            break
        if t_sum + b[bi] > k:
            break
        t_sum += b[bi]
    bi -= 1
    answer = ai + bi + 2
    while ai >= 0:
        t_sum -= a[ai]
        ai -= 1
        while bi <= m-1:
            bi += 1
            if bi == m:
                break
            if t_sum + b[bi] > k:
                break
            t_sum += b[bi]
        bi -= 1
        if ai + bi +2 > answer:
            answer = ai + bi +2
    print(answer)
Buggy code:
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N, M, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))


    nowtime = 0

    Asum = []
    Bsum = []
    tmp = 0
    for a in A:
        tmp += a
        Asum.append(tmp)
    tmp = 0
    for b in B:
        tmp += b
        Bsum.append(tmp)

    maxbooks = 0
    for acount in range(N):
        for bcount in range(before, M):
            if K < Asum[acount] + Bsum[bcount]:
                acount -= 1
                break
        maxbooks = max(maxbooks, acount+bcount)

    print(maxbooks)

    print(acount+bcount-1)



if __name__ == '__main__':
    solve()

Fixed code:
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N, M, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))


    nowtime = 0

    Asum = [0]
    Bsum = [0]
    tmp = 0
    for a in A:
        tmp += a
        Asum.append(tmp)
    tmp = 0
    for b in B:
        tmp += b
        Bsum.append(tmp)

    maxbooks = 0
    before = M
    bcount = M
    for acount in range(N+1):
        if Asum[acount] > K:
            continue
        while K < Asum[acount] + Bsum[bcount]:
            bcount -= 1
        maxbooks = max(maxbooks, acount+bcount)

    print(maxbooks)



if __name__ == '__main__':
    solve()
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 n in range(N + 1):
  while True:
    time = A[n] + B[j]
    if time > K:
      j -= 1
    else:
      ans = max(ans, n + 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()))

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 n in range(N + 1):
  if A[n] > K:
    break
  while B[j] > K - A[n]:
      j -= 1
  ans = max(ans, n + j)
print(ans)
Buggy code:
N, M, K = map(int, input().split())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))
ans_a =0
ans_b =0
time =0

for i in range(N):
    if time + arr_a[i] > K:
        break
    else:
        ans_a +=1
        time += arr_a[i]
for i in range(M):
    if time + arr_b[i] > K:
        break
    else:
        ans_b +=1
        time += arr_b[i]

ans = ans_a + ans_b
ans_koho = ans_a + ans_b
cnt_b = ans_b

for i in range(ans_a):
    ans_koho -= 1
    time -= arr_a[-1*(i+1)]

    while True:
        if cnt_b == M:
            break
        elif time + arr_b[cnt_b] > K:
            break
        else:
            cnt_b += 1
            ans_koho += 1
    ans = max(ans, ans_koho)

print(ans)



Fixed code:
N, M, K = map(int, input().split())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))
ans_a =0
ans_b =0
time =0

for i in range(N):
    if time + arr_a[i] > K:
        break
    else:
        ans_a +=1
        time += arr_a[i]
for i in range(M):
    if time + arr_b[i] > K:
        break
    else:
        ans_b +=1
        time += arr_b[i]

ans = ans_a + ans_b
ans_koho = ans_a + ans_b
cnt_b = ans_b

for i in range(ans_a):
    ans_koho -= 1
    time -= arr_a[ans_a-i-1]

    while True:
        if cnt_b == M:
            break
        elif time + arr_b[cnt_b] > K:
            break
        else:
            time += arr_b[cnt_b]
            cnt_b += 1
            ans_koho += 1
    ans = max(ans, ans_koho)

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


Fixed code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A,B=[0],[0]
for i in range(n):
    A.append(A[i]+a[i])
for i in range(m):
    B.append(B[i]+b[i])
ans,j=0,m
for i in range(n+1):
    if A[i]>k:
        break
    while B[j]>k-A[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)
Buggy code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_time = [0]
time = 0
for i in range(N):
    time += A[i]
    A_time.append(time)
B_time = [0]
time = 0
for i in range(M):
    time += B[i]
    B_time.append(time)

def binarySearch(key):
    left = -1
    right = len(B_time)
    
    while right - left > 1:
        mid = left + (right - left)//2
        if B_time[mid] > key:
            right = mid
        else:
            left = mid
    return left

Max = 0
for i in range(len(A_time)):
    j = binarySearch(K - A_time[i])
    Max = max(Max, i+j)

print(Max)
    

Fixed code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_time = [0]
time = 0
for i in range(N):
    time += A[i]
    A_time.append(time)
B_time = [0]
time = 0
for i in range(M):
    time += B[i]
    B_time.append(time)

def binarySearch(key):
    left = -1
    right = len(B_time)
    
    while right - left > 1:
        mid = left + (right - left)//2
        if B_time[mid] > key:
            right = mid
        else:
            left = mid
    return left

Max = 0
for i in range(len(A_time)):
    j = binarySearch(K - A_time[i])
    Max = max(Max, i+j)
    if j < 0:
        break

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

ruiseki_A = [0]
ruiseki_B = [0]

for i in range(len(A)):
    ruiseki_A.append(ruiseki_A[i]+A[i])
for i in range(len(B)):
    ruiseki_B.append(ruiseki_B[i]+B[i])
#print(ruiseki_A)

ans = 0
for i in range(len(ruiseki_A)):
    tmp = K - ruiseki_A[i]
    if tmp < 0:
        continue
    r = len(B)
    l = 0
    while r-l > 1:
        mid = (r + l) // 2
        if ruiseki_B[mid] <= tmp:
            l = mid
        else:
            r = mid
    ans = max(ans, i+l)

print(ans)

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

ruiseki_A = [0]
ruiseki_B = [0]

for i in range(len(A)):
    ruiseki_A.append(ruiseki_A[i]+A[i])
for i in range(len(B)):
    ruiseki_B.append(ruiseki_B[i]+B[i])
#print(ruiseki_A)

ans = 0
for i in range(len(ruiseki_A)):
    tmp = K - ruiseki_A[i]
    if tmp < 0:
        continue
    r = len(ruiseki_B)
    l = 0
    while r-l > 1:
        mid = (r + l) // 2
        if ruiseki_B[mid] <= tmp:
            l = mid
        else:
            r = mid
    ans = max(ans, i+l)

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

ruisekiA = [0]
ruisekiB = [0]
tmpA=0
tmpB=0
for i in range(len(A)):
    tmpA += A[i]
    ruisekiA.append(tmpA)
for i in range(len(B)):
    tmpB += B[i]
    ruisekiB.append(tmpB)
ans = 0
for i in range(len(ruisekiA)):
    #tmp = ruisekiA[i]
    l = -1
    r = len(ruisekiB)
    while r - l > 1:
        mid = (r + l)//2
        tmp = ruisekiA[i]+ruisekiB[mid]
        if tmp <= K:
            l = mid
        else:
            r = mid
    ans = max(ans, i+l)
print(ans)

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

ruisekiA = [0]
ruisekiB = [0]
tmpA=0
tmpB=0
for i in range(len(A)):
    tmpA += A[i]
    ruisekiA.append(tmpA)
for i in range(len(B)):
    tmpB += B[i]
    ruisekiB.append(tmpB)
ans = 0
for i in range(len(ruisekiA)):
    #tmp = ruisekiA[i]
    l = -1
    r = len(ruisekiB)
    while r - l > 1:
        mid = (r + l)//2
        tmp = ruisekiA[i]+ruisekiB[mid]
        if tmp <= K:
            l = mid
        else:
            r = mid
    if l == -1:
        continue
    ans = max(ans, i+l)
print(ans)
Buggy code:
N, M, K = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))


def cumsum(l):
    s = 0
    for v in l:
        s += v
        yield s


a = (0,) + tuple(cumsum(A))
b = (0,) + tuple(cumsum(B))
ans = 0
m = M
for i in range(N):
    if a[i] > K:
        continue
    for j in range(m, -1, -1):
        if a[i] + b[j] <= K:
            k = j
            break
        else:
            continue
    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()))


def cumsum(l):
    s = 0
    for v in l:
        s += v
        yield s


a = [0] + list(cumsum(A))
b = [0] + list(cumsum(B))
ans = 0
n = N + 1
m = M
for i in range(n):
    if a[i] > K:
        continue
    for j in range(m, -1, -1):
        if a[i] + b[j] <= K:
            m = j
            break
        else:
            continue
    ans = max(ans, i + j)
print(ans)
Buggy code:
def resolve():
    lines = sys.stdin.readlines()

    n, m, k = tuple(map(int, lines[0].strip().split(' ')))
    A = list(map(int, lines[1].strip().split(' ')))
    B = list(map(int, lines[2].strip().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])

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

resolve()

Fixed code:
import sys

def resolve():
    lines = sys.stdin.readlines()

    n, m, k = tuple(map(int, lines[0].strip().split(' ')))
    A = list(map(int, lines[1].strip().split(' ')))
    B = list(map(int, lines[2].strip().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])

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

resolve()
Buggy code:
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AA=[0]*(N+1)
BB=[0]*(M+1)
A3=0
B3=0
high=0
for i in range(0,N):
    A3+=A[i]
    AA[i+1]=A3
for j in range(0,M):
    B3+=B[j]
    BB[j+1]=B3
for i in range(0,N+1):
    while True:
        if BB==[]:
            break
        elif AA[i]+BB[-1]>K:
            BB.pop(-1)
        else:
            break
    if high<i+len(BB)-1:
        high=i+len(BB)-1
print(high)

Fixed code:
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AA=[0]*(N+1)
BB=[0]*(M+1)
A3=0
B3=0
high=0
for i in range(0,N):
    A3+=A[i]
    AA[i+1]=A3
for j in range(0,M):
    B3+=B[j]
    BB[j+1]=B3
for i in range(0,N+1):
    if AA[i]>K:
        break
    while True:
        if BB==[]:
            break
        elif BB==[0]:
            BB=[]
            break
        elif AA[i]+BB[-1]>K:
            BB.pop(-1)
        else:
            break
    if BB!=[]:
        time=AA[i]+BB[-1]
        judge=1
    else:
        time=AA[i]
        judge=0
    if time<=K:
        if judge==0:
            if high<i:
                high=i
        else:
            if high<i+len(BB)-1:
                high=i+len(BB)-1
print(high)
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

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

for j in range(n+1):
  K=k-A[j]
  if K<0:
    break
  else:
    ans=max(ans,bisect.bisect_left(B,K)+j-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()))
ans=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])

for j in range(n+1):
  K=k-A[j]
  if K<0:
    break
  else:
    ans=max(ans,bisect.bisect_right(B,K)+j-1)
print(ans)