#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
template <typename T>
void ndarray(vector<T> &vec, int len) {
  vec.resize(len);
}
template <typename T, typename... Args>
void ndarray(vector<T> &vec, int len, Args... args) {
  vec.resize(len);
  for (auto &v : vec) ndarray(v, args...);
}
template <typename T>
bool mmax(T &m, const T q) {
  if (m < q) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T>
bool mmin(T &m, const T q) {
  if (m > q) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T1, typename T2>
pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) {
  return make_pair(l.first + r.first, l.second + r.second);
}
template <typename T1, typename T2>
pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) {
  return make_pair(l.first - r.first, l.second - r.second);
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto v : vec) os << v << ",";
  os << "]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &vec) {
  os << "deq[";
  for (auto v : vec) os << v << ",";
  os << "]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {
  os << "(" << pa.first << "," << pa.second << ")";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp) {
  os << "{";
  for (auto v : mp) os << v.first << "=>" << v.second << ",";
  os << "}";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) {
  os << "{";
  for (auto v : mp) os << v.first << "=>" << v.second << ",";
  os << "}";
  return os;
}
int N;
vector<int> A;
constexpr lint MOD = 998244353;
lint extgcd(lint a, lint b, lint &x, lint &y) {
  lint d = a;
  if (b != 0)
    d = extgcd(b, a % b, y, x), y -= (a / b) * x;
  else
    x = 1, y = 0;
  return d;
}
lint mod_inverse(lint a, lint m) {
  lint x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}
int main() {
  cin >> N;
  A.resize(N);
  cin >> A;
  map<int, lint> cou;
  for (auto v : A) cou[v]++;
  int J = cou.size();
  vector<lint> sz;
  for (auto pa : cou) sz.push_back(pa.second);
  vector<vector<lint>> dp(J + 1, vector<lint>(J + 1));
  dp[0][0] = 1;
  for (int i = (0), i_end_ = (J); i < i_end_; i++) {
    lint acc = 0;
    for (int j = (0), j_end_ = (J + 1); j < j_end_; j++) {
      if (j) dp[i + 1][j] = acc * sz[j - 1] % MOD;
      (acc += dp[i][j]) %= MOD;
    }
  }
  for (int i = (0), i_end_ = (J + 1); i < i_end_; i++)
    for (int j = (0), j_end_ = (J); j < j_end_; j++)
      (dp[i][j + 1] += dp[i][j]) %= MOD;
  lint ret = 0;
  for (int j = (0), j_end_ = (J); j < j_end_; j++) {
    lint tmp = (lint)sz[j] * (sz[j] - 1);
    lint zan = N - 2;
    lint acc = 0;
    for (int i = (0), i_end_ = (J); i < i_end_; i++) {
      acc += dp[i][j] * tmp % MOD;
      if (zan > 0) acc = acc * zan % MOD;
      zan--;
    }
    while (zan > 0) acc = acc * zan % MOD, zan--;
    (ret += acc) %= MOD;
  }
  lint fa = 1;
  for (int i = (0), i_end_ = (N); i < i_end_; i++) fa = fa * (1 + i) % MOD;
  cout << ret * mod_inverse(fa, MOD) % MOD << endl;
}
