#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const long long MOD = 998244353ll;
enum RESULT { OK, WIN };
int n, v[N], nxt[N], prv[N];
long long dp[N][2], acc[N], inv[N];
long long expr(long long e, long long n) {
  if (n == 0) return 1ll;
  long long tp = expr(e, n / 2ll);
  tp = (tp * tp) % MOD;
  if (n % 2ll) tp = (tp * e) % MOD;
  return tp;
}
void ok(int t, int p) {
  int h = prv[p - 1];
  dp[p][OK] = (acc[h] * inv[n - t + 1]) % MOD;
}
void win(int t, int p) {
  int r = nxt[p - 1];
  int l = prv[p - 1];
  dp[p][WIN] =
      (((acc[r] - acc[l] - dp[p][OK] + 2ll * MOD) % MOD) * inv[n - t + 1]) %
      MOD;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &v[i - 1]);
    dp[i][OK] = expr(n, MOD - 2) % MOD;
    acc[i] = (acc[i - 1] + dp[i][OK]) % MOD;
  }
  sort(v, v + n);
  long long resp = 0ll;
  for (int t = 1; t <= n; t++) inv[t] = expr(t, MOD - 2);
  for (int i = 0; i < n; i++) {
    prv[i] = lower_bound(v, v + n, v[i]) - v;
    nxt[i] = upper_bound(v, v + n, v[i]) - v;
  }
  for (int t = 2; t <= n; t++) {
    for (int p = 1; p <= n; p++) {
      win(t, p);
      ok(t, p);
      resp = (resp + dp[p][WIN]) % MOD;
    }
    for (int p = 1; p <= n; p++) acc[p] = (acc[p - 1] + dp[p][OK]) % MOD;
  }
  printf("%lld\n", resp);
}
