#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int N = 2e5 + 10;
const long long mod = 1e9 + 7;
const long long mod2 = 998244353;
const long long inf = 8e18;
const int LOG = 21;
long long pw(long long a, long long b, long long M) {
  return (!b ? 1
             : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M
                      : pw(a * a % M, b / 2, M)));
}
int len[N], A[N], B[N], P[N], rnk[LOG][N], T, n, m;
bool cmp(int i, int j) {
  int t = T - 1;
  if (T && rnk[t][i] == rnk[t][j]) {
    if (max(i, j) + (1 << t) - 1 > m) return i > j;
    return rnk[t][i + (1 << t)] < rnk[t][j + (1 << t)];
  }
  return rnk[t][i] < rnk[t][j];
}
void Build() {
  for (int i = 1; i <= m; i++) {
    P[i] = i;
    rnk[0][i] = B[i];
  }
  for (T = 1; T < LOG; T++) {
    sort(P + 1, P + m + 1, cmp);
    rnk[T][P[1]] = 1;
    for (int i = 2; i <= m; i++) {
      rnk[T][P[i]] = rnk[T][P[i - 1]] + cmp(P[i - 1], P[i]);
    }
  }
}
int lcp(int i, int j) {
  if (min(i, j) <= 0 || max(i, j) > m) return 0;
  int res = 0, Mx = min(len[i], len[j]);
  for (T = LOG - 1; ~T; T--) {
    if (max(i, j) + (1 << T) - 1 > m || rnk[T][i] != rnk[T][j]) continue;
    res |= 1 << T;
    i += 1 << T;
    j += 1 << T;
  }
  return min({res, Mx});
}
vector<int> seg[4 * N], id[4 * N];
int Mn[4 * N], ps[N], LAST[N];
void Bu(int v, int tl, int tr) {
  if (tl == tr) {
    Mn[v] = lcp(P[tl - 1], P[tl]);
    if (P[tl] < n) {
      seg[v].push_back(P[tl]);
      id[v].push_back(0);
    }
    return;
  }
  int mid = (tl + tr) >> 1;
  Bu(v << 1, tl, mid);
  Bu(v << 1 | 1, mid + 1, tr);
  Mn[v] = min(Mn[v << 1], Mn[v << 1 | 1]);
  int t1 = (int)seg[v << 1].size(), t2 = (int)seg[v << 1 | 1].size(), i = 0,
      j = 0;
  id[v].push_back(0);
  while (i < t1 && j < t2) {
    if (seg[v << 1][i] < seg[v << 1 | 1][j]) {
      id[v].push_back(id[v].back() + 1);
      seg[v].push_back(seg[v << 1][i]);
      i++;
    } else {
      id[v].push_back(id[v].back());
      seg[v].push_back(seg[v << 1 | 1][j]);
      j++;
    }
  }
  for (; i < t1; i++) {
    id[v].push_back(id[v].back() + 1);
    seg[v].push_back(seg[v << 1][i]);
  }
  for (; j < t2; j++) {
    id[v].push_back(id[v].back());
    seg[v].push_back(seg[v << 1 | 1][j]);
  }
}
int Get_mn(int v, int tl, int tr, int l, int r) {
  if (r > m || l < 0) return 0;
  if (l > r || l > tr || r < tl) return 2e9;
  if (l <= tl && tr <= r) {
    return Mn[v];
  }
  int mid = (tl + tr) >> 1;
  return min(Get_mn(v << 1, tl, mid, l, r),
             Get_mn(v << 1 | 1, mid + 1, tr, l, r));
}
int G(int v, int tl, int tr, int l, int r, int lwr) {
  if (l > tr || r < tl) return 0;
  if (l <= tl && tr <= r) {
    return lwr;
  }
  int mid = (tl + tr) >> 1;
  int ans = G(v << 1, tl, mid, l, r, id[v][lwr]);
  ans += G(v << 1 | 1, mid + 1, tr, l, r, lwr - id[v][lwr]);
  return ans;
}
long long Find(int l, int r, int x) {
  int lwr = upper_bound((seg[1]).begin(), (seg[1]).end(), x) - seg[1].begin();
  return G(1, 1, m, l, r, lwr);
}
inline pair<int, int> calc(int ind, int sz) {
  int d = 0, up = rnk[LOG - 1][ind];
  while (up - d > 1) {
    int mid = (up + d) >> 1;
    if (Get_mn(1, 1, m, mid + 1, rnk[LOG - 1][ind]) >= sz) {
      up = mid;
    } else {
      d = mid;
    }
  }
  int Left = up;
  d = rnk[LOG - 1][ind], up = m + 1;
  while (up - d > 1) {
    int mid = (up + d) >> 1;
    if (Get_mn(1, 1, m, rnk[LOG - 1][ind] + 1, mid) >= sz) {
      d = mid;
    } else {
      up = mid;
    }
  }
  int right = d;
  return make_pair(Left, right);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
  }
  for (int i = 1; i < n; i++) {
    B[i] = A[i + 1] - A[i];
    len[i] = (n - i);
  }
  B[n] = -2e9 - 10;
  for (int i = n + 1; i < 2 * n; i++) {
    B[i] = A[i - n] - A[i - n + 1];
    len[i] = 2 * n - i;
  }
  m = 2 * n - 1;
  printf("\n");
  Build();
  LAST[0] = -1;
  for (int i = 1; i <= m; i++) {
    LAST[i] = LAST[i - 1];
    if (P[i] > n) {
      LAST[i] = i;
    }
    ps[i] = ps[i - 1];
    if (P[i] < n) {
      ps[i]++;
    }
  }
  Bu(1, 1, m);
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    if (l == r) {
      printf("%d\n", n - 1);
      continue;
    }
    int sz = r - l;
    r--;
    pair<int, int> cu = calc(l, sz);
    if (LAST[cu.second] >= cu.first) {
      int anot = P[LAST[cu.second]] - n;
      pair<int, int> alan = calc(anot, sz);
      int tot = Find(alan.first, alan.second, 2e9 + 10) -
                Find(alan.first, alan.second, r + 1) +
                Find(alan.first, alan.second, l - sz - 1);
      printf("%d\n", tot);
    } else {
      printf("0\n");
      continue;
    }
  }
  return 0;
}
