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

    let rec loop i mode acc =
        if i = n then acc else
            match mode with
            | 0 -> if a.(i) <  a.(i - 1) then loop (i + 1) (-1) acc else
                   if a.(i) >  a.(i - 1) then loop (i + 1) (+1) acc else
                                              loop (i + 1) mode acc
            | 1 -> if a.(i) >= a.(i - 1) then loop (i + 1) mode acc else
                                              loop (i + 1) 0 (acc + 1)
            | _ -> if a.(i) <= a.(i - 1) then loop (i + 1) mode acc else
                                              loop (i + 1) 0 (acc + 1)
    in
    loop 1 0 1 |> Printf.printf "%d\n"
)