#include <bits/stdc++.h>
using namespace std;
const int mo = 998244353;
const int N = 5005;
int cnt[N], a[N], fac[N];
int n, ans, f[N][N];
int power(int x, int y) {
  int s = 1;
  for (; y; y /= 2, x = 1ll * x * x % mo)
    if (y & 1) s = 1ll * s * x % mo;
  return s;
}
int main() {
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &a[i]), ++cnt[a[i]];
  fac[0] = 1;
  for (int i = (int)(1); i <= (int)(n); i++) fac[i] = 1ll * fac[i - 1] * i % mo;
  f[0][0] = 1;
  for (int i = (int)(1); i <= (int)(n); i++) {
    for (int j = (int)(1); j <= (int)(N - 1); j++)
      f[i][j] = (f[i][j - 1] + f[i - 1][j - 1]) % mo;
    for (int j = (int)(1); j <= (int)(N - 1); j++)
      if (!cnt[j])
        f[i][j] = 0;
      else {
        if (cnt[j] >= 2 && i != n) {
          int ways = 1ll * cnt[j] * (cnt[j] - 1) * f[i][j] % mo;
          ans = (ans + 1ll * ways * fac[n - i - 1]) % mo;
        }
        f[i][j] = 1ll * f[i][j] * cnt[j] % mo;
      }
  }
  ans = 1ll * ans * power(fac[n], mo - 2) % mo;
  printf("%d\n", ans);
}
