#!/usr/bin/env python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import gc class BinaryIndexedTree(): def __init__(self, seq): self.size = len(seq) self.depth = self.size.bit_length() self.build(seq) def build(self, seq): data = seq size = self.size for i, x in enumerate(data): j = i + (i & (-i)) if j < size: data[j] += data[i] self.data = data def get_sum(self, i): data = self.data s = 0 while i: s += data[i] i -= i & -i return s def add(self, i, x): data = self.data size = self.size while i < size: data[i] += x i += i & -i def Inversion(seq): N = len(seq) bit = BinaryIndexedTree([0] * (N + 1)) inv = N * (N - 1) // 2 for x in seq: inv -= bit.get_sum(x) bit.add(x, 1) return inv N, *A = map(int, read().split()) convert = {x: i for i, x in enumerate(sorted(set(A)), 1)} A = tuple(convert[x] for x in A) del convert gc.collet() inv = Inversion(A) counter = [0] * (max(A) + 1) for x in A: counter[x] += 1 for n in range(max(A)): counter[n + 1] += counter[n] print(inv) for i, x in enumerate(A[:-1]): smaller = counter[x - 1] larger = N - counter[x] inv += larger - smaller print(inv)