
import qualified Data.Vector.Unboxed as U
-- import qualified Data.Vector as V
-- import qualified Data.ByteString.Char8 as C
import Data.List
-- import Control.Monad
import Control.Arrow
--import Data.Foldable
--import Data.Char
--import qualified Data.IntMap.Strict as IM
--import qualified Data.IntSet as IS
-- import Data.Sequence as Sq

-- r :: Int -> IO (U.Vector Int)
-- r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

-- r' :: IO [Int]
-- r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine




main = do
    n <- readLn :: IO Int
    s <- U.fromList <$> getLine
    let x = length $ filter id [ f dist from s | from<-[0..n-3], dist<-[1..n-(div from 3)]]
    let r = c 'R' s
    let g = c 'G' s
    let b = n - r - g
    print $ r*g*b - x

f :: Int -> Int -> U.Vector Char -> Bool
f dist from v
    | from+2*dist >= U.length v = False
    | otherwise = "BGR" == (sort $ map ((v U.!).(+from)) [0,dist,2*dist] )

c x = U.length . U.filter (==x)
