object Main extends App {
  import scala.collection.mutable

  var count: Long = 0
  val n = io.StdIn.readLine().toInt
  val arr: mutable.ArrayOps[Int] = split(io.StdIn.readLine())

  def split(str: String): Array[Int] = {
    val buf: mutable.ArrayBuffer[Int] = mutable.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 merge(left: Int, middle: Int, right: Int): Unit = {
    val l = arr.slice(left, middle)
    val r = arr.slice(middle, right)
    val lLen = l.length
    val rLen = r.length

    var i = left
    var li = 0
    var ri = 0

    while(li < lLen && ri < rLen) {
      if (l(li) <= r(ri)) {arr(i) = l(li); i += 1; li += 1}
      else {arr(i) = r(ri); count += (lLen - li); i += 1; ri += 1}
    }

    if (li < lLen) while (li < lLen) {arr(i) = l(li); i += 1; li += 1}
    else while (ri < rLen) {arr(i) = r(ri); i += 1; ri += 1}
  }

  def msort(): Unit = {
    var step = 1
    while(step < n) {
      val par = (0 until n by step+step).par
      par map {left => merge(left, left+step, left+step+step)}
      step += step
    }
  }

  msort()
  println(count)
}