class Fenwick_Tree: def __init__(self, n): self.n = n self.data = [0] * n def add(self, p, x): p += 1 while p <= self.n: self.data[p - 1] += x p += p & -p def sum(self, l, r): '''範囲[l, r)(lからr-1まで)の総和を求める''' return self._sum(r) - self._sum(l) def _sum(self, r): '''範囲[0, r)(0からr-1まで)の総和を求める''' s = 0 while r > 0: s += self.data[r - 1] r -= r & -r return s n = int(input()) A = list(map(int, input().split())) B = [-1 for _ in range(n)] for i in range(n): B[A[i] - 1] = i FT = Fenwick_Tree(n) ans = 0 for i in range(n): ans += FT.sum(B[i], n) FT.add(B[i], 1) print(ans)