#include using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) templateostream& operator<<(ostream& os,const pair&a){return os<<"("<void chmin(T&a,const T&b){if(a>b)a=b;} templatevoid chmax(T&a,const T&b){if(avoid pv(T a,T b){for(T i=a;i!=b;++i)cerr<<(*i)<<" ";cerr<void pv(T a,T b){} #endif ll nextLong() { ll x; scanf("%lld", &x); return x;} const ll MOD = 998244353; struct mint { ll x; mint(ll x=0):x((x%MOD+MOD)%MOD){} mint& operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;} mint& operator-=(const mint a) {if ((x += MOD-a.x) >= MOD) x -= MOD;return *this;} mint& operator*=(const mint a) {(x *= a.x) %= MOD;return *this;} mint operator+(const mint a) const {mint res(*this);return res+=a;} mint operator-(const mint a) const {mint res(*this);return res-=a;} mint operator*(const mint a) const {mint res(*this);return res*=a;} mint pow(ll b) const { mint res(1), a(*this); while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; } // for prime MOD mint inv() const {return pow(MOD-2);} mint& operator/=(const mint a) {return (*this) *= a.inv();} mint operator/(const mint a) const {mint res(*this);return res/=a;} }; ostream& operator<<(ostream& os, const mint& a) {os << a.x; return os;} vector normalize(const vector v) { const int N = v.size(); vector res(N); vector > t(N); REP(i, N) t[i] = { v[i], i }; sort(ALL(t)); int r = 0; REP(i, N) { r += (i > 0 && t[i - 1].first != t[i].first); res[t[i].second] = r; } return res; } struct BIT { using Val = int; int n; vector tree; BIT(int n):n(n),tree(n+1) {} void fill(Val val) { REP(i, n+1) tree[i] = (i&-i) * val; } void add(int idx, Val val) { for (int x=idx+1; x<=n; x+=x&-x) tree[x] += val; } // sum[0, idx] Val range(int idx) { Val sum=0; for (int x=idx+1; x>0; x-=x&-x) sum += tree[x]; return sum; } // sum[a, b] Val range(int a, int b) { return range(b) - range(a - 1); } }; const int MAX_N = 212345; mint P[MAX_N]; mint M[MAX_N]; mint L[MAX_N]; const int SZ = 1123456; ll inv[SZ]; ll fact[SZ]; ll fact_inv[SZ]; mint choose(int n, int r) { if (n < 0 || r < 0 || n < r) return 0; ll res = fact[n] * fact_inv[n-r] % MOD * fact_inv[r] % MOD; return mint(res); } int main2() { int N = nextLong(); vector A_(N); REP(i, N) A_[i] = nextLong(); vector A = normalize(A_); const int R = *max_element(ALL(A)) + 1; pv(ALL(A)); mint ans = 0; P[N+1] = 0; for (int n = N; n >= 1; n--) { P[n] = P[n+1] + (mint(n) / mint(N)); } { REP(i, MAX_N) M[i] = 0; vector sorted = A; sort(ALL(sorted)); REP(i, R) M[i] = lower_bound(ALL(sorted), i) - sorted.begin(); pv(M, M+R); } { mint sm = 0; for (int i = 0; i < N; i++) sm += M[A[i]]; mint sp = 0; for (int n = 1; n <= N; n++) sp += mint(n) / mint(N) * P[n+1]; ans += sm * sp; } { REP(i, MAX_N) L[i] = 0; BIT bit(N+1); for (int i = 0; i < N; i++) { L[i] = i - bit.range(A[i]); bit.add(A[i], 1); } } { mint sn = 0; for (int n = 1; n <= N; n++) sn += mint(n-1) / mint(N-1) * mint(n) / mint(N); mint sl = 0; for (int i = 0; i < N; i++) sl += L[i]; ans += sn * sl; } for (int n = 1; n <= N; n++) ans *= choose(N, n); cout << ans << endl; return 0; } int main() { inv[1] = 1; for (int i = 2; i < SZ; i++) inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD; fact[0] = 1; for (int i = 1; i < SZ; i++) fact[i] = fact[i-1] * i % MOD; fact_inv[0] = 1; for (int i = 1; i < SZ; i++) fact_inv[i] = fact_inv[i-1] * inv[i] % MOD; #ifdef LOCAL for (;!cin.eof();cin>>ws) #endif main2(); return 0; }