#include <bits/stdc++.h>
using namespace std;
int rdn() {
  int ret = 0;
  bool fx = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') fx = 0;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getchar();
  return fx ? ret : -ret;
}
const int N = 5005, mod = 998244353;
int upt(int x) {
  while (x >= mod) x -= mod;
  while (x < 0) x += mod;
  return x;
}
int pw(int x, int k) {
  int ret = 1;
  while (k) {
    if (k & 1) ret = (long long)ret * x % mod;
    x = (long long)x * x % mod;
    k >>= 1;
  }
  return ret;
}
int n, ct[N], dp[N][N], jc[N];
int C(int x) { return (long long)x * (x - 1) % mod; }
int main() {
  n = rdn();
  jc[0] = 1;
  for (int i = 1; i <= n; i++) jc[i] = (long long)jc[i - 1] * i % mod;
  for (int i = 1, d; i <= n; i++) {
    d = rdn();
    ct[d]++;
  }
  for (int j = 0; j <= n; j++) dp[0][j] = 1;
  int ans = 0;
  for (int i = 1; i < n; i++)
    for (int j = 1; j <= n; j++) {
      int sm = dp[i - 1][j - 1];
      if (ct[j]) dp[i][j] = (long long)sm * ct[j] % mod;
      if (ct[j] >= 2)
        ans = (ans + (long long)sm * C(ct[j]) % mod * jc[n - i - 1]) % mod;
      dp[i][j] = upt(dp[i][j] + dp[i][j - 1]);
    }
  ans = (long long)ans * pw(jc[n], mod - 2) % mod;
  printf("%d\n", ans);
  return 0;
}
