import array def main(): n = int(input()) p = list(map(int, input().split())) bit = array.array('i') bit.fromlist(list([0 for i in range(n+2)])) ans = 1 a = 1 c = 1 for i in reversed(p): x = i y = i v = 0 while x > 0: v = v + bit[x] x = x - (x&-x) while y <= n: bit[y] = bit[y] + 1 y = y + (y&-y) t = a * v ans= t + ans a = a * c c = c + 1 print(ans) main()