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

let t = s.map { (char) -> Int in
    if char == "R" {
        return -1
    }
    if char == "G" {
        return 0
    }
    return 1
}

var l: [Int: [Int]] = [-1: [], 0: [], 1: []]

for (i, int) in t.enumerated() {
    l[int]!.append(i)
}

var result = 0
for (i, int) in t.enumerated() {
    for j in i+1..<n where t[j] != int {
        for k in l[-int - t[j]]! where k > j && 2 * j != i + k {
            result += 1
        }
    }
}

print(result)
