#include #include using namespace std; using ll = long long; using mint = atcoder::modint998244353; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const int MX = 200'010; mint fact[MX + 10], finv[MX + 10]; mint c(ll a, ll b) { if (a < b || a < 0 || b < 0) return 0; return fact[a] * finv[a - b] * finv[b]; } void solve() { fact[0] = finv[0] = 1; rep(i, MX) { fact[i + 1] = fact[i] * (i + 1); finv[i + 1] = fact[i + 1].inv(); } ll n; cin >> n; vector a(n); rep(i, n) cin >> a[i]; a.push_back(0); mint ans = 0; rep(i, n) { ans += c(a[i] - 1 + i, i); for (ll j = a[i]; j > a[i + 1]; j--) ans += c(j - 1 + i, i); } cout << ans.val() << '\n'; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int T = 1; for (int t = 0; t < T; t++) { solve(); } return 0; }