MOD = 998244353 n = int(input()) P = list(map(int, input().split())) pos = [-1] * n for i, p in enumerate(P): pos[p] = i ans = 1 l = n r = -1 for i, p in enumerate(pos): if l <= p <= r: ans *= r - l - i + 1 ans %= MOD else: l = min(l, p) r = max(r, p) print(ans)