object Main extends App {
  import scala.collection.mutable.ArrayBuffer

  //val n = io.StdIn.readLine().toInt
  //val arr: Array[Int] = split(io.StdIn.readLine())

  val s = io.Source.fromFile("src/main/scala/ALDS1_5_D_in19.txt")
  val iter = s.getLines()
  val n = iter.next().toInt
  val arr: Array[Int] = split(iter.next())

  def split(str: String): Array[Int] = {
    val buf: ArrayBuffer[Int] = ArrayBuffer.empty[Int]
    var num_builder = 0
    val iter = str.toIterator

    while(iter.hasNext) {
      val v = iter.next()
      if (v != ' ') num_builder = num_builder*10 + v.toInt
      else {buf += num_builder; num_builder = 0}
    }
    (buf += num_builder).toArray
  }

  def sum(index: Int, acc: Int = 0): Int =
    if (index > 0) sum(index - (index & (-index)), acc + bit.getOrElse(index, 0))
    else acc

  def update(n: Int, index: Int, v: Int): Unit =
    if (index <= n) {
      bit.getOrElseUpdate(index, 0)
      bit(index) += v
      update(n, index + (index & -index), v)
    }

  var count: Long = 0
  val maxVal = arr.max
  val bit: collection.mutable.HashMap[Int, Int] = collection.mutable.HashMap.empty[Int, Int]
  for(i <- n-1 to 0 by -1) {
    count += sum(arr(i)-1)
    update(maxVal, arr(i), 1)
  }

  println(count)
}