use std::collections::BTreeMap; fn main() { let n: usize = { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.trim().parse().unwrap() }; let A: Vec = { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|x| x.parse().unwrap()) .collect() }; let modx = 998244353; let mut ans=0; let mut DP: BTreeMap = BTreeMap::new(); for i in 0..n{ let a=A[i]; let mut x=0; if DP.contains_key(&(a-1)){ x=DP[&(a-1)]; } ans=(ans+x)%modx; if DP.contains_key(&(a)){ DP.insert(a,(DP[&(a)]+x+1)%modx); } else{ DP.insert(a,(x+1)%modx); } } println!("{}",ans); }