main = do
    n <- read <$> getLine
    s <- getLine
    let rgb = length (filter (== 'R') s) * length (filter (== 'G') s) * length (filter (== 'B') s)
        ijks = [ (i, j, k) | i <- [1..(n-2)], j <- [(i+1)..(n-1)], k <- [(j+1)..n] ]
        tmp = filter (\(i, j, k) ->
                      j-i == k-j               &&
                      s !! (i-1) /= s !! (j-1) &&
                      s !! (i-1) /= s !! (k-1) &&
                      s !! (j-1) /= s !! (k-1)   ) ijks
    print $ rgb - length tmp
