#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
using namespace std;
int a[5020];
int f[5020][5020], g[5020];
inline int Mod(int x) { return x + ((x >> 31) & 998244353); }
int main(void) {
  int n, x;
  int i, j, o;
  for (i = 2, g[1] = 1; i < 5020; i++)
    g[i] = (long long)Mod(-998244353 / i) * g[998244353 % i] % 998244353;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x;
    a[x]++;
  }
  for (i = 0; i <= n; i++) f[0][i] = 1;
  for (i = 1, o = 0; i <= n; i++)
    for (j = 1; j <= n; j++) {
      f[i][j] = f[i][j - 1];
      if (a[j]) {
        f[i][j] = (f[i][j] + (long long)f[i - 1][j - 1] * a[j] % 998244353 *
                                 g[n - i + 1]) %
                  998244353;
        if (a[j] > 1)
          o = (o + (long long)Mod(f[i][j] - f[i][j - 1]) * (a[j] - 1) %
                       998244353 * g[n - i]) %
              998244353;
      }
    }
  cout << o << endl;
  return 0;
}
