class BIT(): def __init__(self,n): self.BIT=[0]*(n+1) self.num=n def query(self,idx): res_sum = 0 while idx > 0: res_sum += self.BIT[idx] idx -= idx&(-idx) return res_sum #Ai += x O(logN) def update(self,idx,x): while idx <= self.num: self.BIT[idx] += x idx += idx&(-idx) return def cmb(n, r, mod):#コンビネーションの高速計算  if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 998244353 #出力の制限 N = 2*10**5 g1 = [1]*(N+1) # 元テーブル g2 = [1]*(N+1) #逆元テーブル inverse = [1]*(N+1) #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1[i]=( ( g1[i-1] * i ) % mod ) inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod ) g2[i]=( (g2[i-1] * inverse[i]) % mod ) inverse[0]=0 N=int(input()) A=list(map(int,input().split())) S=list(set(A)) S.sort() comp={i:e+1 for e,i in enumerate(S)} n=max(comp[i] for i in comp) rev=0 bit=BIT(n) for i in range(N): c=comp[A[i]] rev+=i-bit.query(c) bit.update(c,1) A.sort() Small=0 tmp=0 for i in range(1,N): if A[i]==A[i-1]: Small+=tmp else: tmp=i Small+=tmp ans=0 S=1 for i in range(1,N+1): S=S*cmb(N,i,mod) S%=mod const=(N*(N+1)//2)**2 const%=mod for i in range(1,N+1): const-=i**2 const%=mod const=(const*pow(2,mod-2,mod))%mod const=(const*inverse[N])%mod const=(const*inverse[N])%mod ans+=S*const*Small ans%=mod ans+=rev*S*(N+1)*inverse[3] ans%=mod print(ans)