#include <bits/stdc++.h>
const int inf = (1ll << 30) - 1;
const int maxn = (int)1e5 + 10;
const int mod = 998244353;
using namespace std;
long long cnt[5050];
int a[5050];
long long binpow(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    y >>= 1;
  }
  return res;
}
int n;
long long dp[5050];
long long S[5050];
long long D[5050];
long long rev[5050];
int C;
void solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
  }
  for (int i = 0; i <= n; i++) {
    rev[i] = binpow(i, mod - 2);
  }
  long long ans = 0;
  int sum = 0;
  for (int i = n; i >= 1; i--) {
    if (cnt[i] == 0) continue;
    sum += cnt[i];
    for (int j = max(sum - 1, 1); j <= n - 1; j++) {
      dp[j] = S[j - 1] * 1ll * rev[j] % mod;
    }
    for (int j = max(sum - 1, 1); j <= n - 1; j++) {
      dp[j] = (dp[j] + (cnt[i] - 1) * 1ll * rev[j]) % mod;
    }
    ans = (ans + (cnt[i]) * 1ll * dp[n - 1]) % mod;
    for (int j = max(sum - 1, 1); j <= n - 1; j++) {
      S[j] = (S[j] + dp[j] * 1ll * cnt[i]) % mod;
    }
  }
  cout << ans * rev[n] % mod << "\n";
}
int main() {
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
