#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int n, a[5005], cnt[5005];
int num[5005], len = 0;
long long fac[5005];
long long dp[5005][5005];
long long quick_pow(long long a, long long b) {
  long long res = 1ll;
  while (b) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
  }
  fac[0] = 1ll;
  for (int i = 1; i <= 5004; i++) fac[i] = fac[i - 1] * i % mod;
  for (int i = 1; i <= 5004; i++)
    if (cnt[i]) {
      num[++len] = i;
      cnt[len] = cnt[i];
    }
  long long ans = 0ll;
  for (int i = 0; i <= len; i++) dp[i][0] = 1ll;
  for (int i = 1; i <= len; i++) {
    for (int j = 1; j <= i; j++) {
      dp[i][j] = (dp[i - 1][j - 1] * cnt[i] + dp[i - 1][j]) % mod;
    }
  }
  for (int i = 1; i <= len; i++) {
    if (cnt[i] >= 2) {
      for (int j = i; j >= 1; j--) {
        ans = (ans + ((dp[i - 1][j - 1] * cnt[i] * (cnt[i] - 1)) % mod *
                      fac[n - 2 - j + 1] % mod)) %
              mod;
      }
    }
  }
  ans = ans * quick_pow(fac[n], mod - 2) % mod;
  printf("%lld\n", ans);
}
