count a b c = length [(i,j,k) | i<-a, j<-(filter (\x -> i<x) b), k<-(filter (\x -> j<x) c), ((j-i) /= (k-j))]
main = do
  n <- readLn
  s <- getLine
  let sdif i j = s!!(i-1) /= s!!(j-1)
  let r = [i | i<-[1..n], s!!(i-1) == 'R']
  let g = [i | i<-[1..n], s!!(i-1) == 'G']
  let b = [i | i<-[1..n], s!!(i-1) == 'B']
  print $ (count r g b) + (count r b g) + (count g b r) + (count g r b) + (count b r g) + (count b g r)