use proconio::input; fn main() { input! { n:usize, p:[usize;n], } const MOD: usize = 998244353; let mut poss = vec![0; n]; for i in 0..n { poss[p[i]] = i; } let mut ans = 1; let mut l = poss[0]; let mut r = poss[0]; for i in 1..n { if l <= poss[i] && poss[i] <= r { ans *= r - l + 1 - i; ans %= MOD; } else { l = l.min(poss[i]); r = r.max(poss[i]); } } println!("{}", ans); }