import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU
import qualified Data.Map.Strict as M
import Data.List

main = abc162d

abc162d = do
    [n] <- getIntList
    s <- BS.getLine
    let rgbV = convRGB s (VU.empty, VU.empty, M.empty)
    print $ solveD rgbV

convRGB s (r,g,b)
    | BS.null s = (r,g,b)
    | BS.head s == 'R' = convRGB (BS.tail s) (VU.cons n r,g,b)
    | BS.head s == 'G' = convRGB (BS.tail s) (r,VU.cons n g,b)
    | BS.head s == 'B' = convRGB (BS.tail s) (r,g,M.insert n n b)
    where n = VU.length r + VU.length g + M.size b + 1

solveD (r,g,b)
    | VU.length r == 1 = subSolveD (VU.head r, g, b)
    | otherwise = subSolveD (VU.head r, g, b) + solveD (VU.tail r, g, b)

subSolveD (r,g,b)
    | VU.length g == 1 = subSubSolveD (r, VU.head g, b)
    | otherwise = subSubSolveD (r, VU.head g, b) + subSolveD (r, VU.tail g, b)

subSubSolveD (r,g,b)
    | g < r
        = M.size b - (if bgrBool then 1 else 0) - (if grbBool then 1 else 0) - (if xbxBool then 1 else 0)
    | r < g
        = M.size b - (if brgBool then 1 else 0) - (if rgbBool then 1 else 0) - (if xbxBool then 1 else 0)
    where bgrBool = let diff = g - (r - g) in diff > 0 && diff <= 4000 && M.member (g - (r - g)) b
          grbBool = let diff = r + (r - g) in diff > 0 && diff <= 4000 && M.member (r + (r - g)) b
          brgBool = let diff = r - (g - r) in diff > 0 && diff <= 4000 && M.member (r - (g - r)) b
          rgbBool = let diff = g + (g - r) in diff > 0 && diff <= 4000 && M.member (g + (g - r)) b
          xbxBool = even (r + g) && M.member (div (r + g) 2) b


readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine