#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000001 int main(){ int N; cin>>N; vector x(N); rep(i,N)cin>>x[i]; fenwick_tree F(N-1); rep(i,N-1){ if(x[i]==x[i+1])F.add(i,1); } vector cnt(N+5,0); int Q; cin>>Q; rep(_,Q){ long long l,r,S; cin>>l>>r>>S; l--; if(r-l>=100){ long long t = F.sum(l,r-1); if(t<=60 && (1LL<1){ int mid = (ok+ng)/2; vector dp(n+1,0); dp[0] = 1; rep(j,n){ int C = 0; for(int k=0;k=n)break; if(cnt[x[l+j+k]]==0){ C++; if(C>mid)break; cnt[x[l+j+k]] = 1; } dp[j+k+1] = min(S+1,dp[j+k+1]+dp[j]); } for(int k=0;k=n)break; cnt[x[l+j+k]] = 0; } } L:; if(dp.back()>S)ng = mid; else ok = mid; } if(ok>=n)cout<<-1<