#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const int mx = 1e5 + 5;
struct query {
  int start;
  int inc;
  int id;
  bool operator<(const query &a) const {
    if (a.inc != inc) return inc > a.inc;
    return id < a.id;
  }
};
int ara[mx], dp[mx], ans[mx];
query ques[mx];
int n, k;
int f(int p) {
  if (p > n) return 0;
  int &ans = dp[p];
  if (ans != -1) return ans;
  return ans = 1 + f(p + ara[p] + k);
}
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> ara[i];
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> ques[i].start >> ques[i].inc;
    ques[i].id = i;
  }
  sort(ques + 1, ques + q + 1);
  k = -1;
  for (int i = 1; i <= q; i++) {
    if (k != ques[i].inc) memset(dp, -1, sizeof dp);
    k = ques[i].inc;
    ans[ques[i].id] = f(ques[i].start);
  }
  for (int i = 1; i <= q; i++) cout << ans[i] << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}

### Prompt

Your challenge is to write a Cpp solution to the following problem:

a is an array of n positive integers, all of which are not greater than n.

You have to process q queries to this array. Each query is represented by two numbers p and k. Several operations are performed in each query; each operation changes p to p + ap + k. There operations are applied until p becomes greater than n. The answer to the query is the number of performed operations.

Input

The first line contains one integer n (1 ≤ n ≤ 100000).

The second line contains n integers — elements of a (1 ≤ ai ≤ n for each i from 1 to n).

The third line containts one integer q (1 ≤ q ≤ 100000).

Then q lines follow. Each line contains the values of p and k for corresponding query (1 ≤ p, k ≤ n).

Output

Print q integers, ith integer must be equal to the answer to ith query.

Example

Input

3
1 1 1
3
1 1
2 1
3 1


Output

2
1
1

Note

Consider first example:

In first query after first operation p = 3, after second operation p = 5.

In next two queries p is greater than n after the first operation.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const int mx = 1e5 + 5;
struct query {
  int start;
  int inc;
  int id;
  bool operator<(const query &a) const {
    if (a.inc != inc) return inc > a.inc;
    return id < a.id;
  }
};
int ara[mx], dp[mx], ans[mx];
query ques[mx];
int n, k;
int f(int p) {
  if (p > n) return 0;
  int &ans = dp[p];
  if (ans != -1) return ans;
  return ans = 1 + f(p + ara[p] + k);
}
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> ara[i];
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> ques[i].start >> ques[i].inc;
    ques[i].id = i;
  }
  sort(ques + 1, ques + q + 1);
  k = -1;
  for (int i = 1; i <= q; i++) {
    if (k != ques[i].inc) memset(dp, -1, sizeof dp);
    k = ques[i].inc;
    ans[ques[i].id] = f(ques[i].start);
  }
  for (int i = 1; i <= q; i++) cout << ans[i] << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}

```