#include using namespace std; using ll=long long; using pll=pair; using tll=tuple; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define all(v) v.begin(),v.end() template inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template inline bool chmax(T &a,T b){ if(a cnt(1000001,0); ll n; cin >> n; vector x(n); rep(i,n) cin >> x[i]; ll q; cin >> q; while(q--){ ll l,r,s; cin >> l >> r >> s; l--; ll w=r-l,ok=0; if((1ll< vr(w,0); ll nr=0,sz=0; rep(nl,w){ auto g=[&](ll idx){ ll p=0; if(cnt[x[l+idx]]==0) p=1; return (sz+p)<=k; }; while(nr dp(w+1,0),sum(w+2,0); dp[0]=1; rep(i,w+1){ dp[i]+=sum[i]; if(s