let k =
    stdin.ReadLine().Split(" ")
    |> Array.map int
    |> (fun a -> a.[2])

let toBookList x =
    x
    |> Array.map int
    |> Array.toList
    |> List.fold (fun arr v ->
        match arr with
        | (time, index) :: tail -> (time + v, index + 1) :: (time, index) :: tail
        | [] -> [ (v, 1) ]) []
    |> List.rev
    |> List.filter (fun (time, _) -> time <= k)


let a =
    stdin.ReadLine().Split(" ") |> toBookList

let b =
    stdin.ReadLine().Split(" ") |> toBookList

[ for (aTime, aIndex) in a do
    for (bTime, bIndex) in b -> (aTime + bTime, aIndex + bIndex) ]
|> List.filter (fun (time, _) -> time <= k)
|> List.fold (fun (aTime, aCount) (vTime, vCount) -> if aTime >= vTime then (aTime, aCount) else (vTime, vCount)) (0, 0)
|> fun (_, c) -> c
|> printfn "%d"