import Foundation

let N = Int(readLine()!)!
let S = [Character](readLine()!)
var r=0,g=0,b=0,rg=0,gb=0,br=0,rgb=0
for i in 0..<N {
  if S[i] == "R" { r += 1; rg += g; br += b; rgb += gb }
  else if S[i] == "G" { g += 1; rg += r; gb += b; rgb += br }
  else if S[i] == "B" { b += 1; gb += g; br += r; rgb += rg }
}
outerLoop: for i in 0..<N-2 {
  innerLoop: for j in i+1..<N-1 {
    var k = 2 * j - i
    if k >= N { break innerLoop }
    var s = Set<Character>([S[i], S[j], S[k]])
    if s.count == 3 { rgb -= 1 }
  }
}
print(rgb)