CodeEff/ECCO huggingface dataset:
# Original solution
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]*(N+1)
b = [0]*(M+1)

#累積和の計算
for i in range(1, N+1):
    a[i] = a[i-1] + A[i-1]
for j in range(1, M+1):
    b[j] = b[j-1] + B[j-1]

ans = 0
j = M
for i in range(N+1):
    left = 0
    right = j
    if K - a[i] < 0:
        break
    while left < right:
        mid = (left + right)//2
        if b[mid] < K - a[i]:
            left = mid + 1
        elif b[mid] > K - a[i]:
            right = mid - 1
    if b[left] <= K - a[i]:
        j = left
    else:
        j = left - 1
    ans = max(ans, i + j)
print(ans)

# Optimized solution
import bisect
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]*(N+1)
b = [0]*(M+1)

#累積和の計算
for i in range(1, N+1):
    a[i] = a[i-1] + A[i-1]
for j in range(1, M+1):
    b[j] = b[j-1] + B[j-1]

ans = 0
# j = M
for i in range(N+1):
#     left = 0
#     right = j
    if K - a[i] < 0:
        break
#     while left < right:
#         mid = (left + right)//2
#         if b[mid] < K - a[i]:
#             left = mid + 1
#         elif b[mid] > K - a[i]:
#             right = mid - 1
#     if b[left] <= K - a[i]:
#         j = left
#     else:
#         j = left - 1
    j = bisect.bisect_right(b, K - a[i]) - 1
    ans = max(ans, i + j)
print(ans)
# Original solution
from itertools import accumulate

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

a_acc = [0] + list(accumulate(a))
b_acc = [0] + list((accumulate(b)))

ans = 0
bn = m

for an in range(n + 1):
    rem = k - a_acc[an]
    if rem < 0:
        break

    # rem >= 0 かつ、b_acc[0] = 0なので、bnはどんなに減っても0で必ず止まります。マイナスになってバグることはありません
    while b_acc[bn] > rem:
        bn -= 1
    ans = max(ans, an + bn)

print(ans)

# Optimized solution
from itertools import accumulate

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

a_acc = [0] + list(accumulate(a))  # aを0冊読む=1冊も読まない場合があるので
b_acc = [0] + list(accumulate(b))  # 今度は[0]が必要です

ans = 0
for an in range(n + 1):
    rem = k - a_acc[an]
    if rem < 0:
        break

    # 最初は 0 <= x < m + 1 の範囲で、この範囲を狭めていきます
    ok = 0
    ng = m + 1   
    # ng = ok + 1のとき、ok <= x < ng は ok <= x < ok + 1で、x = okに確定します
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        # bをmid冊読めるか？
        if b_acc[mid] <= rem:
        # 読めるならok
            ok = mid
        else:
        # 読めないならng
            ng = mid

    bn = ok
    ans = max(ans, an + bn)

print(ans)
# Original solution
from itertools import accumulate
import bisect

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

a_acc = [0] + list(accumulate(a))  # aを0冊読む=1冊も読まない場合があるので、[0]を先頭に追加します
b_acc = list(accumulate(b))  # bisect_rightでは、x以下の要素がいくつあるか？を求めるので、こちらに0は入れません

ans = 0
for an in range(n + 1):
    rem = k - a_acc[an]
    if rem < 0:
        # aをこれ以上読めません
        break

    bn = bisect.bisect_right(b_acc, rem)
    ans = max(ans, an + bn)

print(ans)

# Optimized solution
from itertools import accumulate

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

a_acc = [0] + list(accumulate(a))
b_acc = [0] + list((accumulate(b)))

ans = 0
bn = m

for an in range(n + 1):
    rem = k - a_acc[an]
    if rem < 0:
        break

    # rem >= 0 かつ、b_acc[0] = 0なので、bnはどんなに減っても0で必ず止まります。マイナスになってバグることはありません
    while b_acc[bn] > rem:
        bn -= 1
    ans = max(ans, an + bn)

print(ans)
# Original solution
N,M,K=list(map(int,input().split()))
a=input().split()
A=[int(c) for c in a]
b=input().split()
B=[int(c) for c in b]
answers=[0]
As=[0]
Bs=[0]
wholeA=0
wholeB=0
for a in range(N):
    wholeA+=A[a]
    As.append(wholeA)
for b in range(M):
    wholeB+=B[b]
    Bs.append(wholeB)

for a in range(N+1):
    for b in range(M+1):
        whole = As[a]
        whole+=Bs[b]
        if whole>K:
            break
        else:
            answers.append(a+b)

print((max(answers)))


# Optimized solution
N,M,K=list(map(int,input().split()))
a=input().split()
A=[int(c) for c in a]
b=input().split()
B=[int(c) for c in b]
answers=[0]
As=[0]
Bs=[0]
wholeA=0
wholeB=0
bs = [M]
for a in range(N):
    wholeA+=A[a]
    As.append(wholeA)
for b in range(M):
    wholeB+=B[b]
    Bs.append(wholeB)
for a in range(N+1):
    for b in range(bs[-1],-1,-1):
        whole = As[a]
        whole+=Bs[b]
        if whole<=K:
            answers.append(a+b)
            bs.append(b)
            break
print((max(answers)))
# Original solution
N,M,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
S = 0
ans = 0
for i in range(M):
  S += B[i]
  if S > K:
    b = i - 1
    S -= B[i]
    break
  else:
    ans += 1
    if i==M-1:
      b = M-1
if b==0:
  ans = 0
  S = 0
  for a in A:
    if S + a <= K:
      S += a
      ans += 1
    else:
      break
  if S + B[0]<=K:
    ans+=1
  print(ans)
else:
  a = 0
  max_ans = ans
  while a<N:
    if S + A[a] <= K:
      S += A[a]
      ans += 1
      a += 1
    else:
      break
  max_ans = max(max_ans, ans)
  for j in range(b, -1, -1):
    S -= B[j]
    ans -= 1
    while a<N:
      if S + A[a] <= K:
        S += A[a]
        ans += 1
        a += 1
      else:
        break
      
    max_ans = max(max_ans, ans)
  print(max_ans)

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

S_A = [0] * (N + 1)
S_B = [0] * (M + 1)
for i in range(N):
  S_A[i+1] = S_A[i] + A[i]

for i in range(M):
  S_B[i+1] = S_B[i] + B[i]
  
ans = 0
a = 0
for i in range(M, -1, -1):
  s = S_B[i]
  if s>K:
    continue
  while a<N:
    if s + S_A[a + 1]<=K:
      a += 1
    else:
      break
  ans = max(ans, i + a)
print(ans)
# Original solution
def _integral(A):
    result = []
    sum_value = 0
    result.append(sum_value)
    for i in range(len(A)):
        sum_value += A[i]
        result.append(sum_value)
    return result


def _main(N, M, K, A, B):
    integral_a = _integral(A)
    integral_b = _integral(B)
    top_count = 0
    for a_index in range(len(A) + 1)[::-1]:
        a_value = integral_a[a_index]
        if K < a_value:
            continue
        for b_index in range(len(B) + 1)[::-1]:
            if a_value + integral_b[b_index] <= K:
                if top_count < a_index + b_index:
                    top_count = a_index + b_index
                break
    print(top_count)
    #
    #
    # sum_k = 0.0
    # a_index = 0
    # a_len = len(A)
    # b_index = 0
    # b_len = len(B)
    # while sum_k < K:
    #     current_a = A[a_index] if a_index < a_len else None
    #     current_b = B[b_index] if b_index < b_len else None
    #     if current_a is None and current_b is None:
    #         break
    #
    #     if current_a is not None and current_b is None:
    #         if K < sum_k + current_a:
    #             break
    #         sum_k += current_a
    #         a_index += 1
    #     elif current_a is None and current_b is not None:
    #         if K < sum_k + current_b:
    #             break
    #         sum_k += current_b
    #         b_index += 1
    #     elif current_a < current_b:
    #         if K < sum_k + current_a:
    #             break
    #         sum_k += current_a
    #         a_index += 1
    #     else:
    #         if K < sum_k + current_b:
    #             break
    #         sum_k += current_b
    #         b_index += 1
    #
    # print(a_index + b_index)


if __name__ == "__main__":
    Na, Ma, Ka = list(map(int, input().split()))
    Aa = list(map(float, input().split()))
    Ba = list(map(float, input().split()))
    _main(Na, Ma, Ka, Aa, Ba)


# Optimized solution
def _integral(A):
    result = []
    sum_value = 0
    result.append(sum_value)
    for i in range(len(A)):
        sum_value += A[i]
        result.append(sum_value)
    return result


def _main(N, M, K, A, B):
    integral_a = _integral(A)
    integral_b = _integral(B)
    top_count = 0
    b_max = len(B)
    for a_index in range(len(A) + 1):
        a_value = integral_a[a_index]
        if K < a_value:
            break
        for b_index in range(0, min(len(B) + 1, b_max + 1))[::-1]:
            if a_value + integral_b[b_index] <= K:
                if top_count < a_index + b_index:
                    top_count = a_index + b_index
                b_max = b_index
                break
    print(top_count)


if __name__ == "__main__":
    Na, Ma, Ka = list(map(int, input().split()))
    Aa = list(map(float, input().split()))
    Ba = list(map(float, input().split()))
    _main(Na, Ma, Ka, Aa, Ba)
# Original solution
import bisect
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

asum, bsum = [0], [0]
for i in range(n):
  if k < a[i] + asum[i]:
    break
  asum.append(a[i] + asum[i])
for i in range(m):
  if k < b[i] + bsum[i]:
    break
  bsum.append(b[i] + bsum[i])

ans = 0
for i in range(len(asum)):
  ans = max(ans, i + bisect.bisect(bsum, k-asum[i]) - 1)
print(ans)


# Optimized solution
# 尺取法ver

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

asum, bsum = [0], [0]
for i in range(n):
  if k < a[i] + asum[i]:
    break
  asum.append(a[i] + asum[i])
for i in range(m):
  if k < b[i] + bsum[i]:
    break
  bsum.append(b[i] + bsum[i])

ans = 0
b_count = len(bsum)-1
for a_count in range(len(asum)):
  while asum[a_count] + bsum[b_count] > k:
    b_count -= 1
  ans = max(ans, a_count + b_count)
print(ans)
# Original solution
n,m,k=list(map(int,input().split()))
l=list(map(int,input().split()))
ll=list(map(int,input().split()))

l_ans=[]
for i in range(m+1):
  l_ans.append([0]*(n+1))
ct=0

for i in range(m+1):
  we=i+n
  for j in range(n+1):
    if i==0 and j==0:
      l_ans[i][j]=0
    elif i==0:
      l_ans[i][j]=l_ans[i][j-1]+l[j-1]
    elif j==0:
      l_ans[i][j]=l_ans[i-1][j]+ll[i-1]
    else:
      l_ans[i][j]=l_ans[i][j-1]+l[j-1]
    
    if l_ans[i][0]>k:
      we=0
      break
    if l_ans[i][j]>k:
      we=i+j-1
      break
    elif l_ans[i][j]==k:
      we=i+j
      break
  
  #print(ct,we)

  if we>ct:
    ct=we
#print(l_ans)
print(ct)

# Optimized solution
n,m,k=list(map(int,input().split()))
l=list(map(int,input().split()))
ll=list(map(int,input().split()))

l_l=[0]
for i in range(1,m+1):
  l_l.append(l_l[i-1]+ll[i-1])

ans=0
for i in range(m+1):
  if l_l[i]>k:
    break
  
  sm=0
  j=0
  while j<n and l_l[i]+sm+l[j]<=k:
    sm+=l[j]
    j+=1
  ans=max(ans,i+j)
print(ans)
# Original solution
n ,m, k = list(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
    else:
        while B[j] > k - A[i]:
            j -= 1
    ans = max(ans, i+j)
print(ans)

# Optimized solution
n, m, k = list(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 i in range(n+1):
    if A[i] > k:
        break
    else:
        while k - A[i] < B[j]:
            j -= 1

    ans = max(ans, i+j)

print(ans)
# Original solution
from sys import stdin
from bisect import bisect
input = stdin.readline

N, M, K = list(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, a in enumerate(A):
    time = K - a
    if time < 0:
        break
    cnt = i + 1
    if time != 0:
        tmp = bisect(B, time)
        cnt += tmp
    ans = max(ans, cnt)

for i, b in enumerate(B):
    time = K - b
    if time < 0:
        break
    cnt = i + 1
    if time != 0:
        tmp = bisect(A, time)
        cnt += tmp
    ans = max(ans, cnt)

print(ans)


# Optimized solution
from sys import stdin
input = stdin.readline

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

sumA = [0]
sumB = [0]


for i in range(N):
    sumA.append(sumA[i] + A[i])

for i in range(M):
    sumB.append(sumB[i] + B[i])

ans = 0
t = M

for i in range(N + 1):
    for j in range(t, -1, -1):
        if K < sumA[i] + sumB[j]:
            t -= 1
            continue
        else:
            ans = max(ans, i + j)
            break

print(ans)
# Original solution
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

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

ans = 0

for i in range(N + 1):
    if a[i] > K:
        break

    for j in range(M+1):
        if b[j] + a[i] > K:
            break
        ans = max(ans, i+j)

print(ans)
exit()


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

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

ans = 0
j = M
for i in range(N + 1):
    if a[i] > K:
        break

    while b[j] + a[i] > K:
        j -= 1
    ans = max(ans, i+j)

print(ans)
exit()
# Original solution
import bisect

n, m, k = list(map(int, input().split()))
INF = 10**18
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cum_a = [0] * (n+1)
cum_b = [0] * (m+1)
for i in range(n):
    cum_a[i+1] = cum_a[i] + A[i]
for i in range(m):
    cum_b[i+1] = cum_b[i] + B[i]
INF = 10**18
ans = -INF
for i in range(n+1):
    mod = k - cum_a[i]
    b = bisect.bisect(cum_b, mod)
    if b == 0:
        ans = max(ans, i)
        break
    ans = max(ans, b+i)
print((ans-1))


# Optimized solution
import bisect

n, m, k = list(map(int, input().split()))
INF = 10**18
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cum_a = [0] * (n+1)
cum_b = [0] * (m+1)
for i in range(n):
    cum_a[i+1] = cum_a[i] + A[i]
for i in range(m):
    cum_b[i+1] = cum_b[i] + B[i]
INF = 10**18
ans = -INF
for i in range(n+1):
    mod = k - cum_a[i]
    b = bisect.bisect(cum_b, mod)
    if b == 0:
        ans = max(ans, i)
        break
    ans = max(ans, b+i)
ans -= 1
print(ans)
# Original solution
n,m,k,*x=list(map(int,open(0).read().split()))
s=sum(x[:n])
z=i=j=n
while~i:
	while j<n+m and s+x[j]<=k:s+=x[j];j+=1
	if s<=k:z=max(z,i+j)
	i-=1
	s-=x[i]
print((z-n))

# Optimized solution
n,m,k,*x=list(map(int,open(0).read().split()))
s=sum(x[:n])
z=i=j=n
x+=k,
while~i:
	while s+x[j]<=k:s+=x[j];j+=1
	if s<=k:z=max(z,i+j)
	i-=1
	s-=x[i]
print((z-n))
# Original solution
import itertools
import sys
input = sys.stdin.readline

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

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

for x in range(len(a_cum)):
    if a_cum[x] > k:
        break
    for y in range(len(b_cum)):
        if a_cum[x] + b_cum[y] <= k:
            ans = max(ans, x + y)
        else:
            break

print(ans)


# Optimized solution
import itertools
import sys

input = sys.stdin.readline

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

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

y = m  # len(b_cum) - 1
for x in range(len(a_cum)):
    if a_cum[x] > k:
        break
    while b_cum[y] > k - a_cum[x]:
        y -= 1
    ans = max(ans, x + y)

print(ans)
# Original solution
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
n_a = 0
n_b = 0
t_a = 0
t_b = 0

for i in range(N):
    if sum(A[0:i + 1]) <= K:
        n_a += 1
        t_a += A[i]
        continue
    else:
        break
# print(n_a)
# print(t_a)

for i in range(M):
    if sum(B[0:i + 1]) <= K:
        n_b += 1
        t_b += B[i]
        continue
    else:
        break
# print(n_b)
# print(t_b)

if n_a >= n_b:
    n_b = 0
    t_b = 0
    for i in range(M):
        if sum(B[0:i + 1]) <= K - t_a:
            n_b += 1
            t_b += B[i]
            continue
        else:
            break
    # print(n_b)
    # print(t_b)

else:
    n_a = 0
    t_a = 0
    for i in range(N):
        if sum(A[0:i + 1]) <= K - t_b:
            n_a += 1
            t_a += A[i]
            continue
        else:
            break
    # print(n_a)
    # print(t_a)

print((n_a + n_b))


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

# A,Bそれぞれの累積和を作る
# 初期値は0冊目まで読んだときの値（ここでは0）を入れておく
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

# Bは全て（=M冊目まで）読めることを初期値とする
# Aの山で読む本を増やすにつれて、jは（広義）単調減少する
j = M

# Aの山について、何冊目まで読むか
for i in range(N + 1):

    # Aの山だけでK分オーバーの場合
    # これ以上iを増やしても無意味なので打ち切る
    if a[i] > K:
        break

    # a[i]+b[j] > K　ならjをデクリメント
    # Bの山を全て読めると仮定した後、下の方から一冊ずつ諦める
    # jはiの増加に対して広義単調減少（しゃくとり法）、Mから0まで一回走査するだけで良い
    while b[j] > K - a[i]:
        j -= 1

    # 冊数はi+j、全てのiに対してi+jを比較、最大のものが答え
    ans = max(ans, i + j)

print(ans)
# Original solution
import sys
sys.setrecursionlimit(10 ** 6)

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

def dfs(time,count,i,j):
    global ans,n,m,k,a,b
    if (i == n or time + a[i] > k) and (j == m or time + b[j] > k):
        ans = max(ans, count)
    else:
        if i <= n-1 and time + a[i] <= k:
            dfs(time + a[i],count + 1,i+1,j)
        if j <= m-1 and time + b[j] <= k:
           dfs(time + b[j],count + 1,i,j+1)  

shoki_time = 0
shoki_count = 0
shoki_i = 0
shoki_j = 0
dfs(shoki_time,shoki_count,shoki_i,shoki_j)
print(ans)

# Optimized solution
n,m,k=list(map(int,input().split()))
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
acum1=[0]
for i in range(n): #累積和ai,bjを求める
 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: #ai>Kであれば、どのようにjを選んでもai+bj<=Kとなることはないので探索を終了する
   break
 while acum2[j]>k-acum1[i] and j>0: #各iについて、bj<=K-aiを満たす最大のjを求める
   j-=1
 ans=max(ans,i+j)
print(ans)
# Original solution
import copy
L = list(map(int, input().split())) # N, M, K=map(int,input().split())
N=L[0]
M=L[1]
K=L[2]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
P=[(0,0)]
R=[0]
c=0
while c!=N+M or Q!=[]:
    Q=[]
    S=[]
    c=c+1
    n=len(P)
    for i in range(n):
        a=P[i][0]
        b=P[i][1]
        if a<N and ((a+1,b) not in Q):
            C=R[i]+A[a]
            if C<=K:
                Q.append((a+1,b))
                S.append(C)
        if b<M  and ((a,b+1) not in Q):
            C=R[i]+B[b]
            if C<=K:
                Q.append((a,b+1))
                S.append(C)
    if Q!=[]:
        P=copy.copy(Q)
        R=copy.copy(S)
    else:
        c=c-1
        break
print(c)

# Optimized solution
N, M, K=list(map(int,input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
LA = [0]
LB = [0]
for i in range(N):
    C=LA[i]+A[i]
    if C>K:
        N=i
        break
    else:
        LA.append(C)
for j in range(M):
    C=LB[j]+B[j]
    if C>K:
        M=j
        break
    else:
        LB.append(C)
r=N
for i in range(N+1):
    u=0
    for j in range(r-N+i,M+1):
        if LA[N-i]+LB[j]>K:
            r=max(r,N-i+j-1) # 最大のrを求めたいので結果をrefineする場合だけで回す
            u=1
            break
    if u==0:
        r=max(r,N-i+M)
        break
print(r)
# Original solution
import math
def facts(n):
    ans = []
    for  i in range(1, int(math.sqrt(n)+1)):
        if(n%i==0):
            ans.append(i)
            ans.append(n//i)
    ans = sorted(list(dict.fromkeys(ans)))
    if(ans[-1]==n):
        ans = ans[:-1]
    return ans


n, m,k  = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa  = [0]
pb = [0]
ans = 0
for i in range(n):
    pa.append(a[i]+pa[i])
for i in range(m):
    pb.append(b[i]+pb[i])
for c in range(n+1):
    tmp=pa[c]
    if(tmp > k):
        break
    else:
        for d in range(m+1):
            if(pb[d] <= k-tmp):
                ans = max(ans, c+d)
            else:
                break
print(ans)

# Optimized solution
import math
def facts(n):
    ans = []
    for  i in range(1, int(math.sqrt(n)+1)):
        if(n%i==0):
            ans.append(i)
            ans.append(n//i)
    ans = sorted(list(dict.fromkeys(ans)))
    if(ans[-1]==n):
        ans = ans[:-1]
    return ans


n, m,k  = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa  = [0]
pb = [0]
ans = 0
for i in range(n):
    pa.append(a[i]+pa[i])
for i in range(m):
    pb.append(b[i]+pb[i])
for c in range(n+1):
    if(pa[c] > k):
        break
    else:
        while(pb[m] > k-pa[c]):
            m-=1
        ans = max(ans, c+m)
            
print(ans)
# Original solution
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
result=0
for i in range(len(a)+1):
    for j in range(len(b)+1):
        if sum(a[:i]) + sum(b[:j]) <= k:
            if result < i+j:
                result=i+j
print(result)

# Optimized solution
import sys
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_=[0]
b_=[0]
tmp = 0
for i in a:
    tmp += i
    a_.append(tmp)
tmp = 0
for i in b:
    tmp += i
    b_.append(tmp)

ans=0
j = m
for i in range(n+1):
    if a_[i] > k:
        continue
    while b_[j] + a_[i] > k:
        j -= 1
    ans = max(ans,i+j)
print(ans)
# Original solution
import sys
sys.setrecursionlimit(10**6)

#a = int(input())
#b = list(map(int, input().split()))
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

a.sort()
b.sort()

ans = 0
time = 0

while time <= k:
    if a and b:
        tmp_a = time+a[0]
        tmp_b = time+b[0]
        if tmp_a <= k and tmp_b <= k and a[0] <= b[0]:
            time += a[0]
            a.pop(0)
            ans += 1
        elif tmp_a <= k and tmp_b <= k and b[0] <= a[0]:
            time += b[0]
            b.pop(0)
            ans += 1
        elif tmp_a <= k:
            time += a[0]
            a.pop(0)
            ans += 1
        elif tmp_b <= k:
            time += b[0]
            b.pop(0)
            ans += 1
        else:
            break
    elif a:
        tmp_a = time+a[0]
        if tmp_a <= k:
            time += a[0]
            a.pop(0)
            ans += 1
        else:
            break
    elif b:
        tmp_b = time+b[0]
        if tmp_b <= k:
            time += b[0]
            b.pop(0)
            ans += 1
        else:
            break
    else:
        break

print(ans)

# Optimized solution
import sys
sys.setrecursionlimit(10**6)

N, M, K = list(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から走査すれば良い（毎回Mから始める必要はない）
        j -= 1
    ans = max(ans, i + j)

print(ans)