#include <bits/stdc++.h>
using namespace std;
const long long Mod = 998244353;
const int maxn = 5010;
int n, s[maxn];
long long f[maxn][maxn], inv[maxn];
void upd(long long &x, long long v) { x = (x + v) % Mod; }
int main() {
  scanf("%d", &n);
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= n; i++) {
    inv[i] = (Mod - Mod / i) * inv[Mod % i] % Mod;
  }
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    s[x]++;
  }
  f[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < i; j++) {
      f[i][j] = f[i - 1][j];
    }
    if (!s[i]) {
      continue;
    }
    for (int j = 1; j <= i; j++) {
      upd(f[i][j], f[i - 1][j - 1] * inv[n - j + 1] % Mod * s[i]);
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] < 1) {
      continue;
    }
    for (int j = 1; j < n; j++) {
      upd(ans, f[i - 1][j - 1] * inv[n - j + 1] % Mod * s[i] % Mod *
                   inv[n - j] % Mod * (s[i] - 1));
    }
  }
  cout << ans << endl;
  return 0;
}
