main = do
  n <- readLn
  s <- getLine
  let r = length .filter (== 'R') $ s
      g = length .filter (== 'G') $ s
      b = length .filter (== 'B') $ s
      triplet = [0 | i <- [0..n-1], j <- [0..i-1], let k=2*i-j, k < n, (s!!i /= s!!j) && (s!!j /= s!!k) && (s!!i /= s!!k)]
      rgb = r * g * b - length triplet
  print $ rgb
