#include using namespace std; using ll = long long; constexpr ll mod = 998244353; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); map cnt; ll n, ans = 0; cin >> n; vector a(n); for (auto& x : a) cin >> x; for (ll i = 0; i < n; i++) { cnt[a[i]]++; cnt[a[i]] += cnt[a[i] - 1]; cnt[a[i]] %= mod; } for (auto& i : cnt) ans = (ans + i.second) % mod; ans = (ans + mod - n) % mod; cout << ans << '\n'; }