import java.util.Scanner

import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {

    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    sc.nextLine()
    val s = sc.nextLine().split("").filter(_ != "")


    var rcnt = 0L
    var gcnt = 0L
    var bcnt = 0L
    val rgb = s.map {
      case "R" => rcnt += 1
      case "G" => gcnt += 1
      case "B" => bcnt += 1
    }

    var sum = rcnt * gcnt * bcnt

    (for {
      j <- 0 until n
      i <- 0 until j
      k = 2 * j - i
      if k < n
      if s(i) != s(j)
      if s(i) != s(k)
      if s(k) != s(j)
    } yield (sum -= 1))

    println(sum)
  }

}
