import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

bsToInt :: BS.ByteString -> Int
bsToInt = fst . fromJust . BS.readInt

main :: IO ()
main = do 
    n <- bsToInt <$> BS.getLine  :: IO Int
    rgbs <- BS.unpack <$> BS.getLine :: IO String
    let t1 = sum
            [ 1
            | i <- [0..n-1]
            , j <- [i+1..n-1]
            , k <- [j+1..n-1]
            , j-i /= k-j
            , rgbs !! i /= rgbs !! j
            , rgbs !! i /= rgbs !! k
            , rgbs !! j /= rgbs !! k
            ]

    print t1
