#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long inf = (1ll << 61);
const int MX = 5009;
long long POW(long long x, long long y) {
  if (y == 0) return 1;
  long long ans = POW(x, y / 2) % mod;
  ans = (ans * ans) % mod;
  if (y % 2) ans = (ans * x) % mod;
  return ans;
}
long long pw[MX];
long long modinv(long long x, long long y) { return (x * pw[y]) % mod; }
long long n, cnt[MX], dp[MX][MX];
long long DP(long long x, long long y) {
  if (x == n + 1) return 0;
  long long &ret = dp[x][y];
  if (ret != -1) return ret;
  ret = 0;
  if (cnt[x] >= 2) {
    long long x1 =
        (modinv(cnt[x], n - y) * modinv(cnt[x] - 1, n - y - 1)) % mod;
    ret = x1 % mod;
  }
  ret = (ret + DP(x + 1, y) % mod) % mod;
  if (cnt[x]) {
    long long x1 = (modinv(cnt[x], n - y) * (DP(x + 1, y + 1) % mod)) % mod;
    ret = (ret + x1) % mod;
  }
  return ret;
}
int main() {
  cin >> n;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    cnt[x]++;
  }
  for (int i = 0; i <= n; i++) pw[i] = POW(i, mod - 2);
  cout << DP(1, 0) << endl;
}
