## https://qiita.com/embermaverick05/items/93b7258436c55b4a0528 class BIT: def __init__(self, N): self.N = N self.bits = [0] * (self.N + 1) def update(self, i, x): while i <= self.N: self.bits[i] += x i += i & -i def total(self, i): res = 0 while i > 0: res += self.bits[i] i -= i & -i return res N = int(input()) A = list(map(int, input().split())) bit = BIT(N) count = 0 # 座標圧縮 mapping = {a: i for i, a in enumerate(sorted(set(A)), start=1)} # 転倒数のカウント for i in range(N - 1, -1, -1): # 座標圧縮後の値(rank)を用いてBITに反映 count += bit.total(mapping[A[i]] - 1) bit.update(mapping[A[i]], 1) print(count)