import qualified Data.ByteString.Char8         as C

main = do
    n <- readLn :: IO Int
    s <- C.getLine
    let tempAns = mul $ countRGB s
    print $ tempAns - length [ () | i <- [0 .. n - 2], d <- [1 .. n], i + 2 * d < n, check s i d ]

countRGB = C.foldl addRGB (0, 0, 0)

addRGB (r, g, b) c | c == 'R' = (r + 1, g, b)
                   | c == 'G' = (r, g + 1, b)
                   | c == 'B' = (r, g, b + 1)

mul (r, g, b) = r * g * b

check ss i d =
    notEqual (C.index ss i) (C.index ss $ i + d) (C.index ss $ i + 2 * d)

notEqual i j k = i /= j && j /= k && k /= i
