#include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } //defmodfact const int COMinitMAX = 998444; mint fact[COMinitMAX+1], factinv[COMinitMAX+1]; void modfact(){ fact[0] = 1; for (int i=1; i<=COMinitMAX; i++){ fact[i] = fact[i-1] * i; } factinv[COMinitMAX] = fact[COMinitMAX].inv(); for (int i=COMinitMAX-1; i>=0; i--){ factinv[i] = factinv[i+1] * (i+1); } } mint cmb(int a, int b){ if (a> n; vector a(n); rep(i,0,n) cin >> a[i]; vector dp(n, mint(1)); auto dfs = [&](auto self, int l, int r) -> void { if (r - l <= 1){ return; } int m = (l + r) / 2; self(self, l, m); vector tar(a[l] - a[r-1] + 1); rep(i,l,m){ tar[a[l] - a[i]] = dp[i] * fact[a[i]]; } vector q(a[l] - a[r-1] + 1); rep(i,0,a[l]-a[r-1]+1){ q[i] = factinv[i]; } vector tmp = convolution(tar, q); rep(i,m,r){ // x + a[r-1] + y = a[i] dp[i] += tmp[a[l] - a[i]] * factinv[a[i]]; } self(self, m, r); }; dfs(dfs, 0, n); cout << sum(dp).val() << '\n'; }