object Main extends App {
  val n = io.StdIn.readInt()
  val s = io.StdIn.readLine()

  var count = 0
  for (i <- 0 until n-2)
    for (j <- i until n-1; if (s(i) != s(j)))
      for (k <- j until n; if (s(i) != s(k) && s(j) != s(k) && j-i != k-j)) {
          count += 1
      }

  println(count)
}