import Data.List
import qualified Data.ByteString.Char8 as BS
main :: IO ()
main = do
  _ <- BS.getLine
  s <- BS.getLine
  let ss = zip [1,2 ..] (BS.unpack s)
  let rs = map fst $ filter (\(_, a) -> a == 'R') ss
  let gs = map fst $ filter (\(_, a) -> a == 'G') ss
  let bs = map fst $ filter (\(_, a) -> a == 'B') ss
  let ss = length [(r, g, b) | r <- rs, g <- gs, b <- bs, (abs(g - r) == abs (b - g)) ||(abs(b - r) == abs (g - b) || (abs (r- b) == abs (g - r)))]
  print $ (length rs) * (length gs) * (length bs) - ss

