#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
int dp[5005][5005];
int a[5005], c[5005], inv[5005], ans, ps[5005];
void fmain(int tid) {
  scanf("%d", &n);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    scanf("%d", a + i);
    c[a[i]]++;
  }
  inv[0] = 1;
  for (int(i) = 1; (i) <= (int)(n); (i)++) inv[i] = fastPow(i, 998244353 - 2);
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    dp[1][i] = (long long)c[i] * inv[n] % 998244353;
  for (int i = 2; i <= n; i++) {
    ps[0] = 0;
    for (int j = 1; j <= n; j++) {
      if (dp[i - 1][j]) {
        assert(c[j] >= 0);
        addmod(ans, (long long)(c[j] - 1) * inv[n - i + 1] % 998244353 *
                        dp[i - 1][j] % 998244353);
      }
      ps[j] = ps[j - 1];
      addmod(ps[j], dp[i - 1][j]);
    }
    for (int j = 2; j <= n; j++) {
      dp[i][j] = (long long)ps[j - 1] * (c[j]) % 998244353 * inv[n - i + 1] %
                 998244353;
    }
  }
  printf("%d\n", ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
