peterverebics/CodeNet_Python_118 huggingface dataset:
N, M, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in 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, 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)
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) #a[0]=0だからbしか含まない形も考慮されてる
print(ans)
from itertools import accumulate
from bisect import bisect_right
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Acc=list(accumulate(B))
ans=0
time=0
a_cnt=0
for a in A:
    remain=k-time
    if remain<0:
        break
    b_cnt=bisect_right(Acc,remain)
    ans=max(ans,a_cnt+b_cnt)
    time+=a
    a_cnt+=1
remain=k-time
if remain>=0:
    b_cnt=bisect_right(Acc,remain)
    ans=max(ans,a_cnt+b_cnt)
print(ans)
readints = lambda: list(map(int, input().split()))
n, m, k = readints()
a = readints()
b = readints()
a.insert(0, 0)
b.insert(0, 0)

ans = 0

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

print (ans)
import bisect

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cuma, cumb = [0], [0]
for i in range(1, n+1):
    cuma.append(cuma[i-1] + a[i-1])
for i in range(1, m+1):
    cumb.append(cumb[i-1] + b[i-1])
ans = [0]
for i in range(n+1):
    if cuma[i] <= k:
        t = k - cuma[i]
        j = bisect.bisect_right(cumb, t)
        ans.append(i+j-1)
print(max(ans))
from bisect import bisect_right

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

cumA = [0]
for i in range(N):
    cumA.append(cumA[-1] + A[i])
cumB = [0]
for i in range(M):
    cumB.append(cumB[-1] + B[i])

# print(cumA)
# print(cumB)

ans = 0
for i, s1 in enumerate(cumA):
    j = bisect_right(cumB, K - s1) - 1
    if j >= 0:
        s2 = cumB[j]
        assert s1 + s2 <= K
        ans = max(ans, i + j)

print(ans)
import itertools

n,m,k = map(int,input().split())
a = list(map(int,('0 '+input()).split()))
b = list(map(int,('0 '+input()).split()))

asum = list(itertools.accumulate(a))
bsum = list(itertools.accumulate(b))

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

print(ans)
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

asum=[0]
bsum=[0]

for i in range(n):
  asum.append(asum[i]+A[i])
  
for j in range(m):
  bsum.append(bsum[j]+B[j])

ans=0
ko=m
for i in range(n+1):
  if asum[i]>k:
    break
  while asum[i]+bsum[ko]>k:
    ko-=1
  ans=max(ans,i+ko)
  
print(ans)
from itertools import accumulate

N, M, K = map(int, input().split())
a = [0] + list(accumulate(int(i) for i in input().split()))
b = [0] + list(accumulate(int(i) for i in input().split()))

cnt = 0
best0 = M
for i in range(N+1):
    ai = a[i]
    for j in range(best0, -1, -1):
        bj = b[j]
        if ai + bj <= K:
            cnt = max(cnt, i + j)
            best0 = j
            break

print(cnt)
import sys
input = sys.stdin.readline

from bisect import bisect_right

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

AA = [0]
for a in A:
    AA.append(AA[-1]+a)
BB = [0]
for b in B:
    BB.append(BB[-1]+b)

ans = 0
for i, aa in enumerate(AA):
    if aa > K: break
    ind = bisect_right(BB, K-aa)-1
    ans = max(ans, ind+i)

print(ans)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

na, nb = [0], [0]
for i in range(n):
    na.append(na[i] + a[i])
for j in range(m):
    nb.append(nb[j] + b[j])

ans, j = 0, m
for i in range(n + 1):
    if na[i] > k:
        break
    while nb[j] > k - na[i]:
        j -= 1
    ans = max(ans, i + j)
    
print(ans)
import bisect
N,M,K = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

A_acc=[0]
B_acc=[0]

for a in A:
    A_acc.append(a+A_acc[-1])
for b in B:
    B_acc.append(b+B_acc[-1])

ans=0
for i in range(len(A_acc)):
    a_time = A_acc[i]
    remain = K-a_time
    if remain>=0:
        idx = bisect.bisect_right(B_acc,remain)
        if idx==0:
            continue
        ans=max(ans,i+idx-1)
print(ans)
#abc172c
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=[0]
y=[0]
for i in range(n):
 x.append(x[i]+a[i])
for i in range(m):
 y.append(y[i]+b[i])
res=0
j=m
for i in range(n+1):
 if x[i]>k:
  break
 while y[j]>k-x[i]:
  j-=1
 res=max(res,i+j)
print(res)
import itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M,K = LI()
A = LI()
B = LI()
accumulate_A = [0]+list(itertools.accumulate(A))
accumulate_B = [0]+list(itertools.accumulate(B))
ans,j = 0,M
for i in range(N+1):
    if accumulate_A[i]>K:
        break
    while accumulate_A[i]+accumulate_B[j]>K:
        j -= 1
    ans = max(ans,i+j)
print(ans)
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

i, j = 0, 0
c = 0
num = 0
while i < n and c + A[i] <= k:
    c = c + A[i]
    num += 1
    i += 1
while j < m and B[j] + c <= k:
    c = c + B[j]
    num += 1
    j += 1
for a in range(i-1, -1, -1):
    c -= A[a]
    while j < m and c + B[j] <= k:
        c = c + B[j]
        j += 1
        num = max(num, a+j)
print (num)
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)
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
INF = 10**12
import bisect

n, m, k = map(int, input().split())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]

acum = [0]
for item in a:
    acum.append(acum[-1] + item)
bcum = [0]
for item in b:
    bcum.append(bcum[-1] + item)

ans = 0
for i, item in enumerate(acum):
    if item > k:
        continue
    index = bisect.bisect_right(bcum, k - item) - 1
    num = i + index
    ans = max(ans, num)
print(ans)
i = list(map(int, input().split()))
n,m,k = i[0], i[1], i[2]

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

ruiA = [0]
ruiB = [0]
for i in range(N):
    ruiA.append(ruiA[-1] + A[i])
for i in range(M):
    ruiB.append(ruiB[-1] + B[i])

MAX = 0
j = M

for i in range(N+1):
    if ruiA[i] > K:
        break
    while ruiA[i] + ruiB[j] > K:
        j -= 1
    MAX = max(MAX, i+j)

print(MAX)
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)
from bisect import *
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().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]
ans = 0
for i,a in enumerate(sa):
    if a > k:break
    will = bisect_right(sb,k-a)
    ans = max(i + will - 1, ans)
print(ans)
N,M,K = list(map(int, input().split()))
A = list((map(int, input().split()))) + [10000000000]
B = list((map(int, input().split()))) + [10000000000]

S = 0
a = 0
while S+A[a]<=K:
  S+=A[a]
  a+=1

b = 0
ans = a

while a>=0:
  if S+B[b]<=K:
    S+=B[b]
    b+=1
  else:
    S-=A[a-1] 
    a-=1
  ans = max(ans, a+b)

print(ans)
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_T = [0]
B_T = [0]
c = 0
for i in range(N):
    c += A[i]
    A_T.append(c)
c = 0
for i in range(M):
    c += B[i]
    B_T.append(c)

ans = 0
for i in range(N+1):
    if K - A_T[i] >= 0:
        k = bisect.bisect_right(B_T, K-A_T[i])
        ans = max(ans, k+i-1)
print(ans)
from collections import deque
import numpy as np
import bisect

n, m, k = map(int, input().split())
A = [0] + list(map(int,input().split()))
B = [0] + list(map(int,input().split()))

a = np.cumsum(A)
b = np.cumsum(B)

ans = 0
for i in range(n+1):
    time = k - a[i]
    if time < 0:
        break
    ans = max(ans, bisect.bisect_right(b, time) - 1 + i)

print(ans)
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)
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-1]
for i in range(1, m+1): b[i] += b[i - 1]

ans, b_cnt = 0, m
for a_cnt in range(n+1):
    if a[a_cnt] > k: break
    while a[a_cnt] + b[b_cnt] > k: b_cnt -= 1
    ans = max(ans, a_cnt + b_cnt)

print(ans)
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 j in range(m):
	B.append(B[j]+b[j])

#print(A,B)

maxij = 0
l = m
for i in range(n+1):
	for j in range(m):
#		print(i,l,A[i],B[l],k)
		if(l == -1):
			break
		elif((A[i]+B[l]) <= k):
		 	maxij=max(maxij,i+l)
#		 	print("mm",maxij)
		 	break
		else:
		 	l-=1
print(maxij)
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

from itertools import accumulate
N, M, K = mapint()
As = [0]+list(accumulate(list(mapint())))
Bs = list(accumulate(list(mapint())))
from bisect import bisect_right

ans = 0
for i, a in enumerate(As):
    if a>K:
        break
    idx = bisect_right(Bs, K-a)
    ans = max(ans, i+idx)
print(ans)
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
from itertools import accumulate
AA = [0]+list(accumulate(A))
BB = [0]+list(accumulate(B))
ans = 0
j = 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)
from itertools import accumulate
n,m,k = map(int, input().split())
a = list(map(int,input().split()))[::-1]
b = list(map(int,input().split()))

l = [0] + a + b
acc = list(accumulate(l))

# print(acc)

ans = 0
l = 0
for r in range(1, n+m+1):
    while acc[r] - acc[l] > k:
        l += 1
    # print(l,r)
    if l <= n and r >= n:
        ans = max(ans,r-l)
    # print(ans)
print(ans)
from itertools import accumulate
from bisect import bisect_left,bisect_right
n,m,k=map(int,input().split())
a=list(accumulate(map(int,input().split()),initial=0))
b=list(accumulate(map(int,input().split()),initial=0))
ans=[0]
for i in range(n+1):
    c=bisect_right(b,k-a[i])-1
    if c!=-1:
        ans.append(c+i)
print(max(ans))
from bisect import bisect_right
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().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]
ans = 0
for i in range(n+1):
    cnt_a = i
    rest = k - sa[i]
    if rest < 0:
        break
    cnt_b = bisect_right(sb, rest) - 1
    ans = max(ans, cnt_a+cnt_b)
print(ans)
#　変数 n, m, k, arr1, arr2, acum1, acum2, ans

n, m, k = map(int, input().split())
arr1 = list(map(int,input().split()))
arr2 = list(map(int,input().split()))

acum1 = [0]
for i in range(n):
    acum1.append(acum1[-1]+arr1[i])

acum2 = [0]
for i in range(m):
    acum2.append(acum2[-1]+arr2[i])

ans = 0
j=m
for i in range(n+1):
    if acum1[i] > k:
        break
    while acum2[j] > k - acum1[i] and j>0:
        j -= 1
    ans = max(ans,i+j)
print(ans)
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(N):
    A[i+1]+=A[i]
for i in range(M):
    B[i+1]+=B[i]

idx=N
ans=0
for i in range(N):
    if A[i]>K:
        idx=i-1
        break

idx2=0
for i in range(idx,-1,-1):
    while idx2<M and A[i]+B[idx2+1]<=K:
        idx2+=1
    ans=max(ans,i+idx2)

print(ans)
from numpy import*
n,m,k,*a=int_(open(0).read().split())
c=cumsum
b=c([0]+a[:n])
print(max(range(len(b:=b[b<=k]))+searchsorted(c(a[n:]),k-b+1)))
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = 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
j = M
for i in range(N+1):
    tmp = K - a[i]
    if tmp < 0:
        break
    while b[j] > tmp:
        j -= 1
    ans = max(ans, i + j)
print(ans)
from itertools import accumulate
import bisect
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

aa = list(accumulate(a))
aa.insert(0,0)
bb = list(accumulate(b))
bb.insert(0,0)

ans = 0

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



print(ans)
import numpy as np
a,b,k=map(int,input().split())
n=list(map(int,input().split()))
m=list(map(int,input().split()))
n.insert(0,0)
m.insert(0,0)
n=np.array(n)
m=np.array(m)
n=n.cumsum()
m=m.cumsum()
ans=0
j=len(m)-1
for i in range(len(n)):
    if n[i]>k:
        break
    while m[j]>k-n[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
an = 0
bn = 0
t = 0
for an in range(n):
  if t+a[an] <= k:
    t += a[an]
  else:
    an-=1
    break
an+=1
ans = an
while True:
  while bn < m:
    if t+b[bn] <= k:
      t += b[bn]
      bn += 1
    else:
      break
  ans = max(ans,an+bn)
  if an == 0 or bn == m:
    break
  else:
    an -= 1
    t -= a[an]
print(ans)
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])
c = 0
f = m
for i in range(n+1):
    if a[i]>k:
        break
    while a[i]+b[f]>k:
        f-=1
    c = max(c, i+f)
print(c)
from itertools import accumulate
from bisect import bisect
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
ans = 0
for i in range(n+1):
    if a[i] > k:
        break
    ans = max(ans, i+bisect(b, k-a[i])-1)
print(ans)
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if sum(A)+sum(B)<=k:
    print(n+m)
    exit()

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

from bisect import bisect_right
ans = bisect_right(B,k)
for i in range(n):
    if A[i]>k:
        break
    ans = max(ans, i+1+bisect_right(B,k-A[i]))
print(ans)
import bisect
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
for i in range(1,n):
    a[i] += a[i-1]
for i in range(1,m):
    b[i] += b[i-1]
ans = 0
for i in range(n):
    if a[i] <= k:
        ans = max(ans,i+1 + bisect.bisect_right(b,k-a[i]))
for i in range(m):
    if b[i] <= k:
        ans = max(ans,i+1 + bisect.bisect_right(a,k-b[i]))
print(ans)
from itertools import accumulate
import bisect
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

A=list(accumulate(a))
B=list(accumulate(b))
ans=bisect.bisect_right(B,k)
for i in range(len(a)):
    r = (k-A[i])
    if r<0:
        break
    #print(r,bisect.bisect_left(B,r))
    #print(B[bisect.bisect_left(B,r)])
    ans=max(ans,i+1+bisect.bisect_right(B,r))
print(ans)
N,M,K=map(int,input().split())
A,B=[0],[0]
A+=map(int,input().split())
B+=map(int,input().split())

for i in range(1,N+1):
    A[i]+=A[i-1]
for i in range(1,M+1):
    B[i]+=B[i-1]

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

print(ans)
import sys
from itertools import accumulate

def Main():
    n,m,k = map(int,sys.stdin.readline().rstrip().split())
    a = [0] + list(accumulate(map(int,sys.stdin.readline().rstrip().split())))
    b = [0] + list(accumulate(map(int,sys.stdin.readline().rstrip().split())))

    ans = 0
    j = m
    for i,item in enumerate(a):
        if k<item:  break
        while k<item+b[j]:
            j -= 1
        ans = max(ans,i+j)
    print(ans)
    return

if __name__=='__main__':
    Main()
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)
from bisect import bisect_left, bisect_right
from itertools import accumulate

n, m, k = map(int, input().split())
la = [0] + list(map(int, input().split()))
lb = list(map(int, input().split()))
# n,m,k=3,4,240
# la = [60, 90, 120]
# lb = [80, 150, 80, 150]

la = list(accumulate(la))
lb = list(accumulate(lb))


# x =bisect_right(lb, 600)
# print(lb)
# print(x)


answer = 0
for ia, a in enumerate(la):
    if a <= k:
        ib = bisect_right(lb, k - a)
        answer = max(answer, ia + ib)


print(answer)
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)
from itertools import accumulate
from bisect import bisect_right

N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
A = list(accumulate(A))
B = [0] + list(map(int, input().split()))
B = list(accumulate(B))

ans = 0
for i, a in enumerate(A):
    if a > K:
        break
    n = bisect_right(B, K-a) - 1
    ans = max(ans, i+n)

print(ans)
import numpy as np
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
a=np.cumsum(A)
b=np.cumsum(B)
a=np.insert(a,0,0)
b=np.insert(b,0,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)
from bisect import bisect_right
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
CA = [0 for _ in range(N+1)]
for i in range(N):
    CA[i+1] = A[i]+CA[i]
CB = [0 for _ in range(M+1)]
for j in range(M):
    CB[j+1] = B[j]+CB[j]
cmax = 0
for i in range(N,-1,-1):
    if CA[i]<=K:
        b = K-CA[i]
        ind = bisect_right(CB,b)
        cmax = max(cmax,i+ind-1)
print(cmax)
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

N,M,K=MI()
A=[0]+LI()
B=[0]+LI()
from itertools import accumulate
A=list(accumulate(A))
B=list(accumulate(B))
ans=0
b_cnt=M
for a_cnt in range(N+1):
  if A[a_cnt]>K:
    break
  while A[a_cnt]+B[b_cnt]>K:
    b_cnt-=1
  ans=max(ans,a_cnt+b_cnt)
print(ans)
import bisect
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
sumA=[0]
for i in range(N):
  sumA.append(sumA[-1]+A[i])
sumB=[0]
for i in range(M):
  sumB.append(sumB[-1]+B[i])

ans=0
for i in range(N+1):
  k=K-sumA[i]
  if k<0:
    break
  l=bisect.bisect_right(sumB,k)-1
  ans=max(ans,i+l)
print(ans)
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)
A,B,K=map(int,input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
SumListA=[]
SumListA.append(0)
SumListB=[]
SumListB.append(0)
res =0
a=0
for i in range(A):
  SumListA.append(SumListA[i]+List_A[i])
for i in range(B):
  SumListB.append(SumListB[i]+List_B[i])

j=B
for i in range(A+1):
  if SumListA[i] > K:
    break
  while K-SumListA[i] < SumListB[j]:
    j += -1
  res = max(i+j,res)
print(res)
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, 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)
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-1]
for i in range(1, M + 1):
    B[i] += B[i-1]

ans = 0
b_cnt = M
for a_cnt in range(N + 1):
    if A[a_cnt] > K:
        continue
    while A[a_cnt] + B[b_cnt] > K:
        b_cnt -= 1
    ans = max(ans, a_cnt + b_cnt)

print(ans)
import bisect
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().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]
ans = 0
for i in range(n+1):
    t = sa[i]
    s = i
    tl = k-t
    if tl < 0:
        continue
    s += bisect.bisect_right(sb, tl)-1
    ans = max(ans,s)
print(ans)
n,m,k=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
a=[0]
b=[0]
for i in range(n):
    a.append(a[i]+al[i])
for i in range(m):
    b.append(b[i]+bl[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)
def main():
    from itertools import chain

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

    t = sum(B)
    ans = 0
    j = M
    for i, x in enumerate(chain([0], A)):
        t += x
        while j > 0 and t > K:
            j -= 1
            t -= B[j]
        if t > K: break
        if ans < i + j:
            ans = i + j
    print(ans)


if __name__ == '__main__':
    main()
import bisect
N, M, K = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))

Asums = [0] * (N + 1)
for i, a in enumerate(A):
    Asums[i+1] = Asums[i] + a

Bsums = [0] * (M + 1)
for i, b in enumerate(B):
    Bsums[i+1] = Bsums[i] + b

ans = 0
for anum in range(N + 1):
    t = Asums[anum]
    if K < t:
        break
    bnum = bisect.bisect_right(Bsums, K - t) - 1
    ans = max(ans, anum + bnum)
print(ans)