let K = Int(readLine()!) ?? 0
let rgbArray = Array(readLine()!)
var count = 0

for i in 0...K-1{
    for j in i...K-1{
        for k in j...K-1{
            let bool = rgbArray[i] != rgbArray[j] && rgbArray[j] != rgbArray[k] && rgbArray[i] != rgbArray[k]
            let bool2 = j - i != k - j
            if bool && bool2{
                count += 1
            }
        }
    }
}
print(count)