#include <bits/stdc++.h>
const int mod = 998244353;
const int inf = 1000000009;
const long long int INF = 1000000000000000009;
const long long big = 1000000000000000;
const long double eps = 0.0000000001;
using namespace std;
int DP[5005][5005], I[5005], S[5005], O[5005];
int Pow(int a, int b) {
  int wynik = 1;
  while (b) {
    if (b & 1) wynik = ((long long int)wynik * a) % mod;
    a = ((long long int)a * a) % mod;
    b /= 2;
  }
  return wynik;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    I[a]++;
  }
  for (int i = 0; i <= n; i++) O[i] = Pow(i, mod - 2);
  for (int i = n; i >= 1; i--) S[i] = S[i - 1] + I[i];
  for (int i = 1; i <= n; i++) DP[1][i] = ((long long int)I[i] * O[n]) % mod;
  long long int wynik = 0;
  for (int i = 1; i < n; i++) {
    int suma = 0;
    for (int j = 1; j <= n; j++) {
      if (!I[j]) continue;
      DP[i + 1][j] = ((((long long int)I[j] * O[n - i]) % mod) * suma) % mod;
      wynik += (((long long int)DP[i][j] * (I[j] - 1)) % mod) * O[n - i];
      wynik %= mod;
      suma += DP[i][j];
      suma %= mod;
    }
  }
  cout << wynik;
  return 0;
}
