let N = Int(readLine()!)!
let S = Array(readLine()!)

var count = 0
var numberOfCharacters = Array(repeating: 0, count: 3)
for i in 0 ..< N {
    switch S[i] {
    case "R":
        numberOfCharacters[0] += 1
    case "G":
        numberOfCharacters[1] += 1
    case "B":
        numberOfCharacters[2] += 1
    default:
        break
    }
    guard i + 1 < N else { continue }
    for j in i + 1 ..< N {
        let k = 2 * j - i
        guard k < N else { continue }
        if S[i] != S[j] && S[i] != S[k] && S[j] != S[k] {
            count += 1
        }
    }
}

print(numberOfCharacters.reduce(1, *) - count)
