#include <bits/stdc++.h>
using namespace std;
const int N = 5010, P = 998244353;
int n;
int cnt[N], prod[N];
int dp[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int rep = 0; rep < n; ++rep) {
    int x;
    scanf("%d", &x);
    ++cnt[x];
  }
  dp[0] = 1;
  prod[1] = 1;
  for (int i = 2; i <= n; ++i)
    prod[i] = -(P / i) * (long long)prod[P % i] % P + P;
  for (int i = n - 1; i; --i) prod[i] = prod[i + 1] * (long long)prod[i] % P;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (!cnt[i]) continue;
    if (cnt[i] >= 2) {
      for (int j = 0; j <= n - 2; ++j)
        ans = (ans + ((long long)cnt[i] * (cnt[i] - 1)) % P * dp[j] % P *
                         prod[n - j - 1]) %
              P;
    }
    for (int j = n; j; --j) dp[j] = (dp[j] + dp[j - 1] * (long long)cnt[i]) % P;
  }
  printf("%d\n", ans);
  return 0;
}
