#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 10;
const int maxm = 200000 * 2 + 10;
const int mod = 998244353;
long long num[maxn];
long long ans, sum[maxn], prob[maxn][maxn], inv[maxn];
long long qpow(long long x, long long y) {
  long long res = 1, k = x;
  while (y) {
    if (y & 1) res = res * k % mod;
    k = k * k % mod;
    y /= 2;
  }
  return res;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) inv[i] = qpow(i, mod - 2);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    num[x]++;
  }
  for (int i = 1; i <= n; i++) {
    prob[1][i] = num[i] * inv[n] % mod;
    for (int len = 2; n - len + 1 > 0; len++)
      prob[len][i] = sum[len - 1] * num[i] % mod * inv[n - len + 1] % mod;
    for (int len = 1; len <= n; len++)
      sum[len] = (sum[len] + prob[len][i]) % mod;
  }
  for (int i = 1; i <= n; i++)
    if (num[i] >= 2)
      for (int len = 1; len < n; len++)
        ans = (ans + prob[len][i] * (num[i] - 1) % mod * inv[n - len] % mod) %
              mod;
  cout << ans << endl;
  return 0;
}
