class BinaryIndexedTree(): def __init__(self, n): self.n = n self.BIT = [0] * (self.n + 1) def add(self, i, x): while i <= self.n: self.BIT[i] += x i += i & -i def query(self, i): res = 0 while i > 0: res += self.BIT[i] i -= i & -i return res n = int(input()) a = [int(input()) - 1 for i in range(n)] ans = 0 BIT = BinaryIndexedTree(n) for i in range(n): ans += i - BIT.query(a[i] + 1) BIT.add(a[i] + 1, 1) print(ans) for i in range(n - 1): ans += n - 2 * a[i] - 1 print(ans)