module Main where

import           Control.Monad
import           Debug.Trace
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
import           Data.List
import qualified Data.ByteString               as BS
import qualified Data.ByteString.Char8         as BSC8
import           Data.Char
import           Data.Maybe
import           Data.Ord
import           Data.Vector.Algorithms.Search
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.Array.IO                 as AIO



getvuil :: IO (VU.Vector Int)
getvuil = VU.unfoldr (BSC8.readInt . BSC8.dropWhile isSpace) <$> BSC8.getLine
readi :: BSC8.ByteString -> Int
readi = fst . fromJust . BSC8.readInt
readil :: BSC8.ByteString -> [Int]
readil = map readi . BSC8.words
geti :: IO Int
geti = readi <$> BSC8.getLine
getil :: IO [Int]
getil = readil <$> BSC8.getLine

getNis :: Int -> IO [(Int, BSC8.ByteString)]
getNis 0 = return []
getisl n = do
    [aFst, aSnd] <- BSC8.words <$> BSC8.getLine
    next         <- (getisl (n - 1))
    return ((readi aFst, aSnd) : next)

il2ss :: [Int] -> String
il2ss = unwords . map show

il2sn :: [Int] -> String
il2sn = unlines . map show

main :: IO ()
main = do
    aN <- geti
    aS <- VU.fromList <$> getLine
    let lastC         = VU.last aS
    let lastLastI = searchLastLast aS (VU.length aS - 2) lastC
    let lastLastC     = aS VU.! lastLastI
    let lastLastLastI = searchLastLastLast aS lastLastI lastC lastLastC

    let
        ret = if lastLastI == -1 || lastLastLastI == -1
            then 0
            else foldl
                (\acc1 x ->
                    let
                        firstI = x
                        firstC = aS VU.! x
                    in
                        acc1
                            + (foldl
                                  (\acc2 y ->
                                      let
                                          secondI = y
                                          secondC = aS VU.! y
                                          thirdK  = seleK firstC secondC
                                      in
                                          if firstC == secondC
                                              then acc2
                                              else
                                                  acc2
                                                      + (foldl
                                                            (\acc3 z ->
                                                                let
                                                                    thirdI = z
                                                                    thirdC =
                                                                        aS
                                                                            VU.! z
                                                                in
                                                                    if ((thirdC
                                                                        /= thirdK
                                                                        )
                                                                       || (2
                                                                          * secondI
                                                                          )
                                                                       == (firstI
                                                                          + thirdI
                                                                          )
                                                                       )
                                                                    then

                                                                        acc3
                                                                    else
                                                                        acc3 + 1
                                                            )
                                                            0
                                                            [y + 1 .. VU.length
                                                                    aS
                                                                - 1]
                                                        )
                                  )
                                  0
                                  [x + 1 .. lastLastI]
                              )
                )
                0
                [0 .. lastLastLastI]

    print ret

searchLastLast s x lastC =
    if s VU.! x == lastC then searchLastLast s (x - 1) lastC else x
searchLastLastLast s x lastC lastLastC =
    if s VU.! x == lastC || s VU.! x == lastLastC
        then searchLastLastLast s (x - 1) lastC lastLastC
        else x

seleK first second =
    let firstI = if first == 'R'
            then 1
            else if first == 'G' then 2 else if first == 'B' then 3 else 0
        secondI = if second == 'R'
            then 1
            else if second == 'G' then 2 else if second == 'B' then 3 else 0
        thirdI = firstI + secondI
    in  if thirdI == 3
            then 'B'
            else if thirdI == 4 then 'G' else if thirdI == 5 then 'R' else ' '

