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

bsToInt :: BS.ByteString -> Int
bsToInt = fst . fromJust . BS.readInt

charList :: Char -> BS.ByteString -> Int -> [Int]
charList c' bs' len' = ch c' bs' (len'-1) []
    where
    ch c bs (-1) acc = acc
    ch c bs k    acc = 
        ch c bs (k-1) (if BS.index bs k == c then k:acc else acc) 

main :: IO ()
main = do 
    n <- bsToInt <$> BS.getLine  :: IO Int
    rgbs <- BS.getLine :: IO BS.ByteString
    let ris = charList 'R' rgbs n
    let gis = charList 'G' rgbs n
    let bis = charList 'B' rgbs n

    let t1 = sum
            [ 1
            | ri <- ris
            , gi <- gis
            , bi <- bis
            , let [i, j, k] = sort [ri, gi, bi]
            , j - i /= k - j
            ]

    print $ t1