triple_pair :: [Int] -> [(Int, Int, Int)] triple_pair xs = (init . init) $ zip3 xs (f xs) (f (f xs)) where f :: [Int] -> [Int] f [] = [] f xs = tail xs ++ [head xs] isKadomatsu :: (Int, Int, Int) -> Bool isKadomatsu (a, b, c) | a > b && b < c && a /= c = True | a < b && b > c && a /= c = True | otherwise = False main :: IO () main = interact $ show . length . filter id . map isKadomatsu . triple_pair . map read . tail . words