#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 69, MOD = 998244353;
long long n, ans, cnt[5069], dp[5069], inv[5069];
long long exp(long long base, long long power) {
  if (power == 0) return 1;
  long long half = exp(base, power >> 1) % MOD;
  long long res = (half * half) % MOD;
  if (power & 1) res = (res * base) % MOD;
  return res;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  long long ip;
  for (long long i = 1; i <= n; i++) cin >> ip, cnt[ip]++;
  dp[0] = 1;
  for (long long i = 1; i <= n; i++) inv[i] = exp(i, MOD - 2);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= i; j++) {
      long long fi = (cnt[i] * inv[n - j + 1] + MOD) % MOD,
                se = ((cnt[i] - 1) * inv[n - j] + MOD) % MOD;
      ans =
          (ans + (((se * fi + MOD) % MOD) * dp[j - 1] + MOD) % MOD + MOD) % MOD;
    }
    for (long long j = i; j >= 1; j--)
      dp[j] =
          (dp[j] +
           (((cnt[i] * inv[n - j + 1] + MOD) % MOD) * dp[j - 1] + MOD) % MOD +
           MOD) %
          MOD;
  }
  cout << ans << "\n";
}
