#include <bits/stdc++.h>
using namespace std;
int n;
int tmp[5001];
vector<int> arr;
long long fak[5001];
long long dp[5001][5001];
long long f(int i, int c) {
  if (c == 0)
    return 1;
  else if (c - 1 > i)
    return 0;
  else {
    if (dp[i][c] != -1) return dp[i][c];
    return dp[i][c] =
               (f(i - 1, c - 1) * arr[i] % 998244353 + f(i - 1, c)) % 998244353;
  }
}
long long us(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) {
      ans *= a;
      ans %= 998244353;
    }
    a *= a;
    a %= 998244353;
    b >>= 1;
  }
  return ans;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tmp[i];
  }
  sort(tmp, tmp + n);
  fak[0] = 1;
  for (long long i = 1; i < 5001; i++) fak[i] = fak[i - 1] * i % 998244353;
  int cnt = 1;
  for (int i = 1; i < n; i++) {
    if (tmp[i] != tmp[i - 1]) {
      arr.push_back(cnt);
      cnt = 0;
    }
    cnt++;
  }
  arr.push_back(cnt);
  for (int i = 0; i < 5001; i++)
    for (int j = 0; j < 5001; j++) dp[i][j] = -1;
  long long say = 0;
  for (int i = 0; i < arr.size(); i++) {
    for (int c = 0; c <= i; c++) {
      if (arr[i] < 2) continue;
      long long ekle = arr[i] * (arr[i] - 1) % 998244353;
      ekle *= f(i - 1, c);
      ekle %= 998244353;
      ekle *= fak[n - 2 - c];
      ekle %= 998244353;
      say += ekle;
      say %= 998244353;
    }
  }
  long long taban = fak[n];
  long long ans = say * us(taban, 998244353 - 2) % 998244353;
  cout << ans << endl;
}
