#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using ll = long long;
const int mod = 998244353;
struct Object {
  int a;
  Object(int b = 0) { a = b; }
  operator int() { return a; }
  Object operator+(Object b) { return a + b.a > mod ? a + b.a - mod : a + b.a; }
  Object operator-(Object b) { return a - b.a < 0 ? a - b.a + mod : a - b.a; }
  Object operator*(Object b) { return int(ll(a) * b.a % mod); }
  Object operator^(Object e) {
    if (!e.a) return 1;
    Object q = (*this) ^ Object(e.a / 2);
    return e.a & 1 ? q * q * (*this) : q * q;
  }
  Object operator++() { return ++a; }
  Object operator++(int x) { return a++; }
};
int norm(ll x) { return x < 0 ? int(x % mod + mod) : int(x % mod); }
Object inv(Object x) { return x ^ Object(mod - 2); }
Object operator/(Object a, Object b) { return a * inv(b); }
Object neg(Object x) { return x.a ? -x.a + mod : 0; }
istream &operator>>(istream &i, Object &x) {
  i >> x.a;
  return i;
}
ostream &operator<<(ostream &o, const Object &x) {
  o << x.a;
  return o;
}
const int N = 5e3 + 1;
Object c[N], in[N], dp[N][N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for (int i = int(0); i < int(N); i++) in[i] = inv(i);
  int n;
  cin >> n;
  vector<Object> a;
  for (int i = int(0); i < int(n); i++) {
    Object x;
    cin >> x;
    c[x]++;
  }
  for (int i = int(0); i < int(N); i++)
    if (c[i].a) a.emplace_back(c[i]);
  int d = int((a).size());
  for (int i = int(d - 1); i >= int(0); i--)
    for (int j = int(a[i]); j < int(n + 1); j++) {
      Object p = a[i] * in[j];
      Object x = j > 1 ? p * (a[i] - Object(1)) * in[j - 1] : Object(0);
      dp[i][j] = i + 1 < d ? x + dp[i + 1][j] + p * dp[i + 1][j - 1] : x;
    }
  cout << dp[0][n] << '\n';
  return 0;
}
