#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
inline void gn(long long &first) {
  int sg = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (sg = -1, first = 0) : (first = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') first = first * 10 + c - '0';
  first *= sg;
}
inline void gn(int &first) {
  long long t;
  gn(t);
  first = t;
}
inline void gn(unsigned long long &first) {
  long long t;
  gn(t);
  first = t;
}
inline void gn(double &first) {
  double t;
  scanf("%lf", &t);
  first = t;
}
inline void gn(long double &first) {
  double t;
  scanf("%lf", &t);
  first = t;
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
int s[(100010 << 1)], a[100010], n, N, q, ans[100010];
struct suffix_array {
  pair<pair<int, int>, int> pos[(100010 << 1)];
  int Rank[(100010 << 1)], sa[(100010 << 1)], lcpm[(100010 << 1)][20];
  void build() {
    for (int i = 0; i < N; i++) Rank[i] = s[i];
    for (int j = 0; j < 20; j++) {
      for (int i = 0; i < N; i++) {
        pos[i] = pair<pair<int, int>, int>(
            pair<int, int>(Rank[i], Rank[min(N, i + (1 << j))]), i);
      }
      sort(pos, pos + N);
      int cnt = 0;
      for (int i = 0; i < N; i++) {
        Rank[pos[i].second] = cnt + 1;
        cnt += (pos[i].first != pos[i + 1].first);
      }
      if (cnt == N) break;
    }
    for (int i = 0; i < N; i++) sa[Rank[i]] = i;
    return;
  }
  void lcp_length() {
    int h = 0;
    for (int i = 0; i < N; i++) {
      if (Rank[i] == 1) {
        lcpm[Rank[i]][0] = 0;
        continue;
      }
      h = max(h - 1, 0);
      for (int j = sa[Rank[i] - 1]; s[j + h] == s[i + h]; h++)
        ;
      lcpm[Rank[i]][0] = h;
    }
    for (int j = 1; j < 20; j++) {
      for (int i = 1; i <= N; i++) {
        lcpm[i][j] = min(lcpm[i][j - 1], lcpm[min(N, i + (1 << j - 1))][j - 1]);
      }
    }
    return;
  }
  int query_(int i, int j) {
    if (i == j) return 0x3f3f3f3f;
    int k = 31 - (__builtin_clz(j - i));
    return min(lcpm[i + 1][k], lcpm[j - (1 << k) + 1][k]);
  }
} SA;
struct Query {
  int l, r, mn, mx, id;
} Q[100010];
bool cmp1(Query q1, Query q2) { return q1.l < q2.l; }
bool cmp2(Query q1, Query q2) { return q1.r < q2.r; }
struct Fenwic_tree {
  int B1[100010], B2[100010];
  void clear() {
    memset(B1, 0, sizeof(B1));
    memset(B2, 0, sizeof(B2));
    return;
  }
  void update_up(int u) {
    if (u > n) return;
    while (u > 0) {
      B1[u]++;
      u -= u & (-u);
    }
    return;
  }
  void update_down(int u) {
    if (u <= 0) return;
    while (u <= n) {
      B2[u]++;
      u += u & (-u);
    }
    return;
  }
  int calc_up(int u) {
    if (u > n) return 0;
    int ans = 0;
    while (u <= n) {
      ans += B1[u];
      u += u & (-u);
    }
    return ans;
  }
  int calc_down(int u) {
    if (u <= 0) return 0;
    int ans = 0;
    while (u > 0) {
      ans += B2[u];
      u -= u & (-u);
    }
    return ans;
  }
} BIT;
int main() {
  int l, r, id, mn, mx;
  gn(n);
  N = 2 * n;
  for (int i = 0; i < n; i++) gn(a[i]);
  for (int i = 0; i < n; i++)
    s[i] = a[i] - a[i + 1], s[n + i] = a[i + 1] - a[i];
  s[N] = 0x3f3f3f3f;
  SA.build();
  SA.lcp_length();
  gn(q);
  for (int i = 0; i < q; i++) {
    gn(l);
    gn(r);
    l--;
    r--;
    int len = r - l, p = SA.Rank[n + l];
    Q[i].id = i;
    Q[i].mn = l - len, Q[i].mx = r + 2;
    int st = 0, ed = p;
    while (ed - st > 1) {
      int mid = st + ed >> 1;
      if (SA.query_(mid, p) >= len)
        ed = mid;
      else
        st = mid;
    }
    Q[i].l = ed;
    st = p, ed = N + 1;
    while (ed - st > 1) {
      int mid = st + ed >> 1;
      if (SA.query_(p, mid) >= len)
        st = mid;
      else
        ed = mid;
    }
    Q[i].r = st;
  }
  sort(Q, Q + q, cmp2);
  int pos = 1;
  for (int i = 1; i <= N; i++) SA.sa[i]++;
  for (int i = 0; i < q; i++) {
    l = Q[i].l, r = Q[i].r, id = Q[i].id, mn = Q[i].mn, mx = Q[i].mx;
    for (int j = pos; j <= r; j++) {
      BIT.update_down(SA.sa[j]);
      BIT.update_up(SA.sa[j]);
    }
    pos = r + 1;
    ans[id] = BIT.calc_down(mn) + BIT.calc_up(mx);
  }
  BIT.clear();
  sort(Q, Q + q, cmp1);
  pos = 1;
  for (int i = 0; i < q; i++) {
    l = Q[i].l, r = Q[i].r, id = Q[i].id, mn = Q[i].mn, mx = Q[i].mx;
    for (int j = pos; j < l; j++) {
      BIT.update_down(SA.sa[j]);
      BIT.update_up(SA.sa[j]);
    }
    pos = l;
    ans[id] -= (BIT.calc_down(mn) + BIT.calc_up(mx));
  }
  for (int i = 0; i < q; i++) printf("%d\n", ans[i]);
  return 0;
}
