#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const int N = 5e3 + 100;
long long wins, lose;
long long ways[N][N];
long long num[N], g[N], tot[N], gt[N];
long long pw(long long x, long long q) {
  if (!q) return 1;
  long long rz = pw(x, q >> 1);
  rz = (rz * rz) % MOD;
  if (q & 1) rz = (rz * x) % MOD;
  return rz;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  gt[0] = 1;
  for (int i = 1; i <= n; ++i) gt[i] = gt[i - 1] * (long long)i % MOD;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    num[a[i]]++;
  }
  sort(a.begin(), a.end());
  a.resize(unique(a.begin(), a.end()) - a.begin());
  n = a.size();
  for (int i = 1; i <= n; ++i) tot[i] = tot[i - 1] + num[a[i - 1]];
  g[0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int used = i; used >= 1; --used) {
      ways[i][used] = (ways[i][used] + g[used - 1] * num[a[i - 1]]) % MOD;
      wins = (wins + ways[i][used] * (num[a[i - 1]] - 1) % MOD *
                         gt[tot[n] - used - 1]) %
             MOD;
      g[used] = (g[used] + ways[i][used]) % MOD;
    }
  }
  cout << wins * pw(gt[tot[n]], MOD - 2) % MOD << '\n';
}
