#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } using mint = atcoder::modint998244353; ostream& operator<<(ostream& os, const mint& m){ os << m.val(); return os; } struct FPS: vector{ using vector::vector; FPS inv(int deg){ FPS ans(deg); ans[0] = mint(1)/(*this)[0]; for(int d = 1; d < deg; d<<=1){ vector f(2*d), g(2*d); for(int i = 0; i < min(2*d, (int)this->size()); i++) f[i] = (*this)[i]; for(int i = 0; i < d; i++) g[i] = ans[i]; f = atcoder::convolution(g, atcoder::convolution(g, f)); for(int i = d; i < min(2*d, deg); i++) ans[i] = -f[i]; } return ans; } void shrink() { while (this->size() && this->back() == mint(0)) this->pop_back(); } FPS& operator*=(const FPS &r){ if(this->empty() || r.empty()){ this->clear(); return *this; } auto ret = atcoder::convolution(*this, r); return *this = FPS(ret.begin(), ret.end()); } FPS& operator+=(const FPS &r){ if(this->size() < r.size()) this->resize(r.size()); for(int i = 0; i < (int)r.size(); i++) (*this)[i] += r[i]; return *this; } FPS& operator-=(const FPS &r){ if(this->size() < r.size()) this->resize(r.size()); for(int i = 0; i < (int)r.size(); i++) (*this)[i] -= r[i]; return *this; } FPS operator*(const FPS &r) const { return FPS(*this) *= r; } FPS operator+(const FPS &r) const { return FPS(*this) += r; } FPS operator-(const FPS &r) const { return FPS(*this) -= r; } FPS mod_deg(int deg){ FPS ret(deg); for(int i = 0; i < min(deg, (int)this->size()); i++) ret[i] = (*this)[i]; return ret; } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector p(n); for(int i = 0; i < n; i++) cin >> p[i]; auto from_left = vec2d(n+1, n+1, mint(0)); auto from_left_inv = vec2d(n+1, n+1, mint(0)); from_left[0][0] = 1; for(int i = 0; i < n; i++){ for(int j = 0; j <= i; j++){ from_left[i+1][j] += from_left[i][j]; from_left[i+1][j+1] += from_left[i][j]*p[i]; } } from_left_inv[0][0] = 1; for(int i = 0; i < n; i++){ from_left_inv[i+1][0] = from_left_inv[i][0]; for(int j = 1; j <= n; j++){ from_left_inv[i+1][j] -= from_left_inv[i+1][j-1]*p[i]; from_left_inv[i+1][j] += from_left_inv[i][j]; } } int q; cin >> q; while(q--){ int a, b, k; cin >> a >> b >> k; a--; auto f = from_left[b]; auto g = from_left_inv[a]; mint ans = 0; for(int i = 0; i <= k; i++){ int j = k-i; if(i < f.size() && j < g.size()){ ans += f[i]*g[j]; } } cout << ans << endl; } }