object Main extends App {

  val n =  scala.io.StdIn.readInt()
  val s =  scala.io.StdIn.readLine()

  var result = 0L
  var tempS = s

  (1 to n - 2).foreach { a =>
    val head = tempS.head
    tempS = tempS.tail
    var tempS2 = tempS
    (a + 1 to n - 1).foreach { b =>
      val head2 = tempS2.head
      tempS2 = tempS2.tail
      if (head != head2) {
        val tempS3 = tempS2
        (b + 1 to n).foreach { c =>
          if (b - a != c - b) {
            val cS = tempS3.charAt(c - (b + 1))
            if (cS != head && cS != head2) {
              result = result + 1
            }
          }
        }
      }

    }
  }
  println(result)
}