
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad
import Data.Ord


r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    n <- readLn :: IO Int 
    ps <- r'
    let triples = zip ps (zip (tail ps) (tail (tail ps)))
    let r = length $ filter (\(a,(b,c)) -> let [x,y,z] = sort [a,b,c] in y == b) triples
    print r