#include #include using namespace atcoder; #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using mint = modint998244353; struct modinv { int n; vector d; modinv(): n(2), d({0,1}) {} mint operator()(int i) { while (n <= i) d.push_back(-d[mint::mod()%n]*(mint::mod()/n)), ++n; return d[i]; } mint operator[](int i) const { return d[i];} } invs; struct modfact { int n; vector d; modfact(): n(2), d({1,1}) {} mint operator()(int i) { while (n <= i) d.push_back(d.back()*n), ++n; return d[i]; } mint operator[](int i) const { return d[i];} } facts; struct modfactinv { int n; vector d; modfactinv(): n(2), d({1,1}) {} mint operator()(int i) { while (n <= i) d.push_back(d.back()*invs(n)), ++n; return d[i]; } mint operator[](int i) const { return d[i];} } ifacts; mint comb(int n, int k) { if (n < k || k < 0) return 0; return facts(n)*ifacts(k)*ifacts(n-k); } int main() { int n; cin >> n; vector a(n); rep(i, n) cin >> a[i]; mint ans; rep(i, n) { // down ans += comb(i+a[i]-1, i); // right for (int j = a[i]; j > a[i+1]; --j) { ans += comb(i+j-1, i); } } cout << ans.val() << '\n'; return 0; }