#include <bits/stdc++.h>
using namespace std;
const int N = 5001;
const int MOD = 998244353;
const int LOGN = 30;
const int oo = 1e9;
int pre[N], dp[N][N][2], n, a[N], iv[N];
long long mul(long long a, long long b) { return (a * b) % MOD; }
long long add(long long a, long long b) { return (a + b) % MOD; }
long long sub(long long a, long long b) { return (a - b + MOD) % MOD; }
long long fast(long long a, long long b) {
  if (!b) return 1ll;
  long long res = fast(a, b / 2);
  res = mul(res, res);
  if (b & 1) return mul(res, a);
  return res;
}
long long inve(long long a) { return fast(a, MOD - 2); }
int getFreq(int idx) { return pre[idx] - pre[idx - 1]; }
int calc(int took, int prev, bool take) {
  if (prev > n) return 0;
  if (took >= n) return 0;
  int rem = n - took;
  int &ret = dp[took][prev][take];
  if (ret != -1) return ret;
  ret = calc(took, prev + 1, 0);
  if (take && getFreq(prev) > 1)
    ret = add(ret, mul(getFreq(prev) - 1, iv[rem]));
  if (!take && getFreq(prev) > 0)
    ret = add(ret, mul(mul(getFreq(prev), iv[rem]), calc(took + 1, prev, 1)));
  return ret;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    pre[a[i]]++;
  }
  for (int i = 1; i <= n; ++i) iv[i] = inve(i);
  for (int i = 1; i <= n; ++i) pre[i] += pre[i - 1];
  memset(dp, -1, sizeof dp);
  cout << calc(0, 0, 0) << endl;
  return 0;
}
