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