#include <bits/stdc++.h>
using namespace std;
const int N = 5010, mod = 998244353;
int n, x, ans, f[N][N], cnt[N], inv[N];
int main() {
  scanf("%d", &n);
  inv[1] = 1;
  for (int i = (1); i <= (n); i++) scanf("%d", &x), cnt[x]++;
  for (int i = (2); i <= (n); i++)
    inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
  for (int i = (1); i <= (n); i++) {
    int s = (i == 1);
    for (int j = (1); j <= (n); j++) {
      f[i][j] = 1ll * s * cnt[j] % mod * inv[n - i + 1] % mod;
      if (cnt[j] > 1)
        ans =
            (ans + 1ll * f[i][j] * (cnt[j] - 1) % mod * inv[n - i] % mod) % mod;
      s = (s + f[i - 1][j]) % mod;
    }
  }
  printf("%d\n", ans);
  return 0;
}
