# dataの長さは1番目からnを2進数にしたときのLSBに相当 class Binary_Indexed_Tree: def __init__(self, n) -> None: self._n = n self.data = [0] * (n+1) self.depth = n.bit_length() # al〜arに一律加算ならいもす法でlにx加算、r+1に-x加算すれば良い # aiの値の取得はiまでのsum def add(self, p, x) -> None: """任意の要素ai←ai+xを行う O(logn)""" # pのindexが0以上n-1以下を保証 assert 0 <= p < self._n # 1-indexedに変換 p += 1 while p <= self._n: # 加算 self.data[p-1] += x # LSBの加算 p += p & (-p) # 区間[l, r) def sum(self, l, r) -> int: assert 0 <= l <= r <= self._n return self._sum(r) - self._sum(l) def _sum(self, d) -> int: sm = 0 while d > 0: sm += self.data[d-1] # LSB減算 d -= d & (-d) return sm N = int(input()) BIT = Binary_Indexed_Tree(N+1) M = [int(input()) for _ in range(N)] M = M[::-1] res = 0 for num in M: BIT.add(num, 1) res += BIT._sum(num) print(res)