solve :: [Int] -> Int solve xs | length xs >= 3 = (if judge (take 3 xs) then 1 else 0) + solve (drop 1 xs) | otherwise = 0 where judge :: [Int] -> Bool judge xs@[a1,a2,a3] = (maximum xs == a2 || minimum xs == a2) && a1 /= a3 judge _ = undefined main :: IO () main = do _ <- getLine a <- map read . words <$> getLine :: IO [Int] print $ solve a