#include <bits/stdc++.h>
using namespace std;
const int N = 5005, Mod = 998244353;
int dp[N][N], sum[N][N], a[N], inv[N];
inline int qpow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1ll * ans * a % Mod;
    a = 1ll * a * a % Mod, b >>= 1;
  }
  return ans;
}
int cnt[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), cnt[a[i]]++, inv[i] = qpow(i, Mod - 2);
  sort(a + 1, a + n + 1);
  dp[0][0] = 1;
  int ans = 0, sum;
  for (int i = 1; i <= n; i++) {
    if (i == 1)
      sum = 1;
    else
      sum = 0;
    for (int j = 1; j <= n; j++) {
      if (a[j] == a[j - 1]) {
        ans = (ans + 1ll * dp[i - 1][j - 1] * (cnt[a[j]] - 1) % Mod *
                         inv[n - i + 1] % Mod) %
              Mod;
        continue;
      }
      dp[i][j] = 1ll * sum * cnt[a[j]] % Mod * inv[n - i + 1] % Mod;
      sum = (sum + dp[i - 1][j]) % Mod;
    }
  }
  printf("%d", ans);
  return 0;
}
