样例全过了
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5,M = 998244353;
int n,a[N],cnt[N],pre[2 * N],ans;
bool f[N];
int A(int x,int y){
int mul = 1;
for (int i = 1; i <= y; i++){
mul = (mul * x) % M;
x--;
}
return mul;
}
int C(int x,int y){return (A(x,y) / A(y,y)) % M;}
signed main(){
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i];
cnt[a[i]]++;
}
sort(a + 1,a + n + 1);
for (int i = 1; i <= N - 5; i++) pre[i] = pre[i - 1] + cnt[i];
for (int i = 1; i <= n; i++){
if (cnt[a[i]] < 2 || f[a[i]]) continue;
int c = C(cnt[a[i]],2),c2 = C(cnt[a[i]],3);
ans = (ans + c * (pre[a[i] * 2 - 1] - cnt[a[i]]) + c2) % M;
f[a[i]] = 1;
// cout << c << ' ' << t << ' ' << cnt[a[i]] << ' ' << c2 << ' ' << ans << "\n";
}
cout << ans;
return 0;
}