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()
    val s = sc.next().split("").filter(_.length != 0)

    val r = mutable.Set.empty[Int]
    val g = mutable.Set.empty[Int]
    val b = mutable.Set.empty[Int]

    s.zipWithIndex.foreach { case (str, i) => str match {
      case "R" => r += i
      case "G" => g += i
      case "B" => b += i
    }
    }

    val res = r.flatMap(rr => g.flatMap(gg => b.map(bb => (rr, gg, bb)))).filter { case (r, g, b) => ijk(r, g, b) }
    println(res.size)

  }

  def ijk(a: Int, b: Int, c: Int): Boolean = {
    val seq = Seq(a, b, c).sorted
    seq(1) - seq(0) != seq(2) - seq(1)
  }

}
