import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Bits
import Data.List

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

charLog :: Char -> BS.ByteString -> Int -> Integer
charLog c' bs' len' = ch c' bs' (len'-1) (0::Integer)
    where
    ch c bs (-1)  acc  = acc
    ch c bs n acc = 
        ch c bs (n-1) 
        (shift acc 1 
        .|.
        if BS.index bs n == c then 1 else 0)


charList :: Char -> BS.ByteString -> Int -> [Int]
charList c' bs' len' = ch c' bs' (len'-1) []
    where
    ch c bs (-1) acc = acc
    ch c bs k    acc = 
        ch c bs (k-1) (if BS.index bs k == c then k:acc else acc) 
{-
charListA :: Char -> BS.ByteString -> Int -> UArray Int Int
charListA c' bs' len' = ch c' bs' (len'-1) []
    where
    ch c bs (-1) acc = acc
    ch c bs k    acc = 
        ch c bs (k-1) (if BS.index bs k == c then k:acc else acc) 
--}

(!!!)  ::Integer -> Int -> Bool
bs !!! i = shiftR bs i .&. 1 == 1


summ :: [Int] -> [Int] -> [Int] -> Int
summ xs ys zs  = sum [ len - minus
            | x <- xs
            , y <- ys
            , let diff = abs (x-y)
            , let cands1 = [2*x - y , 2*y - x]
            , let cands = if (x+y) `mod` 2 == 0 then (x+y) `div` 2 : cands1 else cands1
            , let f = [\n ms -> if elem n ms then 1 else 0] <*> cands
            , let minus = sum $ f <*> [zs]
            ]
    where 
        len = length zs


main :: IO ()
main = do 
    n <- bsToInt <$> BS.getLine  :: IO Int
    rgbs <- BS.getLine :: IO BS.ByteString
    let ris = charList 'R' rgbs n
    let gis = charList 'G' rgbs n
    let bis = charList 'B' rgbs n
    {--
    let rs = charLog 'R' rgbs n
    let gs = charLog 'G' rgbs n
    let bs = charLog 'B' rgbs n
    let rsu = listArray (0, length ris - 1) ris :: UArray Int Int
    let gsu = listArray (0, length gis - 1) gis :: UArray Int Int
    let bsu = listArray (0, length bis - 1) bis :: UArray Int Int
--}
    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
            ]
    let t2 = sum
            [ 1
            | ri <- ris
            , gi <- gis
            , bi <- bis
            , let [i, j, k] = sort [ri, gi, bi]
            , j - i /= k - j
            ]

    let f1 [as,bs,cs] = sum
            [ length cs - minus
            | x <- as
            , y <- bs
            , let cands1 = [2*x - y , 2*y - x]
            , let cands = if (x+y) `mod` 2 == 0 then (x+y) `div` 2 : cands1 else cands1
            , let f = [\n ms -> if elem n ms then 1 else 0] <*> cands
            , let minus = sum $ f <*> [cs]
            ]

    -- print $ [ris, gis, bis]
    print $ summ ris gis bis



