import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    N, M, K = MI()
    A = deque(LI())
    B = deque(LI())

    ans = 0
    sm = 0
    while 1:
        #print(A, B, sm)
        if A and B:
            a = A.popleft()
            b = B.popleft()
            if a < b:
                if a + sm <= K:
                    sm = sm + a
                    ans += 1
                    B.appendleft(b)
                else:
                    break
            elif b < a:
                if b + sm <= K:
                    sm = sm + b
                    ans += 1
                    A.appendleft(a)
                else:
                    break
            else:   # a == b
                if a + sm > K: break

                for a2, b2 in zip(A, B):
                    if a2 == b2: continue
                    elif a2 < b2:
                        sm = sm + a
                        ans += 1
                        B.appendleft(b)
                    elif b2 < a2:
                        sm = sm + b
                        ans += 1
                        A.appendleft(a)
        elif A:
            a = A.popleft()
            if sm + a <= K:
                sm = sm + a
                ans += 1
            else:
                break
        elif B:
            b = B.popleft()
            if sm + b <= K:
                sm = sm + b
                ans += 1
            else:
              break
        else:
            break
    print(ans)

if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
from bisect import bisect_right, bisect_left

def solve():
    N, M, K = MI()
    A = LI()
    B = LI()
    A = [0] + list(accumulate(A))
    B = [0] + list(accumulate(B))

    def is_ok(arg, a):
        # b <= K - a
        # print(arg, B[arg], a, K, B[arg] <= K - a)
        return B[arg] <= K - a

    def meguru_bisect(ng, ok, a):
        while (abs(ok - ng) > 1):
            mid = (ok + ng) // 2
            if is_ok(mid, a):
                ok = mid
            else:
                ng = mid
            # print(ok, ng)
        return ok

    # print(A)
    # print(B)
    ans = 0
    for i, a in enumerate(A):
        idx = meguru_bisect(M+1, -1, a)
        if 0 <= idx <= M:
            ans = max(ans, i + idx)
    print(ans)

        



if __name__ == '__main__':
    solve()