#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const int Mod = 998244353;
int n, Num[N], Cnt[N];
int f[N], Inv[N], Sum[N], Answer;
inline int Read() {
  char ch;
  while ((ch = getchar()) < '0' || ch > '9')
    ;
  int x = ch ^ 48;
  while ((ch = getchar()) >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48);
  return x;
}
inline void Init() {
  n = Read();
  for (register int i = 1; i <= n; i++) {
    Num[i] = Read();
    Cnt[Num[i]]++;
  }
  Inv[1] = 1;
  for (register int i = 2; i <= n; i++)
    Inv[i] = 1ll * (Mod - Mod / i) * Inv[Mod % i] % Mod;
  sort(Num + 1, Num + n + 1);
  for (register int i = 1; i <= n; i++) Cnt[i] += Cnt[i - 1];
}
inline void Query() {
  for (register int i = 1; i <= n; i++) {
    f[i] = Inv[n];
    Sum[i] = 1ll * i * Inv[n] % Mod;
  }
  for (register int i = 1; i < n; i++)
    Answer = (Answer + 1ll * Inv[n - 1] * f[i] % Mod * (Cnt[Num[i]] - i)) % Mod;
  for (register int i = 2; i <= n; i++) {
    memset(f, 0, sizeof(f));
    for (register int j = i; j <= n; j++)
      f[j] = 1ll * (Sum[Cnt[Num[j] - 1]] - Sum[i - 2] + Mod) % Mod *
             Inv[n - i + 1] % Mod;
    memset(Sum, 0, sizeof(Sum));
    for (register int j = i; j <= n; j++) Sum[j] = (Sum[j - 1] + f[j]) % Mod;
    for (register int j = i; j < n; j++)
      Answer =
          (Answer + 1ll * Inv[n - i] * f[j] % Mod * (Cnt[Num[j]] - j)) % Mod;
  }
}
int main() {
  Init();
  Query();
  Answer = 2ll * Answer % Mod;
  printf("%d\n", Answer % Mod);
  return 0;
}
