import Foundation

let main: () = {
    let N = getInt()
    let S = getString().map(String.init)
    var (R, G, B) = (0, 0, 0)
    S.forEach { c in
        switch (c) {
            case "R": R += 1
            case "G": G += 1
            case "B": B += 1
            default: break
        }
    }
    let total = R * G * B
    var exc = 0
    for n in 0 ..< N - 2 {
        for m in n + 1 ..< N - 1 {
            let k = m + (m - n)
            if (k >= N) {continue}
            if (S[n] != S[m] && S[n] != S[k] && S[m] != S[k]) {exc += 1}
        }
    }
    let ans = total - exc    
    print(ans)
}()

func getString() -> String { readLine()! }
func getInt() -> Int { Int(getString())! }
func getDouble() -> Double { Double(getString())! }

