def main(): n = int(input()) p = list(map(int,input().split())) bit = list(map(int, [0 for i in range(n+1)])) def get(x): res = 0 while x > 0: res = res + bit[x] x = x - (x&-x) return res def add(x, y): if(x == 0): return while x <= n: bit[x] = bit[x] + y x = x + (x&-x) buf = list(map(int, [0 for i in range(8192)])) a = 1 for i in range(1, n+1): t = a * get(p[n-i]) buf[i&8192] = t + buf[i&8192] add(p[n-i], 1) a = a * i ans = 1 + sum(buf) print(ans) main()