import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector as V

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main = do
    n <- getInt
    s <- getLine
    let nr = length $ filter (== 'R') s
        ng = length $ filter (== 'G') s
        nb = length $ filter (== 'B') s
        rgball = nr * ng * nb
        vs = V.fromList s
        rgb' = length [()| a <- [0..n-1], i <- [1..n], a+2*i <= n-1, check vs a (a+i) (a+2*i)]
    print $ rgball - rgb'

check vs a b c | va /= vb && vb /= vc && vc /= va = True
               | otherwise = False
    where va = vs V.! a
          vb = vs V.! b
          vc = vs V.! c