#include <bits/stdc++.h>
using namespace std;
int x, l, r, n, Q, t, cnt, last, ma[400005], pr[400005], f[400005][20],
    ans[100005], a[200005], e[400005], P[200005];
vector<int> u[400005], c[400005];
map<int, int> ch[400005];
struct ss {
  int i, x;
} A[200005];
struct bla {
  int l, r, s;
} b[1800000];
bool cmp(ss a, ss b) { return a.x < b.x; }
void add(int c) {
  int p = last, np = last = ++cnt, q, nq;
  ma[np] = ma[p] + 1;
  while (p && !ch[p][c]) ch[p][c] = np, p = pr[p];
  if (!p)
    pr[np] = 1;
  else {
    q = ch[p][c];
    if (ma[q] == ma[p] + 1)
      pr[np] = q;
    else {
      ma[nq = ++cnt] = ma[p] + 1;
      pr[nq] = pr[q];
      pr[q] = pr[np] = nq;
      ch[nq] = ch[q];
      while (ch[p][c] == q) ch[p][c] = nq, p = pr[p];
    }
  }
}
void dfs(int x, int y) {
  f[x][0] = y;
  for (int i = 0; i < 20; ++i)
    if (!f[f[x][i]][i])
      break;
    else
      f[x][i + 1] = f[f[x][i]][i];
  for (int i = 0; i < (int)u[x].size(); ++i) dfs(u[x][i], x);
}
void join(int &u, int p, int q, int x) {
  if (!u) u = ++t;
  ++b[u].s;
  if (p == q) return;
  if (x <= p + q >> 1)
    join(b[u].l, p, p + q >> 1, x);
  else
    join(b[u].r, (p + q >> 1) + 1, q, x);
}
void he(int &u, int v) {
  if (!u) {
    b[u = v] = b[v];
    return;
  }
  if (!v) return;
  b[u].s += b[v].s;
  he(b[u].l, b[v].l);
  he(b[u].r, b[v].r);
}
int qiu(int u, int p, int q, int l, int r) {
  if (!u) return 0;
  if (l <= p && q <= r) return b[u].s;
  int s = 0;
  if (l <= p + q >> 1) s = qiu(b[u].l, p, p + q >> 1, l, r);
  if (r > p + q >> 1) s += qiu(b[u].r, (p + q >> 1) + 1, q, l, r);
  return s;
}
void fly(int x) {
  for (int i = 0; i < (int)u[x].size(); ++i) {
    fly(u[x][i]);
    he(e[x], e[u[x][i]]);
  }
  for (int i = 0; i < (int)c[x].size(); ++i) {
    int l = A[c[x][i]].i, r = A[c[x][i]].x, p, q;
    p = 1 + r - l, q = l - 1;
    if (p <= q) ans[c[x][i]] += qiu(e[x], 1, n, p, q);
    p = r + 1 + r - l, q = n;
    if (p <= q) ans[c[x][i]] += qiu(e[x], 1, n, p, q);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = n; i; --i) a[i] -= a[i - 1];
  for (int i = 1; i <= n; ++i) a[i + n] = -a[i];
  for (int i = 1; i <= n + n; ++i) A[i] = (ss){i, a[i]};
  sort(A + 1, A + n + n + 1, cmp);
  for (int i = 1; i <= n + n; ++i) {
    if (i == 1 || A[i].x != A[i - 1].x) ++cnt;
    a[A[i].i] = cnt;
  }
  cnt = last = 1;
  for (int i = 1; i <= n + n; ++i) add(a[i]), P[i] = last;
  for (int i = 2; i <= cnt; ++i) u[pr[i]].push_back(i);
  dfs(1, 0);
  t = 0;
  for (int i = n + 1; i <= n + n; ++i) join(e[P[i]], 1, n, i - n);
  scanf("%d", &Q);
  for (int i = 1; i <= Q; ++i) {
    scanf("%d%d", &l, &r);
    if (l == r) {
      ans[i] = n - 1;
      continue;
    }
    x = P[r];
    A[i].i = l, A[i].x = r;
    for (int j = 19; ~j; --j)
      if (f[x][j] && r - l <= ma[f[x][j]]) x = f[x][j];
    c[x].push_back(i);
  }
  fly(1);
  for (int i = 1; i <= Q; ++i) printf("%d\n", ans[i]);
  return 0;
}
