CodeEff/ECCO huggingface dataset:
# Original solution

n,m,k=list(map(int,input().split(" ")))
a=[-9]
b=list(a)
a.extend(list(map(int,input().split(" "))))
b.extend(list(map(int,input().split(" "))))

t=0
i=1
while i<=n :
    # print("a[{}]={}".format(i,a[i]))
    if t+a[i]>k :
        break
    t+=a[i]
    # print("t=",t)
    i+=1
i-=1
# print("i=",i)
j=1
while j<=m :
    if t+b[j]>k :
        break
    t+=b[j]
    j+=1
j-=1
# print("j=",j)
ans=i+j
for i in range(i,0,-1):
    t-=a[i]
    # print("i-1=",i-1,end='  ')
    while j+1<=m and t+b[j+1]<=k :
        j+=1
        t+=b[j]
    # print("j=",j)
    ans=max(ans,i-1+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(" ")))

t=0
i=0
while i<n :
    if t+a[i]>k :
        break
    t+=a[i]
    i+=1

j=0
while j<m :
    if t+b[j]>k :
        break
    t+=b[j]
    j+=1

ans=i+j
while i>0 :
    i-=1
    t-=a[i]
    while j<m and t+b[j]<=k :
        t+=b[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(" ")))

t=0
i=0
while i<n :
    if t+a[i]>k :
        break
    t+=a[i]
    i+=1

j=0
while j<m :
    if t+b[j]>k :
        break
    t+=b[j]
    j+=1

ans=i+j
while i>0 :
    i-=1
    t-=a[i]
    while j<m and t+b[j]<=k :
        t+=b[j]
        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(" ")))
b=list(map(int,input().split(" ")))

t=0
i=0
while i<n :
    if t+a[i]>k :
        break
    t+=a[i]
    i+=1

# j=0
# while j<m :
#     if t+b[j]>k :
#         break
#     t+=b[j]
#     j+=1
j=0
for x in b :
    # print("mk1 x=",x)
    if t+x>k :
        break
    t+=x
    j+=1

ans=i+j
while i>0 :
    i-=1
    t-=a[i]
    if t+x>k :
        continue
    else:
        t+=x
        j+=1
    for x in b :
        # print("mk2 x=",x)
        if t+x>k :
            break
        t+=x
        j+=1
    # while j<m and t+b[j]<=k :
    #     t+=b[j]
    #     j+=1
    ans=max(ans,i+j)

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

dp=[[0 for j in range(K+1)] for i in range(max(N,M)+1)]
if(N<M):
    ma=M
    mi=N
    turn='M'
else:
    ma=N
    mi=M
    turn='N'

if(turn=='M'):
    for i in range(ma):
        for j in range(K+1):
            if(mi<=i):
                if(B[i]<j):
                    dp[i+1][j]=max(dp[i][j-B[i]]+1,dp[i][j])
                else:
                    dp[i+1][j]=dp[i][j]
            else:

                if(A[i]<j and B[i]<j):

                    dp[i+1][j]=max(dp[i][j-A[i]-B[i]]+2,dp[i][j])

                elif(A[i]<j):
                    dp[i+1][j]=max(dp[i][j-A[i]]+1,dp[i][j])
                elif(B[i]<j):
                    dp[i+1][j]=max(dp[i][j-B[i]]+1,dp[i][j])
                else:
                    dp[i+1][j]=dp[i][j]
else:
    for i in range(ma):
        for j in range(K+1):
            if(mi<=i):
                if(A[i]<j):
                    dp[i+1][j]=max(dp[i][j-A[i]]+1,dp[i][j])
                else:
                    dp[i+1][j]=dp[i][j]
            else:
                if(A[i]<j and B[i]<j):
                    dp[i+1][j]=max(dp[i][j-A[i]-B[i]]+2,dp[i][j])

                elif(A[i]<j):
                    dp[i+1][j]=max(dp[i][j-A[i]]+1,dp[i][j])
                elif(B[i]<j):
                    dp[i+1][j]=max(dp[i][j-B[i]]+1,dp[i][j])
                else:
                    dp[i+1][j]=dp[i][j]

print((dp[ma][K]))


# Optimized solution
N,M,K=list(map(int,input().split()))
A=[]
B=[]
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=[0 for i in range(len(A)+1)]
for i in range(1,len(A)+1):
    a[i]=a[i-1]+A[i-1]

b=[0 for i in range(len(B)+1)]
for i in range(1,len(B)+1):
    b[i]=b[i-1]+B[i-1]

j=M
ans=0
for i in range(len(A)+1):

    if(K<a[i]):
        break
    #print(a[i]+b[j])
    while(a[i]+b[j]>K):
        j=j-1
    ans=max(ans,i+j)

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

n, m, k = list(map(int, input().split()))
A = list(accumulate([0]+list(map(int, input().split()))))
B = list(accumulate([0]+list(map(int, input().split()))))
ans = 0
for i, a in enumerate(A):
    if a > k:
        break
    j = bisect.bisect_right(B, k-a)-1
    temp = i+j
    ans = max(ans, temp)
print(ans)

# Optimized solution
from itertools import accumulate
import bisect

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

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

for n in range(1+N):
  C = bisect_right(B,K-A[n])-1
  if C!=-1:
    ans.append(C+n)

print((max(ans)))

# Optimized solution
from bisect import *
from itertools import *
N,M,K = list(map(int,input().split()))
A = [0]+list(accumulate(list(map(int,input().split()))))
B = [0]+list(accumulate(list(map(int,input().split()))))
ans = [0]

for n in range(1+N):
  C = bisect_right(B,K-A[n])-1
  if C!=-1:
    ans+=[C+n]

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

# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def dfs(n, m, total, count, N, M, K, As, Bs):
    if total > K:
        return count - 1

    if n == N and m == M:
        return count

    if n < N:
        c1 = dfs(n + 1, m, total + As[n], count + 1, N, M, K, As, Bs)
    else:
        c1 = count

    if m < M:
        c2 = dfs(n, m + 1, total + Bs[m], count + 1, N, M, K, As, Bs)
    else:
        c2 = count

    return max(c1, c2)


def solve():
    N, M, K = list(map(int, input().split()))

    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    return dfs(0, 0, 0, 0, N, M, K, As, Bs)


def main():
    print((solve()))


if __name__ == "__main__":
    main()


# Optimized solution
from bisect import bisect_right


def solve():
    N, M, K = list(map(int, input().split()))

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

    sum_as = [0] * (N+1)
    sum_bs = [0] * (M+1)

    for i, a in enumerate(A):
        sum_as[i+1] = sum_as[i] + a

    for i, b in enumerate(B):
        sum_bs[i+1] = sum_bs[i] + b
    sum_bs = sum_bs[1:]

    answer = 0
    for i, sa in enumerate(sum_as):
        remain = K - sa
        if remain < 0:
            continue
        
        idx = bisect_right(sum_bs, remain)
        answer = max(answer, i + idx)

    return answer


def main():
    print((solve()))


if __name__ == "__main__":
    main()
# Original solution
from bisect import bisect_right


def solve():
    N, M, K = list(map(int, input().split()))

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

    sum_as = [0] * (N+1)
    sum_bs = [0] * (M+1)

    for i, a in enumerate(A):
        sum_as[i+1] = sum_as[i] + a

    for i, b in enumerate(B):
        sum_bs[i+1] = sum_bs[i] + b
    sum_bs = sum_bs[1:]

    answer = 0
    for i, sa in enumerate(sum_as):
        remain = K - sa
        if remain < 0:
            continue
        
        idx = bisect_right(sum_bs, remain)
        answer = max(answer, i + idx)

    return answer


def main():
    print((solve()))


if __name__ == "__main__":
    main()


# Optimized solution
from itertools import chain


def solve():
    N, M, K = list(map(int, input().split()))

    A = list(map(int, input().split()))
    *B, = list(map(int, input().split()))

    answer = 0

    sum_b = sum(B)
    idx_b = M
    remain = K

    for i, a in enumerate(chain([0], A)):
        remain -= a
        if remain < 0:
            break

        while sum_b > remain:
            if idx_b < 0:
                break
            idx_b -= 1
            b = B[idx_b]
            sum_b -= b

        answer = max(answer, i + idx_b)

    return answer


def main():
    print((solve()))


if __name__ == "__main__":
    main()
# Original solution
from itertools import chain


def solve():
    N, M, K = list(map(int, input().split()))

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

    answer = 0

    sum_b = sum(B)
    idx_b = M
    remain = K

    for i, a in enumerate(chain([0], A)):
        remain -= a
        if remain < 0:
            break

        while sum_b > remain:
            if idx_b < 0:
                break
            idx_b -= 1
            b = B[idx_b]
            sum_b -= b

        answer = max(answer, i + idx_b)

    return answer


def main():
    print((solve()))


if __name__ == "__main__":
    main()


# Optimized solution
from itertools import chain


def solve():
    N, M, K = list(map(int, input().split()))

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

    answer = 0

    sum_b = sum(B)
    idx_b = M
    remain = K

    for i, a in enumerate(chain([0], A)):
        remain -= a
        if remain < 0:
            break

        while sum_b > remain and idx_b >= 0:
            idx_b -= 1
            b = B[idx_b]
            sum_b -= b
        
        i += idx_b
        answer = i if answer < i else answer

    return answer


def main():
    print((solve()))


if __name__ == "__main__":
    main()
# Original solution
N,M,K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_accumulate_cost = [0]
lastCost = 0
for i in range(N):
    lastCost += A[i]
    A_accumulate_cost.append(lastCost)

B_accumulate_cost = [0]
lastCost = 0
for i in range(M):
    lastCost += B[i]
    B_accumulate_cost.append(lastCost)

max_num = 0
for i in range(N+1):
    A_cost = A_accumulate_cost[i]
    if (A_cost > K):
        break

    for j in range(M, -1, -1):
        if (A_cost + B_accumulate_cost[j] <= K):
            if (i + j > max_num):
                max_num = i+j
            break

print(max_num)

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

A_accumulate_cost = [0]
lastCost = 0
for i in range(N):
    lastCost += A[i]
    A_accumulate_cost.append(lastCost)

B_accumulate_cost = [0]
lastCost = 0
for i in range(M):
    lastCost += B[i]
    B_accumulate_cost.append(lastCost)

max_num = 0
p = M
for i in range(N+1):
    A_cost = A_accumulate_cost[i]
    if A_cost > K:
        break

    for j in range(p, -1, -1):
        if A_cost + B_accumulate_cost[j] <= K:
            p = j
            if i + j > max_num:
                max_num = i+j
            break

print(max_num)
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
def main():
    N, M, K = list(map(int, readline().split()))
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]

    #方針:A,Bそれぞれ前からi,j番目までとったときの合計がK以内であるときのi+jを求める
    #A,Bそれぞれの山の一番上の本だけを比較して時間が小さい方を選ぶことを繰り返すのは間違い。

    csumA = [0]
    for i in range(N):
        csumA.append(csumA[i] + A[i])

    csumB = [0]
    for i in range(M):
        csumB.append(csumB[i] + B[i])

    mx = 0
    for i in range(N+1):
        # r:= Aの山の上からi番目までの本を読むとき、残りの時間
        if K < csumA[i]:
            break
        left = -1
        right = M+1
        while right-left>1: 
            mid = (left+right)//2
            if K - csumA[i] >= csumB[mid]:
                left = mid
            else:
                right = mid
        mx = max(mx, i+left)
    print(mx)

if __name__ == '__main__':
    main()


# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
def main():
    N, M, K = list(map(int, readline().split()))
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]

    #方針:A,Bそれぞれ前からi,j番目までとったときの合計がK以内であるときのi+jを求める
    #A,Bそれぞれの山の一番上の本だけを比較して時間が小さい方を選ぶことを繰り返すのは間違い。

    csumA = [0]
    for i in range(N):
        csumA.append(csumA[i] + A[i])

    csumB = [0]
    for i in range(M):
        csumB.append(csumB[i] + B[i])

    mx = 0
    for i in range(N+1):
        # r:= Aの山の上からi番目までの本を読むとき、残りの時間
        r = K-csumA[i]
        if r < 0:
            break
        left = -1
        right = M+1
        while right-left>1: 
            mid = (left+right)//2
            if r >= csumB[mid]:
                left = mid
            else:
                right = mid

        mx = max(mx, i+left)
    print(mx)

if __name__ == '__main__':
    main()
# Original solution
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = [0] + A
B = [0] + B
BM = M
X = 0
SA = 0
for i in range(N + 1):
    SA += A[i]
    SB = 0
    for j in range(M + 1):
        SB += B[j]
        if SA + SB <= K:
            X = max(X, i + j)
            M = j
        else:
            break
print(X)

# 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])
x = 0
bj = M
for i in range(N + 1):
    if a[i] > K:
        break
    for j in range(bj, -1, -1):
        if a[i] + b[j] <= K:
            bj = j
            x = max(x, i + j)
            break
print(x)
# Original solution
from itertools import accumulate
import bisect
n, m, k = list(map(int, input().split()))
Acum = [0]+list(accumulate(list(map(int, input().split()))))
Bcum = [0]+list(accumulate(list(map(int, input().split()))))

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


# Optimized solution
from itertools import accumulate
n, m, k = list(map(int, input().split()))
Acum = [0]+list(accumulate(list(map(int, input().split()))))
Bcum = [0]+list(accumulate(list(map(int, input().split()))))

ans = 0
b = m
for a in range(n+1):
    if k < Acum[a]:
        break
    while k < Acum[a]+Bcum[b]:
        b -= 1
    if ans < a+b:
        ans = a+b
print(ans)
# Original solution
def go(s,b):
    count=-1
    for i in b:
        if s>=i:
           count+=1

    return count

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

a= (list(map(int,input().split(" "))))
b= (list(map(int,input().split(" "))))

c,d=[],[]
s=0
for i in a:
   s+=i
   c.append(s)
s=0
for i in b:
   s+=i
   d.append(s)

mx=0
for i,j in enumerate(c):
    if j<=k:
        for q,w in enumerate(d):
            if j+w<=k:
                if i+q+2>mx:
                    mx=i+q+2
            else:
                break
        if i+1>mx:
            mx=i+1
    else:
        break
for q,w in enumerate(d):
    if w<=k:
        if q+1>mx:
            mx=1+q
    else:
        break
print(mx)


# Optimized solution
n, m, k = list(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]

j,mx= m,0
for i in range(n+1):
    if a[i]>k:
        break
    while(b[j]>k-a[i]):
        j-=1
    if (i+j>mx):
        mx=i+j
print(mx)
# Original solution
from sys import stdin
data = stdin.readlines()

n = int(data[0].split()[0])
m = int(data[0].split()[1])

k = int(data[0].split()[2])

a = [int(s) for s in data[1].split()]
b = [int(s) for s in data[2].split()]

c = [0]
time = 0
for i in range(1,n+m+1):
    for j in range(0,i+1):
        if j <= n and 0 <= i-j <= m:
            if sum(a[0:j])+sum(b[0:i-j]) <= k:
                c.append(i)
print((max(c)))

# Optimized solution
from sys import stdin
data = stdin.readlines()

n = int(data[0].split()[0])
m = int(data[0].split()[1])

k = int(data[0].split()[2])

A = [int(s) for s in data[1].split()]
B = [int(s) for s in data[2].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 a[i]+b[j] > k:
            j -= 1
        ans = max(ans, i+j)
print(ans)
# Original solution
import sys

def resolve():
    lines = sys.stdin.readlines()

    n, m, k = tuple(map(int, lines[0].strip().split(' ')))
    a = list(map(int, lines[1].strip().split(' ')))
    b = list(map(int, lines[2].strip().split(' ')))
    c_max = 0
    c = 0
    s = 0
    for q in b:
        s += q
        if s > k:
            break
        c += 1
    c_max = max(c, c_max)
    s = 0
    c = 0
    for p in a:
        s += p
        c += 1
        if s > k:
            break
        sb = s
        cb = c
        for q in b:
            sb += q
            if sb > k:
                break
            cb += 1
        c_max = max(cb, c_max)


    print(c_max)

resolve()

# Optimized solution
import sys

def resolve():
    lines = sys.stdin.readlines()

    n, m, k = tuple(map(int, lines[0].strip().split(' ')))
    A = list(map(int, lines[1].strip().split(' ')))
    B = list(map(int, lines[2].strip().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])

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

resolve()
# Original solution
n,m,k = list(map(int,input().split()))
shelfA = list(map(int,input().split()))
shelfB = list(map(int,input().split()))
prodA = [0]*(n+1)
prodB = [0]*(m+1)
for i in range(1,n+1):
    prodA[i] = prodA[i-1] + shelfA[i-1]
for i in range(1,m+1):
    prodB[i] = prodB[i-1] + shelfB[i-1]
if(n>=m):
    ans = [-1]*(n+1)
    for i in range(n+1):
        for j in range(m+1):
            if(prodA[i]+prodB[j] <= k):
                if(ans[i] < i+j):
                    ans[i] = i+j
            else:
                break
            
else:
    ans = [-1]*(m+1)
    for i in range(m+1):
        for j in range(n+1):
            if(prodB[i]+prodA[j] <= k):
                if(ans[i] < i+j):
                    ans[i] = i+j
            else:
                break

print((max(ans)))

# Optimized solution
n,m,k = list(map(int,input().split()))
shelfA = list(map(int,input().split()))
shelfB = list(map(int,input().split()))
prodA = [0]*(n+1)
prodB = [0]*(m+1)
for i in range(1,n+1):
    prodA[i] = prodA[i-1] + shelfA[i-1]
for i in range(1,m+1):
    prodB[i] = prodB[i-1] + shelfB[i-1]

ans = -1
j = m
for i in range(n+1):
    if(prodA[i]>k):
        break
    while(prodB[j] > k - prodA[i]):
        # print(prodB[j],j,k-prodA[i])
        j-=1
    # print(ans)
    ans = max(ans,i+j)



print(ans)
# Original solution
from collections import deque
import bisect
n,m,k = list(map(int, input().split()))
a = deque(list(map(int, input().split())))
b = deque(list(map(int, input().split())))
ans = 0
a.appendleft(0)
b.appendleft(0)

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

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

print(ans)

# Optimized solution
from collections import deque
import bisect
n,m,k = list(map(int, input().split()))
a = [0]
b = [0]
a1 = list(map(int, input().split()))
b1 = list(map(int, input().split()))
# a1 = [1000000]*200000
# b1 = [1000000]*200000
ans = 0
a = a + a1
b = b + b1

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

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

print(ans)
# Original solution
n, m, k = [int(e) for e in input().split()]
a = [int(e) for e in input().split()]
b = [int(e) for e in input().split()]

count = 0
while True:
    if len(a) > 0 and a[0] <= k:
        k -= a[0]
        a.pop(0)
        count += 1
        continue
    if len(b) > 0 and b[0] <= k:
        k -= b[0]
        b.pop(0)
        count += 1
        continue
    break
print(count)

# Optimized solution
n, m, k = [int(e) for e in input().split()]
a = [int(e) for e in input().split()]
b = [int(e) for e in input().split()]

i = 0
j = 0

total_max = 0

while i < n:
    if a[i] > k:
        break
    k -= a[i]
    i += 1
    
while j < m:
    if b[j] > k:
        break
    k -= b[j]
    j += 1

total_max = i + j
    
while i > 0 and j < m:
    k += a[i - 1]
    i -= 1
    while j < m:
        if b[j] > k:
            break
        k -= b[j]
        j += 1
    if total_max < i + j:
        total_max = i + j
    
print(total_max)
# Original solution
import sys
sys.setrecursionlimit(1000000)

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

ai = 0
bi = 0

def read(ai, bi, count, rest):
    if rest <= 0:
        return count
    else:
        if ai >= N:
            a_c = count
        else:
            if rest >= A[ai]:
                a_c = read(ai+1, bi, count+1, rest - A[ai])
            else:
                a_c = count

        if bi >= M:
            b_c = count
        else:
            if rest >= B[bi]:
                b_c = read(ai, bi+1, count+1, rest - B[bi])
            else:
                b_c = count

        return max(a_c, b_c)

res = read(ai,bi,0,K)
print(res)


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

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

# 尺取りの要領でiを増やしjを減らす
res, j = 0, M
for i in range(N+1):
    if cumA[i] > K:
        break
    while cumB[j] > K - cumA[i]:
        j -= 1
    res = max(res, i+j)

print(res)
# Original solution
n,m,k = list(map(int, input().split()))
a = [0]+list(map(int, input().split()))
b = [0]+list(map(int, input().split()))

Goukei_a=[a[0]]
for i in range(1,n+1):
    Goukei_a.append(Goukei_a[i-1]+a[i])

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

goukei=0
kaisuu=0
ans=0

for i in range(0,n+1):
    if Goukei_a[i]>k:
        break
    for j in range(0,m+1):
        if Goukei_b[j]>k:
            break
        goukei=Goukei_a[i]+Goukei_b[j]
        if goukei<=k:
            ans=max(ans,i+j)
        else:
            break
    
print(ans)

# Optimized solution
n,m,k = list(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]

b_cnt=m
ans=0

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)
# 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)
cnt  =0

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

for i in range(n+1):
    for j in range(m+1):
        if A[i] + B[j] <= k:
            cnt = max(i+j, cnt)

print(cnt)

# Optimized 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)
cnt  =0

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

j = m
for i in range(n+1):
    if A[i] > k:
        break
    while B[j] + A[i] > k:
        j -= 1
    cnt = max(cnt, i + j)

print(cnt)