#include using namespace std; using ll = long long; #include using mint = atcoder::modint998244353; mint ans[5010]; mint p[5010]; int le[5010],ri[5010],k[5010]; void solve(int l,int r,vector&idx){ if(r-l==1){ for(int i = 0;i>1; vector> left(mid-l+1,vector(mid-l+1,0)); vector> right(r-mid+1,vector(r-mid+1,0)); left[mid-l][0] = 1; for(int i = mid-1;i>=l;i--){ int ni = i - l; for(int j = mid-l;j>=0;j--){ left[ni][j] = left[ni+1][j]; if(j-1>=0) left[ni][j] += left[ni+1][j-1] * p[i]; } } right[0][0] = 1; for(int i = mid;i=0;j--){ right[ni][j] = right[ni-1][j]; if(j-1>=0) right[ni][j] += right[ni-1][j-1] * p[i]; } } vector ls,rs; for(int i = 0;i=mid-l+1||k[ni]-j>=r-mid+1) continue; ans[ni] += left[nni][j] * right[nnj][k[ni]-j]; } } } solve(l,mid,ls); solve(mid,r,rs); } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin>>n; for(int i = 0;i>a; p[i] = a; } int q; cin>>q; vector idx(q); for(int i = 0;i>le[i]>>ri[i]>>k[i]; le[i]--; } solve(0,n,idx); for(int i = 0;i