class SegTree: def __init__(self, op, e, n, v=None): self._n = n self._op = op self._e = e self._log = (n - 1).bit_length() self._size = 1 << self._log self._d = [self._e()] * (self._size << 1) if v is not None: for i in range(self._n): self._d[self._size + i] = v[i] for i in range(self._size - 1, 0, -1): self._d[i] = self._op(self._d[i << 1], self._d[i << 1 | 1]) def set(self, p, x): p += self._size self._d[p] = x while p: l, r = p, p^1 if l > r: l, r = r, l self._d[p >> 1] = self._op(self._d[l], self._d[r]) p >>= 1 def get(self, p): return self._d[p + self._size] #[l, r)の区間で求める def prod(self, l, r): sml, smr = self._e(), self._e() l += self._size r += self._size while l < r: if l & 1: sml = self._op(sml, self._d[l]) l += 1 if r & 1: r -= 1 smr = self._op(self._d[r], smr) l >>= 1 r >>= 1 return self._op(sml, smr) def all_prod(self): return self._d[1] def op(x, y): return x+y def e(): return 0 def nPr(n, r, mod): if ( r<0 or r>n ): return 0 return g1[n] * g2[n-r] % mod def nCr(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return (g1[n] * g2[r] % mod) * g2[n-r] % mod import sys input = sys.stdin.readline MOD = 998244353 N = int(input()) P = list(map(int, input().split())) g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル fact = [1, 1] fact_inv = [1, 1] for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % MOD ) inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD ) g2.append( (g2[-1] * inverse[-1]) % MOD ) fact.append( (fact[-1] * i) % MOD ) fact_inv.append(fact_inv[-1] * inverse[-1] % MOD) ST = SegTree(op, e, N) ans = 0 for i in range(N): p = P[i] gt = N-p lt = p-1 l_gt = ST.prod(p, N) l_lt = i-l_gt r_gt = gt-l_gt r_lt = lt-l_lt #print(p, l_lt, l_gt, r_lt, r_gt) #ans += 1 ans += nCr(l_gt+r_lt, l_gt, MOD) * nCr(l_lt+r_gt, l_lt, MOD) % MOD ans %= MOD ST.set(p-1, 1) print(ans)