Buggy python submission (verdict: Time Limit Exceeded):
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  AS.append(i+AS[-1])
for i in B:
  BS.append(i+BS[-1])
p=n+m+2
f=m+2
for i in range(1,n+2):
  for j in range(1,f):
    if AS[-i]+BS[-j]<=k:
      r=max(r,p-i-j)
      f=j
      break
print(r)

Fixed submission:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  if i+AS[-1]<=k:
    AS.append(i+AS[-1])
  else:
    break
    
for i in B:
  if i+BS[-1]<=k:
    BS.append(i+BS[-1])
  else:
    break
    
j=len(BS)-1
for i in range(len(AS)):
  while AS[i]+BS[j]>k:
    j-=1
  r=max(r,i+j)
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  AS.append(i+AS[-1])
for i in B:
  BS.append(i+BS[-1])
p=n+m+2
f=m+2
for i in range(1,n+2):
  for j in range(1,f):
    if AS[-i]+BS[-j]<=k:
      r=max(r,p-i-j)
      f=j
      break
print(r)

Fixed submission:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  if i+AS[-1]<=k:
    AS.append(i+AS[-1])
  else:
    break
    
for i in B:
  if i+BS[-1]<=k:
    BS.append(i+BS[-1])
  else:
    break
    
j=len(BS)-1
for i in range(len(AS)):
  while AS[i]+BS[j]>k:
    j-=1
  r=max(r,i+j)
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=[]
for i in A:
  if i+AS[-1]>k:
    break
  AS.append(i+AS[-1])
for i in B:
  if i+BS[-1]>k:
    break
  BS.append(i+BS[-1])
for i in range(len(AS)):
  for j in range(len(BS)):
    if AS[i]+BS[j]<=k:
      r.append(i+j)
print(sorted(r)[-1])

Fixed submission:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  if i+AS[-1]<=k:
    AS.append(i+AS[-1])
  else:
    break
    
for i in B:
  if i+BS[-1]<=k:
    BS.append(i+BS[-1])
  else:
    break
    
j=len(BS)-1
for i in range(len(AS)):
  while AS[i]+BS[j]>k:
    j-=1
  r=max(r,i+j)
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  AS.append(i+AS[-1])
  if AS[-1]>k:
    break
for i in B:
  BS.append(i+BS[-1])
  if BS[-1]>k:
    break
for i in range(len(AS)):
  for j in range(len(BS)):
    if AS[i]+BS[j]<=k:
      if i+j>r:
        r=i+j
print(r)

Fixed submission:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  if i+AS[-1]<=k:
    AS.append(i+AS[-1])
  else:
    break
    
for i in B:
  if i+BS[-1]<=k:
    BS.append(i+BS[-1])
  else:
    break
    
j=len(BS)-1
for i in range(len(AS)):
  while AS[i]+BS[j]>k:
    j-=1
  r=max(r,i+j)
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  AS.append(i+AS[-1])
for i in B:
  BS.append(i+BS[-1])
for i in range(n+1):
  for j in range(m+1):
    if AS[i]+BS[j]<=k:
      if i+j>r:
        r=i+j
print(r)

Fixed submission:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  if i+AS[-1]<=k:
    AS.append(i+AS[-1])
  else:
    break
    
for i in B:
  if i+BS[-1]<=k:
    BS.append(i+BS[-1])
  else:
    break
    
j=len(BS)-1
for i in range(len(AS)):
  while AS[i]+BS[j]>k:
    j-=1
  r=max(r,i+j)
print(r)