#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, f, g, i, m, n;
long long y = 998244353;
long long xa[6000] = {0}, xb[6000] = {0}, xc[6000] = {0}, xd[6000] = {0},
          xe[6000] = {0};
long long w[6000] = {0};
int main() {
  scanf("%lld", &a);
  for (i = 1; i <= a; i++) {
    scanf("%lld", &xa[i]);
  }
  sort(xa + 1, xa + a + 1);
  xc[0] = xc[1] = 1;
  xd[0] = xd[1] = 1;
  xe[0] = xe[1] = 1;
  for (i = 2; i <= a; i++) {
    xc[i] = xc[y % i] * (y - y / i) % y;
    xd[i] = xd[i - 1] * xc[i] % y;
    xe[i] = xe[i - 1] * i % y;
  }
  b = 0;
  c = 0;
  for (i = 1; i <= a; i++) {
    if (xa[i] != b) c++;
    b = xa[i];
    xb[c]++;
  }
  b = 0;
  w[0] = 1;
  for (i = 1; i <= c; i++) {
    for (m = 0; m + 2 <= a; m++) {
      b += w[m] * xb[i] % y * (xb[i] - 1) % y * xe[a - 2 - m] % y;
      b %= y;
    }
    for (m = c; m >= 1; m--) {
      w[m] += w[m - 1] * xb[i];
      w[m] %= y;
    }
  }
  printf("%lld\n", b * xd[a] % y);
}
