#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000 + 10, MOD = 998244353;
long long dp[MAXN][MAXN], rev[MAXN], ans;
int n, a[MAXN];
long long powe(long long a, long long b) {
  long long res = 1;
  for (b; b; b /= 2) {
    if (b % 2) res *= a, res %= MOD;
    a *= a;
    a %= MOD;
  }
  return res;
}
long long frac(long num, long denum) { return num * rev[denum] % MOD; }
int main() {
  for (int i = 0; i < MAXN; i++) rev[i] = powe(i, MOD - 2);
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  int li = 0;
  vector<int> vec;
  vec.push_back(0);
  vec.push_back(1);
  for (int i = 1; i < n; i++) {
    if (a[i] != a[li]) li = i, vec.push_back(0);
    vec.back()++;
  }
  dp[0][0] = 1;
  for (int i = 1; i < vec.size(); i++)
    for (int j = 0; j <= i; j++) {
      dp[i][j] = dp[i - 1][j];
      if (j > 0) dp[i][j] += dp[i - 1][j - 1] * frac(vec[i], n - j + 1);
      dp[i][j] %= MOD;
      ans += (dp[i - 1][j] * frac(vec[i], n - j) % MOD) *
             frac(vec[i] - 1, n - j - 1);
      ans %= MOD;
    }
  cout << ans;
}
