#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 10, MOD = 998244353;
long long inv[MAXN], N, ans, f[5005][5005], t[MAXN], tot, num[MAXN], sum[MAXN];
long long val[MAXN];
int main() {
  scanf("%lld", &N);
  inv[1] = 1;
  for (long long i = 2; i <= N * 10; i++)
    inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
  for (long long i = 1; i <= N; i++) scanf("%lld", val + i);
  sort(val + 1, val + N + 1);
  val[0] = -1;
  for (long long i = 1; i <= N; i++) {
    if (val[i] != val[i - 1])
      num[++tot]++;
    else
      num[tot]++;
  }
  if (tot == N) {
    puts("0");
    return 0;
  }
  for (long long i = 1; i <= tot; i++) {
    f[i][0] = 1;
    sum[0] = 1;
    for (long long j = i; j; j--) {
      f[i][j] = sum[j - 1] * num[i] % MOD * inv[N - j + 1] % MOD;
      sum[j] += f[i][j];
    }
  }
  for (long long i = 1; i <= tot; i++) {
    for (long long j = i; j; j--) {
      (ans += (f[i][j] * (num[i] - 1) % MOD * inv[N - j] % MOD)) %= MOD;
    }
  }
  printf("%lld", ans % MOD);
  return 0;
}
