#include <bits/stdc++.h>
using namespace std;
long long a[1001000];
const long long mod = 998244353;
struct data {
  long long f, id;
} d[1001000];
bool cmp(data &a, data &b) { return a.f > b.f; }
map<long long, long long> mp;
int fr[201000], ed[201000];
long long jc[201000];
inline long long extend_gcd(long long a, long long b, long long &x,
                            long long &y) {
  if (a == 0 && b == 0) return -1ll;
  if (b == 0) {
    x = 1ll;
    y = 0ll;
    return a;
  }
  long long d = extend_gcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
inline long long ny(long long a, long long n) {
  long long x, y, d = extend_gcd(a, n, x, y);
  if (d == 1) {
    if (x % n <= 0)
      return x % n + n;
    else
      return x % n;
  } else
    return -1ll;
}
int vv[201000], sum[201000];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    d[i].id = i;
    d[i].f = a[i];
  }
  sort(d + 1, d + n + 1, cmp);
  int num = 0;
  for (int i = 1; i <= n; i++) {
    if (mp[d[i].f] == 0) mp[d[i].f] = ++num;
  }
  for (int i = 1; i <= n; i++) a[i] = mp[a[i]];
  jc[0] = 1;
  for (int i = 1; i <= n; i++) {
    jc[i] = jc[i - 1] * i % mod;
  }
  for (int i = 1; i <= n; i++) {
    if (!fr[a[i]]) fr[a[i]] = i;
  }
  for (int i = n; i >= 1; i--) {
    if (!ed[a[i]]) ed[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) vv[i] = 0;
  for (int i = 1; i <= num; i++) {
    vv[fr[i] + 1]--;
    vv[ed[i] + 1]++;
  }
  sum[0] = 0;
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + vv[i];
  int tot = -1;
  for (int i = 1; i <= n; i++) {
    if (sum[i] >= 0) {
      tot++;
    }
  }
  long long ans = 0;
  for (int i = 0; i <= tot; i++) {
    ans = (ans + jc[tot] * ny(jc[i], mod) % mod * ny(jc[tot - i], mod) % mod) %
          mod;
  }
  printf("%I64d\n", ans);
}
