Scanf.scanf "%d %d %d" (fun n m k ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let b = Array.init m (fun _ -> Scanf.scanf " %d" (fun b -> b)) in

    let sa = Array.make (n + 1) 0 in
    let sb = Array.make (m + 1) 0 in
    for i = 0 to n - 1 do sa.(i + 1) <- sa.(i) + a.(i) done;
    for i = 0 to m - 1 do sb.(i + 1) <- sb.(i) + b.(i) done;

    let rec loop ia =
        if ia > n then n else
            if sa.(ia) <= k then loop (ia + 1) else ia - 1
    in
    let ia = loop 0 in
    let rec loop ib =
        if ib > m then m else
            if sb.(ib) + sa.(ia) <= k then loop (ib + 1) else ib - 1
    in
    let ib = loop 0 in
    let rec loop ia ib best =
        if ia < 0 || ib > m then best else
            if sa.(ia) + sb.(ib) <= k then (
                let best = max best (ia + ib) in
                loop ia (ib + 1) best
            ) else loop (ia - 1) ib best
    in
    loop ia ib (ia + ib) |> Printf.printf "%d\n"
)