def main(): n = int(input()) p = list(map(int, input().split())) bit = 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 or y <= n: v = v + bit[x] bit[y] = bit[y] + 1 x = x - (x&-x) y = y + (y&-y) if y > n: y = n + 1 t = a * v ans= t + ans a = a * c c = c + 1 print(ans) main()