{-# LANGUAGE Strict #-}
import           Data.List           ((\\))
import           Data.Vector.Unboxed (Unbox, Vector, (!))
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  n <- readLn
  s <- getLine
  print $ solve n s

solve :: Int -> String -> Int
solve n s = sum [f i k | i <- [0 .. n - 3], k <- [i + 1 .. n - 1]]
  where
    s' = V.fromList s :: Vector Char
    r = scanCount (== 'R') s' :: Vector Int
    g = scanCount (== 'G') s' :: Vector Int
    b = scanCount (== 'B') s' :: Vector Int
    f i k = h $ ['R', 'G', 'B'] \\ [s' ! i, s' ! k]
      where
        h [c] = t c ! k - t c ! i - x
          where
            x = if cond2 then 1 else 0
            cond2 = (k - i) `mod` 2 == 0 && s' ! (i + (k - i) `div` 2) == c
        h _ = 0
    t 'R' = r
    t 'G' = g
    t 'B' = b

scanCount :: Unbox a => (a -> Bool) -> Vector a -> Vector Int
scanCount p = V.scanl' (\c x -> if p x then c + 1 else c) 0
