import kotlin.math.*
import java.util.*

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val s = readLine()!!
  var r = 0L
  var g = 0L
  var b = 0L
  for (c in s) {
    when (c) {
      'R' -> r++
      'G' -> g++
      else -> b++
    }
  }
  var ans = r * g * b
  for (i in 1..n - 2) {
    for (k in i + 2..n) {
      if ((i + k) % 2 != 0) continue
      val j = (i + k) / 2
      if (s[i - 1] != s[j - 1] && s[j - 1] != s[k - 1] && s[k - 1] != s[i - 1]) ans--
    }
  }
  println(ans)
}
