import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as VU
import Data.List ((\\))

main :: IO ()
main = do
  let
    unsafeCharToInt :: Char -> Int
    unsafeCharToInt 'R' = 0
    unsafeCharToInt 'G' = 1
    unsafeCharToInt 'B' = 2
    tally :: VU.Vector Int -> VU.Vector Int
    tally= VU.accumulate (const . succ) (VU.replicate 3 0) . VU.map (flip (,) ())
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  cs <- VU.fromList . map unsafeCharToInt <$> getLine :: IO (VU.Vector Int)
  let
    counts = tally cs :: VU.Vector Int
  print $ VU.product counts - length [() | k <- [2..(n - 1)], l <- [1..(k `div` 2)], null ([0, 1, 2] \\ map (cs VU.!) [k - 2 * l, k - l, k])]

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}
