#include <bits/stdc++.h>
using namespace std;
const int N = 5000 + 10, mod = 998244353;
int rd() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
}
int n, m = 5000, inv[N], a[N], f[2][N];
int main() {
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= m; ++i)
    inv[i] = (mod - 1ll * mod / i * inv[mod % i] % mod) % mod;
  n = rd();
  for (int i = 1; i <= n; ++i) ++a[rd()];
  int nw = 1, la = 0, ans = 0;
  f[la][0] = 1;
  for (int i = 1, j = 0; i <= m; ++i) {
    if (!a[i]) continue;
    for (int l = 0; l <= j; ++l) {
      f[nw][l] = (f[nw][l] + f[la][l]) % mod;
      int dx = 1ll * f[la][l] * inv[n - l] % mod * a[i] % mod;
      f[nw][l + 1] = (f[nw][l + 1] + dx) % mod;
      ans = (ans + 1ll * dx * inv[n - l - 1] % mod * (a[i] - 1) % mod) % mod;
      f[la][l] = 0;
    }
    ++j, swap(nw, la);
  }
  printf("%d\n", ans);
  return 0;
}
