#include <bits/stdc++.h>
using namespace std;
const int N = 400123;
const int inf = 1e9 + 3;
int z, n, q, a, b;
string s;
int ans[N];
struct Query {
  int a, b, id;
};
struct SuffixAutomaton {
  struct State {
    map<int, int> nbs;
    int suf = -1, len = 0, minlen = 0, vis = 0, first = 0;
    vector<int> ways;
    bool good = false;
    bool clone = false;
    vector<Query> qs;
  };
  struct fenwick {
    int ft[N];
    fenwick() {}
    void clear() { memset(ft, 0, sizeof ft); }
    void insert(int second, int v) {
      second++;
      for (; second < N; second += second & -second) ft[second] += v;
    }
    int q(int second) {
      int res = 0;
      for (; second; second -= second & -second) res += ft[second];
      return res;
    }
    int query(int second, int first) {
      if (second > first) return 0;
      if (first >= N) return 0;
      second++;
      first++;
      return q(first) - (second > 1 ? q(second - 1) : 0);
    }
  };
  fenwick tree;
  vector<State> first;
  int up[20][N];
  int wherefirst[N];
  vector<int> g[N];
  void lca() {
    for (int i = 0; i < first.size(); i++) up[0][i] = max(0, first[i].suf);
    for (int d = 1; d < 20; d++) {
      for (int i = 0; i < first.size(); i++) {
        up[d][i] = up[d - 1][up[d - 1][i]];
      }
    }
  }
  int bs(int s, int len) {
    for (int d = 19; d >= 0; d--) {
      if (len <= first[up[d][s]].len) {
        s = up[d][s];
      }
    }
    return s;
  }
  int get_query_vertex(int a, int b) {
    a++;
    a += n;
    b += n;
    if (a > b) return n - 1;
    int len = b - a + 1;
    return bs(wherefirst[b], len);
  }
  void init(vector<int>& s) {
    int last = 0;
    first.reserve(2 * s.size());
    first.push_back(State());
    for (int i = 0; i < s.size(); i++) {
      int c = s[i];
      first.push_back(State());
      int r = first.size() - 1;
      first[r].suf = 0;
      first[r].len = i + 1;
      first[r].first = i;
      wherefirst[i] = r;
      int p = last;
      while (p >= 0 && !first[p].nbs.count(c)) {
        first[p].nbs[c] = r;
        p = first[p].suf;
      }
      if (p != -1) {
        int q = first[p].nbs[c];
        if (first[p].len + 1 == first[q].len) {
          first[r].suf = q;
        } else {
          first.push_back(first[q]);
          int qq = first.size() - 1;
          first[qq].len = first[p].len + 1;
          first[qq].clone = true;
          first[q].suf = first[r].suf = qq;
          while (p >= 0 && first[p].nbs[c] == q) {
            first[p].nbs[c] = qq;
            p = first[p].suf;
          }
        }
      }
      first[r].minlen = first[first[r].suf].len + 1;
      last = r;
      if (i == n - 1) {
        for (State& s : first) s.good = true;
      }
    }
  }
  void build() {
    for (int v = 0; v < first.size(); v++) {
      if (v) {
        g[first[v].suf].push_back(v);
      }
    }
  }
  void work(int v) {
    for (Query q : first[v].qs) {
      int cur = 0;
      cur -= tree.query(q.b + (q.b - q.a + 1), N - 2);
      cur -= tree.query(1, q.a - 1);
      ans[q.id] = cur;
    }
    if (first[v].good && !first[v].clone) {
      tree.insert(first[v].first, 1);
    }
    for (int w : g[v]) {
      work(w);
    }
    for (Query q : first[v].qs) {
      int cur = 0;
      cur += tree.query(q.b + (q.b - q.a + 1), N - 2);
      cur += tree.query(1, q.a - 1);
      ans[q.id] += cur;
    }
  }
};
SuffixAutomaton sa;
vector<int> v;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  int last;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    if (!i)
      v.push_back(inf);
    else
      v.push_back(t - last);
    last = t;
  }
  for (int i = 0; i < n; i++) {
    v.push_back(-v[i]);
  }
  sa.init(v);
  sa.build();
  sa.lca();
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> a >> b;
    --a;
    --b;
    if (a >= b) {
      ans[i] = n - 1;
      continue;
    }
    int v = sa.get_query_vertex(a, b);
    sa.first[v].qs.push_back({a, b, i});
  }
  sa.work(0);
  for (int i = 0; i < q; i++) {
    cout << ans[i] << "\n";
  }
  return 0;
}
