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() {
  int x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return x * f;
}
const int N = 200010, LOG = 19, INF = 0x3f3f3f3f;
struct node {
  int ch[2], sumv;
} T[N * LOG];
int root[N], lt;
inline void pushup(int o) {
  T[o].sumv = T[T[o].ch[0]].sumv + T[T[o].ch[1]].sumv;
}
void qadd(int& o, int rt, int l, int r, int x, int v) {
  o = ++lt, T[o] = T[rt];
  if (l == r) {
    T[o].sumv += v;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    qadd(T[o].ch[0], T[rt].ch[0], l, mid, x, v);
  else
    qadd(T[o].ch[1], T[rt].ch[1], mid + 1, r, x, v);
  pushup(o);
}
int qask(int o, int rt, int l, int r, int x, int y) {
  if (x <= l && r <= y) return T[o].sumv - T[rt].sumv;
  int mid = (l + r) >> 1;
  if (y <= mid)
    return qask(T[o].ch[0], T[rt].ch[0], l, mid, x, y);
  else if (x > mid)
    return qask(T[o].ch[1], T[rt].ch[1], mid + 1, r, x, y);
  else
    return qask(T[o].ch[0], T[rt].ch[0], l, mid, x, mid) +
           qask(T[o].ch[1], T[rt].ch[1], mid + 1, r, mid + 1, y);
}
int a[N], Hash[N], lh, c[N], x[N], y[N], sa[N], h[N], rk[N], mn[LOG][N], bit[N];
void tsort(int n, int m) {
  for (int i = 1; i <= m; ++i) c[i] = 0;
  for (int i = 1; i <= n; ++i) ++c[x[i]];
  for (int i = 1; i <= m; ++i) c[i] += c[i - 1];
  for (int i = n; i; --i) sa[c[x[y[i]]]--] = y[i];
}
void geth(int n) {
  for (int i = 1; i <= n; ++i) rk[sa[i]] = i;
  for (int i = 1, p = 0; i <= n; ++i) {
    if (p) --p;
    int j = sa[rk[i] - 1];
    while (a[i + p] == a[j + p]) ++p;
    h[rk[i]] = p;
  }
}
void getT(int n) {
  for (int i = 1; i <= n; ++i) qadd(root[i], root[i - 1], 1, n, sa[i], 1);
}
void getmn(int n) {
  for (int i = 1; i <= n; ++i)
    mn[0][i] = h[i], bit[i] = bit[i - 1] + ((1 << (bit[i - 1] + 1)) < i);
  for (int i = 1; i <= bit[n]; ++i) {
    for (int j = 1; j <= n; ++j)
      mn[i][j] = min(mn[i - 1][j], mn[i - 1][j + (1 << (i - 1))]);
  }
}
inline int qmin(int x, int y) {
  int k = bit[y - x + 1];
  return min(mn[k][x], mn[k][y - (1 << k) + 1]);
}
void getsa(int n) {
  int m = lh;
  for (int i = 1; i <= n; ++i) x[i] = a[i], y[i] = i;
  tsort(n, m);
  for (int k = 1; k <= n; k <<= 1) {
    int p = 0;
    for (int i = n - k + 1; i <= n; ++i) y[++p] = i;
    for (int i = 1; i <= n; ++i)
      if (sa[i] > k) y[++p] = sa[i] - k;
    tsort(n, m), swap(x, y);
    p = 1, x[sa[1]] = 1;
    for (int i = 2; i <= n; ++i)
      x[sa[i]] = (y[sa[i]] == y[sa[i - 1]] && y[sa[i] + k] == y[sa[i - 1] + k])
                     ? p
                     : ++p;
    if (p == n) break;
    m = p;
  }
  geth(n);
  getmn(n);
  getT(n);
}
int findleft(int l, int r, int x, int len) {
  while (l < r) {
    int mid = (l + r) >> 1;
    if (qmin(mid, x) >= len)
      r = mid;
    else
      l = mid + 1;
  }
  return (l == x && h[x] < len) ? l : l - 1;
}
int findright(int l, int r, int x, int len) {
  while (l < r) {
    int mid = (l + r) >> 1;
    if (qmin(x, mid) >= len)
      l = mid + 1;
    else
      r = mid;
  }
  return l - 1;
}
int main() {
  int n = read(), m = n * 2 - 1;
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = 1; i < n; ++i) Hash[++lh] = a[i] = a[i + 1] - a[i];
  Hash[++lh] = a[n] = INF;
  for (int i = 1; i < n; ++i) Hash[++lh] = a[i + n] = -a[i];
  sort(Hash + 1, Hash + lh + 1);
  lh = unique(Hash + 1, Hash + lh + 1) - Hash - 1;
  for (int i = 1; i < (n << 1); ++i)
    a[i] = lower_bound(Hash + 1, Hash + lh + 1, a[i]) - Hash;
  getsa(m);
  int Q = read();
  while (Q--) {
    int l = read(), r = read();
    if (l == r) {
      printf("%d\n", n - 1);
      continue;
    }
    int x = rk[n + l], len = r - l;
    int L = findleft(1, x, x, len), R = findright(x + 1, m, x + 1, len),
        ans = 0;
    if (l > len + 1) ans += qask(root[R], root[L - 1], 1, m, 1, l - len - 1);
    if (r + len + 1 <= n)
      ans += qask(root[R], root[L - 1], 1, m, r + 1, n - len);
    printf("%d\n", ans);
  }
  return 0;
}