#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; const int MOD=998244353; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; vector A(n); rep(i,n) cin>>A[i]; map dp; rep(i,n){ dp[A[i]]++; if(dp.count(A[i]-1)) dp[A[i]]=(dp[A[i]]+dp[A[i]-1])%MOD; } ll ans=0; for(auto [a,b]:dp) ans=(ans+b)%MOD; ans=(ans-n+MOD)%MOD; cout<