// Tal vez si pase :'v

#include <bits/stdc++.h>

using namespace std;

const int MAX_POS = 1e5, MAX_K = 1e3, MAX_N = 1e5 + 10;

int n, a[MAX_N];
int memo[MAX_POS][MAX_K];

int BF (int p, int k) {
  int cnt = 0;
  while (p <= n) p = p + a[p] + k, cnt++;
  return cnt;
}

int dp (int p, int k) {
  if (p > n) return 0;
  if (p >= MAX_POS or k >= MAX_K) return BF(p, k);
  int& ret = memo[p][k];
  if (~ret) return ret;
  return ret = 1 + dp(p + a[p] + k, k);
}

void pre () {
  memset(memo, -1, sizeof memo);
  for (int p = 1; p < MAX_POS; p++) for (int k = 1; k < MAX_POS; k++) dp(p, k);
}

int main () {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  pre();
  int q;
  scanf("%d", &q);
  while (q--) {
    int p, k;
    scanf("%d %d", &p, &k);
    if (p < MAX_POS and k < MAX_K) printf("%d\n", memo[p][k]);
    else printf("%d\n", BF(p, k));
  }
  return (0);
}


// Tal vez si pase :'v

#include <bits/stdc++.h>

using namespace std;

const int CHUNK= 400, MAX_N = 1e5 + 10;

int n, a[MAX_N];
int memo[MAX_N][CHUNK];

int BF (int p, int k) {
  int cnt = 0;
  while (p <= n) p = p + a[p] + k, cnt++;
  return cnt;
}

int dp (int p, int k) {
  if (p > n) return 0;
  int& ret = memo[p][k];
  if (~ret) return ret;
  return ret = 1 + dp(p + a[p] + k, k);
}

void pre () {
  memset(memo, -1, sizeof memo);
  for (int i = 1; i <= n; i++) for (int j = 1; j < CHUNK; j++) dp(i, j);
}

int main () {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  pre();
  int q;
  scanf("%d", &q);
  while (q--) {
    int p, k;
    scanf("%d %d", &p, &k);
    if (k < CHUNK) printf("%d\n", memo[p][k]);
    else printf("%d\n", BF(p, k));
  }
  return (0);
}


#include <cstdio>
#define max(a,b) ((a>b)?a:b)
#define ll long long

inline ll read(){
    ll x = 0; int zf = 1; char ch = ' ';
    while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
    if (ch == '-') zf = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}

int a[100005];
int b[100001][100];

int main(){
    int n = read();
    for (int i = 1; i <= n; ++i)
        a[i] = read();
    for (int i = 1; i <= max(100, n); ++i){
        for (int j = n; j >= 1; --j){
            if (j + a[j] + i > n)
                b[j][i] = 1;
            else
                b[j][i] = b[j+a[j]+i][i] + 1;
        }
    }
    int q = read();
    int p, k, cnt;
    for (int I = 1; I <= n; ++I){
        p = read(), k = read();
        if (k <= 100)
            printf("%d\n", b[p][k]);
        else{
            cnt = 0;
            for (int i = p; i <= n; i += a[i] + k, ++cnt);
            printf("%d\n", cnt);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define maxn 100005
#define ll long long
using namespace std;
int n,q;
int a[maxn];
int dp[maxn][350];//dp[i][j]为从i开始每次加j，操作次数
void work()
{
	for(int i=n;i>=1;i--)
	{
		for(int j=3;j>=1;j--)
		{
			if(i+a[i]+j>n)dp[i][j]=1;
			else dp[i][j]=dp[i+a[i]+j][j]+1;
		}
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	work();
	scanf("%d",&q);
	int p,k;
	while(q--)
	{
		scanf("%d%d",&p,&k);
		if(k>=317)
		{
			int ans=0;
			while(p<=n)
			{
				ans++;
				p=p+a[p]+k;
			}
			printf("%d\n",ans);
		}
		printf("%d\n",dp[p][k]);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int dp[100003][403],n,p,k,a[100003];
int fuc(int x,int y){int ret=0;while(x<n)x=x+a[x]+y,ret++;return ret;}
int main(){
	cin>>n;for(int i=0;i<n;i++)scanf("%d",a+i);
	for(int i=n-1;i>=0;i--)
		for(int j=1;j<=400;j++)
			if(i+a[i]+j>=n)dp[i][j]=1;
			else dp[i][j]=dp[i+a[i]+j][j]+1;
	int T;cin>>T;while(T--){
		cin>>p>>k;p--;if(k<=400)cout<<dp[p][k]<<endl;
		else cout<<fuc(p,k)<<endl;
	}
}


#include <cstdio>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a<b)?a:b)
#define ll long long

inline ll read(){
    ll x = 0; int zf = 1; char ch = ' ';
    while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
    if (ch == '-') zf = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}

int a[100005];
int b[100001][101];

int main(){
    int n = read();
    for (int i = 1; i <= n; ++i)
        a[i] = read();
    for (int i = 1; i <= min(100, n); ++i){
        for (int j = n; j >= 1; --j){
            if (j + a[j] + i > n)
                b[j][i] = 1;
            else
                b[j][i] = b[j+a[j]+i][i] + 1;
        }
    }
    int q = read();
    int p, k, cnt;
    for (int I = 1; I <= q; ++I){
        p = read(), k = read();
        if (k <= 100)
            printf("%d\n", b[p][k]);
        else{
            cnt = 0;
            for (int i = p; i <= n; i += a[i] + k, ++cnt);
            printf("%d\n", cnt);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
int f[maxn][400],n,Ans,N,Now,x,Q,a[maxn],k;
inline int read(){
	int ret=0;char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=getchar();
	return ret;
}
int main(){
	n=read(),N=sqrt(n);
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=n;i;i--)
	for (int j=1;j<=N;j++) f[i][j]=i+a[i]+j<=n? f[i+a[i]+j][j]+1:1;
	Q=read();
	while (Q--){
		x=read(),k=read();
		if (k<=N) printf("%d\n",f[x][k]);
		else{Ans=0;while (x<=n) x+=a[x]+k,Ans++;printf("%d\n",Ans);}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e5+10;
int a[MAXN];
map<pair<int, int>, int>mp;

struct node{
    int p, k;
}gg[MAXN];

int main(void){
    int n, q, p, k;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    cin >> q;
    while(q--){
        int indx=0, num=0;
        cin >> p >> k;
        pair<int, int> cnt=make_pair(p, k);
        if(mp[cnt]){
            cout << mp[cnt] << endl;
            continue;
        }
        while(p<=n){
            // cout << p << " ";
            gg[indx].p=p;
            gg[indx++].k=k;
            p=p+a[p]+k;
            // num++;
        }
        // cout << p << endl;
        indx--;
        while(indx>=0){
            pair<int, int> cc=make_pair(gg[indx].p, gg[indx].k);
            if(!mp[cc]){
                mp[cc]=++num;
            }
            // cout << cc.first << " " << cc.second << " " << mp[cc] << endl;
            indx--;
        }
        cout << mp[cnt] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e5+10;
int a[MAXN], vis[510][MAXN];

int main(void){
    int n, q, p, k;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    for(int i=1; i<=500; i++){
        for(int j=n; j>0; j--){
            vis[i][j]=i+j+a[j]>n?1:vis[i][a[j]+j+i]+1;
        }
    }
    cin >> q;
    while(q--){
        cin >> p >> k;
        if(k<=500) cout << vis[k][p] << endl;
        else{
            int ans=0;
            while(p<=n){
                p+=a[p]+k;
                ans++;
            }
            cout << ans << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e5+10;
int a[MAXN];
map<pair<int, int>, int>mp;

struct node{
    int p, k;
}gg[MAXN];

int main(void){
    int n, q, p, k;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    cin >> q;
    while(q--){
        int indx=0, num=0;
        cin >> p >> k;
        pair<int, int> cnt=make_pair(p, k);
        if(mp[cnt]){
            cout << mp[cnt] << endl;
            continue;
        }
        while(p<=n){
            gg[indx].p=p;
            gg[indx++].k=k;
            p=p+a[p]+k;
        }
        indx--;
        while(indx>=0){
            pair<int, int> cc=make_pair(gg[indx].p, gg[indx].k);
            if(!mp[cc]){
                mp[cc]=++num;
            }else ++num;
            indx--;
        }
        cout << mp[cnt] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e5+10;
int a[MAXN];
map<pair<int, int>, int>mp;

struct node{
    int p, k;
}gg[MAXN];

int main(void){
    int n, q, p, k;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    cin >> q;
    while(q--){
        int indx=0, num=0;
        cin >> p >> k;
        pair<int, int> cnt=make_pair(p, k);
        if(mp[cnt]){
            cout << mp[cnt] << endl;
            continue;
        }
        pair<int, int> pai=make_pair(p, k);
        while(p<=n&&(!mp[pai])){
            gg[indx].p=p;
            gg[indx++].k=k;
            p=p+a[p]+k;
            pair<int, int> pai=make_pair(p, k);
        }
        indx--;
        while(indx>=0){
            pair<int, int> cc=make_pair(gg[indx].p, gg[indx].k);
            if(!mp[cc]){
                mp[cc]=++num;
            }else ++num;
            indx--;
        }
        cout << mp[cnt] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e5+10;
int a[MAXN], vis[510][MAXN];

int main(void){
    int n, q, p, k;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    for(int i=1; i<=500; i++){
        for(int j=n; j>0; j--){
            vis[i][j]=i+j+a[j]>n?1:vis[i][a[j]+j]+1;
        }
    }
    cin >> q;
    while(q--){
        cin >> p >> k;
        if(k<=500) cout << vis[k][p] << endl;
        else{
            int ans=0;
            while(p<=n){
                p+=a[p]+k;
                ans++;
            }
            cout << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e5+10;
int a[MAXN], vis[510][MAXN];

int main(void){
    int n, q, p, k;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    for(int i=1; i<=500; i++){
        for(int j=n; j>0; j--){
            vis[i][j]=i+j+a[j]>n?1:vis[i][a[j]+j+i]+1;
        }
    }
    cin >> q;
    while(q--){
        cin >> p >> k;
        if(k<=500) cout << vis[k][p] << endl;
        else{
            int ans=0;
            while(p<=n){
                p+=a[p]+k;
                ans++;
            }
            cout << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e5+10;
int a[MAXN], vis[510][MAXN];

int main(void){
    // std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, q, p, k;
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
    }
    for(int i=1; i<=500; i++){
        for(int j=n; j>0; j--){
            vis[i][j]=i+j+a[j]>n?1:vis[i][a[j]+j+i]+1;
        }
    }
    scanf("%d", &q);
    while(q--){
        scanf("%d%d", &p, &k);
        if(k<=500) cout << vis[k][p] << endl;
        else{
            int ans=0;
            while(p<=n){
                p+=a[p]+k;
                ans++;
            }
            cout << ans << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e5+10;
int a[MAXN], vis[510][MAXN];

int main(void){
    int n, q, p, k;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    for(int i=1; i<=500; i++){
        for(int j=n; j>0; j--){
            vis[i][j]=i+j+a[j]>n?1:vis[i][a[j]+j+1]+1;
        }
    }
    cin >> q;
    while(q--){
        cin >> p >> k;
        if(k<=500) cout << vis[k][p] << endl;
        else{
            int ans=0;
            while(p<=n){
                p+=a[p]+k;
                ans++;
            }
            cout << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e5+10;
int a[MAXN], vis[510][MAXN];

int main(void){
    // std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, q, p, k;
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
    }
    for(int i=1; i<=500; i++){
        for(int j=n; j>0; j--){
            vis[i][j]=i+j+a[j]>n?1:vis[i][a[j]+j+i]+1;
        }
    }
    scanf("%d", &q);
    while(q--){
        scanf("%d%d", &p, &k);
        if(k<=500) printf("%d\n", vis[k][p]);
        else{
            int ans=0;
            while(p<=n){
                p+=a[p]+k;
                ans++;
            }
            printf("%d\n", ans);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e5+10;
int a[MAXN], vis[510][MAXN];

int main(void){
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, q, p, k;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    for(int i=1; i<=500; i++){
        for(int j=n; j>0; j--){
            vis[i][j]=i+j+a[j]>n?1:vis[i][a[j]+j+i]+1;
        }
    }
    cin >> q;
    while(q--){
        cin >> p >> k;
        if(k<=500) cout << vis[k][p] << endl;
        else{
            int ans=0;
            while(p<=n){
                p+=a[p]+k;
                ans++;
            }
            cout << ans << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    int n,sq;
    double s;
    cin>>n;
    s=sqrt(n);
    sq=ceil(s);
    int a[n+1];
    a[0]=0;
    for(int i=1;i<=n;i++) cin>>a[i];
    int q;
    cin>>q;
    int dp[n+1][sq+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<sq;j++) dp[i][j]=0;
    }
    for(int i=1;i<sq;i++){
        for(int j=1;j<=n;j++){
            int t=j,ans=0;
            while(t<=n){
                ans++;
                if(t+a[t]+i<=n&&dp[t+a[t]+i][i]){
                    ans=ans+dp[t+a[t]+i][i];
                    break;
                }
                t=t+a[t]+i;
            }
            dp[j][i]=ans;
        }
    }
    while(q--){
        int p,k;
        cin>>p>>k;
        if(k<sq){
            cout<<dp[p][k]<<endl;
        }
        else{
            int ans=0;
            while(p<=n){
                p=p+a[p]+k;
                ans++;
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N=1e5,sq=300;

int dp[N+1][sq];

int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    int a[n+1];
    a[0]=0;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int j=1;j<sq;j++){
        for(int i=n;i>0;i--){
            dp[i][j]=1;
            if(i+a[i]+j<=n) dp[i][j]+=dp[i+a[i]+j][j];
        }
    }
    int q;
    cin>>q;
    while(q--){
        int p,k;
        cin>>p>>k;
        if(k<sq){
            cout<<dp[p][k]<<endl;
        }
        else{
            int ans=0;
            while(p<=n){
                p=p+a[p]+k;
                ans++;
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    int n,sq=300;
    double s;
    cin>>n;
    int a[n+1];
    a[0]=0;
    for(int i=1;i<=n;i++) cin>>a[i];
    int q;
    cin>>q;
    int dp[n+1][sq];
    for(int i=0;i<=n;i++){
        for(int j=0;j<sq;j++) dp[i][j]=0;
    }
    for(int i=1;i<sq;i++){
        for(int j=1;j<=n;j++){
            int t=j,ans=0,f=1;
            while(t<=n&&f){
                ans++;
                t=t+a[t]+i;
                if(t<=n&&dp[t][i]){
                    ans=ans+dp[t][i];
                    f=0;
                }
            }
            dp[j][i]=ans;
        }
    }
    while(q--){
        int p,k;
        cin>>p>>k;
        if(k<sq){
            cout<<dp[p][k]<<endl;
        }
        else{
            int ans=0;
            while(p<=n){
                p=p+a[p]+k;
                ans++;
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    int n,sq;
    double s;
    cin>>n;
    s=sqrt(n);
    sq=ceil(s);
    int a[n+1];
    a[0]=0;
    for(int i=1;i<=n;i++) cin>>a[i];
    int q;
    cin>>q;
    int dp[n+1][sq];
    for(int i=0;i<=n;i++){
        for(int j=0;j<sq;j++) dp[i][j]=0;
    }
    for(int i=1;i<sq;i++){
        for(int j=1;j<=n;j++){
            int t=j,ans=0,f=1;
            while(t<=n&&f){
                ans++;
                t=t+a[t]+i;
                if(t<=n&&dp[t][i]){
                    ans=ans+dp[t][i];
                    f=0;
                }
            }
            dp[j][i]=ans;
        }
    }
    while(q--){
        int p,k;
        cin>>p>>k;
        if(k<sq){
            cout<<dp[p][k]<<endl;
        }
        else{
            int ans=0;
            while(p<=n){
                p=p+a[p]+k;
                ans++;
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int arr[100001];

int main()
{
    int n,q;
    scanf("%d",&n);
    for(int i = 1;i<=n;i++)
        scanf("%d",&arr[i]);
    scanf("%d",&q);
    while(q--) {
        int p,k;
        scanf("%d %d",&p,&k);
        int ans = (n-p + arr[p] + k) / (arr[p] + k);
        printf("%d\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
#define MAXK 600
using namespace std;

int arr[100001];
int dp[100001][MAXK];
int n;

int solve(int i,int k) {
    if(i > n)
        return 0;

    if(dp[i][k])
        return dp[i][k];

    return dp[i][k] = 1 + solve(i+arr[i]+k,k);
}

void preCalc() {
    for(int i = 1;i<=n;i++) {
        for(int j = 1;j<=MAXK;j++) {
            solve(i,j);
        }
    }
}

int simulate(int i,int k) {
    if(i > n)
        return 0;
    return dp[i][k] = 1 + solve(i+arr[i]+k,k);
}

int main()
{
    int q;
    scanf("%d",&n);
    for(int i = 1;i<=n;i++)
        scanf("%d",&arr[i]);
    preCalc();
    scanf("%d",&q);
    while(q--) {
        int p,k;
        scanf("%d %d",&p,&k);
        if(k > MAXK) {
            printf("%d\n",simulate(p,k));
        } else {
            printf("%d\n",dp[p][k]);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define MAXK 600
using namespace std;

int arr[100001];
int dp[100001][MAXK+1];
int n;

int solve(int i,int k) {
    if(i > n)
        return 0;

    if(dp[i][k])
        return dp[i][k];

    return dp[i][k] = 1 + solve(i+arr[i]+k,k);
}

void preCalc() {
    for(int i = 1;i<=n;i++) {
        for(int j = 1;j<=MAXK;j++) {
            solve(i,j);
        }
    }
}

int simulate(int i,int k) {
    if(i > n)
        return 0;
    return 1 + simulate(i+arr[i]+k,k);
}

int main()
{
    int q;
    scanf("%d",&n);
    for(int i = 1;i<=n;i++)
        scanf("%d",&arr[i]);
    preCalc();
    scanf("%d",&q);
    while(q--) {
        int p,k;
        scanf("%d %d",&p,&k);
        if(k > MAXK) {
            printf("%d\n",simulate(p,k));
        } else {
            printf("%d\n",dp[p][k]);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define MAXK 1000
using namespace std;

int arr[100001];
int dp[100001][MAXK];
int n;

int solve(int i,int k) {
    if(i > n)
        return 0;

    if(dp[i][k])
        return dp[i][k];

    return dp[i][k] = 1 + solve(i+arr[i]+k,k);
}

void preCalc() {
    for(int i = 1;i<=n;i++) {
        for(int j = 1;j<=MAXK;j++) {
            solve(i,j);
        }
    }
}

int simulate(int i,int k) {
    if(i > n)
        return 0;
    return dp[i][k] = 1 + solve(i+arr[i]+k,k);
}

int main()
{
    int q;
    scanf("%d",&n);
    for(int i = 1;i<=n;i++)
        scanf("%d",&arr[i]);
    preCalc();
    scanf("%d",&q);
    while(q--) {
        int p,k;
        scanf("%d %d",&p,&k);
        if(k > MAXK) {
            printf("%d\n",simulate(p,k));
        } else {
            printf("%d\n",dp[p][k]);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define MAXK 600
using namespace std;

int arr[100001];
int dp[100001][MAXK+1];
int n;

int solve(int i,int k) {
    if(i > n)
        return 0;

    if(dp[i][k])
        return dp[i][k];

    return dp[i][k] = 1 + solve(i+arr[i]+k,k);
}

void preCalc() {
    for(int i = 1;i<=n;i++) {
        for(int j = 1;j<=MAXK;j++) {
            solve(i,j);
        }
    }
}

int simulate(int i,int k) {
    if(i > n)
        return 0;
    return dp[i][k] = 1 + solve(i+arr[i]+k,k);
}

int main()
{
    int q;
    scanf("%d",&n);
    for(int i = 1;i<=n;i++)
        scanf("%d",&arr[i]);
    preCalc();
    scanf("%d",&q);
    while(q--) {
        int p,k;
        scanf("%d %d",&p,&k);
        if(k > MAXK) {
            printf("%d\n",simulate(p,k));
        } else {
            printf("%d\n",dp[p][k]);
        }
    }
    return 0;
}


/*=================================
# Created time: 2018-08-20 22:05
# Filename: d.cpp
# Description:
=================================*/
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sqr(x) (x)*(x)
#define lowbit(x) (x)&(-x)
#define pii pair<int, int>
#define ls(a,b) (((a)+(b)) << 1)
#define rs(a,b) (((a)+(b)) >> 1)
#define fin(a) freopen(a,"r",stdin);
#define fout(a) freopen(a,"w",stdout);
#define FORP(i,a,b) for(int i=(a);i<=(b);i++)
#define FORM(i,a,b) for(int i=(a);i>=(b);i--)

#define maxn 100005
#define maxm 100005
#define MOD 1000000007
#define INF 1070000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template<class T> inline
void read(T& num){
    num = 0; bool f = 1;char ch = getchar();
    while(ch < '0' || ch > '9') { if(ch == '-') f = 0;ch = getchar();}
    while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}
    num = f ? num: -num;
}
template<class T> inline
void write(T x,char ch){
	int s[100];
	if (x==0) {putchar('0'); putchar(ch); return;}
	if (x<0) {putchar('-'); x=-x;} int num=0;
	while (x){ s[num++]=(x%10); x=x/10;}
	FORM(i,num-1,0) putchar(s[i]+'0'); putchar(ch);
}
/*==================split line==================*/
const double pi = acos(-1);
const double eps = 1e-8;
int ch[maxn][2], v[maxn], sz[maxn], fa[maxn];
int n, sum;
set<int> s;
map<int, int> h;
void DFS(int x){
	sz[x] = 1;
	if (ch[x][0] && ch[x][0] != -1) {DFS(ch[x][0]); sz[x] += sz[ch[x][0]];}
	if (ch[x][1] && ch[x][1] != -1) {DFS(ch[x][1]); sz[x] += sz[ch[x][1]];}
}
void dfs(int x, int up, int down){
	//if (down > up) {sum += sz[x]; return;}
	if (v[x] < down || v[x] > up) sum++;
	else s.insert(v[x]);
	if (ch[x][0] && ch[x][0] != -1) dfs(ch[x][0], min(v[x], up), down);
	if (ch[x][1] && ch[x][1] != -1) dfs(ch[x][1], up, max(v[x], down));
}
int main(){
	//fin("d.in");
	read(n);
	FORP(i, 1, n){
		read(v[i]); if (!h.count(v[i])) h[v[i]] = 1; else h[v[i]] = h[v[i]] + 1;
		int l, r; read(l); read(r);
		if (l != -1) ch[i][0] = l, fa[l] = i;
		if (r != -1) ch[i][1] = r, fa[r] = i;
	}
	int root;
	FORP(i, 1, n) if (fa[i] == 0) root = i;
	DFS(root);
	dfs(root, INF, -INF);
	sum = 0;
	for (set<int>::iterator it = s.begin(); it != s.end(); it++) sum += h[*it];
	write(n -sum,'\n');
}


/*=================================
# Created time: 2018-08-20 21:43
# Filename: e.cpp
# Description:
=================================*/
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sqr(x) (x)*(x)
#define lowbit(x) (x)&(-x)
#define pii pair<int, int>
#define ls(a,b) (((a)+(b)) << 1)
#define rs(a,b) (((a)+(b)) >> 1)
#define fin(a) freopen(a,"r",stdin);
#define fout(a) freopen(a,"w",stdout);
#define FORP(i,a,b) for(int i=(a);i<=(b);i++)
#define FORM(i,a,b) for(int i=(a);i>=(b);i--)

#define maxn 100005
#define maxm 100005
#define MOD 1000000007
#define INF 1070000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template<class T> inline
void read(T& num){
    num = 0; bool f = 1;char ch = getchar();
    while(ch < '0' || ch > '9') { if(ch == '-') f = 0;ch = getchar();}
    while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}
    num = f ? num: -num;
}
template<class T> inline
void write(T x,char ch){
	int s[100];
	if (x==0) {putchar('0'); putchar(ch); return;}
	if (x<0) {putchar('-'); x=-x;} int num=0;
	while (x){ s[num++]=(x%10); x=x/10;}
	FORM(i,num-1,0) putchar(s[i]+'0'); putchar(ch);
}
/*==================split line==================*/
const double pi = acos(-1);
const double eps = 1e-8;
int n;
int dp[maxn][601];
int a[maxn];
int main(){
	read(n); FORP(i, 1, n) read(a[i]);
	FORP(k, 1, min(600, n)){
		FORM(i, n, 1) {
			int t = i + a[i] + k;
			dp[i][k] = 1;
			while (t <= n) t = t + a[t] + k, dp[i][k]++;
		}
	}
	int q;
	read(q);
	FORP(i, 1, q){
		int p, k; read(p); read(k);
		if (k <= min(600, n)) write(dp[p][k],'\n');
		else {
			int t = p + a[p] + k;
			int ans = 1;
			while (t <= n) t = t + a[t] + k, ans++;
			write(ans,'\n');
		}
	}
}


/*=================================
# Created time: 2018-08-20 21:43
# Filename: e.cpp
# Description:
=================================*/
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sqr(x) (x)*(x)
#define lowbit(x) (x)&(-x)
#define pii pair<int, int>
#define ls(a,b) (((a)+(b)) << 1)
#define rs(a,b) (((a)+(b)) >> 1)
#define fin(a) freopen(a,"r",stdin);
#define fout(a) freopen(a,"w",stdout);
#define FORP(i,a,b) for(register int i=(a);i<=(b);i++)
#define FORM(i,a,b) for(int i=(a);i>=(b);i--)

#define maxn 100005
#define maxm 100005
#define MOD 1000000007
#define INF 1070000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template<class T> inline
void read(T& num){
    num = 0; bool f = 1;char ch = getchar();
    while(ch < '0' || ch > '9') { if(ch == '-') f = 0;ch = getchar();}
    while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}
    num = f ? num: -num;
}
template<class T> inline
void write(T x,char ch){
	int s[100];
	if (x==0) {putchar('0'); putchar(ch); return;}
	if (x<0) {putchar('-'); x=-x;} int num=0;
	while (x){ s[num++]=(x%10); x=x/10;}
	FORM(i,num-1,0) putchar(s[i]+'0'); putchar(ch);
}
/*==================split line==================*/
const double pi = acos(-1);
const double eps = 1e-8;
int n;
int dp[maxn][601];
int a[maxn];
int main(){
	read(n); FORP(i, 1, n) read(a[i]);
	FORP(k, 1, min(600, n)){
		FORM(i, n, 1) {
			int t = i + a[i] + k;
			dp[i][k] = 1;
			//while (t <= n) t = t + a[t] + k, dp[i][k]++;
			dp[i][k] = dp[i][k] + dp[t][k];
		}
	}
	int q;
	read(q);
	FORP(i, 1, q){
		int p, k; read(p); read(k);
		if (k <= min(600, n)) write(dp[p][k],'\n');
		else {
			int t = p + a[p] + k;
			int ans = 1;
			while (t <= n) t = t + a[t] + k, ans++;
			write(ans,'\n');
		}
	}
}


/*=================================
# Created time: 2018-08-20 21:43
# Filename: e.cpp
# Description:
=================================*/
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sqr(x) (x)*(x)
#define lowbit(x) (x)&(-x)
#define pii pair<int, int>
#define ls(a,b) (((a)+(b)) << 1)
#define rs(a,b) (((a)+(b)) >> 1)
#define fin(a) freopen(a,"r",stdin);
#define fout(a) freopen(a,"w",stdout);
#define FORP(i,a,b) for(register int i=(a);i<=(b);i++)
#define FORM(i,a,b) for(int i=(a);i>=(b);i--)

#define maxn 100005
#define maxm 100005
#define MOD 1000000007
#define INF 1070000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template<class T> inline
void read(T& num){
    num = 0; bool f = 1;char ch = getchar();
    while(ch < '0' || ch > '9') { if(ch == '-') f = 0;ch = getchar();}
    while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}
    num = f ? num: -num;
}
template<class T> inline
void write(T x,char ch){
	int s[100];
	if (x==0) {putchar('0'); putchar(ch); return;}
	if (x<0) {putchar('-'); x=-x;} int num=0;
	while (x){ s[num++]=(x%10); x=x/10;}
	FORM(i,num-1,0) putchar(s[i]+'0'); putchar(ch);
}
/*==================split line==================*/
const double pi = acos(-1);
const double eps = 1e-8;
int n;
int dp[maxn][601];
int a[maxn];
int main(){
	read(n); FORP(i, 1, n) read(a[i]);
	FORP(k, 1, min(600, n)){
		FORM(i, n, 1) {
			int t = i + a[i] + k;
			dp[i][k] = 1;
			//while (t <= n) t = t + a[t] + k, dp[i][k]++;
			if (t <= n) dp[i][k] = dp[i][k] + dp[t][k];
		}
	}
	int q;
	read(q);
	FORP(i, 1, q){
		int p, k; read(p); read(k);
		if (k <= min(600, n)) write(dp[p][k],'\n');
		else {
			int t = p + a[p] + k;
			int ans = 1;
			while (t <= n) t = t + a[t] + k, ans++;
			write(ans,'\n');
		}
	}
}


/*=================================
# Created time: 2018-08-20 21:43
# Filename: e.cpp
# Description:
=================================*/
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sqr(x) (x)*(x)
#define lowbit(x) (x)&(-x)
#define pii pair<int, int>
#define ls(a,b) (((a)+(b)) << 1)
#define rs(a,b) (((a)+(b)) >> 1)
#define fin(a) freopen(a,"r",stdin);
#define fout(a) freopen(a,"w",stdout);
#define FORP(i,a,b) for(int i=(a);i<=(b);i++)
#define FORM(i,a,b) for(int i=(a);i>=(b);i--)

#define maxn 100005
#define maxm 100005
#define MOD 1000000007
#define INF 1070000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template<class T> inline
void read(T& num){
    num = 0; bool f = 1;char ch = getchar();
    while(ch < '0' || ch > '9') { if(ch == '-') f = 0;ch = getchar();}
    while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}
    num = f ? num: -num;
}
template<class T> inline
void write(T x,char ch){
	int s[100];
	if (x==0) {putchar('0'); putchar(ch); return;}
	if (x<0) {putchar('-'); x=-x;} int num=0;
	while (x){ s[num++]=(x%10); x=x/10;}
	FORM(i,num-1,0) putchar(s[i]+'0'); putchar(ch);
}
/*==================split line==================*/
const double pi = acos(-1);
const double eps = 1e-8;
int n;
int dp[maxn][501];
int a[maxn];
int main(){
	read(n); FORP(i, 1, n) read(a[i]);
	FORP(k, 1, min(500, n)){
		FORM(i, n, 1) {
			int t = i + a[i] + k;
			dp[i][k] = 1;
			while (t <= n) t = t + a[t] + k, dp[i][k]++;
		}
	}
	int q;
	read(q);
	FORP(i, 1, q){
		int p, k; read(p); read(k);
		if (k <= min(500, n)) write(dp[p][k],'\n');
		else {
			int t = i + a[i] + k;
			int ans = 1;
			while (t <= n) t = t + a[t] + k, ans++;
			write(ans,'\n');
		}
	}
}


/*=================================
# Created time: 2018-08-20 21:43
# Filename: e.cpp
# Description:
=================================*/
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sqr(x) (x)*(x)
#define lowbit(x) (x)&(-x)
#define pii pair<int, int>
#define ls(a,b) (((a)+(b)) << 1)
#define rs(a,b) (((a)+(b)) >> 1)
#define fin(a) freopen(a,"r",stdin);
#define fout(a) freopen(a,"w",stdout);
#define FORP(i,a,b) for(int i=(a);i<=(b);i++)
#define FORM(i,a,b) for(int i=(a);i>=(b);i--)

#define maxn 100005
#define maxm 100005
#define MOD 1000000007
#define INF 1070000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template<class T> inline
void read(T& num){
    num = 0; bool f = 1;char ch = getchar();
    while(ch < '0' || ch > '9') { if(ch == '-') f = 0;ch = getchar();}
    while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}
    num = f ? num: -num;
}
template<class T> inline
void write(T x,char ch){
	int s[100];
	if (x==0) {putchar('0'); putchar(ch); return;}
	if (x<0) {putchar('-'); x=-x;} int num=0;
	while (x){ s[num++]=(x%10); x=x/10;}
	FORM(i,num-1,0) putchar(s[i]+'0'); putchar(ch);
}
/*==================split line==================*/
const double pi = acos(-1);
const double eps = 1e-8;
int n;
int dp[maxn][701];
int a[maxn];
int main(){
	read(n); FORP(i, 1, n) read(a[i]);
	FORP(k, 1, min(700, n)){
		FORM(i, n, 1) {
			int t = i + a[i] + k;
			dp[i][k] = 1;
			while (t <= n) t = t + a[t] + k, dp[i][k]++;
		}
	}
	int q;
	read(q);
	FORP(i, 1, q){
		int p, k; read(p); read(k);
		if (k <= min(700, n)) write(dp[p][k],'\n');
		else {
			int t = p + a[p] + k;
			int ans = 1;
			while (t <= n) t = t + a[t] + k, ans++;
			write(ans,'\n');
		}
	}
}


/*=================================
# Created time: 2018-08-20 21:43
# Filename: e.cpp
# Description:
=================================*/
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sqr(x) (x)*(x)
#define lowbit(x) (x)&(-x)
#define pii pair<int, int>
#define ls(a,b) (((a)+(b)) << 1)
#define rs(a,b) (((a)+(b)) >> 1)
#define fin(a) freopen(a,"r",stdin);
#define fout(a) freopen(a,"w",stdout);
#define FORP(i,a,b) for(int i=(a);i<=(b);i++)
#define FORM(i,a,b) for(int i=(a);i>=(b);i--)

#define maxn 100005
#define maxm 100005
#define MOD 1000000007
#define INF 1070000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template<class T> inline
void read(T& num){
    num = 0; bool f = 1;char ch = getchar();
    while(ch < '0' || ch > '9') { if(ch == '-') f = 0;ch = getchar();}
    while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}
    num = f ? num: -num;
}
template<class T> inline
void write(T x,char ch){
	int s[100];
	if (x==0) {putchar('0'); putchar(ch); return;}
	if (x<0) {putchar('-'); x=-x;} int num=0;
	while (x){ s[num++]=(x%10); x=x/10;}
	FORM(i,num-1,0) putchar(s[i]+'0'); putchar(ch);
}
/*==================split line==================*/
const double pi = acos(-1);
const double eps = 1e-8;
int n;
int dp[maxn][501];
int a[maxn];
int main(){
	read(n); FORP(i, 1, n) read(a[i]);
	FORP(k, 1, min(500, n)){
		FORM(i, n, 1) {
			int t = i + a[i] + k;
			dp[i][k] = 1;
			while (t <= n) t = t + a[t] + k, dp[i][k]++;
		}
	}
	int q;
	read(q);
	FORP(i, 1, q){
		int p, k; read(p); read(k);
		if (k <= min(500, n)) write(dp[p][k],'\n');
		else {
			int t = p + a[p] + k;
			int ans = 1;
			while (t <= n) t = t + a[t] + k, ans++;
			write(ans,'\n');
		}
	}
}


#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std; typedef long long ll;
const int MAXN = 10 + 1e6;
const ll oo = 1 + 1e18, mod = 7 + 1e9;

int n, q, a[MAXN], f[300][100111];

void khoitao(){
  int m = sqrt(n);
  for (int i = 1; i <= m; i++){
    for (int j = n; j >= 1; j--){
      if (j + a[j] + i <= n) f[i][j] = f[i][j + a[j] + i] + 1;
      else f[i][j] = 1;
    }
  }
}

int calc(int k, int p){
  int res = 0;
  while (p <= n){
    p = p + k + a[p];
    res++;
  }
  return res;
}

int main(){
  #define TASK "ABC"
  #ifndef ONLINE_JUDGE
  freopen(TASK".inp","r",stdin),freopen(TASK".out","w",stdout);
  #endif ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);

  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];

  khoitao();

  cin >> q;
  while (q--){
    int p, k; cin >> p >> k;
    if (k * k >= n){
      calc(k, p);
    }
    else cout << f[k][p] << '\n';
  }

  return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std; typedef long long ll;
const int MAXN = 10 + 1e6;
const ll oo = 1 + 1e18, mod = 7 + 1e9;

int n, q, a[100111], f[350][100111];

void khoitao(){
  int m = sqrt(n);
  for (int i = 1; i <= m; i++){
    for (int j = n; j >= 1; j--){
      if (j + a[j] + i <= n) f[i][j] = f[i][j + a[j] + i] + 1;
      else f[i][j] = 1;
    }
  }
}

int calc(int k, int p){
  int res = 0;
  while (p <= n){
    p = p + k + a[p];
    res++;
  }
  return res;
}

int main(){
  #define TASK "ABC"
  #ifndef ONLINE_JUDGE
  freopen(TASK".inp","r",stdin),freopen(TASK".out","w",stdout);
  #endif ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);

  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];

  khoitao();

  cin >> q;
  while (q--){
    int p, k; cin >> p >> k;
    if (k >= n / k){
      cout << calc(k, p) << '\n';
    }
    else cout << f[k][p] << '\n';
  }

  return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std; typedef long long ll;
const int MAXN = 10 + 1e6;
const ll oo = 1 + 1e18, mod = 7 + 1e9;

int n, q, a[MAXN], f[300][100111];

void khoitao(){
  int m = sqrt(n);
  for (int i = 1; i <= m; i++){
    for (int j = n; j >= 1; j--){
      if (j + a[j] + i <= n) f[i][j] = f[i][j + a[j] + i] + 1;
      else f[i][j] = 1;
    }
  }
}

int calc(int k, int p){
  int res = 0;
  while (p <= n){
    p = p + k + a[p];
    res++;
  }
  return res;
}

int main(){
  #define TASK "ABC"
  #ifndef ONLINE_JUDGE
  freopen(TASK".inp","r",stdin),freopen(TASK".out","w",stdout);
  #endif ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);

  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];

  khoitao();

  cin >> q;
  while (q--){
    int p, k; cin >> p >> k;
    if (k * k >= n){
      cout << calc(k, p) << '\n';
    }
    else cout << f[k][p] << '\n';
  }

  return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std; typedef long long ll;
const int MAXN = 10 + 1e6;
const ll oo = 1 + 1e18, mod = 7 + 1e9;

int n, q, a[MAXN], f[320][100111];

void khoitao(){
  int m = sqrt(n);
  for (int i = 1; i <= m; i++){
    for (int j = n; j >= 1; j--){
      if (j + a[j] + i <= n) f[i][j] = f[i][j + a[j] + i] + 1;
      else f[i][j] = 1;
    }
  }
}

int calc(int k, int p){
  int res = 0;
  while (p <= n){
    p = p + k + a[p];
    res++;
  }
  return res;
}

int main(){
  #define TASK "ABC"
  #ifndef ONLINE_JUDGE
  freopen(TASK".inp","r",stdin),freopen(TASK".out","w",stdout);
  #endif ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);

  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];

  khoitao();

  cin >> q;
  while (q--){
    int p, k; cin >> p >> k;
    if (k * k >= n){
      cout << calc(k, p) << '\n';
    }
    else cout << f[k][p] << '\n';
  }

  return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std; typedef long long ll;
const int MAXN = 10 + 1e6;
const ll oo = 1 + 1e18, mod = 7 + 1e9;

int n, q, a[100111], f[350][100111];

void khoitao(){
  int m = sqrt(n);
  for (int i = 1; i <= m; i++){
    for (int j = n; j >= 1; j--){
      if (j + a[j] + i <= n) f[i][j] = f[i][j + a[j] + i] + 1;
      else f[i][j] = 1;
    }
  }
}

int calc(int k, int p){
  int res = 0;
  while (p <= n){
    p = p + k + a[p];
    res++;
  }
  return res;
}

int main(){
  #define TASK "ABC"
  #ifndef ONLINE_JUDGE
  freopen(TASK".inp","r",stdin),freopen(TASK".out","w",stdout);
  #endif ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);

  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];

  khoitao();

  cin >> q;
  while (q--){
    int p, k; cin >> p >> k;
    if (k * k >= n){
      cout << calc(k, p) << '\n';
    }
    else cout << f[k][p] << '\n';
  }

  return 0;
}


#include <unordered_map>
#include <iostream>
#include <cstdio>
using namespace std;
int n,arr[100005],q,p,k;
unordered_map <int,int> umap[100005];
int hitung(int p,int k){
	if(umap[p].find(k)!=umap[p].end())
		return umap[p][k];
	if(p+arr[p]+k>n)
		umap[p][k]=1;
	else
		umap[p][k]=1+hitung(p+arr[p]+k,k);
	return umap[p][k];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&arr[i]);
	scanf("%d",&q);
	for(int query=1;query<=q;query++)
	{
		scanf("%d%d",&p,&k);
		printf("%d\n",hitung(p,k));
	}
}


#include <unordered_map>
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
int n,arr[100005],q,p,k;
map <int,int> umap[100005];
int hitung(int p,int k){
	if(umap[p].find(k)!=umap[p].end())
		return umap[p][k];
	if(p+arr[p]+k>n)
		umap[p][k]=1;
	else
		umap[p][k]=1+hitung(p+arr[p]+k,k);
	return umap[p][k];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&arr[i]);
	scanf("%d",&q);
	for(int query=1;query<=q;query++)
	{
		scanf("%d%d",&p,&k);
		printf("%d\n",hitung(p,k));
	}
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <utility>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pii;
typedef long long LL;
#define INF 1000000000000000LL
int tikus,lubang,postikus[5005],now=1,tadi=0;
pii poslubang[5005],tampungkiri[5005],tampungkanan[5005];
long long dp[5][5005],pre[5005];
int jarak(int a,int b){
	return abs(a-b);
}
void isidp(int jenis,int l,int r,int optl,int optr){
	if(l>r)
		return;
	long long biaya=0;
	int mid=(l+r)>>1;
	int bataskiri=max(optl,mid-poslubang[jenis].se+1);
	dp[now][mid]=dp[tadi][mid];
	int opt=mid+1;
	for(int i=min(mid,optr);i>=bataskiri;i--)
	{
		biaya=pre[mid]-pre[i-1];
		if(biaya+dp[tadi][i-1]<dp[now][mid])
		{
			dp[now][mid]=min(dp[now][mid],biaya+dp[tadi][i-1]);
			opt=i;
		}
	}
	isidp(jenis,l,mid-1,optl,opt);
	isidp(jenis,mid+1,r,opt,optr);
}
void merge(int jenis,int kiri,int kanan){			//jenisnya 0 berarti int, jenis 1 berarti pii
	int mid=(kiri+kanan)>>1,nkiri=0,nkanan=0;
	for(int i=kiri;i<=mid;i++)
	{
		if(jenis==0)
			tampungkiri[nkiri++]=mp(postikus[i],i);
		else
			tampungkiri[nkiri++]=poslubang[i];
	}
	for(int i=mid+1;i<=kanan;i++)
	{
		if(jenis==0)
			tampungkanan[nkanan++]=mp(postikus[i],i);
		else
			tampungkanan[nkanan++]=poslubang[i];
	}
	tampungkanan[nkanan].fi=tampungkiri[nkiri].fi=1000000001;
	int j=0,k=0;
	for(int i=kiri;i<=kanan;i++)
	{
		if(tampungkiri[j].fi<tampungkanan[k].fi)
		{
			if(jenis==0)
				postikus[i]=tampungkiri[j].fi;
			else
				poslubang[i]=tampungkiri[j];
			j++;
		}
		else
		{
			if(jenis==0)
				postikus[i]=tampungkanan[k].fi;
			else
				poslubang[i]=tampungkanan[k];
			k++;
		}
	}

}
void sorting(int jenis,int kiri,int kanan){
	if(kiri==kanan)
		return;
	int mid=(kiri+kanan)>>1;
	sorting(jenis,kiri,mid);
	sorting(jenis,mid+1,kanan);
	merge(jenis,kiri,kanan);
}
void hitung_pre(int indekslubang){
	pre[0]=0;
	for(int i=1;i<=tikus;i++)
		pre[i]=pre[i-1]+jarak(postikus[i],poslubang[indekslubang].fi);
}
int main()
{
	scanf("%d%d",&tikus,&lubang);
	for(int i=1;i<=tikus;i++)
		scanf("%d",&postikus[i]);
	//sort(postikus+1,postikus+tikus+1);
	for(int i=1;i<=lubang;i++)
	{
		scanf("%d%d",&poslubang[i].fi,&poslubang[i].se);
	}
	sorting(0,1,tikus);
	sorting(1,1,lubang);
	//sort(poslubang+1,poslubang+lubang+1);
	dp[now][0]=0;
	for(int i=1;i<=tikus;i++)
	{
		if(i<=poslubang[1].se)
			dp[now][i]=jarak(postikus[i],poslubang[1].fi)+dp[now][i-1];
		else
			dp[now][i]=INF;
	}
	swap(now,tadi);
	for(int ulang=2;ulang<=lubang;ulang++)
	{
		hitung_pre(ulang);
		dp[now][0]=0;
		isidp(ulang,1,tikus,1,tikus);
		swap(now,tadi);
	}
	/*cout<<"ini table dpnya "<<endl;
	for(int i=1;i<=lubang;i++)
	{
		for(int j=1;j<=tikus;j++)
			cout<<dp[i][j]<<" ";
		cout<<endl;
	}*/
	if(dp[tadi][tikus]==INF)
		printf("-1\n");
	else
		printf("%lld\n",dp[tadi][tikus]);
}


#include <unordered_map>
#include <iostream>
#include <cstdio>
using namespace std;
#define konstan 320
int n,arr[100005],q,p,k,dp[konstan+5][100005];
void hitung_dp(int k){
	for(int i=n;i>=1;i--)
	{
		if(i+k+arr[i]>n)
			dp[k][i]=1;
		else
			dp[k][i]=1+dp[k][i+k+arr[i]];
	}
}
int hitung(int p,int k){
	int ret=0;
	while(p<=n)
	{
		ret++;
		p=p+arr[p]+k;
	}
	return ret;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&arr[i]);
	for(int  i=1;i<=konstan;i++)
		hitung_dp(i);
	scanf("%d",&q);
	for(int query=1;query<=q;query++)
	{
		scanf("%d%d",&p,&k);
		printf("%d\n",(k<=konstan)?dp[k][p]:hitung(p,k));
	}
}


#include <unordered_map>
#include <iostream>
#include <cstdio>
using namespace std;
int n,arr[100005],q,p,k;
unordered_map <int,int> umap[100005];
int hitung(int p,int k){
	if(umap[p].find(k)!=umap[p].end())
		return umap[p][k];
	if(p+arr[p]+k>n)
		umap[p][k]=1;
	else
		umap[p][k]=1+hitung(p+arr[p]+k,k);
	return umap[p][k];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		umap[i].reserve(1<<5);
		umap[i].max_load_factor(0.25);
	}
	for(int i=1;i<=n;i++)
		scanf("%d",&arr[i]);
	scanf("%d",&q);
	for(int query=1;query<=q;query++)
	{
		scanf("%d%d",&p,&k);
		printf("%d\n",hitung(p,k));
	}

}


#include <unordered_map>
#include <iostream>
#include <cstdio>
using namespace std;
int n,arr[100005],q,p,k;
unordered_map <int,int> umap[100005];
int hitung(int p,int k){
	if(umap[p].find(k)!=umap[p].end())
		return umap[p][k];
	if(p+arr[p]+k>n)
		umap[p][k]=1;
	else
		umap[p][k]=1+hitung(p+arr[p]+k,k);
	return umap[p][k];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&arr[i]);
	scanf("%d",&q);
	for(int query=1;query<=q;query++)
	{
		scanf("%d%d",&p,&k);
		printf("%d\n",hitung(p,k));
	}

}


#include <unordered_map>
#include <iostream>
#include <cstdio>
using namespace std;
#define konstan 320
int n,arr[100005],q,p,k,dp[konstan+5][100005];
void hitung_dp(int k){
	for(int i=n;i>=1;i--)
	{
		if(i+k+arr[i]>n)
			dp[k][i]=1;
		else
			dp[k][i]=1+dp[k][i+k+arr[i]];
	}
}
int hitung(int p,int k){
	int ret=0;
	while(p<n)
	{
		ret++;
		p=p+arr[p]+k;
	}
	return ret;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&arr[i]);
	for(int  i=1;i<=konstan;i++)
		hitung_dp(i);
	scanf("%d",&q);
	for(int query=1;query<=q;query++)
	{
		scanf("%d%d",&p,&k);
		printf("%d\n",(k<=konstan)?dp[k][p]:hitung(p,k));
	}
}


#include <unordered_map>
#include <iostream>
#include <cstdio>
using namespace std;
int n,arr[100005],q,p,k;
unordered_map <int,int> umap[100005];
int hitung(int p,int k){
	if(umap[p].find(k)!=umap[p].end())
		return umap[p][k];
	if(p+arr[p]+k>n)
		umap[p][k]=1;
	else
		umap[p][k]=1+hitung(p+arr[p]+k,k);
	return umap[p][k];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		umap[i].reserve(1<<3);
		umap[i].max_load_factor(0.25);
	}
	for(int i=1;i<=n;i++)
		scanf("%d",&arr[i]);
	scanf("%d",&q);
	for(int query=1;query<=q;query++)
	{
		scanf("%d%d",&p,&k);
		printf("%d\n",hitung(p,k));
	}

}


#include <unordered_map>
#include <iostream>
#include <cstdio>
using namespace std;
int n,arr[100005],q,p,k;
unordered_map <int,int> umap[100005];
int hitung(int p,int k){
	if(umap[p].find(k)!=umap[p].end())
		return umap[p][k];
	if(p+arr[p]+k>n)
		umap[p][k]=1;
	else
		umap[p][k]=1+hitung(p+arr[p]+k,k);
	return umap[p][k];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		umap[i].reserve(1024);
		umap[i].max_load_factor(0.25);
	}
	for(int i=1;i<=n;i++)
		scanf("%d",&arr[i]);
	scanf("%d",&q);
	for(int query=1;query<=q;query++)
	{
		scanf("%d%d",&p,&k);
		printf("%d\n",hitung(p,k));
	}

}


#include <unordered_map>
#include <iostream>
#include <cstdio>
using namespace std;
int n,arr[100005],q,p,k;
unordered_map <int,int> umap[100005];
int hitung(int p,int k){
	if(umap[p].find(k)!=umap[p].end())
		return umap[p][k];
	if(p+arr[p]+k>n)
		umap[p][k]=1;
	else
		umap[p][k]=1+hitung(p+arr[p]+k,k);
	return umap[p][k];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		umap[i].reserve(1<<4);
		umap[i].max_load_factor(0.25);
	}
	for(int i=1;i<=n;i++)
		scanf("%d",&arr[i]);
	scanf("%d",&q);
	for(int query=1;query<=q;query++)
	{
		scanf("%d%d",&p,&k);
		printf("%d\n",hitung(p,k));
	}

}


#include <bits/stdc++.h>
#define maxn 100005
using namespace std;

int N,A[maxn],k,p,Q,cont;

int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N ;

    for(int i=1;i<=N;i++)
        cin >> A[i];

    cin >> Q;

    while(Q--)
    {
      cin >> p >> k;
      while(p<=N)
          p=p+k+A[p] ,cont++;
      cout << cont << "\n";
      cont=0;
    }
}


#include<bits/stdc++.h>
#define lsc(x) scanf("%lld",&x);
#define sc(x) scanf("%d",&x);
#define lpr(x) printf("%lld ",x);
#define pr(x) printf("%d ",x);
#define n_l printf("\n");
#define VI vector<int>
#define VII vector<long long int>
#define m_p make_pair
#define pb push_back

using namespace std;
const int N=(int)1e5+5;
const int sqr=200;
int dp[sqr][N];
typedef long long ll;
int a[N];
int main(){
    int n;sc(n);
    for(int i=1;i<=n;i++) sc(a[i]);
    for (int i=1;i<=sqr;i++)
        for (int j=n;j>0;j--)
            if (i+j+a[j] >n) dp[i][j]=1;
            else dp[i][j]=dp[i][i+j+a[j]]+1;
    int m;sc(m);
    while(m--){
        int i,j;sc(i);sc(j);
        if (j<=sqr) pr(dp[j][i])
        else{
            int ans=0;
            while(i<=n){
                i=i+a[i]+j;
                ans++;
            }
            pr(ans);
        }
        n_l;
    }
    return 0;
}


#include<bits/stdc++.h>
#define lsc(x) scanf("%lld",&x);
#define sc(x) scanf("%d",&x);
#define lpr(x) printf("%lld ",x);
#define pr(x) printf("%d ",x);
#define n_l printf("\n");
#define VI vector<int>
#define VII vector<long long int>
#define m_p make_pair
#define pb push_back

using namespace std;
const int N=(int)1e5+5;
const int sqr=200;
int dp[sqr][N];
typedef long long ll;
int a[N];
int main(){
    ll n;lsc(n);
    for(int i=1;i<=n;i++) sc(a[i]);
    for (int i=1;i<sqr;i++)
        for (int j=n;j>0;j--){
            if (i+j+a[j] >n) dp[i][j]=1;
            else dp[i][j]=dp[i][i+j+a[j]]+1;
        }
    ll m;lsc(m);
    while(m--){
        ll i,j;lsc(i);lsc(j);
        if (j<sqr) pr(dp[j][i])
        else{
            ll ans=0;
            while(i<=n){
                i=i+a[i]+j;
                ans++;
            }
            pr(ans);
        }
        n_l;
    }
    return 0;
}


#include<bits/stdc++.h>
#define lsc(x) scanf("%lld",&x);
#define sc(x) scanf("%d",&x);
#define lpr(x) printf("%lld ",x);
#define pr(x) printf("%d ",x);
#define n_l printf("\n");
#define VI vector<int>
#define VII vector<long long int>
#define m_p make_pair
#define pb push_back

using namespace std;
const int N=(int)1e5+5;
const int sqr=200;
int dp[sqr][N];
typedef long long ll;
int a[N];
int main(){
    int n;sc(n);
    for(int i=1;i<=n;i++) sc(a[i]);
    for (int i=1;i<=sqr;i++)
        for (int j=n;j>0;j--){
            if (i+j+a[j] >n) dp[i][j]=1;
            else dp[i][j]=dp[i][i+j+a[j]]+1;
        }
    int m;sc(m);
    while(m--){
        int i,j;sc(i);sc(j);
        if (j<sqr) pr(dp[j][i])
        else{
            int ans=0;
            while(i<=n){
                i=i+a[i]+j;
                ans++;
            }
            pr(ans);
        }
        n_l;
    }
    return 0;
}


#include<bits/stdc++.h>
#define lsc(x) scanf("%lld",&x);
#define sc(x) scanf("%d",&x);
#define lpr(x) printf("%lld ",x);
#define pr(x) printf("%d ",x);
#define n_l printf("\n");
#define VI vector<int>
#define VII vector<long long int>
#define m_p make_pair
#define pb push_back

using namespace std;
const int N=(int)1e5+5;
const int sqr=200;
int dp[sqr][N];
typedef long long ll;
int a[N];
int main(){
    int n;sc(n);
    for(int i=1;i<=n;i++) sc(a[i]);
    for (int i=1;i<=sqr;i++)
        for (int j=n;j>0;j--){
            if (i+j+a[j] >n) dp[i][j]=1;
            else dp[i][j]=dp[i][i+j+a[j]]+1;
        }
    int m;sc(m);
    while(m--){
        ll i,j;lsc(i);lsc(j);
        if (j<sqr) pr(dp[j][i])
        else{
            ll ans=0;
            while(i<=n){
                i=i+a[i]+j;
                ans++;
            }
            pr(ans);
        }
        n_l;
    }
    return 0;
}


#include<bits/stdc++.h>
#define lsc(x) scanf("%lld",&x);
#define sc(x) scanf("%d",&x);
#define lpr(x) printf("%lld ",x);
#define pr(x) printf("%d ",x);
#define n_l printf("\n");
#define VI vector<int>
#define VII vector<long long int>
#define m_p make_pair
#define pb push_back

using namespace std;
const int N=(int)1e5+5;
const int sqr=sqrt(N);
int dp[sqr][N];
typedef long long ll;
int a[N];
int main(){
    int n;sc(n);
    for(int i=1;i<=n;i++) sc(a[i]);
    for (int i=1;i<=sqr;i++)
        for (int j=n;j>0;j--)
            if (i+j+a[j] >n) dp[i][j]=1;
            else dp[i][j]=dp[i][i+j+a[j]]+1;
    int m;sc(m);
    while(m--){
        int i,j;sc(i);sc(j);
        if (j<=sqr) pr(dp[j][i])
        else{
            int ans=0;
            while(i<=n){
                i=i+a[i]+j;
                ans++;
            }
            pr(ans);
        }
        n_l;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int dp[100005][320],ans,p,k,n,q;
int t[100005];
int main()
{
    cin >> n;
    for(int i=1;i<=n;i++)cin>>t[i];
    for(int p=1;p<=n;p++)
    {
        for(int k=1;k<=310;k++)
        {   int ep=p;
            while(ep<=n)dp[p][k]++,ep+=t[ep]+k;
        }
    }
    cin >>q;
    while(q--)
    {
        cin >> p>>k;
        if(k<=310)cout<<dp[p][k]<<endl;
        else
        {   ans=0;
            while(p<=n)ans++,p=p+t[p]+k;
            cout << ans<<endl;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
int dp[100005][320],ans,p,k,n,q;
int t[100005];
int main()
{
    cin >> n;
    for(int i=1;i<=n;i++)cin>>t[i];
    for(int p =1;p<=n;p++)
    {   int ep=p;
        for(int k=1;k<=310;k++)
        {
            dp[p][k]=1;
            while(ep+k+t[ep]<=n)dp[p][k]++,ep+=t[ep];
        }
    }
    cin >>q;
    while(q--)
    {
        cin >> p>>k;
        if(k<=310)cout<<dp[p][k]<<endl;
        else
        {
            ans=1;
            while(p+k+t[p]<=n)p+=t[p],ans++;
            cout <<ans<<endl;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
int dp[100005][320],ans,p,k,n,q;
int t[100005];
int go(int p,int k)
{
    if(p>n)return 0;
    return dp[p][k]=(dp[p][k] ? dp[p][k]:go(p+t[p]+k,k)+1);
}
int main()
{
    cin >> n;
    for(int i=1;i<=n;i++)cin>>t[i];
    for(int p=1;p<=n;p++)
    {
        for(int k=1;k<=310;k++)
        {
            if(!dp[p][k])go(p,k);
        }
    }
    cin >>q;
    while(q--)
    {
        cin >> p>>k;
        if(k<=310)cout << go(p,k)<<endl;
        else
        {   ans=0;
            while(p<=n)ans++,p=p+t[p]+k;
            cout << ans<<endl;
        }

    }
}


#include <bits/stdc++.h>
using namespace std;
int dp[100005][320],ans,p,k,n,q;
int t[100005];
int main()
{
    cin >> n;
    for(int i=1;i<=n;i++)cin>>t[i];
    for(int p=1;p<=n;p++)
    {
        for(int k=1;k<=310;k++)
        {   int ep=p;
            while(ep<=n)dp[p][k]++,ep+=t[ep]+k;
        }
    }
    cin >>q;
    while(q--)
    {
        cin >> p>>k;
        if(k<=310)cout<<dp[p][k]<<endl;
        else
        {
            while(p<=n)ans++,p=p+t[p]+k;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
int dp[100005][320],ans,p,k,n,q;
int t[100005];
int main()
{
    cin >> n;
    for(int i=1;i<=n;i++)cin>>t[i];
    for(int p=1;p<=n;p++)
    {
        for(int k=1;k<=310;k++)
        {   int ep=p;
            while(ep<=n)dp[p][k]++,ep+=t[ep]+k;
        }
    }
    cin >>q;
    while(q--)
    {
        cin >> p>>k;
        if(k<=310)cout<<dp[p][k]<<endl;
        else
        {   ans=0;
            while(p<=n)ans++,p=p+t[p]+k;
            cout << ans;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
int dp[100005][320],ans,p,k,n,q;
int t[100005];
int go(int p,int k)
{
    if(p>n)return 0;
    return dp[p][k]=(dp[p][k]?dp[p][k]:go(p+t[p]+k,k)+1);
}
int main()
{
    cin >> n;
    for(int i=1;i<=n;i++)cin>>t[i];
    for(int p=1;p<=n;p++)
    {
        for(int k=1;k<=310;k++)
        {
            if(!dp[p][k])go(p,k);
        }
    }
    cin >>q;
    while(q--)
    {
        cin >> p>>k;
        if(k<=310)cout<<dp[p][k]<<endl;
        else cout << go(p,k)<<endl;

    }
}


#include <bits/stdc++.h>
using namespace std;
int dp[100005][320],ans,p,k,n,q;
int t[100005];
int go(int p,int k)
{
    if(p>n)return 0;
    return dp[p][k]=(dp[p][k]?dp[p][k]:go(p+t[p]+k,k)+1);
}
int main()
{
    cin >> n;
    for(int i=1;i<=n;i++)cin>>t[i];
    for(int p=1;p<=n;p++)
    {
        for(int k=1;k<=310;k++)
        {
            if(!dp[p][k])go(p,k);
        }
    }
    cin >>q;
    while(q--)
    {
        cin >> p>>k;
        if(k<=310)cout<<dp[p][k]<<endl;
        else cout << go(p,k);

    }
}


#include <bits/stdc++.h>
using namespace std;
int dp[100005][320],ans,p,k,n,q;
int t[100005];
int go(int p,int k)
{
    if(p>n)return 0;
    return dp[p][k]=go(p+t[p]+k,k)+1;
}
int main()
{
    cin >> n;
    for(int i=1;i<=n;i++)cin>>t[i];
    for(int p=1;p<=n;p++)
    {
        for(int k=1;k<=310;k++)
        {
            if(!dp[p][k])go(p,k);
        }
    }
    cin >>q;
    while(q--)
    {
        cin >> p>>k;
        if(k<=310)cout<<dp[p][k]<<endl;
        else
        {   ans=0;
            while(p<=n)ans++,p=p+t[p]+k;
            cout << ans<<endl;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define inf      0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n,q,k;
int arr[100100];
int dp[333][100100];

int solve(int p){
  if(p>n)return 0;
  int &ret=dp[k][p];
  if(~ret)return dp[k][p];
  return ret=1+solve(p+arr[p]+k);
}

int solve2(int p){
  if(p>n)return 0;
  return 1+solve2(p+arr[p]+k);
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
  sc(n);
  for(int i=1;i<=n;++i)
    sc(arr[i]);
  sc(q);
  int p;
  memset(dp,-1,sizeof dp);
  while(q--){
    sc(p),sc(k);
    if(k<333)printf("%d\n",solve(p));
    else printf("%d\n",solve2(p));
  }
}


// :V :V :V
#include <bits/stdc++.h>
using namespace std;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define inf      0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n,q,k;
int arr[100100];
map<int,int> dp;

int solve(int p){
  if(p>n)return 0;
  int &ret=dp[p*321+k];
  if(ret>0)return dp[p*321+k];
  return ret=1+solve(p+arr[p]+k);
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
  sc(n);
  for(int i=1;i<=n;++i)
    sc(arr[i]);
  sc(q);
  int p;
  while(q--){
    sc(p),sc(k);
    printf("%d\n",solve(p));
  }
}


#include <bits/stdc++.h>
using namespace std;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define inf      0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n,q,k;
int arr[100100];
int dp[333][100100];

int solve(int p){
  if(p>n)return 0;
  int &ret=dp[k][p];
  if(~ret)return dp[k][p];
  return ret=1+solve(p+arr[p]+k);
}

int solve2(int p){
  if(p>n)return 0;
  return 1+solve2(p+arr[p]+k);
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
  sc(n);
  for(int i=1;i<=n;++i)
    sc(arr[i]);
  sc(q);
  int p;
  memset(dp,-1,sizeof dp);
  while(q--){
    sc(p),sc(k);
    if(k<333)printf("%d\n",solve(p));
    elseprintf("%d\n",solve2(p));
  }
}


// :V :V :V
#include <bits/stdc++.h>
using namespace std;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define inf      0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n,q,k;
int arr[100100];
map<int,int> dp;

int solve(int p){
  if(p>n)return 0;
  int &ret=dp[p*1321+k];
  if(ret>0)return dp[p*321+k];
  return ret=1+solve(p+arr[p]+k);
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
  sc(n);
  for(int i=1;i<=n;++i)
    sc(arr[i]);
  sc(q);
  int p;
  while(q--){
    sc(p),sc(k);
    printf("%d\n",solve(p));
  }
}


#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define inf      0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n,q,k;
int arr[100100];
hash_map<int,int> dp[100100];

int solve(int p){
  if(p>n)return 0;
  int &ret=dp[p][k];
  if(ret>0)return dp[p][k];
  return ret=1+solve(p+arr[p]+k);
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
  sc(n);
  for(int i=1;i<=n;++i)
    sc(arr[i]);
  sc(q);
  int p;
  while(q--){
    sc(p),sc(k);
    printf("%d\n",solve(p));
  }
}


#include <bits/stdc++.h>
using namespace std;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define inf      0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n,q,k;
int arr[100100];
map<int,int> dp[100100];

int solve(int p){
  if(p>n)return 0;
  int &ret=dp[p][k];
  if(ret>0)return dp[p][k];
  return ret=1+solve(p+arr[p]+k);
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
  sc(n);
  for(int i=1;i<=n;++i)
    sc(arr[i]);
  sc(q);
  int p;
  while(q--){
    sc(p),sc(k);
    printf("%d\n",solve(p));
  }
}


#include <bits/stdc++.h>
using namespace std;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define inf      0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n,q,k;
int arr[100100];
map<int,int> dp[100100];

int solve(int p){
  if(p>n)return 0;
  int &ret=dp[k][p];
  if(ret>0)return ret;
  return ret=1+solve(p+arr[p]+k);
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
  sc(n);
  for(int i=1;i<=n;++i)
    sc(arr[i]);
  sc(q);
  int p;
  while(q--){
    sc(p),sc(k);
    printf("%d\n",solve(p));
  }
}


#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define inf      0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n,q,k;
int arr[100100];
hash_map<int,int> dp[100100];

int solve(int p){
  if(p>n)return 0;
  int &ret=dp[k][p];
  if(ret>0)return ret;
  return ret=1+solve(p+arr[p]+k);
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
  sc(n);
  for(int i=1;i<=n;++i)
    sc(arr[i]);
  sc(q);
  int p;
  while(q--){
    sc(p),sc(k);
    printf("%d\n",solve(p));
  }
}


#include <bits/stdc++.h>
using namespace std;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define inf      0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n,q,k;
int arr[100100];
map<int,int> dp[100100];

int solve(int p){
  if(p>n)return 0;
  if(dp[p].count(k))return dp[p][k];
  return dp[p][k]=1+solve(p+arr[p]+k);
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
  sc(n);
  for(int i=1;i<=n;++i)
    sc(arr[i]);
  sc(q);
  int p;
  while(q--){
    sc(p),sc(k);
    printf("%d\n",solve(p));
  }
}


#include <bits/stdc++.h>
using namespace std;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define inf      0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n,q,k;
int arr[100100];
int dp[100100];

int solve(int p){
  if(p>n)return 0;
  int &ret=dp[p];
  if(~ret)return ret;
  return ret=1+solve(p+arr[p]+k);
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
  sc(n);
  for(int i=1;i<=n;++i)
    sc(arr[i]);
  memset(dp,-1,sizeof dp);
  sc(q);
  int p;
  while(q--){
    sc(p),sc(k);
    printf("%d\n",solve(p));
  }
}


#include <bits/stdc++.h>
using namespace std;

const int N = 100005, M = 501;
int mo[N][M], a[N], n, p, k;

void makemo(){
    for(int pp = n; pp; pp--)
        for(int kk = (int)sqrt(n); kk; kk--)
            if(pp + a[pp - 1] + kk <= n){
                mo[pp][kk] = mo[pp + a[pp - 1] + kk][kk] + 1;
            } else {
                mo[pp][kk] = 1;
            }
}

int query(){
    if(k <= sqrt(n)) return mo[p][k];
    int ans = 0;
    while(p <= n){
        p = p + a[p - 1] + k;
        ans++;
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    int q;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    makemo();
    cin >> q;
    while(q--){
        cin >> p >> k;
        cout << query() << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define clow order_of_key
#define key find_by_order
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordset;

const int N = 101001, M = 501;
int mo[N][M], a[N], n, p, k;

void makemo(){
    for(int pp = n; pp; pp--)
        for(int kk = (int)sqrt(n); kk; kk--)
            if(pp + a[pp - 1] + kk <= n)
                mo[pp][kk] = mo[pp + a[pp - 1] + kk][kk] + 1;
}

int query(){
    if(k <= sqrt(n)) return mo[p][k];
    int ans = 0;
    while(p <= n){
        p = p + a[p - 1] + k;
        ans++;
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    memset(mo, 0, sizeof mo);
    int q;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    makemo();
    cin >> q;
    while(q--){
        cin >> p >> k;
        cout << query() << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define clow order_of_key
#define key find_by_order
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordset;

const int N = 101001, M = 501;
int mo[N][M], a[N], n, p, k;

void makemo(){
    for(int pp = n; pp; pp--)
        for(int kk = (int)sqrt(n); kk; kk--)
            mo[pp][kk] = mo[pp + a[pp - 1] + kk][kk] + 1;
}

int query(){
    if(k <= sqrt(n)) return mo[p][k];
    int ans = 0;
    while(p <= n){
        p = p + a[p - 1] + k;
        ans++;
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    memset(mo, 0, sizeof mo);
    int q;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    makemo();
    cin >> q;
    while(q--){
        cin >> p >> k;
        cout << query() << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define clow order_of_key
#define key find_by_order
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordset;

const int N = 101001, M = 501;
int mo[N][M], a[N], n, p, k;

void makemo(){
    for(int pp = n; pp; pp--)
        for(int kk = (int)sqrt(n); kk; kk--)
            if(pp + a[pp - 1] + kk <= n){
                mo[pp][kk] = mo[pp + a[pp - 1] + kk][kk] + 1;
            } else {
                mo[pp][kk] = 1;
            }
}

int query(){
    if(k <= sqrt(n)) return mo[p][k];
    int ans = 0;
    while(p <= n){
        p = p + a[p - 1] + k;
        ans++;
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    memset(mo, 0, sizeof mo);
    int q;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    makemo();
    cin >> q;
    while(q--){
        cin >> p >> k;
        cout << query() << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define clow order_of_key
#define key find_by_order
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordset;

const int N = 101001, M = 1001;
int mo[N][M], a[N], n, p, k;

void makemo(){
    for(int pp = n; pp; pp--)
        for(int kk = (int)sqrt(n); kk; kk--)
            mo[pp][kk] = mo[pp + a[pp - 1] + kk][kk] + 1;
}

int query(){
    if(k <= sqrt(n)) return mo[p][k];
    int ans = 0;
    while(p <= n){
        p = p + a[p - 1] + k;
        ans++;
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    memset(mo, 0, sizeof mo);
    int q;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    makemo();
    cin >> q;
    while(q--){
        cin >> p >> k;
        cout << query() << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define clow order_of_key
#define key find_by_order
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordset;

const int N = 105001, M = 1001;
int mo[N][M], a[N], n, p, k;

void makemo(){
    for(int pp = n; pp; pp--)
        for(int kk = (int)sqrt(n); kk; kk--)
            mo[pp][kk] = mo[pp + a[pp - 1] + kk][kk] + 1;
}

int query(){
    if(k <= sqrt(n)) return mo[p][k];
    int ans = 0;
    while(p <= n){
        p = p + a[p - 1] + k;
        ans++;
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    memset(mo, 0, sizeof mo);
    int q;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    makemo();
    cin >> q;
    while(q--){
        cin >> p >> k;
        cout << query() << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define SZ(a) ((int)a.size())
//#pragma GCC optimize(2)
using namespace std;
const int N=1e6+1;
const int M=1e9+7;
const double eps=1e-6;
typedef complex<double>C;
const double PI(acos(-1.0));
//size() use int
//__gcd, atan2(y,x)=y/x , __int128
//c(n,k)=c(n-1,k-1)+c(n-1,k)
//c(i,r),i for r to n =c(n+1,r+1)
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//int sum(int x){return x?BIT[x]+sum(x-(x&-x)):0;}
//int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
//LL pw(LL a, LL b,LL M) { return b ? b & 1 ? a*pw(a, b - 1,M) % M : pw(a*a%M, b>>1,M) : 1; }
//log() = ln() , log(x)/log(y)=log(y)-base-x
//watch out LL
//INT_MAX 127,INT_MIN 128
int a[N],n,q,m,d[N],ans[N];
struct A{
	int p,k,id;
}Q[N];
bool cmp(A x,A y){return x.k<y.k;}
int find(int u,int k){
	if(u>n)return 0;
	if(d[u])return d[u];
	int t=find(u+a[u]+k,k)+1;
	return d[u]=t;
}
int main(){Accel
	cin>>n;
	FOR(i,1,n)cin>>a[i];
	cin>>m;
	REP(i,m){
		cin>>Q[i].p>>Q[i].k,Q[i].id=i;
	}
	sort(Q,Q+m,cmp);
	int tk=0;
	REP(i,m){
		if(Q[i].k!=tk){
			tk=Q[i].k;
			Re(d,0);
		}
		ans[Q[i].id]=find(Q[i].p,Q[i].k);
	}
	REP(i,m)cout<<ans[i]<<endl;
}


#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define SZ(a) ((int)a.size())
//#pragma GCC optimize(2)
using namespace std;
const int N=1e5+1;
const int K=sqrt(N);
const int M=1e9+7;
const double eps=1e-6;
typedef complex<double>C;
const double PI(acos(-1.0));
//size() use int
//__gcd, atan2(y,x)=y/x , __int128
//c(n,k)=c(n-1,k-1)+c(n-1,k)
//c(i,r),i for r to n =c(n+1,r+1)
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//int sum(int x){return x?BIT[x]+sum(x-(x&-x)):0;}
//int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
//LL pw(LL a, LL b,LL M) { return b ? b & 1 ? a*pw(a, b - 1,M) % M : pw(a*a%M, b>>1,M) : 1; }
//log() = ln() , log(x)/log(y)=log(y)-base-x
//watch out LL
//INT_MAX 127,INT_MIN 128
int a[N],n,q;
int f[N][K],sz;
int dfs(int p,int k){
	if(p>n)return 0;
	if(k<sz){
		if(f[p][k])return f[p][k];
		return f[p][k]=dfs(p+a[p]+k,k)+1;
	}
	return dfs(p+a[p]+k,k)+1;
}
int main(){Accel
	cin>>n;
	sz=sqrt(n);
	FOR(i,1,n)cin>>a[i];
	cin>>q;
	REP(i,q){
		int a,b;
		cin>>a>>b;
		cout<<dfs(a,b)<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n+1];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int nums[6];
    for (int i = 0; i < n; ++i) {
        if (a[i] == 4)
            nums[0]++;
        else if (a[i] == 8 && nums[1] < nums[0])
            nums[1]++;
        else if (a[i] == 15 && nums[2] < nums[1])
            nums[2]++;
        else if (a[i] == 16 && nums[3] < nums[2])
            nums[3]++;
        else if (a[i] == 23 && nums[4] < nums[3])
            nums[4]++;
        else if (a[i] == 42 && nums[5] < nums[4])
            nums[5]++;
    }
    cout << n - 6 * nums[5] << "\n";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n+1];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int nums[6]={0};
    for (int i = 0; i < n; ++i) {
        if (a[i] == 4)
            nums[0]++;
        else if (a[i] == 8 && nums[1] < nums[0])
            nums[1]++;
        else if (a[i] == 15 && nums[2] < nums[1])
            nums[2]++;
        else if (a[i] == 16 && nums[3] < nums[2])
            nums[3]++;
        else if (a[i] == 23 && nums[4] < nums[3])
            nums[4]++;
        else if (a[i] == 42 && nums[5] < nums[4])
            nums[5]++;
    }
    cout << n - 6 * nums[5] << "\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
int  a[500001];
int seq[6],s[6]={4,8,15,16,23,42};
int main()
{
    int n;
    cin>>n;
    for(int i=0 ;i<n ;i++)
    {
        scanf("%d",&a[i]);
        a[i]=lower_bound(s,s+6,a[i])-s;
    }
    for(int i=0 ;i<n ;i++)
    {
        if(a[i]==0)
        {
            seq[0]++;
        }
        else
        {
            if(seq[a[i]-1]>0)
            {
                --seq[a[i]-1];
                ++seq[a[i]];
            }
        }
    }

    printf("%d\n",-seq[5]*6+n);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=5e5+1;
int a[500001],idx[maxn];
stack<int> st;
int ans=0;int n;
int dfs(int id,int now)
{
    if(now==6)
    {
        ans++;
        return 0;
    }
    for(int i=id+1 ;i<n ;i++)
    {
        if(idx[i]==0&&a[i]==now+1)
        {
            now++;
            idx[i]=1;
            dfs(i,now);
            break;
        }
    }

}
int main()
{

    int zan;
    cin>>n;

    for(int i=0 ; i<n; i++)
    {
        scanf("%d",&zan);
        if(zan==4) zan=1;
        else if(zan==8) zan=2;
        else if(zan==15) zan=3;
        else if(zan==16) zan=4;
        else if(zan==23) zan=5;
        else if(zan==42) zan=6;
        a[i]=zan;
    }
    for(int i=0 ;i<n ;i++)
    {

        if(a[i]==1&&idx[i]==0)
        {
            idx[i]=1;
            dfs(i,1);
        }
    }
    //printf("%d\n",ans);
    n=n-ans*6;
    printf("%d\n",n);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 1;
int a[500001], idx[maxn];
queue<int> q[7];
int ans = 0;
int n;
int dfs(int now)
{
    if (now == 7)
    {
        ans++;
        return 0;
    }
    if(q[now].size())
    {
        ++now;
        q[now-1].pop();
        dfs(now);
    }

}
int main()
{

    int zan;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        scanf("%d", &zan);
        if (zan == 4)
            zan = 1;
        else if (zan == 8)
            zan = 2;
        else if (zan == 15)
            zan = 3;
        else if (zan == 16)
            zan = 4;
        else if (zan == 23)
            zan = 5;
        else if (zan == 42)
            zan = 6;
        a[i] = zan;
        q[zan].push(i);
    }
    while(!q[1].empty())
    {

        dfs(2);
        q[1].pop();

    }
    //printf("%d\n",ans);
    n = n - ans * 6;
    printf("%d\n", n);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[10]={};
int main()
{
    int n;

    int zan;
    cin>>n;
    for(int i=0 ; i<n; i++)
    {
        scanf("%d",&zan);
        if(zan==4) zan=1;
        else if(zan==8) zan=2;
        else if(zan==15) zan=3;
        else if(zan==16) zan=4;
        else if(zan==23) zan=5;
        else if(zan==42) zan=6;
        else zan=0;
        a[zan]++;
    }
    int minm=a[1];
    for(int i=2 ;i<=6 ;i++)
    {
        //printf("%d ",a[i]);
        if(a[i]<minm)
        {
            minm=a[i];
        }
    }
    printf("%d\n",n-minm*6);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[10];
int main()
{
    int n;

    int zan;
    cin>>n;
    for(int i=0 ; i<n; i++)
    {
        scanf("%d",&zan);
        if(zan==4) zan=1;
        else if(zan==8) zan=2;
        else if(zan==15) zan=3;
        else if(zan==16) zan=4;
        else if(zan==23) zan=5;
        else if(zan==42) zan=6;
        a[zan]++;
    }
    int minm=a[1];
    for(int i=2 ;i<=6 ;i++)
    {
        //printf("%d ",a[i]);
        if(a[i]<minm)
        {
            minm=a[i];
        }
    }
    printf("%d\n",n-minm*6);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=5e5+1;
int a[500001],idx[maxn];
stack<int> st;
int ans=0;int n;
int dfs(int id,int now)
{
    if(now==6)
    {
        ans++;
        return 0;
    }
    for(int i=id+1 ;i<n ;i++)
    {
        if(idx[i]==0&&a[i]==now+1)
        {
            now++;
            idx[i]=1;
            dfs(i,now);
        }
    }

}
int main()
{

    int zan;
    cin>>n;

    for(int i=0 ; i<n; i++)
    {
        scanf("%d",&zan);
        if(zan==4) zan=1;
        else if(zan==8) zan=2;
        else if(zan==15) zan=3;
        else if(zan==16) zan=4;
        else if(zan==23) zan=5;
        else if(zan==42) zan=6;
        a[i]=zan;
    }
    for(int i=0 ;i<n ;i++)
    {

        if(idx[i]==0&&a[i]==1)
        {
            idx[i]=1;
            dfs(i,1);
        }
    }
    //printf("%d\n",ans);
    n=n-ans*6;
    printf("%d\n",n);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[1000];
int main()
{

    int n;
    int ans=0;
    int zan;
    cin>>n;

    for(int i=0 ; i<n; i++)
    {
        scanf("%d",&zan);
        if(zan==4) zan=1;
        if(zan==8) zan=2;
        if(zan==15) zan=3;
        if(zan==16) zan=4;
        if(zan==23) zan=5;
        if(zan==42) zan=6;
        a[zan]++;
    }
    int minm=9999999;
    for(int i=1 ;i<7 ;i++)
    {
        //printf("%d ",a[i]);
        minm=min(a[i],minm);
    }
    printf("%d\n",n-minm*6);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 1;
int a[500001], idx[maxn];
vector< int> v[7];
int ans = 0;
int n;
int dfs(int id, int now)
{
    if (now == 7)
    {
        ans++;
        return 0;
    }
    int idi=upper_bound(v[now].begin(),v[now].end(),id)-v[now].begin();
    for (int i = idi; i < v[now].size(); i++)
    {
        int idz=v[now][i];
        if (idx[idz] == 0)
        {
            now++;
            idx[idz] = 1;
            dfs(idi, now);
            break;
        }
    }
}
int main()
{

    int zan;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        scanf("%d", &zan);
        if (zan == 4)
            zan = 1;
        else if (zan == 8)
            zan = 2;
        else if (zan == 15)
            zan = 3;
        else if (zan == 16)
            zan = 4;
        else if (zan == 23)
            zan = 5;
        else if (zan == 42)
            zan = 6;
        a[i] = zan;
        v[zan].push_back(i);
    }
    for (int i = 0; i < v[1].size(); i++)
    {
        int idz=v[1][i];
        if (idx[idz] == 0)
        {
            idx[idz] = 1;
            dfs(idz, 2);
        }
    }
    //printf("%d\n",ans);
    n = n - ans * 6;
    printf("%d\n", n);

    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
long long t[6],ans,n,s,a[110],k,h=9999999999;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	if(n<6)
		cout<<n<<endl;
	else
	{
		sort(a,a+n);
		int w=1;
		for(int i=1;i<n;i++)
		{
			if(a[i]==a[i-1] && i!=n-1)
				w++;
			else if(a[i]!=a[i-1] && i!=n-1)
			{
				t[k]=w;
				w=1;
				k++;
			}
			else
			{
				w++;
				t[k]=w;
				//cout<<k<<" "<<w<<endl;
				w=1;
				k++;
			}
		}
		for(int i=0;i<6;i++)
		{
			h=min(h,t[i]);
		//	cout<<t[i]<<endl;
		}
		for(int i=0;i<6;i++)
		{
			t[i]-=h;
			ans+=t[i];
		}
		cout<<ans<<endl;
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
long long t[6],ans,n,s,a[110],k,h=9999999999;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	if(n<6)
		cout<<n<<endl;
	else
	{
		sort(a,a+n);
		int w=1;
		for(int i=1;i<n;i++)
		{
			if(a[i]==a[i-1] && i!=n-1)
				w++;
			else if(a[i]!=a[i-1] && i!=n-1)
			{
				t[k]=w;
				w=1;
				k++;
			}
			else
			{
				if(a[i]!=a[i-1])
				{
					t[k]=w;
					k++;
					w=1;
				}
				else
					w++;
				t[k]=w;
				//cout<<k<<" "<<w<<endl;
				w=1;
				k++;
			}
		}
		for(int i=0;i<6;i++)
		{
			h=min(h,t[i]);
			//cout<<t[i]<<endl;
		}
		for(int i=0;i<6;i++)
		{
			t[i]-=h;
			ans+=t[i];
		}
		cout<<ans<<endl;
	}
}


/*  C++ Template for Competetive Coding
 $ All functions in template has suffix "Function"
 $ Sieve,Factorial,BinaryExpo,ModInverse
 $ FASTIO !!

 -Anuj Mittal
 unusual_wonder
 */
#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int a,int n)//binary exponentation
{
    int r;
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
        r=powerFunction(a,n/2);
    if(n%2==0)
        return ((r)%MOD)*((r)%MOD)%MOD;
    else
        return ((r)%MOD)*((r)%MOD)*((a)%MOD)%MOD;
}
int modInverseFunctionFunction(int no) {
    int inverse=1;
    while(P>0){
        if(P&1){
            inverse=(inverse%MOD*no%MOD)%MOD;
        }
        no=(no%MOD*no%MOD)%MOD;
        P=P/2;
    }
    P=MOD-2;
    return inverse%MOD;
}
void sieveFunction(int maxLimit)
{
    memset(prime, true, sizeof(prime));
    prime[0]=prime[1]=false;
    for(int i=2;maxLimit>=i;i++)
    {
        if(prime[i])
        {
            for(int j=2*i;maxLimit>j;j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit)
{
    factorial[0]=1;
    for(int i=1;i<=maxLimit;i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int GCD(int a, int b)
{
    // Everything divides 0
    if (a == 0)
        return b;
    if (b == 0)
        return a;
    // base case
    if (a == b)
        return a;
    // a is greater
    if (a > b)
        return GCD(a%b, b);
    return GCD(a, b%a);
}

signed main()
{
    int n;
    cin>>n;
    int arr[n];
    vector<int> v[43];
    for(int i=0;n>i;i++)
    {
        cin>>arr[i];
        v[arr[i]].push_back(i);
    }
    int ans=0;
    int mark[n];
    memset(mark, 0, sizeof(mark));
    for(int i=0;v[4].size()>i;i++)
    {
        for(int j=0;v[8].size()>j;j++)
        {
            if(v[8][j]<v[4][i] || mark[j])
                continue;
            for(int k=0;v[15].size()>k;k++)
            {
                if(v[15][k]<v[8][j]||mark[k])
                    continue;
                for(int l=0;v[16].size()>l;l++)
                {
                    if(v[16][l]<v[15][k]||mark[l])
                        continue;
                    for(int m=0;v[23].size()>m;m++)
                    {
                        if(v[23][m]<v[16][l]||mark[m])
                            continue;
                        for(int z=0;v[42].size()>z;z++)
                        {
                            if(v[42][z]<v[23][m]||mark[z])
                                continue;
                            else
                            {
                                ans++;
                                mark[i]=mark[j]=mark[k]=mark[l]=mark[m]=mark[z]=1;
                                goto l;
                            }

                        }
                    }
                }
            }
        }
    l:
        continue;
    }
    cout<<n-ans*6<<endl;
}


/*  C++ Template for Competetive Coding
 $ All functions in template has suffix "Function"
 $ Sieve,Factorial,BinaryExpo,ModInverse
 $ FASTIO !!

 -Anuj Mittal
 unusual_wonder
 */
#include <bits/stdc++.h>
//#define int long long
#define MOD 1000000007
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int a,int n)//binary exponentation
{
    int r;
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
        r=powerFunction(a,n/2);
    if(n%2==0)
        return ((r)%MOD)*((r)%MOD)%MOD;
    else
        return ((r)%MOD)*((r)%MOD)*((a)%MOD)%MOD;
}
int modInverseFunctionFunction(int no) {
    int inverse=1;
    while(P>0){
        if(P&1){
            inverse=(inverse%MOD*no%MOD)%MOD;
        }
        no=(no%MOD*no%MOD)%MOD;
        P=P/2;
    }
    P=MOD-2;
    return inverse%MOD;
}
void sieveFunction(int maxLimit)
{
    memset(prime, true, sizeof(prime));
    prime[0]=prime[1]=false;
    for(int i=2;maxLimit>=i;i++)
    {
        if(prime[i])
        {
            for(int j=2*i;maxLimit>j;j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit)
{
    factorial[0]=1;
    for(int i=1;i<=maxLimit;i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int GCD(int a, int b)
{
    // Everything divides 0
    if (a == 0)
        return b;
    if (b == 0)
        return a;
    // base case
    if (a == b)
        return a;
    // a is greater
    if (a > b)
        return GCD(a%b, b);
    return GCD(a, b%a);
}

signed main()
{
    int n;
    cin>>n;
    int arr[n];
    vector<int> v[43];
    for(int i=0;n>i;i++)
    {
        cin>>arr[i];
        v[arr[i]].push_back(i);
    }
    int ans=0;
    int mark[n];
    memset(mark, 0, sizeof(mark));
    int aaa[43];
    memset(aaa, 0, sizeof(aaa));
    for(int i=0;v[4].size()>i;i++)
    {
        for(int j=aaa[8];v[8].size()>j;j++)
        {
            if(v[8][j]<v[4][i] || mark[v[8][j]])
                continue;
            for(int k=aaa[15];v[15].size()>k;k++)
            {
                if(v[15][k]<v[8][j]||mark[v[15][k]])
                   continue;
                for(int l=aaa[16];v[16].size()>l;l++)
                {
                    if(v[16][l]<v[15][k]||mark[v[16][l]])
                       continue;
                    for(int m=aaa[23];v[23].size()>m;m++)
                    {
                        if(v[23][m]<v[16][l]||mark[v[23][m]])
                            continue;
                        for(int z=aaa[42];v[42].size()>z;z++)
                        {
                            if(v[42][z]<v[23][m]||mark[v[42][z]])
                                continue;
                            else
                            {
                                ans++;
                                mark[v[4][i]]=mark[v[8][j]]=mark[v[15][k]]=mark[v[16][l]]=mark[v[23][m]]=mark[v[42][z]]=1;
                                aaa[4]+=1;
                                aaa[8]+=1;
                                aaa[15]+=1;
                                aaa[16]+=1;
                                aaa[23]+=1;
                                aaa[42]+=1;
                                goto l;
                            }

                        }
                    }
                }
            }
        }
    l:
        continue;
    }
    cout<<n-ans*6<<endl;
}


/*  C++ Template for Competetive Coding
 $ All functions in template has suffix "Function"
 $ Sieve,Factorial,BinaryExpo,ModInverse
 $ FASTIO !!

 -Anuj Mittal
 unusual_wonder
 */
#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int a,int n)//binary exponentation
{
    int r;
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
        r=powerFunction(a,n/2);
    if(n%2==0)
        return ((r)%MOD)*((r)%MOD)%MOD;
    else
        return ((r)%MOD)*((r)%MOD)*((a)%MOD)%MOD;
}
int modInverseFunctionFunction(int no) {
    int inverse=1;
    while(P>0){
        if(P&1){
            inverse=(inverse%MOD*no%MOD)%MOD;
        }
        no=(no%MOD*no%MOD)%MOD;
        P=P/2;
    }
    P=MOD-2;
    return inverse%MOD;
}
void sieveFunction(int maxLimit)
{
    memset(prime, true, sizeof(prime));
    prime[0]=prime[1]=false;
    for(int i=2;maxLimit>=i;i++)
    {
        if(prime[i])
        {
            for(int j=2*i;maxLimit>j;j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit)
{
    factorial[0]=1;
    for(int i=1;i<=maxLimit;i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int GCD(int a, int b)
{
    // Everything divides 0
    if (a == 0)
        return b;
    if (b == 0)
        return a;
    // base case
    if (a == b)
        return a;
    // a is greater
    if (a > b)
        return GCD(a%b, b);
    return GCD(a, b%a);
}

signed main()
{
    int n;
    cin>>n;
    int arr[n];
    vector<int> v[43];
    for(int i=0;n>i;i++)
    {
        cin>>arr[i];
        v[arr[i]].push_back(i);
    }
    int ans=0;
    int mark[n];
    memset(mark, 0, sizeof(mark));
    int aaa[43];
    memset(aaa, 0, sizeof(aaa));
    for(int i=0;v[4].size()>i;i++)
    {
        for(int j=aaa[8];v[8].size()>j;j++)
        {
            if(v[8][j]<v[4][i] || mark[v[8][j]])
                continue;
            for(int k=aaa[15];v[15].size()>k;k++)
            {
                if(v[15][k]<v[8][j]||mark[v[15][k]])
                   continue;
                for(int l=aaa[16];v[16].size()>l;l++)
                {
                    if(v[16][l]<v[15][k]||mark[v[16][l]])
                       continue;
                    for(int m=aaa[23];v[23].size()>m;m++)
                    {
                        if(v[23][m]<v[16][l]||mark[v[23][m]])
                            continue;
                        for(int z=aaa[42];v[42].size()>z;z++)
                        {
                            if(v[42][z]<v[23][m]||mark[v[42][z]])
                                continue;
                            else
                            {
                                ans++;
                                mark[v[4][i]]=mark[v[8][j]]=mark[v[15][k]]=mark[v[16][l]]=mark[v[23][m]]=mark[v[42][z]]=1;
                                aaa[4]+=1;
                                aaa[8]+=1;
                                aaa[15]+=1;
                                aaa[16]+=1;
                                aaa[23]+=1;
                                aaa[42]+=1;
                                goto l;
                            }

                        }
                    }
                }
            }
        }
    l:
        continue;
    }
    cout<<n-ans*6<<endl;
}


/*  C++ Template for Competetive Coding
 $ All functions in template has suffix "Function"
 $ Sieve,Factorial,BinaryExpo,ModInverse
 $ FASTIO !!

 -Anuj Mittal
 unusual_wonder
 */
#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int a,int n)//binary exponentation
{
    int r;
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
        r=powerFunction(a,n/2);
    if(n%2==0)
        return ((r)%MOD)*((r)%MOD)%MOD;
    else
        return ((r)%MOD)*((r)%MOD)*((a)%MOD)%MOD;
}
int modInverseFunctionFunction(int no) {
    int inverse=1;
    while(P>0){
        if(P&1){
            inverse=(inverse%MOD*no%MOD)%MOD;
        }
        no=(no%MOD*no%MOD)%MOD;
        P=P/2;
    }
    P=MOD-2;
    return inverse%MOD;
}
void sieveFunction(int maxLimit)
{
    memset(prime, true, sizeof(prime));
    prime[0]=prime[1]=false;
    for(int i=2;maxLimit>=i;i++)
    {
        if(prime[i])
        {
            for(int j=2*i;maxLimit>j;j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit)
{
    factorial[0]=1;
    for(int i=1;i<=maxLimit;i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int GCD(int a, int b)
{
    // Everything divides 0
    if (a == 0)
        return b;
    if (b == 0)
        return a;
    // base case
    if (a == b)
        return a;
    // a is greater
    if (a > b)
        return GCD(a%b, b);
    return GCD(a, b%a);
}

signed main()
{
    int n;
    cin>>n;
    int arr[n];
    vector<int> v[43];
    for(int i=0;n>i;i++)
    {
        cin>>arr[i];
        v[arr[i]].push_back(i);
    }
    int ans=0;
    int mark[n];
    memset(mark, 0, sizeof(mark));
    for(int i=0;v[4].size()>i;i++)
    {
        for(int j=0;v[8].size()>j;j++)
        {
            if(v[8][j]<v[4][i] || mark[j])
                continue;
            for(int k=0;v[15].size()>k;k++)
            {
                if(v[15][k]<v[8][j]||mark[k])
                    continue;
                for(int l=0;v[16].size()>l;l++)
                {
                    if(v[16][l]<v[15][k]||mark[l])
                        continue;
                    for(int m=0;v[23].size()>m;m++)
                    {
                        if(v[23][m]<v[16][l]||mark[m])
                            continue;
                        for(int z=0;v[42].size()>z;z++)
                        {
                            if(v[42][z]<v[23][m]||mark[z])
                                continue;
                            else
                            {
                                ans++;
                                mark[i]=mark[j]=mark[k]=mark[l]=mark[m]=mark[z]=1;
                            }

                        }
                    }
                }
            }
        }
    }
    cout<<n-ans*6<<endl;
}


/*  C++ Template for Competetive Coding
 $ All functions in template has suffix "Function"
 $ Sieve,Factorial,BinaryExpo,ModInverse
 $ FASTIO !!

 -Anuj Mittal
 unusual_wonder
 */
#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int a,int n)//binary exponentation
{
    int r;
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
        r=powerFunction(a,n/2);
    if(n%2==0)
        return ((r)%MOD)*((r)%MOD)%MOD;
    else
        return ((r)%MOD)*((r)%MOD)*((a)%MOD)%MOD;
}
int modInverseFunctionFunction(int no) {
    int inverse=1;
    while(P>0){
        if(P&1){
            inverse=(inverse%MOD*no%MOD)%MOD;
        }
        no=(no%MOD*no%MOD)%MOD;
        P=P/2;
    }
    P=MOD-2;
    return inverse%MOD;
}
void sieveFunction(int maxLimit)
{
    memset(prime, true, sizeof(prime));
    prime[0]=prime[1]=false;
    for(int i=2;maxLimit>=i;i++)
    {
        if(prime[i])
        {
            for(int j=2*i;maxLimit>j;j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit)
{
    factorial[0]=1;
    for(int i=1;i<=maxLimit;i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int GCD(int a, int b)
{
    // Everything divides 0
    if (a == 0)
        return b;
    if (b == 0)
        return a;
    // base case
    if (a == b)
        return a;
    // a is greater
    if (a > b)
        return GCD(a%b, b);
    return GCD(a, b%a);
}

signed main()
{
    int n;
    cin>>n;
    int arr[n];
    vector<int> v[43];
    for(int i=0;n>i;i++)
    {
        cin>>arr[i];
        v[arr[i]].push_back(i);
    }
    int ans=0;
    int mark[n];
    memset(mark, 0, sizeof(mark));
    for(int i=0;v[4].size()>i;i++)
    {
        for(int j=0;v[8].size()>j;j++)
        {
            if(v[8][j]<v[4][i] || mark[v[8][j]])
                continue;
            for(int k=0;v[15].size()>k;k++)
            {
                if(v[15][k]<v[8][j]||mark[v[15][k]])
                    continue;
                for(int l=0;v[16].size()>l;l++)
                {
                    if(v[16][l]<v[15][k]||mark[v[16][l]])
                        continue;
                    for(int m=0;v[23].size()>m;m++)
                    {
                        if(v[23][m]<v[16][l]||mark[v[23][m]])
                            continue;
                        for(int z=0;v[42].size()>z;z++)
                        {
                            if(v[42][z]<v[23][m]||mark[v[42][z]])
                                continue;
                            else
                            {
                                ans++;
                                mark[v[4][i]]=mark[v[8][j]]=mark[v[15][k]]=mark[v[16][l]]=mark[v[23][m]]=mark[v[42][z]]=1;
                                goto l;
                            }

                        }
                    }
                }
            }
        }
    l:
        continue;
    }
    cout<<n-ans*6<<endl;
}