{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE StrictData #-}
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.List
import Data.Char

rgb :: [Char] -> Int
rgb s = go 0 0 0 s
    where go :: Int -> Int -> Int -> [Char] -> Int
          go r g b []     = r*g*b
          go r g b (x:xs) 
              | x == 'R'  = go (r+1) g b xs
              | x == 'G'  = go r (g+1) b xs
              | x == 'B'  = go r g (b+1) xs
              | otherwise = undefined

main :: IO ()
main = do
    n <- readLn
    s <- VU.unfoldrN n BS.uncons <$> BS.getLine
    print $ rgb (VU.toList s) - length [ () | i <- [0..n-3], j <- [1..(n-i-1)`div`2], s VU.! i /= s VU.! (i+j), s VU.! (i+j) /= s VU.! (i+2*j), s VU.! i /= s VU.! (i+2*j)]