#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, LOG = 19, INF = 1e9 + 10;
int s[N], m, n;
int bu[LOG][N], sa[N], lcp[LOG][N], lg;
pair<pair<int, int>, int> tmp[N];
vector<int> seg[4 * N];
void build_suffix_array() {
  for (int i = (int)1; i <= n; i++) bu[0][i] = s[i];
  for (lg = 1; (1 << lg) <= 2 * n; lg++) {
    for (int i = (int)1; i <= n; i++)
      tmp[i] = {
          {bu[lg - 1][i],
           i + (1 << (lg - 1)) <= n ? bu[lg - 1][i + (1 << (lg - 1))] : -INF},
          i};
    sort(tmp + 1, tmp + n + 1);
    for (int i = (int)1; i <= n; i++)
      bu[lg][tmp[i].second] = (i > 1 && tmp[i].first == tmp[i - 1].first)
                                  ? bu[lg][tmp[i - 1].second]
                                  : i;
  }
  lg--;
  for (int i = (int)1; i <= n; i++) sa[bu[lg][i]] = i;
  int j, k = 0;
  for (int i = (int)1; i <= n; i++)
    if (bu[lg][i] != n) {
      j = sa[bu[lg][i] + 1];
      while (i + k <= n && j + k <= n && s[i + k] == s[j + k]) k++;
      lcp[0][bu[lg][i]] = k;
      if (k > 0) k--;
    }
  for (int j = (int)1; j <= lg; j++)
    for (int i = (int)1; i <= n - 1; i++)
      lcp[j][i] =
          min(lcp[j - 1][i],
              i + (1 << (j - 1)) < n ? lcp[j - 1][i + (1 << (j - 1))] : 0);
}
void build(int i, int lo, int hi) {
  if (lo == hi) {
    seg[i].push_back(sa[lo]);
    return;
  }
  int mid = lo + hi >> 1, c1 = i << 1, c2 = c1 | 1;
  build(c1, lo, mid);
  build(c2, mid + 1, hi);
  merge(seg[c1].begin(), seg[c1].end(), seg[c2].begin(), seg[c2].end(),
        back_inserter(seg[i]));
}
int ask(int i, int lo, int hi, int ql, int qr, int lowval, int hival) {
  if (hi < ql || qr < lo) return 0;
  if (ql <= lo && hi <= qr)
    return upper_bound(seg[i].begin(), seg[i].end(), hival) -
           lower_bound(seg[i].begin(), seg[i].end(), lowval);
  int mid = lo + hi >> 1, c1 = i << 1, c2 = c1 | 1;
  return ask(c1, lo, mid, ql, qr, lowval, hival) +
         ask(c2, mid + 1, hi, ql, qr, lowval, hival);
}
int query(int l, int r) {
  int pos = bu[lg][l], len = r - l;
  int lo = pos;
  for (int j = lg; j >= 0; j--)
    if (lo - (1 << j) > 0 && lcp[j][lo - (1 << j)] >= len) lo -= 1 << j;
  int hi = pos;
  for (int j = lg; j >= 0; j--)
    if (lcp[j][hi] >= len) hi += 1 << j;
  int res = 0;
  if (m + 1 <= m + l - (r - l) - 1)
    res += ask(1, 1, n, lo, hi, m + 1, m + l - (r - l) - 1);
  res += ask(1, 1, n, lo, hi, m + r + 1, n);
  return res;
}
int main() {
  scanf("%d", &m);
  for (int i = (int)1; i <= m; i++) scanf("%d", s + i);
  for (int i = (int)1; i <= m - 1; i++) s[i] -= s[i + 1];
  for (int i = (int)m + 1; i <= 2 * m - 1; i++) s[i] = -s[i - m];
  n = 2 * m - 1;
  build_suffix_array();
  build(1, 1, n);
  int l, r, q, ans;
  for (scanf("%d", &q); q--;) {
    scanf("%d%d", &l, &r);
    if (l == r)
      ans = m - 1;
    else
      ans = query(l, r);
    printf("%d\n", ans);
  }
  return 0;
}
