#include <bits/stdc++.h>
using namespace std;
int N;
int a[5005];
int cnt[5005];
int sn[5005];
long long dp[5005][5005], col[5005];
long long inv[5005];
long long qpow(long long x, int n) {
  if (n < 0) return 1;
  long long res = 1;
  while (n) {
    if (n & 1) res = res * x % int(998244353);
    x = x * x % int(998244353);
    n /= 2;
  }
  return res;
}
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (int i = 1; i <= N; i++) {
    sn[i] = sn[i - 1] + cnt[a[i]];
    inv[i] = qpow(i, int(998244353) - 2);
  }
  for (int i = N; i >= 1; i--) {
    if (!cnt[i]) continue;
    for (int j = 1; j <= N; j++) {
      if (sn[i - 1] + 1 < j) continue;
      dp[i][j] = inv[N - j] * (cnt[i] - 1 + col[j + 1]) % int(998244353);
      col[j] = (col[j] + cnt[i] * dp[i][j] % int(998244353)) % int(998244353);
    }
  }
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    ans = (ans + cnt[i] * dp[i][1] % int(998244353)) % int(998244353);
  }
  cout << ans * inv[N] % int(998244353) << endl;
  return 0;
}
