kumiawase :: Int -> [a] -> [[a]]
kumiawase 0 xs = [[]]
kumiawase n [] = []
kumiawase n (x:xs) = (map (x:) $ kumiawase (n-1) xs) ++ (kumiawase n xs)



syouhi0 consumed n [] = 0
syouhi0 consumed n (x:xs) = if x`elem`consumed
                               then syouhi0 consumed (n+1) xs
                               else syouhi1 0 (x:consumed) (n+1) xs + syouhi0 consumed (n+1) xs

syouhi1 diff consumed n [] = 0
syouhi1 diff consumed n (x:xs) = if x`elem`consumed
                                    then syouhi1 (diff+1) consumed (n+1) xs
                                    else syouhi2 diff 0 (x:consumed) (n+1) xs + syouhi1 (diff+1) consumed (n+1) xs

syouhi2 diff_past diff_current consumed n [] = 0
syouhi2 diff_past diff_current consumed n (x:xs) = if x`elem`consumed
                                             then syouhi2 diff_past (diff_current+1) consumed (n+1) xs
                                             else if (diff_past/=diff_current)
                                               then 1 + syouhi2 diff_past (diff_current+1) consumed (n+1) xs
                                               else syouhi2 diff_past (diff_current+1) consumed (n+1) xs



main = do
  n <- read<$>getLine :: IO Int
  s<-getLine
  print $ syouhi0 [] 0 s
  {-print $ length $
    filter (\[i, j, k] -> (s!!(i-1))/= (s!!(j-1)) && (s!!(i-1))/= (s!!(k-1))&& (s!!(j-1))/= (s!!(k-1))) $
    filter (\[i, j, k] -> j-i /= k-j )
    $ kumiawase 3 [1..n]-}