#include <bits/stdc++.h>
using namespace std;
struct suffix_array {
  int first, second, idx;
} suff[200000 + 1];
struct query {
  int first, second, l, r, id;
} q[200000 + 1];
pair<int, int> t[200000 + 1];
map<int, int> frecv;
int P[17 + 1][200000 + 1];
int where[200000 + 1];
int res[200000 + 1];
int aib[200000 + 1];
int v[200000 + 1];
int N, Q, T, step;
void Update(int p) {
  while (p <= N) {
    aib[p] += 1;
    p += (p & (-p));
  }
}
int Query(int p) {
  int sum = 0;
  while (p) {
    sum += aib[p];
    p -= (p & (-p));
  }
  return sum;
}
bool cmp(const suffix_array A, const suffix_array B) {
  if (A.first == B.first) return A.second < B.second;
  return A.first < B.first;
}
void Build_suffix() {
  int i, len, cnt = 0;
  for (i = 1; i <= N; ++i) suff[i] = {t[i].first, 0, t[i].second};
  for (step = 0; (1 << step) <= N; ++step) {
    sort(suff + 1, suff + N + 1, cmp);
    P[step][suff[1].idx] = 1;
    for (i = 2; i <= N; ++i)
      if (suff[i].first == suff[i - 1].first &&
          suff[i].second == suff[i - 1].second)
        P[step][suff[i].idx] = P[step][suff[i - 1].idx];
      else
        P[step][suff[i].idx] = P[step][suff[i - 1].idx] + 1;
    len = 1 << step;
    for (i = 1; i <= N; ++i)
      if (i + len <= N)
        suff[i] = {P[step][i], P[step][i + len], i};
      else
        suff[i] = {P[step][i], -1, i};
  }
  for (i = 1; i <= N; ++i) where[P[step - 1][i]] = i;
}
int LCP(int first, int second) {
  int k, len = 0;
  for (k = step - 1; k >= 0 && first <= N && second <= N; --k)
    if (P[k][first] == P[k][second])
      len += (1 << k), first += (1 << k), second += (1 << k);
  return len;
}
int CautBinL(int l, int r) {
  int f, st, dr, mid, len = r - l;
  for (st = 1, dr = P[step - 1][l]; st <= dr;) {
    mid = (st + dr) / 2;
    if (LCP(l, where[mid]) < len)
      st = mid + 1;
    else {
      f = mid;
      dr = mid - 1;
    }
  }
  return f;
}
int CautBinR(int l, int r) {
  int f, st, dr, mid, len = r - l;
  for (st = P[step - 1][l], dr = N; st <= dr;) {
    mid = (st + dr) / 2;
    if (LCP(l, where[mid]) < len)
      dr = mid - 1;
    else {
      f = mid;
      st = mid + 1;
    }
  }
  return f;
}
bool cmp1(const query A, const query B) { return A.r > B.r; }
bool cmp2(const query A, const query B) {
  return 2 * A.l - A.r < 2 * B.l - B.r;
}
int main() {
  int i, j, l, r;
  scanf("%d", &N);
  for (i = 1; i <= N; ++i) scanf("%d", &v[i]);
  for (i = 1; i <= N; ++i) ++frecv[v[i]];
  for (i = 1; i < N; ++i) t[i] = {v[i] - v[i + 1], i};
  for (i = 1; i < N; ++i) t[N + i - 1] = {v[i + 1] - v[i], N + i - 1};
  N = 2 * N - 2;
  sort(t + 1, t + N + 1);
  Build_suffix();
  scanf("%d", &Q);
  for (int t = 1; t <= Q; ++t) {
    scanf("%d %d", &l, &r);
    if (l == r)
      res[t] = N / 2;
    else
      q[++T] = {CautBinL(l, r), CautBinR(l, r), l, r, t};
  }
  sort(q + 1, q + T + 1, cmp1);
  for (j = N, i = 1; i <= T; ++i) {
    while (j > N / 2 + q[i].r) Update(P[step - 1][j--]);
    res[q[i].id] += Query(q[i].second) - Query(q[i].first - 1);
  }
  for (i = 1; i <= N; ++i) aib[i] = 0;
  sort(q + 1, q + T + 1, cmp2);
  for (j = N / 2 + 1, i = 1; i <= T; ++i) {
    while (j < N / 2 + 2 * q[i].l - q[i].r) Update(P[step - 1][j++]);
    res[q[i].id] += Query(q[i].second) - Query(q[i].first - 1);
  }
  for (i = 1; i <= Q; ++i) printf("%d\n", res[i]);
  return 0;
}
