import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val n = in.readLine().toInt
    val s = in.readLine()

    val cs = s.toCharArray.map(_.toInt - '0')

    val thirdChars = new Array[Set[Int]](n)
    val thirdCharsCount = new Array[Int](n)

    thirdChars(n - 1) = Set(cs(n - 1))
    thirdCharsCount(n - 1) = 1
    for {
      i <- (n - 2) to 2 by -1
    } {
      thirdChars(i) = thirdChars(i + 1) + cs(i)
      thirdCharsCount(i) = thirdChars(i).size
    }

    var count = 0
    val firstMemo = Array.ofDim[Boolean](10)
    val secondMemo = Array.ofDim[Boolean](n - 1, 10)

    for (
      i <- 0 until (n - 2)
      if !firstMemo(cs(i))
    ) {
      for (
        j <- i + 1 until (n - 1)
        if !secondMemo(i)(cs(j))
      ) {
        count += thirdCharsCount(j + 1)
        secondMemo(i)(cs(j)) = true
      }
      firstMemo(cs(i)) = true
    }

    System.out.println(
      count
    )
  }
}
