import scala.io.StdIn.{readInt, readLine}
object Main {
    def main(args: Array[String]): Unit = {
        val len = readInt
        val arr = readLine.split(" ").map(_.toInt)
        println(mergeSort(arr, 0, len - 1))
    }
    def mergeSort(arr: Array[Int], left: Int, right: Int): Long = {
        if (left < right) {
            val mid = (right + left) / 2
            val r1 = mergeSort(arr, left, mid)
            val r2 = mergeSort(arr, mid + 1, right)
            val r3 = merge(arr, left, mid, right)
            r1 + r2 + r3
        } else {
            0
        }
    }
    def merge(arr: Array[Int], left: Int, mid: Int, right: Int): Long = {
        var reverse = 0L
        val tmp = arr.slice(left, mid + 1) // 左側を一時配列にコピー
        var leftPtr = 0
        var rightPtr = mid + 1
        for (i <- (left to right)) {
            if (leftPtr >= tmp.length) {
                // 左側を使い切った場合 : 交換の必要なし
                rightPtr += 1
            } else if (rightPtr  > right) {
                // 右側を使い切った場合
                arr(i) = tmp(leftPtr)
                leftPtr += 1
            } else {
                if (arr(rightPtr) < tmp(leftPtr)){
                    arr(i) = arr(rightPtr)
                    rightPtr += 1
                    reverse += tmp.length.toLong - leftPtr.toLong
                } else {
                    arr(i) = tmp(leftPtr)
                    leftPtr += 1
                }
            }
        }
        reverse
    }
}
