object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val a, b, c = Array.fill(n)(sc.nextInt()).sorted

  val bCount = Array.fill(n)(0L)
  var pc = 0
  for (pb <- 0 until n) {
    while (pc < n && c(pc) <= b(pb)) {
      pc += 1
    }
    bCount(pb) = n - pc
  }

  val bCountRSum = bCount.scanRight(0L)(_ + _)

  var pb = 0
  var ans = 0L
  for (pa <- 0 until n) {
    while (pb < n && b(pb) <= a(pa)) {
      pb += 1
    }
    ans += bCountRSum(pb)
  }

  println(ans)
}
