open Printf
open Scanf

let id x = x

let n, m, k = scanf "%d %d %d\n" (fun n m k -> n, m, k)
let aIn = Array.init n (fun i -> scanf "%d " id)
let bIn = Array.init m (fun i -> scanf "%d " id)

exception Break

let main () =
    let aa = Array.make (n + 1) 0 in
    let sum = ref 0 in
    for i = 1 to n do
        sum := !sum + aIn.(i - 1);
        aa.(i) <- !sum
    done;
    let bb = Array.make (m + 1) 0 in
    sum := 0;
        for i = 1 to m do
        sum := !sum + bIn.(i - 1);
        bb.(i) <- !sum
    done;
    let ai = ref 0 in
    let bi = ref 0 in
    try while true do
        let curA = aa.(!ai) in
        let curB = bb.(!bi) in
        if !ai < n && !bi < m then begin
            let nextA = aa.(!ai + 1) in
            let nextB = bb.(!bi + 1) in
            if nextA + curB <= k && curA + nextB <= k then begin
                if nextA < nextB then begin
                    incr ai
                end else begin
                    incr bi
                end
            end else if nextA + curB <= k then begin
                incr ai
            end else if curA + nextB <= k then begin
                incr bi
            end else begin
                raise Break
            end
        end else if !ai < n then begin
            let nextA = aa.(!ai + 1) in
            if nextA + curB <= k then incr ai
            else raise Break
        end else if !bi < m then begin
            let nextB = bb.(!bi + 1) in
            if curA + nextB <= k then incr bi
            else raise Break
        end else begin
            raise Break
        end
    done with Break -> ();
    Printf.printf "%d\n" (!ai + !bi)

let () = main ()
