#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000002, N = 200100;
int a[N], r[N], sa[N], h[N], ans[N], L[N], R[N], _l[N], _r[N], C[N], n, t, cnt,
    Q;
pair<pair<int, int>, int> c[N];
vector<pair<int, int> > q[N];
vector<int> q1[N], q2[N];
set<pair<int, int> > p;
void deal(int i, int w, int *a) {
  for (typeof(p.end()) it = p.upper_bound(make_pair(h[i] + 1, -1));
       it != p.end(); p.erase(it++))
    a[it->second] = i + w;
}
int A(int x) {
  int s = 0;
  for (; x; x -= x & -x) s += C[x];
  return s;
}
void M(int x) {
  for (; x <= t; x += x & -x) C[x]++;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (int)n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < (int)n - 1; i++) a[i] = a[i + 1] - a[i], a[i + n] = -a[i];
  a[n - 1] = -inf + 1;
  a[(t = n + n) - 1] = -inf + 2;
  for (int i = 0; i < (int)t; i++) r[i] = a[i] += inf;
  for (int d = 1; d < t; d += d) {
    for (int i = 0; i < (int)t; i++)
      c[i] = make_pair(make_pair(r[i], r[i + d]), i);
    sort(c, c + t);
    cnt = r[c[0].second] = 0;
    for (int i = 0; i < (int)t - 1; i++)
      r[c[i + 1].second] = (cnt += (c[i].first != c[i + 1].first));
    if (cnt == t) break;
  }
  for (int i = 0; i < (int)t; i++) sa[r[i]] = i;
  for (int k = 0, i = 0, j; i < t; h[r[i++]] = k, k = max(k - 1, 0))
    if (r[i] != 0)
      for (j = sa[r[i] - 1]; a[j + k] == a[i + k]; k++)
        ;
  h[t] = -1;
  scanf("%d", &Q);
  for (int i = 0; i < (int)Q; i++)
    scanf("%d%d", L + i, R + i), --L[i], --R[i],
        q[r[L[i] + n]].push_back(make_pair(R[i] - L[i], i));
  for (int i = 0; i < (int)t + 1; i++) {
    deal(i, -1, _r);
    for (int j = 0; j < (int)q[i].size(); j++) p.insert(q[i][j]);
  }
  for (int i = t - 1; i >= 0; i--) {
    for (int j = 0; j < (int)q[i].size(); j++) p.insert(q[i][j]);
    deal(i, 0, _l);
  }
  for (int i = 0; i < (int)Q; i++)
    q1[_l[i]].push_back(i), q2[_r[i]].push_back(i),
        L[i] = max(2 * L[i] - R[i], 0);
  for (int i = 0; i < (int)t; i++) {
    for (int j = 0; j < (int)q1[i].size(); j++) {
      int d = q1[i][j];
      ans[d] -= A(n) - A(R[d] + 1) + A(L[d]);
    }
    M(sa[i] + 1);
    for (int j = 0; j < (int)q2[i].size(); j++) {
      int d = q2[i][j];
      ans[d] += A(n) - A(R[d] + 1) + A(L[d]);
    }
  }
  for (int i = 0; i < (int)Q; i++) printf("%d\n", ans[i]);
}
