#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
const long long MOD = 998244353;
int n;
int a[MAXN];
long long ans;
long long fac[MAXN];
long long inv[MAXN];
long long sum[MAXN];
long long f[MAXN][MAXN];
long long power(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) (res *= a) %= MOD;
    (a *= a) %= MOD;
    b >>= 1;
  }
  return res;
}
int main() {
  scanf("%d", &n);
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % MOD;
  inv[n] = power(fac[n], MOD - 2);
  for (int i = n; i >= 1; i--) inv[i - 1] = inv[i] * i % MOD;
  for (int i = 1; i <= n; i++) (inv[i] *= fac[i - 1]) %= MOD;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  int cnt = 1;
  for (int i = n; i >= 1; i--, cnt++)
    if (a[i] != a[i - 1]) {
      for (int j = 1; j <= i; j++) {
        f[i][j] = (cnt - 1 + sum[j + 1]) * inv[n - j] % MOD;
        (sum[j] += f[i][j] * cnt) %= MOD;
      }
      (ans += f[i][1] * cnt) %= MOD;
      cnt = 0;
    }
  printf("%d\n", (int)(ans * inv[n] % MOD));
  return 0;
}
