class BIT: def __init__(self, n): self._n = n self.data = [0]*(n+1) def add(self, p, x): # pは0-indexed assert 0 <= p < self._n p += 1 while p <= self._n: self.data[p] += x p += p & -p def sum_range(self, l, r): # l,rは0-indexedで閉区間[l,r]の区間和を求める assert 0 <= l <= r <= self._n return self._sum(r+1)-self._sum(l) def _sum(self, r): s = 0 while r > 0: s += self.data[r] r -= r & -r return s def lower_bound(self, x): # a0+a1+...+ai>=xなるiのminを求める(0-indexed) lo = 1 hi = self._n ret = 1 << 60 while lo <= hi: m = (lo+hi)//2 if self._sum(m) >= x: ret = min(ret, m) hi = m-1 else: lo = m+1 return ret-1 N = int(input()) M = [int(input())-1 for _ in range(N)] B = BIT(N) ans = 0 for i in range(N): num = B.sum_range(0, M[i]) ans += i-num B.add(M[i], 1) print(ans)