import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.set_int_max_str_digits(10**6) N = int(readline()) P = tuple(map(int, read().split())) class BinaryIndexedTree(): def __init__(self, seq): self.size = len(seq) self.depth = self.size.bit_length() self.build(seq) def build(self, seq): data = seq size = self.size for i, x in enumerate(data): j = i + (i & (-i)) if j < size: data[j] += data[i] self.data = data def __repr__(self): return self.data.__repr__() def get_sum(self, i): data = self.data s = 0 while i: s += data[i] i -= i & -i return s def add(self, i, x): data = self.data size = self.size while i < size: data[i] += x i += i & -i def find_kth_element(self, k): data = self.data size = self.size x, sx = 0, 0 dx = 1 << (self.depth) for i in range(self.depth - 1, -1, -1): dx = (1 << i) if x + dx >= size: continue y = x + dx sy = sx + data[y] if sy < k: x, sx = y, sy return x + 1 bit = BinaryIndexedTree([0] * (N+1)) inv = [0] * N for i, x in enumerate(P): inv[i] = x - 1 - bit.get_sum(x) bit.add(x, 1) P, inv nums = inv[::-1] coefs = list(range(1, N+1)) while True: n = len(nums) if n == 1: break for i in range(1, n, 2): nums[i - 1] += coefs[i - 1] * nums[i] coefs[i - 1] *= coefs[i] nums = nums[::2] coefs = coefs[::2] print(nums[0] + 1)