#include #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define per(i,a,b) for(int i=(a);i>=(b);--i) #define pii pair #define vi vector #define fi first #define se second #define pb push_back #define ALL(x) x.begin(),x.end() #define sz(x) int(x.size()) #define ll long long using namespace std; const int N = 3e5 + 5,P = 998244353; int n,p[N],A[N],B[N],C[N],D[N]; ll fac[N],ifac[N]; ll fpow(ll x,ll y = P - 2){ ll res = 1; while(y){ if(y & 1)res = res * x % P; x = x * x % P; y >>= 1; } return res; } void init(){ fac[0] = 1; rep(i,1,n){ fac[i] = fac[i - 1] * i % P; } ifac[n] = fpow(fac[n]); per(i,n,1){ ifac[i - 1] = ifac[i] * i % P; } } ll comb(ll n,ll m){ if(m > n || m < 0)return 0; return fac[n] * ifac[m] % P * ifac[n - m] % P; } int t[N]; void upd(int x,int v){ for(;x <= n;x += x & -x)t[x] += v; } int sum(int x){ int res = 0; for(;x > 0;x -= x & -x)res += t[x]; return res; } int main(){ cin.tie(0)->sync_with_stdio(0); cin >> n; rep(i,1,n)cin >> p[i]; init(); rep(i,1,n){ A[i] = sum(p[i]); B[i] = i - 1 - A[i]; upd(p[i],1); } rep(i,1,n)t[i] = 0; per(i,n,1){ C[i] = sum(p[i]); D[i] = n - i - C[i]; upd(p[i],1); } ll ans = 0; rep(i,1,n){ ans += comb(A[i] + D[i],A[i]) * comb(B[i] + C[i],C[i]) % P; ans %= P; } cout << ans << endl; return 0; }