{-# LANGUAGE Strict #-}
import           Data.Vector.Unboxed ((!))
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 = rgb - a
  where s' = V.fromList s
        rgb = product $ map (\c -> count (== c) s) ['R', 'G', 'B']
        a = count
              (\(i, j, k) -> s' ! i /= s' ! j
                             && s' ! j /= s' ! k
                             && s' ! k /= s' ! i)
              [(i, j, k) | i <- [0 .. n - 3]
                       , j <- [i + 1 .. i + (n - 1 - i) `div` 2]
                       , let k = i + (j - i) * 2]

count :: (a -> Bool) -> [a] -> Int
count p = length . filter p
