#include <bits/stdc++.h>
using namespace std;
int c[5001];
long long dp[5001], s[5001];
long long ModularExponentation(long long a, int n) {
  long long ans = 1;
  for (; n; n /= 2) {
    if (n % 2) {
      ans = (ans * a) % 998244353;
    }
    a = (a * a) % 998244353;
  }
  return ans;
}
long long ModularInverse(long long a) {
  return ModularExponentation(a, 998244353 - 2);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    ++c[x];
  }
  dp[0] = 1;
  for (int i = 1, t = 0; i <= n; ++i, t += c[i]) {
    if (c[i] == 0) {
      continue;
    }
    if (c[i] > 1) {
      for (int j = 0, k = 2, val = c[i] * (c[i] - 1); j <= t; ++j, ++k) {
        s[k] = (s[k] + val * dp[j]) % 998244353;
      }
    }
    if (c[i]) {
      for (int j = t + 1, val = c[i]; j > 0; --j) {
        dp[j] = (dp[j] + val * dp[j - 1]) % 998244353;
      }
    }
  }
  long long invFact = 1;
  for (int i = 2; i <= n; ++i) {
    invFact = (i * invFact) % 998244353;
  }
  invFact = ModularInverse(invFact);
  long long ans = 0;
  for (int i = n; i > 1; --i) {
    ans = (ans + invFact * s[i]) % 998244353;
    invFact = (invFact * (n - i + 1)) % 998244353;
  }
  printf("%lld\n", ans);
  return 0;
}
