// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.


let makeTrioSequence (lst:int array) = 
    if lst.Length < 3 then
        []
    else
        [for i in 1..(lst.Length - 2) -> [|lst.[i-1]; lst.[i]; lst.[i+1]|]]

let isSecondElementSecondBiggest (lst:int array) = 
    [for i in 0..(lst.Length-1) -> (i, lst.[i])]
    |> List.sortBy(fun (index, value) -> value)
    |> List.item 1
    |> fst = 1

[<EntryPoint>]
let main argv = 
    let numOfElements = stdin.ReadLine() |> int

    let elements = stdin.ReadLine().Split(' ') |> Array.map int

    let count = elements
                |> makeTrioSequence
                |> List.filter(fun x -> isSecondElementSecondBiggest x)
                |> List.length

    printfn "%d" count

    0 // return an integer exit code
