#include //ライブラリなどなど using std::cin; using std::cout; using std::endl; using std::vector; using std::pair; using ll=long long; const int MOD=998244353; const int MAX=1e6; struct Binary_indexed_tree{ int N; vector bit; Binary_indexed_tree(int n):N(n){ bit.resize(N+1); } void add(int x,ll a){ for(x;x<=N;x+=(x&-x)) bit[x]+=a; } ll sum(int x){ ll ret=0; for(x;x>0;x-=(x&-x)) ret+=bit[x]; return ret; } }; vector inv,finv,fac; void COMinit(){ inv.resize(MAX),finv.resize(MAX),fac.resize(MAX); fac[0]=fac[1]=1; finv[0]=finv[1]=1; inv[1]=1; for(int i=2;i &A){ std::map memo; for(int i=0;i A){ ll ret=0; ll sum=1; for(int i=1;i<=N;i++) sum=sum*COM(N,i)%MOD; for(int i=1;i<=N;i++){ ret+=sum*modpow(COM(N,i),MOD-2)%MOD*COM(N-2,i-2)%MOD; ret%=MOD; } ll cnt=0; Binary_indexed_tree BIT(N); comp(A); for(int i=0;i A){ vector> dp(N+1,vector(2)); dp[0][0]=1; for(int i=1;i<=N;i++){ dp[i][1]=(dp[i-1][0]*COM(N-1,i-1)%MOD+dp[i-1][1]*COM(N,i)%MOD)%MOD; dp[i][0]=dp[i-1][0]*COM(N,i)%MOD; } vector multi(N+2); multi[N+1]=1; ll sum=0; for(int i=N;i>=1;i--){ multi[i]=multi[i+1]*COM(N,i)%MOD; sum+=multi[i+1]*COM(N-1,i-1)%MOD*dp[i-1][1]%MOD; sum%=MOD; } vector B=A; sort(B.begin(),B.end()); ll cnt=0; for(int i=0;i>N; vector A(N); for(int i=0;i>A[i]; COMinit(); cout<<(same(N,A)+differ(N,A))%MOD<