#include #include using namespace std; using namespace atcoder; using mint=modint998244353; #define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++) int main() { int N; cin >> N; vector A(N); rep(i, 0, N){ cin >> A[i]; } int L = A[0]; vector fact(L + 1, 1), fact_inv(L + 1, 1); rep(i, 1, L + 1) fact[i] = fact[i - 1] * i; fact_inv[L] = fact[L].inv(); for(int i = L; i > 0; i--){ fact_inv[i - 1] = fact_inv[i] * i; } mint ans = 0; vector dp(N); auto f = [&](auto self, int l, int r) -> void { if(l + 1 == r){ dp[l] += fact[A[l]]; ans += dp[l] * fact_inv[A[l]]; return; } int m = (l + r) / 2; self(self, l, m); vector X(A[l] - A[m - 1] + 1), Y(A[l] - A[r - 1] + 1); rep(i, l, m) X[A[l] - A[i]] += dp[i]; rep(i, 0, Y.size()) Y[i] += fact_inv[i]; X = convolution(X, Y); rep(i, m, r) dp[i] += X[A[l] - A[i]]; self(self, m, r); }; f(f, 0, N); cout << ans.val() << "\n"; }