#include <bits/stdc++.h>
using namespace std;
int n, tot;
int b[400005], s[400005], sa[400005], ra[400005], height[400005], nue[400005],
    sum[400005];
int st[400005][25], tree[400005], lc[400005 * 40], rc[400005 * 40],
    a[400005 * 40];
bool cmp(int x, int y) {
  if (s[x] != s[y]) return s[x] < s[y];
  return x < y;
}
void build_sa() {
  n = n * 2 - 1;
  for (int i = 1; i <= n; i++) sa[i] = i;
  sort(sa + 1, sa + n + 1, cmp);
  ra[sa[1]] = 1;
  for (int i = 2; i <= n; i++) {
    if (s[sa[i]] == s[sa[i - 1]]) {
      ra[sa[i]] = ra[sa[i - 1]];
    } else {
      ra[sa[i]] = ra[sa[i - 1]] + 1;
    }
  }
  for (int k = 1; k <= n; k <<= 1) {
    int ge = 0;
    for (int i = n - k + 1; i <= n; i++) nue[++ge] = i;
    for (int i = 1; i <= n; i++) {
      sum[i] = 0;
      if (sa[i] > k) nue[++ge] = sa[i] - k;
    }
    for (int i = 1; i <= n; i++) sum[ra[i]]++;
    for (int i = 2; i <= n; i++) sum[i] += sum[i - 1];
    for (int i = n; i; i--) {
      sa[sum[ra[nue[i]]]--] = nue[i];
    }
    swap(ra, nue);
    ra[sa[1]] = 1;
    for (int i = 2; i <= n; i++) {
      if (nue[sa[i]] > nue[sa[i - 1]] || sa[i - 1] + k > n ||
          nue[sa[i] + k] != nue[sa[i - 1] + k]) {
        ra[sa[i]] = ra[sa[i - 1]] + 1;
      } else {
        ra[sa[i]] = ra[sa[i - 1]];
      }
    }
  }
  int h = 0;
  for (int i = 1; i <= n; i++) {
    if (ra[i] == 1) continue;
    if (h) h--;
    int j = sa[ra[i] - 1];
    while (j + h <= n && i + h <= n && s[j + h] == s[i + h]) h++;
    height[ra[i]] = h;
  }
}
int insert(int x, int y, int l, int r, int wh) {
  x = ++tot;
  a[x] = a[y] + 1;
  if (l == r) {
    return x;
  }
  int mid = (l + r) / 2;
  if (mid >= wh) lc[x] = insert(lc[x], lc[y], l, mid, wh), rc[x] = rc[y];
  if (mid < wh) rc[x] = insert(rc[x], rc[y], mid + 1, r, wh), lc[x] = lc[y];
  return x;
}
int query(int x, int y, int l, int r, int tx, int ty) {
  if (!x && !y) return 0;
  if (tx > ty) return 0;
  if (l >= tx && r <= ty) return a[y] - a[x];
  int mid = (l + r) / 2, ret = 0;
  if (mid >= tx) ret += query(lc[x], lc[y], l, mid, tx, ty);
  if (mid < ty) ret += query(rc[x], rc[y], mid + 1, r, tx, ty);
  return ret;
}
int calc(int l, int r) {
  if (l > r) swap(l, r);
  int t = 0;
  l++;
  if (l == r) return height[r];
  for (; l + (1 << t) < r; t++)
    ;
  if (l + (1 << t) > r) t--;
  return min(st[l][t], st[r - (1 << t) + 1][t]);
}
int find(int s, int x, int op) {
  int l, r, m;
  if (op)
    l = s, r = n;
  else
    l = 1, r = s;
  while (l != r) {
    m = (l + r) >> 1;
    if (op) m++;
    if (calc(m, s) < x) {
      if (op)
        r = m - 1;
      else
        l = m + 1;
    } else {
      if (op)
        l = m;
      else
        r = m;
    }
  }
  return l;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i < n; i++) s[i] = b[i + 1] - b[i];
  s[n] = 1;
  for (int i = 1; i < n; i++) s[n + i] = -s[i];
  build_sa();
  for (int i = 1; i < n * 2; i++) st[i][0] = height[i];
  for (int j = 1; j <= 20; j++) {
    for (int i = 1; i < n * 2; i++) {
      st[i][j] = st[i][j - 1];
      if (i + (1 << (j - 1)) <= n)
        st[i][j] = min(st[i][j], st[i + (1 << (j - 1))][j - 1]);
    }
  }
  tree[0] = 1;
  for (int i = 1; i <= n; i++) {
    tree[i] = insert(tree[i], tree[i - 1], 1, n, sa[i]);
  }
  int N = (n + 1) / 2;
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x == y) {
      printf("%d\n", N - 1);
      continue;
    }
    int l = x, r = y;
    x = find(ra[l], r - l, 0), y = find(ra[l], r - l, 1);
    printf("%d\n",
           query(tree[x - 1], tree[y], 1, n, N + 1, N + (l - 1) - (r - l)) +
               query(tree[x - 1], tree[y], 1, n, N + (r + 1), n));
  }
  return 0;
}
