#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include using namespace std; long long big=(1ll<<61); int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector a(n); for(auto &nx : a){cin >> nx;} vector g(n,0); for(int i=1;i dp(n+5,0); vector mem(n+5,0); int clk=0; int q; cin >> q; while(q>0){ q--; int l,r; long long s; cin >> l >> r >> s; l--; r--; int maxj=min(61,r-l); if((1ll<s){ cout << "0\n"; // always > S, so 0 continue; } if(r-l>=100){ // f >= Fib_i cout << "1\n"; continue; } int ans=-1; for(int k=2;;k++){ dp[l]=1; for(int i=l+1;i<=r+1;i++){ dp[i]=0; clk++; int cnt=0; for(int j=i-1;j>=l;j--){ if(mem[a[j]]!=clk){ mem[a[j]]=clk; cnt++; } if(cnt<=k){ dp[i]+=dp[j]; } else{break;} if(dp[i]>s){break;} } if(dp[i]>s){ ans=k-1; break; } } // cerr << dp[r] << "\n"; if(ans!=-1){break;} } cout << ans << "\n"; } return 0; }