main = do
    n <- read <$> getLine
    s <- getLine
    let ijks = [ (i, j, k) | i <- [1..(n-2)], j <- [(i+1)..(n-1)], k <- [(j+1)..n] ]
        notFullfill = filter (\(i, j, k) ->
                              j-i == k-j               ||
                              s !! (i-1) == s !! (j-1) ||
                              s !! (i-1) == s !! (k-1) ||
                              s !! (j-1) == s !! (k-1)   ) ijks
    print $ length ijks - length notFullfill
