import Data.List

count :: [Int] -> Int
count [] = 0
count (x:[]) = 0
count (x:y:[]) = 0
count (x:y:z:ll) = count (y:z:ll) + if x < y && y < z || x > y && y > z then 1 else 0

main = do
  n <- readLn :: IO Int
  xs <- map read . words <$> getLine :: IO [Int]
  putStrLn . show $ count xs
