{-# 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

main :: IO ()
main = do
    n <- readLn 
    s <- VU.unfoldrN n BS.uncons <$> BS.getLine
    print $ rgb n s 0 (0,0,0) - 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+j+j), s VU.! i /= s VU.! (i+j+j)]
    where rgb :: Int -> VU.Vector Char -> Int -> (Int,Int,Int) -> Int
          rgb n s cnt (r,g,b)
              | n == cnt          = r*g*b
              | s VU.! cnt == 'R' = rgb n s (cnt+1) (r+1,g,b)
              | s VU.! cnt == 'G' = rgb n s (cnt+1) (r,g+1,b)
              | s VU.! cnt == 'B' = rgb n s (cnt+1) (r,g,b+1)
              | otherwise         = undefined