N = int(input()) P = list(map(int, input().split())) MOD = 998244353 ind = [0] * N for i in range(N): ind[P[i]] = i ans = 1 l = r = ind[0] for k in range(1, N): i = ind[k] nl, nr = min(l, i), max(r, i) if (l, r) == (nl, nr): ans *= r - l + 1 - k ans %= MOD l, r = nl, nr print(ans)