#include <bits/stdc++.h>
using namespace std;
vector<long long> readvec(long long length, long long off = 0);
template <typename T>
string ts(T v);
long long mod = 998244353;
template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result % modulus;
}
long long inv(long long x) { return modpow(x, mod - 2, mod); }
long long mul(long long x, long long y) { return (x * y) % mod; }
long long add(long long x, long long y) { return (x + y) % mod; }
long long subtract(long long x, long long y) { return (x + (mod - y)) % mod; }
long long factorial(long long x) {
  long long ans = 1;
  for (long long i = 1; i <= x; i++) ans = mul(ans, i);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> v = readvec(n);
  vector<long long> counts(5100);
  for (long long x : v) counts[x]++;
  vector<long long> fact(5100);
  for (long long i = 0; i < 5100; i++) fact[i] = factorial(i);
  vector<vector<long long> > f(5100, vector<long long>(5100));
  for (long long x = 0; x <= n; x++) {
    for (long long d = 0; d <= n; d++) {
      if (d == 0) f[x][d] = 1;
    }
  }
  long long good = 0;
  for (long long d = 1; d <= n; d++) {
    for (long long x = 1; x <= n; x++) {
      f[x][d] = add(f[x][d], mul(f[x - 1][d - 1], counts[x]));
      f[x][d] = add(f[x][d], f[x - 1][d]);
    }
  }
  for (long long x = 1; x <= n; x++) {
    for (long long d = 0; d <= n - 2; d++) {
      if (counts[x] >= 2) {
        long long z = mul(f[x - 1][d], counts[x]);
        z = mul(z, counts[x] - 1);
        z = mul(z, fact[n - d - 2]);
        good = add(good, z);
      }
    }
  }
  long long all = fact[n];
  cout << mul(good, inv(all)) << endl;
}
template <typename T>
string ts(T v) {
  stringstream ss;
  ss << "[";
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) ss << ", ";
    ss << *it;
  }
  ss << "]";
  return ss.str();
}
vector<long long> readvec(long long length, long long off) {
  vector<long long> v;
  for (long long i = 0; i < length; i++) {
    long long x;
    cin >> x;
    v.push_back(x + off);
  }
  return v;
}
