#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int main() {
  int N;
  cin >> N;
  vector<int> nums(N), inv(N + 1);
  inv[1] = 1;
  for (int i = 2; i <= N; i++) {
    inv[i] = (MOD - ((MOD / i) * (long long)inv[MOD % i]) % MOD);
  }
  for (int i = 0; i < N; i++) {
    cin >> nums[i];
  }
  sort(nums.begin(), nums.end());
  vector<int> distinct, count;
  for (size_t i = 0; i < nums.size(); i++) {
    if (i > 0 && nums[i] == nums[i - 1]) {
      (*count.rbegin())++;
    } else {
      distinct.push_back(nums[i]);
      count.push_back(1);
    }
  }
  vector<int> sumcnt(count.size());
  for (size_t i = 0; i < count.size(); i++) {
    sumcnt[i] = count[i];
    if (i > 0) {
      sumcnt[i] += sumcnt[i - 1];
    }
  }
  vector<int> dp[2];
  dp[0].resize(distinct.size(), 0);
  dp[1].resize(distinct.size(), 0);
  long long ans = 0;
  for (size_t i = 0; i < distinct.size(); i++) {
    dp[1][i] = (count[i] * (long long)inv[N]) % MOD;
    if (count[i] > 1) {
      ans += ((dp[1][i] * (long long)inv[N - 1]) % MOD * (count[i] - 1)) % MOD;
      ans %= MOD;
    }
    if (i > 0) {
      dp[1][i] = (dp[1][i] + dp[1][i - 1]) % MOD;
    }
  }
  for (int cnt = 2; cnt <= N; cnt++) {
    int cur = cnt & 1;
    int pre = cur ^ 1;
    for (size_t i = cnt - 1; i < distinct.size(); i++) {
      dp[cur][i] = ((long long)count[i] * inv[N - cnt + 1]) % MOD;
      dp[cur][i] = ((long long)dp[cur][i] * dp[pre][i - 1]) % MOD;
      if (count[i] > 1) {
        ans += (((long long)dp[cur][i] * inv[N - cnt]) % MOD * (count[i] - 1)) %
               MOD;
        ans %= MOD;
      }
      if (int(i) > cnt - 1) {
        dp[cur][i] = (dp[cur][i] + dp[cur][i - 1]) % MOD;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
