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

Fixed submission:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
current=0
for i in range(n):
  current+=a[i]
  asum.append(current)
current=0
pointer=0
for i in range(m):
  current+=b[i]
  bsum.append(current)
for i in range(n+1):
  if asum[i]>k:
    pointer=i-1
    break
  if i==n:
    pointer=n
ans=pointer
bpointer=0
for i in range(pointer,-1,-1):
  while bpointer<m+1 and bsum[bpointer]+asum[i]<=k:
    bpointer+=1
    if bpointer==m+1:
      break
  bpointer-=1
  ans=max(ans,i+bpointer)
print(ans)

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

Fixed submission:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
current=0
for i in range(n):
  current+=a[i]
  asum.append(current)
current=0
pointer=0
for i in range(m):
  current+=b[i]
  bsum.append(current)
for i in range(n+1):
  if asum[i]>k:
    pointer=i-1
    break
  if i==n:
    pointer=n
ans=pointer
bpointer=0
for i in range(pointer,-1,-1):
  while bpointer<m+1 and bsum[bpointer]+asum[i]<=k:
    bpointer+=1
    if bpointer==m+1:
      break
  bpointer-=1
  ans=max(ans,i+bpointer)
print(ans)

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

Fixed submission:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
current=0
for i in range(n):
  current+=a[i]
  asum.append(current)
current=0
pointer=0
for i in range(m):
  current+=b[i]
  bsum.append(current)
for i in range(n+1):
  if asum[i]>k:
    pointer=i-1
    break
  if i==n:
    pointer=n
ans=pointer
bpointer=0
for i in range(pointer,-1,-1):
  while bpointer<m+1 and bsum[bpointer]+asum[i]<=k:
    bpointer+=1
    if bpointer==m+1:
      break
  bpointer-=1
  ans=max(ans,i+bpointer)
print(ans)

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

Fixed submission:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
current=0
for i in range(n):
  current+=a[i]
  asum.append(current)
current=0
pointer=0
for i in range(m):
  current+=b[i]
  bsum.append(current)
for i in range(n+1):
  if asum[i]>k:
    pointer=i-1
    break
  if i==n:
    pointer=n
ans=pointer
bpointer=0
for i in range(pointer,-1,-1):
  while bpointer<m+1 and bsum[bpointer]+asum[i]<=k:
    bpointer+=1
    if bpointer==m+1:
      break
  bpointer-=1
  ans=max(ans,i+bpointer)
print(ans)

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

Fixed submission:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
current=0
for i in range(n):
  current+=a[i]
  asum.append(current)
current=0
pointer=0
for i in range(m):
  current+=b[i]
  bsum.append(current)
for i in range(n+1):
  if asum[i]>k:
    pointer=i-1
    break
  if i==n:
    pointer=n
ans=pointer
bpointer=0
for i in range(pointer,-1,-1):
  while bpointer<m+1 and bsum[bpointer]+asum[i]<=k:
    bpointer+=1
    if bpointer==m+1:
      break
  bpointer-=1
  ans=max(ans,i+bpointer)
print(ans)

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

Fixed submission:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
current=0
for i in range(n):
  current+=a[i]
  asum.append(current)
current=0
pointer=0
for i in range(m):
  current+=b[i]
  bsum.append(current)
for i in range(n+1):
  if asum[i]>k:
    pointer=i-1
    break
  if i==n:
    pointer=n
ans=pointer
bpointer=0
for i in range(pointer,-1,-1):
  while bpointer<m+1 and bsum[bpointer]+asum[i]<=k:
    bpointer+=1
    if bpointer==m+1:
      break
  bpointer-=1
  ans=max(ans,i+bpointer)
print(ans)

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

Fixed submission:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
current=0
for i in range(n):
  current+=a[i]
  asum.append(current)
current=0
pointer=0
for i in range(m):
  current+=b[i]
  bsum.append(current)
for i in range(n+1):
  if asum[i]>k:
    pointer=i-1
    break
  if i==n:
    pointer=n
ans=pointer
bpointer=0
for i in range(pointer,-1,-1):
  while bpointer<m+1 and bsum[bpointer]+asum[i]<=k:
    bpointer+=1
    if bpointer==m+1:
      break
  bpointer-=1
  ans=max(ans,i+bpointer)
print(ans)

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

Fixed submission:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
current=0
for i in range(n):
  current+=a[i]
  asum.append(current)
current=0
pointer=0
for i in range(m):
  current+=b[i]
  bsum.append(current)
for i in range(n+1):
  if asum[i]>k:
    pointer=i-1
    break
  if i==n:
    pointer=n
ans=pointer
bpointer=0
for i in range(pointer,-1,-1):
  while bpointer<m+1 and bsum[bpointer]+asum[i]<=k:
    bpointer+=1
    if bpointer==m+1:
      break
  bpointer-=1
  ans=max(ans,i+bpointer)
print(ans)

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

Fixed submission:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
current=0
for i in range(n):
  current+=a[i]
  asum.append(current)
current=0
pointer=0
for i in range(m):
  current+=b[i]
  bsum.append(current)
for i in range(n+1):
  if asum[i]>k:
    pointer=i-1
    break
  if i==n:
    pointer=n
ans=pointer
bpointer=0
for i in range(pointer,-1,-1):
  while bpointer<m+1 and bsum[bpointer]+asum[i]<=k:
    bpointer+=1
    if bpointer==m+1:
      break
  bpointer-=1
  ans=max(ans,i+bpointer)
print(ans)