kadomatsu :: [Int] -> Int kadomatsu [x,y] = 0 kadomatsu (x:y:z:ts) = f + kadomatsu (y:z:ts) where f | (maximum [x,y,z] == y || minimum [x,y,z] == y) && x /= z = 1 | otherwise = 0 main = do getLine ts <- map read . words <$> getLine print $ kadomatsu ts