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


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


cnt :: BS.ByteString -> Int -> [[Int]]
cnt rgbs' n' = cn rgbs' (n'-1) [0] [0] [0]
    where
    cn rgbs (-1) rs gs bs = [rs, gs, bs]
    cn rgbs n rs@(r:_) gs@(g:_) bs@(b:_)
        | BS.index rgbs n == 'R' = cn rgbs (n-1) (1+r:rs) (  g:gs) (  b:bs) 
        | BS.index rgbs n == 'G' = cn rgbs (n-1) (  r:rs) (1+g:gs) (  b:bs)
        | BS.index rgbs n == 'B' = cn rgbs (n-1) (  r:rs) (  g:gs) (1+b:bs)


main :: IO ()
main = do 
    n <- bsToInt <$> BS.getLine  :: IO Int
    rgbs <- BS.getLine :: IO BS.ByteString
    let cnts = cnt rgbs n
    let ucnts = map  (listArray (0, n)) cnts ::[UArray Int Int]

    let t2 = 
            [ after - minus
            | i <- [0..n-3]
            , j <- [i+1..n-2]
            , let ci = BS.index rgbs i
            , let cj = BS.index rgbs j
            , ci /= cj
            , let rgbi
                    | notElem 'R' [ci, cj] = 0
                    | notElem 'G' [ci, cj] = 1
                    | notElem 'B' [ci, cj] = 2
                    ::Int
            , let after = ucnts !! rgbi ! (j+1)
            , let minus 
                    | after > 0 && 2*j - i < n && notElem (BS.index rgbs (2*j-i)) [ci, cj] = 1
                    | otherwise                = 0
            ]

    print $ sum t2
