import Data.Maybe (fromJust) import qualified Data.ByteString.Char8 as BSC8 main :: IO () main = do BSC8.getLine xs <- map (fst . fromJust . BSC8.readInt) . BSC8.words <$> BSC8.getLine print $ countKadomatsu xs countKadomatsu :: [Int] -> Int countKadomatsu = para phi 0 where phi x ([], st) = st phi x ([y], st) = st phi x ([y, z], st) = st phi x ((p:q:r:_), st) = if p /= r && ((p > q && q < r) || (p < q && q > r)) then st + 1 else st para :: (a -> ([a], b) -> b) -> b -> [a] -> b para phi b = step where step [] = b step (x:xs) = phi x (xs, step xs)