type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f

let util = ABC(stdin)

let isOK w =
  w
  |> Array.sort
  |> Array.item 1
  |> (=) (w.[1])
  
let N = util.Scan1 int
let xs = util.ScanVecH int

xs
|> Array.windowed 3
|> Array.filter isOK
|> Array.length
|> printfn "%d"
