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
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  cs <- VU.fromList . map fromEnum <$> getLine :: IO (VU.Vector Int)
  print . length $ [() | i <- [0..(n - 3)], j <- [(i + 1)..(n - 2)], k <- [(j + 1)..(n - 1)] \\ [2 * j - i], null (map fromEnum "RGB" \\ map (cs VU.!) [i, j, k])]

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