#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int maxn = 5e3 + 5;
long long cnt[maxn];
long long dp[maxn];
long long inv[maxn];
void solve() {
  int n;
  cin >> n;
  inv[1] = 1;
  for (int i = 2; i <= n; i++) {
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  }
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  dp[0] = 1;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = n; j >= 0; j--) {
      if (cnt[i] >= 2) {
        ans += dp[j] * cnt[i] % mod * (cnt[i] - 1) % mod * inv[n - j] % mod *
               inv[n - j - 1] % mod;
        ans %= mod;
      }
      if (j) {
        dp[j] += dp[j - 1] * cnt[i] % mod * inv[n - j + 1] % mod;
        dp[j] %= mod;
      }
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int c = 0;
  int t;
  if (!c) {
    t = 1;
  } else {
    cin >> t;
  }
  while (t--) {
    solve();
  }
}
