#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
const double pi = acos(-1.0);
int n, cnt[5050], a[5050], x[5050], m;
long long dp[5050][5050], fac[5050];
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while ((ch < '0') || (ch > '9')) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ((ch >= '0') && (ch <= '9')) {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * f;
}
long long qpow(long long x, int y) {
  long long ans = 1;
  while (y) {
    if (y & 1) ans = ans * x % 998244353;
    x = x * x % 998244353;
    y >>= 1;
  }
  return ans;
}
int main() {
  n = read();
  for (register int i = 1; i <= n; i++) {
    a[i] = read();
    x[i] = a[i];
  }
  sort(x + 1, x + 1 + n);
  m = unique(x + 1, x + 1 + n) - x - 1;
  for (register int i = 1; i <= n; i++) {
    a[i] = lower_bound(x + 1, x + 1 + m, a[i]) - x;
    cnt[a[i]]++;
  }
  fac[0] = 1;
  for (register int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % 998244353;
  for (register int i = 0; i <= m; i++) dp[i][0] = 1;
  for (register int i = 1; i <= m; i++) {
    for (register int j = 1; j <= i; j++) {
      dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1] * cnt[i]) % 998244353;
    }
  }
  long long ans = 0;
  for (register int i = 1; i <= m; i++) {
    if (cnt[i] >= 2)
      for (register int j = 1; j <= i; j++)
        ans = (ans + dp[i - 1][j - 1] * cnt[i] * (cnt[i] - 1) % 998244353 *
                         fac[n - j - 1] % 998244353) %
              998244353;
  }
  ans = ans * qpow(fac[n], 998244353 - 2) % 998244353;
  printf("%lld", ans);
  return 0;
}
