// RGB Triplets

func main() {
  let n = Int(readLine()!)!
  let s = Array(readLine()!)
  var removes = 0
  var counts: [Character:Int] = [
    "R" : 0,
    "G" : 0,
    "B" : 0
  ]

  for i in 0..<n {
    let m = min(i, n-i-1)
    if m > 0 {
      for j in 1...m {
        if s[i-j] != s[i] && s[i] != s[i+j] && s[i+j] != s[i-j] {
          removes += 1
        }
      }
    }
    counts[s[i]]! += 1
  }

  print(counts["R"]! * counts["G"]! * counts["B"]! - removes)
}

main()