#include <bits/stdc++.h>
template <int MOD>
struct ModInt {
  using lint = long long;
  int val;
  ModInt(lint v = 0) : val(v % MOD) {
    if (val < 0) val += MOD;
  };
  ModInt operator+() const { return ModInt(val); }
  ModInt operator-() const { return ModInt(MOD - val); }
  ModInt inv() const { return this->pow(MOD - 2); }
  ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
  ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
  ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
  ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
  ModInt pow(lint n) const {
    auto x = ModInt(1);
    auto b = *this;
    while (n > 0) {
      if (n & 1) x *= b;
      n >>= 1;
      b *= b;
    }
    return x;
  }
  ModInt& operator+=(const ModInt& x) {
    if ((val += x.val) >= MOD) val -= MOD;
    return *this;
  }
  ModInt& operator-=(const ModInt& x) {
    if ((val -= x.val) < 0) val += MOD;
    return *this;
  }
  ModInt& operator*=(const ModInt& x) {
    val = lint(val) * x.val % MOD;
    return *this;
  }
  ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }
  bool operator==(const ModInt& b) const { return val == b.val; }
  bool operator!=(const ModInt& b) const { return val != b.val; }
  friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept {
    return is >> x.val;
  }
  friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept {
    return os << x.val;
  }
};
constexpr int MOD = 998244353;
using mint = ModInt<MOD>;
void solve() {
  int n;
  std::cin >> n;
  std::vector<mint> inv(n + 1);
  inv[0] = 0;
  for (int x = 1; x <= n; ++x) inv[x] = mint(x).inv();
  std::vector<int> cnt(n, 0);
  for (int i = 0; i < n; ++i) {
    int x;
    std::cin >> x;
    ++cnt[--x];
  }
  std::vector<mint> dp(n + 1, 0);
  dp[0] = 1;
  mint lose = 0;
  int lower = 0;
  for (auto c : cnt) {
    for (int k = n - 1; k >= 0; --k) {
      auto p = dp[k] * c * inv[n - k];
      lose += p * (lower - k) * inv[n - k - 1];
      dp[k + 1] += p;
    }
    lower += c;
  }
  lose += dp[n];
  std::cout << mint(1) - lose << "\n";
}
int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  solve();
  return 0;
}
