class BIT: def __init__(self,n): self.n = n; self.k = [0]*(n+1) def a(self,i,x): while i<=self.n: self.k[i] += x; i += i&-i def s(self,i): t = 0 while i>0: t += self.k[i]; i -= i&-i return t n = int(input()); mod = 998244353; fa = [1]*(n+1); fi = [1]*(n+1) for i in range(1,n): fa[i+1] = fa[i]*(i+1)%mod fi[n] = pow(fa[n],mod-2,mod) for i in range(n,0,-1): fi[i-1] = fi[i]*i%mod def cmb(n,r): return fa[n]*fi[n-r]%mod*fi[r]%mod if 0<=r<=n else 0 bit = BIT(n); ans = 0 for i,v in enumerate(map(int,input().split())): ls = bit.s(v); ll = i-ls; bit.a(v,1) ans += cmb(ls+n-v-ll,ls)*cmb(ll+v-1-ls,ll) print(ans%mod)