import scala.io.StdIn._
import scala.annotation.tailrec

object Main extends App {

  val n = readInt
  val s = readLine

  var result = 0L

  @tailrec
  def solve(charIndexes: Seq[(Char, Int)]): Unit = {

    def nots(notChar: Char, seq: Seq[(Char, Int)]) = seq.filterNot(_._1 == notChar)
    charIndexes.headOption match {
      case None => 
      case Some(i) =>
        val notCharIndexes = nots(i._1, charIndexes)
        notCharIndexes.foreach { j =>
          result += nots(j._1, notCharIndexes).filter{ k =>
            i._2 < j._2 && j._2 < k._2 && j._2 - i._2 != k._2 - j._2
          }.length
        }
        solve(charIndexes.tail)
    }
  }

  solve(s.zipWithIndex)

  println(result)
}
