Problem: John Doe has a crooked fence, consisting of n rectangular planks, lined up from the left to the right: the plank that goes i-th (1 ≤ i ≤ n) (from left to right) has width 1 and height hi. We will assume that the plank that goes i-th (1 ≤ i ≤ n) (from left to right) has index i.

A piece of the fence from l to r (1 ≤ l ≤ r ≤ n) is a sequence of planks of wood with indices from l to r inclusive, that is, planks with indices l, l + 1, ..., r. The width of the piece of the fence from l to r is value r - l + 1.

Two pieces of the fence from l1 to r1 and from l2 to r2 are called matching, if the following conditions hold:

  * the pieces do not intersect, that is, there isn't a single plank, such that it occurs in both pieces of the fence; 
  * the pieces are of the same width; 
  * for all i (0 ≤ i ≤ r1 - l1) the following condition holds: hl1 + i + hl2 + i = hl1 + hl2. 



John chose a few pieces of the fence and now wants to know how many distinct matching pieces are for each of them. Two pieces of the fence are distinct if there is a plank, which belongs to one of them and does not belong to the other one.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of wood planks in the fence. The second line contains n space-separated integers h1, h2, ..., hn (1 ≤ hi ≤ 109) — the heights of fence planks.

The third line contains integer q (1 ≤ q ≤ 105) — the number of queries. Next q lines contain two space-separated integers li and ri (1 ≤ li ≤ ri ≤ n) — the boundaries of the i-th piece of the fence.

Output

For each query on a single line print a single integer — the number of pieces of the fence that match the given one. Print the answers to the queries in the order, in which the queries are given in the input.

Examples

Input

10
1 2 2 1 100 99 99 100 100 100
6
1 4
1 2
3 4
1 5
9 10
10 10


Output

1
2
2
0
2
9

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int data = 0, w = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    data = (data << 1) + (data << 3) + (ch ^ 48), ch = getchar();
  return data * w;
}
int n, q, len[1000005], pr[1000005], tot = 1, last = 1;
map<int, int> ch[400005];
void insert(int x) {
  int p = last, np = ++tot;
  len[np] = len[p] + 1;
  while (p && !ch[p][x]) ch[p][x] = np, p = pr[p];
  if (!p)
    pr[np] = 1;
  else {
    int q = ch[p][x];
    if (len[q] == len[p] + 1)
      pr[np] = q;
    else {
      int nq = ++tot;
      len[nq] = len[p] + 1;
      ch[nq] = ch[q];
      pr[nq] = pr[q];
      pr[np] = pr[q] = nq;
      while (ch[p][x] == q) ch[p][x] = nq, p = pr[p];
    }
  }
  last = np;
}
int pos[1000005], pos2[1000005], p[400005][25], h[1000005];
vector<int> v[400005];
int rt[1000005], sum[13 * 1000005], ls[13 * 1000005], rs[13 * 1000005], cnt;
int insert(int x, int l, int r, int pos) {
  if (!x) x = ++cnt;
  sum[x]++;
  if (l == r) return x;
  int mid = l + r >> 1;
  (pos <= mid) ? ls[x] = insert(ls[x], l, mid, pos)
               : rs[x] = insert(rs[x], mid + 1, r, pos);
  return x;
}
int ask(int x, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return sum[x];
  int mid = (l + r) >> 1, ans = 0;
  if (ql <= mid) ans += ask(ls[x], l, mid, ql, qr);
  if (mid < qr) ans += ask(rs[x], mid + 1, r, ql, qr);
  return ans;
}
int merge(int x, int y, int l, int r) {
  if (!x || !y) return x | y;
  int mid = (l + r) >> 1;
  int z = ++cnt;
  sum[z] = sum[x] + sum[y];
  if (l == r) return z;
  ls[z] = merge(ls[x], ls[y], l, mid);
  rs[z] = merge(rs[x], rs[y], mid + 1, r);
  return z;
}
void dfs(int x) {
  p[x][0] = pr[x];
  for (int i = 1; i <= 18; i++) p[x][i] = p[p[x][i - 1]][i - 1];
  for (auto y : v[x]) dfs(y), rt[x] = merge(rt[x], rt[y], 1, n);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) h[i] = read();
  for (int i = n; i >= 1; i--) h[i] -= h[i - 1];
  for (int i = 2; i <= n; i++) insert(h[i]), pos[i] = last;
  insert((int)2e9);
  for (int i = 2; i <= n; i++)
    insert(-h[i]), rt[last] = insert(rt[last], 1, n, i);
  for (int i = 2; i <= tot; i++) v[pr[i]].push_back(i);
  dfs(1);
  q = read();
  while (q--) {
    int l = read(), r = read(), x = pos[r];
    if (l == r) {
      cout << n - 1 << '\n';
      continue;
    }
    for (int i = 18; i >= 0; i--)
      if (len[p[x][i]] >= r - l) x = p[x][i];
    int ans = 0;
    if (r - l + 1 <= l - 1) ans += ask(rt[x], 1, n, r - l + 1, l - 1);
    if (r + r - l + 1 <= n) ans += ask(rt[x], 1, n, r + r - l + 1, n);
    cout << ans << '\n';
  }
  return 0;
}