open System
let str1 = Console.ReadLine().Split() |> Array.map uint32
let aList = Console.ReadLine().Split() |> Array.toList |> List.map uint32
let bList = Console.ReadLine().Split() |> Array.toList |> List.map uint32
let k = str1.[2]

let rec tsundoku list1 list2 time counter =
    //printfn "A:%A\nB:%A\nTime:%d" list1 list2 time
    match list1 with
    | head1 :: tail1 ->
        match list2 with
        | head2 :: tail2 ->
            if head2 > time && head1 > time then counter 
            else
                if head1 = head2 
                then
                    if list1.Length > list2.Length 
                    then tsundoku tail1 list2 (time - head1) (counter + 1)
                    else tsundoku list1 tail2 (time - head2) (counter + 1)
                else
                    if head1 > head2 
                    then tsundoku list1 tail2 (time - head2) (counter + 1)
                    else tsundoku tail1 list2 (time - head1) (counter + 1)
        | [] -> 
            if head1 > time then counter else
                tsundoku tail1 list2 (time - head1) (counter + 1)
    | [] -> 
        match list2 with
        | head2 :: tail2 ->
            if head2 > time then counter else
                tsundoku list1 tail2 (time - head2) (counter + 1)
        | [] -> counter

printfn "%d" (tsundoku aList bList k 0)