#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long p(long long a, long long b) {
  if (b == 0) return 1;
  long long tmp = p(a, b / 2);
  if (b % 2 == 0) return (tmp * tmp) % mod;
  return ((tmp * tmp) % mod * a) % mod;
}
long long inve(long long x) { return p(x, mod - 2); }
long long n;
long long cnt[5011];
long long sum[5011];
long long f[5011][5011];
long long inv[5011];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (long long i = 0; i <= 5010; i++) inv[i] = inve(i);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    cnt[x]++;
  }
  for (long long j = n - 1; j >= 1; j--) {
    for (long long i = n; i >= j; i--) {
      if (!cnt[i]) continue;
      f[i][j] = ((((cnt[i] - 1) * inv[n - j]) % mod +
                  (inv[n - j] * sum[i + 1]) % mod) %
                     mod +
                 mod) %
                mod;
    }
    for (long long i = n; i >= 1; i--)
      sum[i] = ((cnt[i] * f[i][j]) % mod + sum[i + 1]) % mod;
  }
  for (long long i = 1; i <= n; i++)
    f[i][1] = ((f[i][1] * inv[n]) % mod * cnt[i]) % mod;
  long long res = 0;
  for (long long i = 1; i <= n; i++) res = (res + f[i][1]) % mod;
  cout << res;
}
