def permutation_rank(n, seq): def add(idx, v): while idx <= n: fenwick[idx] += v idx += idx & -idx return def read(idx): ret = 0 while idx > 0: ret += fenwick[idx] idx -= idx & -idx return ret def rec(b, e): if e - b == 1: return vals[b], b + 1 m = (b + e) // 2 ls, lp = rec(b, m) rs, rp = rec(m, e) return rs * lp + ls, lp * rp fenwick = [0] * (n + 1) for i in range(2, n + 1): add(i, 1) vals = [] ret = 0 for i, c in enumerate(seq): vals += [read(c + 1)] add(c + 1, -1) vals = vals[::-1] ans = rec(0, n)[0] return ans + 1 def solve(): import sys input = sys.stdin.readline N = int(input()) A = [a - 1 for a in map(int, input().split())] print(permutation_rank(N, A)) solve()