{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE StrictData #-}
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.List
import Data.Char

fun :: Int -> VU.Vector Char -> (Int,Int) -> Int
fun n s (i,j) 
    | s VU.! i == s VU.! j = 0
    | otherwise            = length [ () | k <- [i+1..j-1], s VU.! i /= s VU.! k, s VU.! k /= s VU.! j, 2*k /= j+i ]

main :: IO ()
main = do
    n <- readLn
    s <- VU.unfoldrN n BS.uncons <$> BS.getLine
    print $ sum [fun n s (i,j) | i <- [0..n-4], j <- [i+3..n-1]]