[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let n = read int
    let ps = reads int
    List.windowed 3 ps
    |> List.filter (fun xs -> (List.sort xs).[1] = xs.[1])
    |> List.length
    |> printfn "%i"
    0