Buggy python submission (verdict: Runtime Error):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
temp,temp2=0,0
Sa,Sb=[0]*n,[0]*m
for i in range(n):
    temp+=a[i]
    Sa[i]=temp
for i in range(m):
    temp2+=b[i]
    Sb[i]=temp2
ans,j=0,m-1
for i in range(n):
    if Sa[i]>k: break
    while Sa[i]+Sb[j]>k: j-=1
    ans=max(ans,i+j+2)
print(ans)

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

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

Buggy python submission (verdict: Runtime Error):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
temp,temp2=0,0
Sa,Sb=[0]*n,[0]*m
for i in range(n):
    temp+=a[i]
    Sa[i]=temp
for i in range(m):
    temp2+=b[i]
    Sb[i]=temp2
ans,j=0,m-1
for i in range(n):
    if a[i]>k: break
    while a[i]+b[j]>k: j-=1
    ans=max(ans,i+j)
print(ans)

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

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

Buggy python submission (verdict: Runtime Error):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
temp,temp2=0,0
Sa,Sb=[0]*n,[0]*m
for i in range(n):
    temp+=a[i]
    Sa[i]=temp
for i in range(m):
    temp2+=b[i]
    Sb[i]=temp2
temp=0
flag=0
ans=0
for i in range(n-1,-1,-1):
    S=Sa[i]
    if S+Sb[temp]>k: continue
    while S+Sb[temp]<=k:
        temp+=1
        if temp==m:
            flag=1
            break
    t=(i+1)+temp
    if t>ans: ans=t
    #if flag: break
print(ans)

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

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

Buggy python submission (verdict: Runtime Error):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
temp=0
an,bn=0,0
ans=0
while temp<=k:
    if an==n and bn==m: break
    if an>=n:
        temp+=b[bn]
        if temp>k: break
        bn+=1
    elif bn>=m:
        temp+=a[an]
        if temp>k: break
        an+=1
    else:
        if a[an]<b[bn]:
            temp+=a[an]
            if temp>k: break
            an+=1
        elif a[an]>b[bn]:
            temp+=b[bn]
            if temp>k: break
            bn+=1
        else:
            cnt=0
            while True:
                if a[an]<b[bn]:
                    temp+=a[an]
                    an+=1
                    bn-=cnt
                    break
                elif a[an]>b[bn]:
                    temp+=b[bn]
                    bn+=1
                    an-=cnt
                    break
                if an==n:
                    break
                if bn==m:
                    break
                temp+=a[an]
                if temp>k:
                    break
                an+=1
                bn+=1
                ans+=1
                cnt+=1
            if temp>k:
                break
    ans+=1
print(ans)

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

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

Buggy python submission (verdict: Runtime Error):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
temp=0
an,bn=0,0
ans=0
bf=[]
flag=0
while temp<=k:
    if an==n and bn==m: break
    if an>=n:
        temp+=b[bn]
        if temp>k: break
        bn+=1
    elif bn>=m:
        temp+=a[an]
        if temp>k: break
        an+=1
    else:
        if a[an]<b[bn]:
            if flag:
                b=temp[:]+b[:]
                bn-=len(temp)
                temp=[]
                flag=0
            temp+=a[an]
            if temp>k: break
            an+=1
        elif a[an]>b[bn]:
            if flag:
                a=temp[:]+a[:]
                an-=len(temp)
                temp=[]
                flag=0
            temp+=b[bn]
            if temp>k: break
            bn+=1
        else:
            temp+=a[an]
            if temp>k: break
            bf.append(a[an])
            flag=1
            an+=1
            bn+=1
    ans+=1
print(ans)

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

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