#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5, P = 998244353;
int n, ans, cnt[N], type[N], dp[N][2];
int power(int x, int y) {
  return y ? 1LL * power(1LL * x * x % P, y / 2) * (y & 1 ? x : 1) % P : 1;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[x]++, type[x] = 1;
  }
  partial_sum(type, type + n + 1, type);
  for (int j = n, sum = 0; ~j; sum = 0, j--)
    for (int i = n, tmp = power(n - j, P - 2); i; i--)
      if (cnt[i] > 0) {
        dp[i][j & 1] = (j <= type[i] ? 1LL * (cnt[i] - 1 + sum) * tmp % P : 1);
        (sum += 1LL * cnt[i] * dp[i][j & 1 ^ 1] % P) %= P;
      }
  for (int i = 0; i <= n; i++) (ans += 1LL * cnt[i] * dp[i][1] % P) %= P;
  cout << 1LL * ans * power(n, P - 2) % P;
}
