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.getLine :: IO BS.ByteString
    let t1 = sum
            [ 1
            | i <- [0..n-1]
            , j <- [i+1..n-1]
            , k <- [j+1..n-1]
            , j-i /= k-j
            , BS.index rgbs i /= BS.index rgbs j
            , BS.index rgbs i /= BS.index rgbs k
            , BS.index rgbs j /= BS.index rgbs k
            ]

    print t1