#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;
}
