#include <bits/stdc++.h>
using namespace std;
vector<long long> fact(2000010);
vector<long long> inv(2000010);
const long long mod = 998244353;
long long modpow(long long x, long long y) {
  return !y ? 1 : ((y % 2 ? x : 1) * modpow((x * x) % mod, y / 2)) % mod;
}
long long choose(long long x, long long y) {
  if (y > x) return 0;
  return (fact[x] * inv[y] % mod) * inv[x - y] % mod;
}
long long permute(long long x, long long y) {
  if (y > x) return 0;
  return (fact[x] * inv[x - y]) % mod;
}
void precalc() {
  fact[0] = 1;
  inv[0] = 1;
  for (long long i = 1; i <= 2000000; i++) {
    fact[i] = fact[i - 1] * i % mod;
  }
  inv[2000000] = modpow(fact[2000000], mod - 2);
  for (long long i = 1999999; i > 0; i--) {
    inv[i] = inv[i + 1] * (i + 1) % mod;
  }
}
signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  precalc();
  long long n;
  cin >> n;
  vector<long long> arr(n + 1);
  for (long long i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  vector<long long> freq(n + 1);
  for (long long i = 1; i <= n; i++) {
    freq[arr[i]]++;
  }
  set<long long> s;
  for (long long i = 1; i <= n; i++) {
    s.insert(arr[i]);
  }
  vector<long long> a;
  a.push_back(0);
  for (long long nxt : s) a.push_back(nxt);
  cout << "\n";
  long long ans = 0;
  vector<vector<long long>> dp(n + 1, vector<long long>(n + 1));
  dp[0][0] = 1;
  for (long long i = 1; i < a.size(); i++) {
    for (long long j = 0; j <= i; j++) {
      dp[i][j] += dp[i - 1][j];
      dp[i][j] %= mod;
      if (j) dp[i][j] += dp[i - 1][j - 1] * freq[a[i]] % mod;
      dp[i][j] %= mod;
      if (j && freq[a[i]] > 1) {
        long long total = permute(n, j + 1);
        long long num = freq[a[i]] - 1;
        num *= dp[i - 1][j - 1] * freq[a[i]] % mod;
        num %= mod;
        long long prob = num * modpow(total, mod - 2);
        prob %= mod;
        ans += prob;
        ans %= mod;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
