import sys sys.set_int_max_str_digits(1000000) N = int(input()) P = tuple(map(int, input().split())) class BIT(): def __init__(self, sequence): self.size = len(sequence) self.depth = self.size.bit_length() self.build(sequence) def build(self, sequence): data = sequence size = self.size for I, X in enumerate(data): J = I + (I & (-I)) if J < size: data[J] += data[I] self.data = data def 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(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, g = BIT([0] * (N + 1)), [0] * N for I, X in enumerate(P): g[I] = X - 1 - bit.SUM(X) bit.ADD(X, 1) NUMS, COES = g[::-1], list(range(1, N + 1)) while True: N = len(NUMS) if N == 1: break for i in range(1, N, 2): NUMS[i - 1] += COES[i - 1] * NUMS[i] COES[i - 1] *= COES[i] NUMS = NUMS[::2] COES = COES[::2] print(NUMS[0] + 1)