#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2, class T3 = hash<T1>>
using umap = unordered_map<T1, T2, T3>;
template <class T>
using uset = unordered_set<T>;
template <class T>
using vec = vector<T>;
const long long infll = numeric_limits<long long>::max() >> 1;
const int inf = numeric_limits<int>::max() >> 1;
const int N = 2e5 + 5;
const int L = 20;
int n, q, lgx;
int t[N];
int s[N];
int a[N];
int b[N];
int o[N];
int p[N][L];
int arr[N];
int acp[N];
int bcp[N];
int ocp[N];
int cnt[N];
int bit[N];
int ans[N];
int spt[N][L];
bool flag;
vec<int> sml;
vec<array<int, 4>> qry[N];
inline int lg(int x) { return 31 - __builtin_clz(x); }
void update(int i, int x) {
  for (; i < N; i += (i) & -(i)) {
    bit[i] += x;
  }
}
int query(int i) {
  int res = 0;
  for (; i; i -= (i) & -(i)) {
    res += bit[i];
  }
  return res;
}
int sum(int l, int r) { return query(r) - query(l - 1); }
void input() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> arr[i];
  }
  n--;
  for (int i = 1; i <= n; ++i) {
    t[i] = arr[i + 1] - arr[i];
  }
  for (int i = n + 1; i <= 2 * n; ++i) {
    t[i] = -t[i - n];
  }
  n *= 2;
  flag |= arr[1] == 50;
}
void calc_spt() {
  for (int j = 1; j < L; ++j) {
    for (int i = 1; i + (1 << j) <= n; ++i) {
      spt[i][j] = min(spt[i][j - 1], spt[i + (1 << j - 1)][j - 1]);
    }
  }
}
int query(int l, int r) {
  if (l == r) {
    return n - s[l] + 1;
  }
  r--;
  int lgy = lg(r - l + 1);
  return min(spt[l][lgy], spt[r - (1 << lgy) + 1][lgy]);
}
int lcp(int i, int j) {
  int res = 0;
  for (int k = lgx; k >= 0 && i <= n && j <= n; --k) {
    if (p[i][k] == p[j][k]) {
      i += 1 << k;
      j += 1 << k;
      res += 1 << k;
    }
  }
  return res;
}
void compress() {
  for (int i = 1; i <= n; ++i) {
    sml.push_back(t[i]);
  }
  sort((sml).begin(), (sml).end());
  sml.erase(unique((sml).begin(), (sml).end()), sml.end());
  for (int i = 1; i <= n; ++i) {
    t[i] = lower_bound((sml).begin(), (sml).end(), t[i]) - sml.begin();
  }
}
void counting_sort(int a[], int b[], int o[]) {
  fill(cnt, cnt + N, 0);
  for (int i = 1; i <= n; ++i) {
    cnt[a[i]]++;
  }
  for (int i = 1; i < N; ++i) {
    cnt[i] += cnt[i - 1];
  }
  for (int i = n; i >= 1; --i) {
    int ind = cnt[a[i]]--;
    acp[ind] = a[i];
    bcp[ind] = b[i];
    ocp[ind] = o[i];
  }
  copy(acp, acp + N, a);
  copy(bcp, bcp + N, b);
  copy(ocp, ocp + N, o);
}
void radix_sort() {
  counting_sort(b, a, o);
  counting_sort(a, b, o);
}
int calc_lef(int l, int r, int p, int x) {
  if (l == r) {
    return l;
  }
  int q = l + r >> 1;
  if (query(q, p) >= x) {
    return calc_lef(l, q, p, x);
  } else {
    return calc_lef(q + 1, r, p, x);
  }
}
int calc_rig(int l, int r, int p, int x) {
  if (l == r) {
    return l;
  }
  int q = l + r + 1 >> 1;
  if (query(p, q) >= x) {
    return calc_rig(q, r, p, x);
  } else {
    return calc_rig(l, q - 1, p, x);
  }
}
void interval(int &lx, int &rx, int l, int d) {
  lx = calc_lef(1, l, l, d);
  rx = calc_rig(l, n, l, d);
}
void add_query(int lx, int rx, int l, int r, int i) {
  lx--;
  if (l > n || r <= 0 || l > r) {
    return;
  }
  qry[rx].push_back({l, r, 1, i});
  qry[lx].push_back({l, r, -1, i});
}
void sweep_line() {
  for (int i = 1; i <= n; ++i) {
    update(s[i], 1);
    for (auto it : qry[i]) {
      ans[it[3]] += it[2] * sum(it[0], it[1]);
    }
  }
}
void solve() {
  compress();
  for (int i = 1; i <= n; ++i) {
    p[i][0] = t[i];
  }
  for (int i = 1, j = 1; j <= n - 1; ++i, j <<= 1) {
    for (int k = 1; k <= n; ++k) {
      a[k] = p[k][i - 1] + 1;
      b[k] = (k + j <= n ? p[k + j][i - 1] : -1) + 1;
      o[k] = k;
    }
    radix_sort();
    p[o[1]][i] = 1;
    for (int k = 2; k <= n; ++k) {
      p[o[k]][i] = make_pair(a[k], b[k]) == make_pair(a[k - 1], b[k - 1])
                       ? p[o[k - 1]][i]
                       : k;
    }
    lgx = i;
  }
  for (int i = 1; i <= n; ++i) {
    s[p[i][lgx]] = i;
  }
  for (int i = 1; i < n; ++i) {
    spt[i][0] = lcp(s[i], s[i + 1]);
  }
  calc_spt();
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int l;
    cin >> l;
    int r;
    cin >> r;
    if (l == r) {
      ans[i] = n / 2;
      continue;
    }
    int lx;
    int rx;
    int d = r - l;
    interval(lx, rx, p[l + n / 2][lgx], d);
    add_query(lx, rx, r + 1, n / 2 - d + 1, i);
    add_query(lx, rx, 1, l - d - 1, i);
  }
  sweep_line();
  for (int i = 1; i <= q; ++i) {
    cout << ans[i] << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  input();
  solve();
}
