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