#include<bits/stdc++.h>#define int long long
usingnamespacestd;constintmod=998244353;constintN=1000010;intfac[N]={1,1},a[N],c[N];intn;inlineintlowbit(intx){returnx&(-x);}inlinevoidmodify(intp){while(p<=n){++c[p];p+=lowbit(p);}return;}inlineintask(intp){ints=0;while(p){s+=c[p];p-=lowbit(p);}returns;}signedmain(){ints=0;cin>>n;for(inti=1;i<=n;i++){cin>>a[i];}for(inti=2;i<=n;i++){fac[i]=(fac[i-1]*i)%mod;}for(inti=1;i<=n;i++){(s+=(fac[n-i])*(a[i]-1-ask(a[i]-1))%mod)%=mod;modify(a[i]);}cout<<s+1<<endl;}