func main() {
    let N = Int(readLine()!)!
    let S = Array(readLine()!)
    
    var count: [Character: Int] = ["R": 0, "G": 0, "B": 0]
    for c in S {
        count[c]! += 1
    }
    
    var ans = 1
    for c in "RGB" {
        ans *= count[c]!
    }
    
    for i in 1...((N - 1) / 2) {
        var first = 0
        while first + 2 * i < N {
            let mid = first + i
            let last = first + 2 * i
            if S[first] != S[mid] && S[mid] != S[last] && S[first] != S[last] {
                ans -= 1
            }
            first += 1
        }
    }
    
    print(ans)
}

main()
