let n = Int(readLine()!)!
let s = Array(readLine()!)

var d: [Character: Int] = ["R": 0, "G": 0, "B": 0]

for char in s {
    d[char]! += 1
}

var result = d["R"]! * d["G"]! * d["B"]!
for i in 0..<n {
    for j in i+1..<n {
        let k = 2 * j - i
        if k >= n {break}
        if s[i] != s[j] && s[j] != s[k] && s[k] != s[i] {
            result -= 1
        } 
    }
}

print(result)
