#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
  long long int r = 1;
  x = x % p;
  while (y) {
    if (y & 1) r = r * x % p;
    y = y >> 1;
    x = x * x % p;
  }
  return r;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int csrand(int l = 0, int r = 1e9) {
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}
const int N = 5e3 + 99;
long long int dp[N][N], inv[N];
int freq[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < N; i++) inv[i] = power(i, 998244353 - 2, 998244353);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    freq[x]++;
  }
  dp[0][0] = 1;
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    long long int pre = 0;
    for (int j = 1; j <= n; j++) {
      pre = (pre + dp[i - 1][j - 1]) % 998244353;
      dp[i][j] = (((pre * freq[j]) % 998244353) * inv[n - i + 1]) % 998244353;
      if (freq[j] >= 2) {
        ans = (ans + ((dp[i][j] * (freq[j] - 1)) % 998244353 * inv[n - i]) %
                         998244353) %
              998244353;
      }
    }
  }
  cout << ans << '\n';
}
