#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
template <class T>
inline bool read(T &x) {
  int c = getchar();
  int sgn = 1;
  while (~c && c < '0' || c > '9') {
    if (c == '-') sgn = -1;
    c = getchar();
  }
  for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  x *= sgn;
  return ~c;
}
const int INF = 2000000009;
const int MX = 5005;
const double EPS = 1e-9;
const long long MOD = 998244353;
long long inv[MX], dp[MX][MX], cnt[MX];
int n;
long long bigmod(long long b, long long p) {
  if (p == 0) return 1;
  if (p & 1) return b * bigmod(b, p - 1) % MOD;
  long long ret = bigmod(b, p >> 1);
  return ret * ret % MOD;
}
void pre() {
  for (int i = 1; i < MX; i++) inv[i] = bigmod(i, MOD - 2);
  memset(dp, -1, sizeof(dp));
}
long long rec(int taken, int pos) {
  if (pos > n || taken >= n) return 0;
  long long &ret = dp[taken][pos];
  if (ret != -1) return ret;
  ret = rec(taken, pos + 1);
  if (cnt[pos] == 0) return ret;
  long long p = cnt[pos] * inv[n - taken] % MOD;
  ret = (ret + p * rec(taken + 1, pos + 1)) % MOD;
  if (cnt[pos] == 1) return ret;
  long long p2 = (cnt[pos] - 1LL) * inv[n - taken - 1] % MOD;
  ret = (ret + p * p2) % MOD;
  return ret;
}
int main() {
  pre();
  n = ({
    int a;
    read(a);
    a;
  });
  for (int i = 0; i < n; i++)
    cnt[({
      int a;
      read(a);
      a;
    })]++;
  printf("%lld\n", rec(0, 1));
  return 0;
}
