import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val S = in.next()

  //
  var _R = Vector[Int]()
  var _G = Vector[Int]()
  var _B = Vector[Int]()

  for (i <- 0 until N) {
    S(i) match {
      case 'R' => _R :+= i
      case 'G' => _G :+= i
      case 'B' => _B :+= i
    }
  }

  val R = _R.toArray
  val G = _G.toArray
  val B = _B.toSet

  var ans = R.length.toLong * G.length * _B.length

  for (_ri <- R; _gi <- G) {
    var ri = _ri
    var gi = _gi

    if (ri > gi) {
      val tmp = ri
      ri = gi
      gi = tmp
    }

    val hoge = gi - ri

    if (B(ri - hoge))
      ans -= 1

    if (B(gi + hoge))
      ans -= 1

    if (hoge % 2 == 0)
      if (B(ri + hoge/2))
        ans -= 1
  }

  println(ans)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
