
open System

let [|n; m; k|] = stdin.ReadLine().Split() |> Array.map int64
let a = stdin.ReadLine().Split() |> Array.map int64
let b = stdin.ReadLine().Split() |> Array.map int64

let sheet = Array2D.init a.Length b.Length (fun i j -> int64(Array.sum(a.[..i]) + Array.sum(b.[..j])))


let calc s = 
    let maxY = (Array2D.length1 s) - 1
    let maxX = (Array2D.length2 s) - 1
    let mutable c:int64 = 0L
    for i in 0..maxY do
        for j in 0 .. maxX do
            if (sheet.[i, j] <= k && s.[i, j] >= c) then c<-int64(i+j) else c<-c

    c

calc sheet |> fun x -> (if x=0L then x else x+2L) |> printf "%d"
