#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const long long int INFLL = 0x3f3f3f3f3f3f3f3fll;
long long int getint() {
  long long int ret = 0;
  bool f = 0;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') f ^= 1;
  while (c >= '0' && c <= '9') {
    ret = ret * 10 + c - '0';
    c = getchar();
  }
  return f ? -ret : ret;
}
using namespace std;
const int MAXN = 200000;
namespace SA {
int sa[MAXN + 10], *rk, h[MAXN + 10];
int wa[MAXN + 10], wb[MAXN + 10], ws[MAXN + 10], wv[MAXN + 10];
bool cmp(int *rk, int i, int j, int len) {
  return rk[i] == rk[j] && rk[i + len] == rk[j + len];
}
void calsa(int *r, int n, int m) {
  int *x = wa, *y = wb, i, j, p;
  for (i = 1; i <= m; ++i) ws[i] = 0;
  for (i = 1; i <= n; ++i) ++ws[x[i] = r[i]];
  for (i = 1; i <= m; ++i) ws[i] += ws[i - 1];
  for (i = n; i >= 1; --i) sa[ws[x[i]]--] = i;
  for (j = 1, p = 1; p < n; m = p, j <<= 1) {
    for (p = 0, i = n - j + 1; i <= n; ++i) y[++p] = i;
    for (i = 1; i <= n; ++i)
      if (sa[i] > j) y[++p] = sa[i] - j;
    for (i = 1; i <= m; ++i) ws[i] = 0;
    for (i = 1; i <= n; ++i) ++ws[wv[i] = x[y[i]]];
    for (i = 1; i <= m; ++i) ws[i] += ws[i - 1];
    for (i = n; i >= 1; --i) sa[ws[wv[i]]--] = y[i];
    for (swap(x, y), x[sa[1]] = 1, i = 2, p = 1; i <= n; ++i)
      x[sa[i]] = cmp(y, sa[i], sa[i - 1], j) ? p : ++p;
  }
  rk = x;
}
void calh(int *r, int n) {
  for (int i = 1, k = 0, j; i <= n; h[rk[i++]] = k)
    for (k ? --k : 0, j = sa[rk[i] + 1]; r[i + k] == r[j + k]; ++k)
      ;
}
}  // namespace SA
using SA::h;
using SA::rk;
using SA::sa;
int a[MAXN + 10], hsh[MAXN + 10], n, N;
int st[MAXN + 10][20], lg[MAXN + 10];
int L[MAXN + 10], R[MAXN + 10], ans[MAXN + 10];
void init() {
  lg[0] = -1;
  for (int i = 1; i <= N; ++i) {
    st[i][0] = h[i];
    lg[i] = lg[i >> 1] + 1;
  }
  for (int j = 1; j <= lg[N]; ++j) {
    int len = 1 << (j - 1);
    for (int i = 1; i + (len << 1) - 1 <= N; ++i)
      st[i][j] = min(st[i][j - 1], st[i + len][j - 1]);
  }
}
int query(int l, int r) {
  if (l == r) return INF;
  int t = lg[r - l];
  return min(st[l][t], st[r - (1 << t)][t]);
}
void getseq(int p, int len, int &pl, int &pr) {
  int l = 1, r = p;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (query(mid, p) >= len) {
      pl = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  l = p;
  r = N;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (query(p, mid) >= len) {
      pr = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
}
int c[MAXN + 10];
vector<int> vec[MAXN + 10];
void update(int p) {
  while (p <= N) ++c[p], p += p & -p;
}
int query(int p) {
  int ret = 0;
  while (p) ret += c[p], p -= p & -p;
  return ret;
}
int querytr(int l, int r) {
  if (l > r) return 0;
  return query(r) - query(l - 1);
}
int main() {
  n = getint();
  for (int i = 1; i <= n; ++i) a[i] = getint();
  n--;
  N = 2 * n;
  for (int i = 1; i <= n; ++i) hsh[i] = a[i] = a[i + 1] - a[i];
  for (int i = n + 1; i <= N; ++i) hsh[i] = a[i] = -a[i - n];
  sort(hsh + 1, hsh + N + 1);
  int m = unique(hsh + 1, hsh + N + 1) - hsh - 1;
  for (int i = 1; i <= N; ++i)
    a[i] = lower_bound(hsh + 1, hsh + m + 1, a[i]) - hsh;
  SA::calsa(a, N, m);
  SA::calh(a, N);
  init();
  int q = getint();
  for (int i = 1; i <= q; ++i) {
    int &l = L[i] = getint(), &r = R[i] = getint();
    if (l == r) {
      ans[i] = n;
      continue;
    }
    --r;
    int p = rk[l + n], pl, pr;
    getseq(p, r - l + 1, pl, pr);
    vec[pl - 1].push_back(-i);
    vec[pr].push_back(i);
  }
  for (int i = 1; i <= N; ++i) {
    update(sa[i]);
    for (int j = 0; j < vec[i].size(); ++j) {
      int id = vec[i][j], flag = 1;
      if (id < 0) id = -id, flag = -1;
      ans[id] += flag * (querytr(1, L[id] - (R[id] - L[id] + 2)) +
                         querytr(R[id] + 2, n - R[id] + L[id]));
    }
  }
  for (int i = 1; i <= q; ++i) printf("%d\n", ans[i]);
  return 0;
}
