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;
pair<int, int> Li[200050];
int v[200050], Dif[200050], sx[200050], sy[200050], sg[200050], li[200050],
    st[200050][18], d[200050];
int n, m, ans;
inline int Read() {
  int x = 0;
  char y;
  do y = getchar();
  while (y < '0' || y > '9');
  do x = x * 10 + y - '0', y = getchar();
  while (y >= '0' && y <= '9');
  return x;
}
void Doubly(int x) {
  int Cnt = 0;
  for (int i = n * 2 - x; i < n * 2; i++) sy[++Cnt] = i;
  for (int i = 1; i < n * 2; i++)
    if (sx[i] > x) sy[++Cnt] = sx[i] - x;
  memset(d, 0, sizeof(d));
  for (int i = 1; i < n * 2; i++) d[li[i]]++;
  for (int i = 1; i < n * 2; i++) d[i] += d[i - 1];
  for (int i = 1; i < n * 2; i++) sx[++d[li[sy[i]] - 1]] = sy[i];
  memset(d, 0, sizeof(d));
  d[sx[1]] = 1;
  for (int i = 2; i < n * 2; i++)
    d[sx[i]] =
        d[sx[i - 1]] + 1 -
        (li[sx[i]] == li[sx[i - 1]] && li[sx[i] + x] == li[sx[i - 1] + x]);
  for (int i = 1; i < n * 2; i++) li[i] = d[i];
  return;
}
void SA() {
  for (int i = 1; i < n * 2; i++) Li[i] = make_pair(Dif[i], i);
  sort(Li + 1, Li + n * 2);
  for (int i = 1; i < n * 2; i++) sx[i] = Li[i].second;
  li[Li[1].second] = 1;
  for (int i = 2; i < n * 2; i++)
    li[Li[i].second] = (Li[i].first != Li[i - 1].first) + li[Li[i - 1].second];
  for (int i = 1; i < n * 2 - 1; i <<= 1) Doubly(i);
  int Cnt = 0;
  for (int i = 1; i < n * 2; i++) {
    Cnt = Cnt ? --Cnt : 0;
    if (li[i] == 1) continue;
    while (sx[li[i] - 1] + Cnt < n * 2 &&
           Dif[i + Cnt] == Dif[sx[li[i] - 1] + Cnt])
      Cnt++;
    st[li[i] - 1][0] = Cnt;
  }
  return;
}
struct Node {
  Node* c[2];
  int sz;
} * rt[200050];
namespace Chairman_Tree {
Node *cur, statePool[5000050], Emp, *emp;
inline Node* GetNew() {
  cur->c[0] = cur->c[1] = emp;
  return cur++;
}
Node* Insert(int x, int y, Node* z, int o) {
  int mid = x + y >> 1;
  Node* New = GetNew();
  New->sz = z->sz + 1;
  if (x != y)
    if (o <= mid)
      New->c[1] = z->c[1], New->c[0] = Insert(x, mid, z->c[0], o);
    else
      New->c[0] = z->c[0], New->c[1] = Insert(mid + 1, y, z->c[1], o);
  return New;
}
int Query(int x, int y, Node* z, Node* o, int p, int u) {
  int mid = x + y >> 1;
  if (x == p && y == u) return z->sz - o->sz;
  if (u <= mid)
    return Query(x, mid, z->c[0], o->c[0], p, u);
  else if (p > mid)
    return Query(mid + 1, y, z->c[1], o->c[1], p, u);
  else
    return Query(x, mid, z->c[0], o->c[0], p, mid) +
           Query(mid + 1, y, z->c[1], o->c[1], mid + 1, u);
}
void Set_up() {
  cur = statePool;
  emp = rt[0] = &Emp;
  emp->c[0] = emp->c[1] = emp;
  for (int i = 1; i < n * 2; i++)
    rt[i] = Insert(1, n * 2 - 1, rt[i - 1], sx[i]);
  return;
}
}  // namespace Chairman_Tree
void Pretreat() {
  for (int i = 1; i < n; i++) Dif[i] = v[i + 1] - v[i];
  Dif[n] = 0x3f7f7f7f;
  for (int i = 1; i < n; i++) Dif[n + i] = -Dif[i];
  SA();
  for (int j = 1; j < 18; j++)
    for (int i = 1; i < n * 2; i++)
      if (st[i][j - 1])
        st[i][j] = min(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);
  Chairman_Tree::Set_up();
  return;
}
void GetBorder(int x, int y, int& z, int& o) {
  y -= x;
  z = o = li[x];
  for (int i = 18 - 1; ~i; i--) {
    if (z > 1 << i && st[z - (1 << i)][i] >= y) z -= 1 << i;
    if (st[o][i] >= y) o += 1 << i;
  }
  return;
}
int main() {
  n = Read();
  for (int i = 1; i <= n; i++) v[i] = Read();
  Pretreat();
  m = Read();
  while (m--) {
    int k = Read(), l = Read(), Le, Ri;
    if (k == l) {
      printf("%d\n", n - 1);
      continue;
    }
    GetBorder(k, l, Le, Ri);
    ans = 0;
    if (k - 1 << 1 >= l)
      ans = Chairman_Tree::Query(1, n * 2 - 1, rt[Ri], rt[Le - 1], n + 1,
                                 n + 2 * k - l - 1);
    if (n + l + 1 <= 2 * n - 1)
      ans += Chairman_Tree::Query(1, n * 2 - 1, rt[Ri], rt[Le - 1], n + l + 1,
                                  2 * n - 1);
    printf("%d\n", ans);
  }
  return 0;
}