#include <bits/stdc++.h>
using namespace std;
const int n0 = 5003, mod = 998244353;
int n, a[n0], dp[n0][n0][2], p[n0], last[n0], fact[n0], invf[n0];
void add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
int bp(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1) res = (long long)res * x % mod;
    x = (long long)x * x % mod;
    y /= 2;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  fact[0] = invf[0] = 1;
  for (int i = 1; i < n0; i++) {
    fact[i] = (long long)fact[i - 1] * i % mod;
    invf[i] = bp(fact[i], mod - 2);
  }
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  {
    int j = 1;
    for (int i = 1; i <= n; i++) {
      while (j <= n && a[j] != a[i]) {
        j++;
      }
      last[i] = j;
    }
  }
  int ans = 0;
  dp[0][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      p[j] = (j) ? p[j - 1] : 0;
      add(p[j], dp[i - 1][j][0]);
    }
    for (int j = i; j <= n; j++) {
      dp[i][j][0] = p[last[j] - 1];
      dp[i][j][1] = p[j] - p[last[j]];
      if (dp[i][j][1] < 0) dp[i][j][1] += mod;
      add(ans, (long long)2 * dp[i][j][1] * fact[n - i] % mod);
    }
  }
  cout << (long long)ans * invf[n] % mod;
}
