#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void input(T &x) {
  register char c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
inline long long bigmod(long long p, long long e, long long M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
using namespace std;
const int maxn = 5e5 + 5;
int wa[maxn], wb[maxn], wv[maxn], wc[maxn];
int r[maxn], sa[maxn], rak[maxn], height[maxn], dp[maxn][22], SIGMA = 0;
int cmp(int *r, int a, int b, int l) {
  return r[a] == r[b] && r[a + l] == r[b + l];
}
void da(int *r, int *sa, int n, int m) {
  int i, j, p, *x = wa, *y = wb, *t;
  for (i = 0; i < m; i++) wc[i] = 0;
  for (i = 0; i < n; i++) wc[x[i] = r[i]]++;
  for (i = 1; i < m; i++) wc[i] += wc[i - 1];
  for (i = n - 1; i >= 0; i--) sa[--wc[x[i]]] = i;
  for (j = 1, p = 1; p < n; j *= 2, m = p) {
    for (p = 0, i = n - j; i < n; i++) y[p++] = i;
    for (i = 0; i < n; i++)
      if (sa[i] >= j) y[p++] = sa[i] - j;
    for (i = 0; i < n; i++) wv[i] = x[y[i]];
    for (i = 0; i < m; i++) wc[i] = 0;
    for (i = 0; i < n; i++) wc[wv[i]]++;
    for (i = 1; i < m; i++) wc[i] += wc[i - 1];
    for (i = n - 1; i >= 0; i--) sa[--wc[wv[i]]] = y[i];
    for (t = x, x = y, y = t, p = 1, x[sa[0]] = 0, i = 1; i < n; i++)
      x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;
  }
}
void calheight(int *r, int *sa, int n) {
  int i, j, k = 0;
  for (i = 1; i <= n; i++) rak[sa[i]] = i;
  for (i = 0; i < n; height[rak[i++]] = k) {
    for (k ? k-- : 0, j = sa[rak[i] - 1]; r[i + k] == r[j + k]; k++)
      ;
  }
}
void initRMQ(int n) {
  for (int i = 0; i <= n; i++) dp[i][0] = height[i];
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 0; i + (1 << j) - 1 <= n; i++) {
      dp[i][j] = min(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
    }
  }
}
int askRMQ(int L, int R) {
  int k = 0;
  while ((1 << (k + 1)) <= R - L + 1) k++;
  return min(dp[L][k], dp[R - (1 << k) + 1][k]);
}
const int N = 5e5 + 5;
int L[N * 20], R[N * 20], V[N * 20];
int sz = 0;
int a[N];
int root[N];
int n;
void build(int &n, int b, int e) {
  n = ++sz;
  V[n] = 0;
  if (b == e) return;
  int mid = (b + e) / 2;
  build(L[n], b, mid);
  build(R[n], mid + 1, e);
}
void updateP(int &n, int pre, int b, int e, int v) {
  n = ++sz;
  L[n] = L[pre], R[n] = R[pre], V[n] = V[pre];
  if (b == e && b == v) {
    V[n]++;
    return;
  }
  int mid = (b + e) / 2;
  if (v <= mid)
    updateP(L[n], L[pre], b, mid, v);
  else
    updateP(R[n], R[pre], mid + 1, e, v);
  V[n] = V[L[n]] + V[R[n]];
}
int queryP(int r1, int r2, int b, int e, int High) {
  if (b > High) return 0;
  if (e <= High) return V[r2] - V[r1];
  int mid = (b + e) / 2;
  return queryP(L[r1], L[r2], b, mid, High) +
         queryP(R[r1], R[r2], mid + 1, e, High);
}
int initRoot;
int Out(int l, int r, int x, int y) {
  int p1 = root[r];
  int p2 = (l - 1 >= 0) ? root[l - 1] : initRoot;
  int res = queryP(p2, p1, 1, n, y);
  if (x - 1 >= 1) res -= queryP(p2, p1, 1, n, x - 1);
  return res;
}
int Seg[5 * N];
void update(int n, int b, int e, int pos, int v) {
  if (b > pos || e < pos) return;
  if (b == e) {
    Seg[n] = v;
    return;
  }
  int mid = (b + e) / 2;
  if (pos <= mid)
    update(((n) << 1), b, mid, pos, v);
  else
    update(((n) << 1 | 1), mid + 1, e, pos, v);
  Seg[n] = Seg[((n) << 1)] + Seg[((n) << 1 | 1)];
}
int query(int n, int b, int e, int i, int j) {
  if (b > j || e < i) return 0;
  if (b >= i && e <= j) return Seg[n];
  int mid = (b + e) / 2;
  return query(((n) << 1), b, mid, i, j) +
         query(((n) << 1 | 1), mid + 1, e, i, j);
}
int h[N];
map<int, int> Map;
int RevPos[N];
int main() {
  input(n);
  for (int i = 1; i <= n; i++) input(h[i]), Map[h[i]]++;
  vector<int> vec;
  for (int i = 1; i < n; i++) {
    vec.push_back(h[i] - h[i + 1]);
    vec.push_back(h[i + 1] - h[i]);
  }
  sort((vec).begin(), (vec).end());
  vec.resize(unique((vec).begin(), (vec).end()) - vec.begin());
  int nc = 0;
  for (int i = 1; i < n; i++) {
    int x = h[i] - h[i + 1];
    r[nc++] = lower_bound((vec).begin(), (vec).end(), x) - vec.begin() + 2;
    SIGMA = max(r[nc - 1], SIGMA);
  }
  r[nc++] = 1;
  for (int i = 1; i < n; i++) {
    int x = -h[i] + h[i + 1];
    RevPos[i] = nc;
    r[nc++] = lower_bound((vec).begin(), (vec).end(), x) - vec.begin() + 2;
    SIGMA = max(SIGMA, r[nc - 1]);
  }
  r[nc] = 0;
  da(r, sa, nc + 1, SIGMA + 1);
  calheight(r, sa, nc);
  initRMQ(nc);
  build(initRoot, 1, n);
  for (int i = 0; i <= nc; i++) {
    int ind = sa[i];
    if (ind <= n - 1) {
      update(1, 0, nc, i, 1);
      if (i == 0)
        update(root[i], initRoot, 1, n, ind + 1);
      else
        updateP(root[i], root[i - 1], 1, n, ind + 1);
    } else
      root[i] = (i - 1 >= 0 ? root[i - 1] : initRoot);
  }
  int q, l, r;
  input(q);
  for (int i = 0; i < q; i++) {
    input(l), input(r);
    int len = r - l;
    if (len == 0)
      cout << n - 1 << endl;
    else {
      int x = rak[RevPos[l]];
      int low = 1, high = x, mid, ans = x + 1;
      while (low <= high) {
        mid = (low + high) / 2;
        if (askRMQ(mid, x) >= len) {
          ans = mid;
          high = mid - 1;
        } else
          low = mid + 1;
      }
      int L = ans - 1;
      low = x + 1, high = nc;
      ans = x;
      while (low <= high) {
        mid = (low + high) / 2;
        if (askRMQ(x + 1, mid) >= len) {
          ans = mid;
          low = mid + 1;
        } else
          high = mid - 1;
      }
      int R = ans;
      int Xlow = max(1, l - len);
      int xHig = r;
      int res = query(1, 0, nc, L, R);
      res -= Out(L, R, Xlow, xHig);
      printf("%d\n", res);
    }
  }
  return 0;
}
