#include <bits/stdc++.h>
using namespace std;
struct pod {
  int l, p, nr;
};
const int INF = 5000000000;
bool por(pod a, pod b) {
  if (a.l < b.l) return true;
  if (a.l > b.l) return false;
  if (a.p < b.p) return true;
  if (a.p > b.p) return false;
  return a.nr < b.nr;
}
vector<int> T1;
int l1, size1;
void Stworz1(int n) {
  int p = 1;
  while (p < n) p *= 2;
  l1 = p;
  size1 = 2 * p - 1;
  for (int i = 0; i <= size1; ++i) T1.push_back(INF);
}
void Dodaj1(int a, int x) {
  a += l1;
  T1[a] = x;
  a /= 2;
  while (a != 0) {
    T1[a] = min(T1[2 * a], T1[2 * a + 1]);
    a /= 2;
  }
}
int Mini1(int a, int b) {
  a += l1;
  b += l1;
  int w = min(T1[a], T1[b]);
  while (a / 2 != b / 2) {
    if (a % 2 == 0) w = min(w, T1[a + 1]);
    if (b % 2 == 1) w = min(w, T1[b - 1]);
    a /= 2;
    b /= 2;
  }
  return w;
}
vector<vector<int> > T2;
int l2, size2;
void Stworz2(int n) {
  int p = 1;
  while (p < n) p *= 2;
  l2 = p;
  size2 = 2 * p - 1;
  vector<int> t;
  for (int i = 0; i <= size2; ++i) T2.push_back(t);
}
void Dodaj2(int a, int x) {
  a += l2;
  while (a != 0) {
    T2[a].push_back(x);
    a /= 2;
  }
}
int Szukaj1(vector<int>& a, int x) {
  int l = 0, p = a.size() - 1, s, r = -1;
  while (l <= p) {
    s = (l + p) / 2;
    if (a[s] >= x) {
      r = s;
      p = s - 1;
    } else
      l = s + 1;
  }
  return r;
}
int Szukaj2(vector<int>& a, int x) {
  int l = 0, p = a.size() - 1, s, r = -1;
  while (l <= p) {
    s = (l + p) / 2;
    if (a[s] <= x) {
      r = s;
      l = s + 1;
    } else
      p = s - 1;
  }
  return r;
}
int f(vector<int>& a, int l, int r) {
  int L = Szukaj1(a, l);
  int P = Szukaj2(a, r);
  if (L != -1 && P != -1 && L <= P) return P - L + 1;
  return 0;
}
int Ile2(int a, int b, int l, int r) {
  if (l > r) return 0;
  a += l2;
  b += l2;
  int w = f(T2[a], l, r);
  if (a != b) w += f(T2[b], l, r);
  while (a / 2 != b / 2) {
    if (a % 2 == 0) w += f(T2[a + 1], l, r);
    if (b % 2 == 1) w += f(T2[b - 1], l, r);
    a /= 2;
    b /= 2;
  }
  return w;
}
void SuffixArray(vector<int> a, vector<int>& sa, vector<int>& lcp, int p) {
  vector<vector<int> > kmr(p + 1);
  for (int i = 0; i < a.size(); ++i) kmr[0].push_back(a[i]);
  for (int i = 1; i <= p; ++i) {
    vector<pod> t;
    for (int j = 0; j + (1 << i) - 1 < a.size(); ++j) {
      t.push_back({kmr[i - 1][j], kmr[i - 1][j + (1 << (i - 1))], j});
      kmr[i].push_back(-1);
    }
    sort(t.begin(), t.end(), por);
    int nr = 0;
    for (int j = 0; j < t.size(); ++j) {
      if (j != 0 && (t[j].l != t[j - 1].l || t[j].p != t[j - 1].p)) ++nr;
      kmr[i][t[j].nr] = nr;
    }
  }
  sa = kmr[p];
  vector<int> gdzie(sa.size());
  for (int i = 0; i < sa.size(); ++i) gdzie[sa[i]] = i;
  for (int i = 0; i < sa.size(); ++i) {
    if (sa[i] == sa.size() - 1) continue;
    int d = 0;
    if (i != 0 && sa[i - 1] != sa.size() - 1)
      d = max(0, (int)lcp[sa[i - 1]] - 1);
    while (a[i + d] == a[gdzie[sa[i] + 1] + d]) ++d;
    lcp[sa[i]] = d;
  }
}
int Szukaj3(vector<int>& a, int L, int P, int x) {
  int l = L, p = P, s, r = -1;
  while (l <= p) {
    s = (l + p) / 2;
    if (Mini1(s, P) >= x) {
      r = s;
      p = s - 1;
    } else
      l = s + 1;
  }
  return r;
}
int Szukaj4(vector<int>& a, int L, int P, int x) {
  int l = L, p = P, s, r = -1;
  while (l <= p) {
    s = (l + p) / 2;
    if (Mini1(L, s) >= x) {
      r = s;
      l = s + 1;
    } else
      p = s - 1;
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) cin >> h[i];
  if (n == 1) {
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) cout << "0" << endl;
    return 0;
  }
  vector<int> a;
  for (int i = 0; i < n - 1; ++i) a.push_back(h[i] - h[i + 1]);
  a.push_back(INF);
  for (int i = 0; i < n - 1; ++i) a.push_back(h[i + 1] - h[i]);
  int m = a.size();
  int p = 0;
  while ((1 << p) < m) ++p;
  for (int i = 0; i < (1 << p) - 1; ++i) a.push_back(INF);
  vector<int> sa(m), lcp(m - 1);
  SuffixArray(a, sa, lcp, p);
  Stworz1(m - 1);
  for (int i = 0; i < m - 1; ++i) Dodaj1(i, lcp[i]);
  Stworz2(m);
  for (int i = 0; i < m; ++i) {
    if (i <= n - 1)
      Dodaj2(sa[i], -1);
    else
      Dodaj2(sa[i], i - n);
  }
  for (int i = 1; i <= size2; ++i) sort(T2[i].begin(), T2[i].end());
  int q;
  cin >> q;
  vector<int> gdzie(sa.size());
  for (int i = 0; i < m; ++i) gdzie[sa[i]] = i;
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    --l;
    --r;
    if (l == r) {
      cout << n - 1 << endl;
      continue;
    }
    int nr = sa[l], d = r - l + 1;
    int L = Szukaj3(lcp, 0, nr - 1, d - 1);
    int P = Szukaj4(lcp, nr, m - 1, d - 1);
    int odp;
    if (L == -1 && P == -1) odp = 0;
    if (L == -1 && P != -1) {
      odp = Ile2(nr, P, 0, l - d) + Ile2(nr, P, r + 1, n - 2);
      if (gdzie[P + 1] >= n &&
          !(gdzie[P + 1] >= l - d + 1 + n && gdzie[P + 1] <= r + n))
        ++odp;
    }
    if (L != -1 && P == -1) {
      odp = Ile2(L, nr - 1, 0, l - d) + Ile2(L, nr - 1, r + 1, n - 2);
      if (gdzie[nr] >= n && !(gdzie[nr] >= l - d + 1 + n && gdzie[nr] <= r + n))
        ++odp;
    }
    if (L != -1 && P != -1) {
      odp = Ile2(L, P, 0, l - d) + Ile2(L, P, r + 1, n - 2);
      if (gdzie[P + 1] >= n &&
          !(gdzie[P + 1] >= l - d + 1 + n && gdzie[P + 1] <= r + n))
        ++odp;
    }
    cout << odp << endl;
  }
  return 0;
}
