#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 5;
const long long inf = 1e9 + 5;
long long n, h[N], sA[2 * N], rB[2 * N], G, rA[2 * N], lcp[2 * N], ans[N],
    pos[2 * N], tmp[2 * N];
long long pw[2 * N], rmq[25][2 * N], mylog[2 * N], bit[2 * N], hs[2 * N], m, q;
const long long base = 1610612741;
const long long mod = 1311322777;
long long add(long long x, long long y) { return (1ll * x + 1ll * y) % mod; }
long long del(long long x, long long y) {
  return ((1ll * x - 1ll * y) % mod + mod) % mod;
}
long long mul(long long x, long long y) { return (1ll * x * 1ll * y) % mod; }
long long get(long long pos) {
  long long sum = 0;
  while (pos > 0) {
    sum += bit[pos];
    pos -= pos & (-pos);
  }
  return sum;
}
void up(long long pos, long long val) {
  while (pos < 2 * N) {
    bit[pos] += val;
    pos += pos & (-pos);
  }
}
bool cmp(long long x, long long y) {
  if (rA[x] != rA[y]) return rA[x] < rA[y];
  return rA[x + G] < rA[y + G];
}
long long geths(long long l, long long r) {
  return del(hs[r], mul(hs[l - 1], pw[r - l + 1]));
}
long long get(long long x, long long y) {
  long long l = 1, r = m - max(x, y) + 1, md;
  while (l < r) {
    long long md = (l + r + 1) >> 1;
    if (geths(x, x + md - 1) == geths(y, y + md - 1))
      l = md;
    else
      r = md - 1;
  }
  if (geths(x, x + l - 1) == geths(y, y + l - 1)) return l;
  return 0;
}
long long getrmq(long long x, long long y) {
  if (x > y) return inf;
  long long bit = mylog[y - x + 1];
  return min(rmq[bit][x], rmq[bit][y - (1ll << bit) + 1]);
}
vector<pair<pair<long long, long long>, pair<long long, long long> > > query;
vector<pair<long long, long long> > qu, vec;
signed main() {
  cin.tie(0), ios_base::sync_with_stdio(0);
  pw[0] = 1;
  for (long long i = 0; i < 2 * N; i++) mylog[i] = log2(i);
  for (long long i = 1; i < 2 * N; i++) pw[i] = mul(pw[i - 1], base);
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> h[i];
  for (long long i = 1; i <= n - 1; i++) sA[i] = i, rA[i] = h[i + 1] - h[i];
  sA[n] = n, rA[n] = INT_MAX;
  m = 2 * n - 1;
  for (long long i = n + 1; i <= m; i++)
    sA[i] = i, rA[i] = h[i - n] - h[i - n + 1];
  for (long long i = 1; i <= m; i++) hs[i] = add(mul(hs[i - 1], base), rA[i]);
  for (long long i = m + 1; i < 3 * N; i++) rA[i] = INT_MAX;
  for (G = 1; G <= m; G *= 2) {
    sort(sA + 1, sA + 1 + m, cmp);
    for (long long i = 1; i <= m; i++)
      rB[sA[i]] = rB[sA[i - 1]] + cmp(sA[i - 1], sA[i]);
    for (long long i = 1; i <= m; i++) rA[i] = rB[i];
    if (rA[sA[m]] == m) break;
  }
  for (long long i = 1; i <= m; i++) pos[sA[i]] = i;
  for (long long i = 1; i <= m - 1; i++) {
    lcp[i] = get(sA[i], sA[i + 1]);
    rmq[0][i] = lcp[i];
  }
  for (long long bit = 1; bit < 25; bit++) {
    for (long long i = 1; i <= m - 1; i++) {
      long long j = i + (1ll << (bit - 1));
      if (j > m - 1) break;
      rmq[bit][i] = min(rmq[bit - 1][i], rmq[bit - 1][j]);
    }
  }
  cin >> q;
  for (long long i = 1; i <= q; i++) {
    long long l, r, len;
    cin >> l >> r;
    len = r - l + 1;
    qu.push_back(make_pair(l, r));
    if (l == r)
      ans[i] = n - 1;
    else
      query.push_back(make_pair(make_pair(min(n + l - len, m + 1), len - 1),
                                make_pair(l, i)));
  }
  sort(query.begin(), query.end());
  long long po = n + 1;
  for (long long i = 0; i < (long long)(query.size()); i++) {
    long long le = query[i].first.first, li = query[i].second.first,
              id = query[i].second.second, len = query[i].first.second;
    while (po <= le) {
      up(pos[po], 1), po++;
    }
    long long Left, Right, l = 1, r = pos[li], md;
    while (l < r) {
      long long md = (l + r) >> 1;
      if (getrmq(md, pos[li] - 1) >= len)
        r = md;
      else
        l = md + 1;
    }
    Left = l;
    l = pos[li], r = m;
    while (l < r) {
      long long md = (l + r + 1) >> 1;
      if (getrmq(pos[li], md - 1) >= len)
        l = md;
      else
        r = md - 1;
    }
    Right = l;
    if (Left <= Right) ans[id] += get(Right) - get(Left - 1);
  }
  query.clear();
  for (long long i = 1; i <= q; i++) {
    long long l, r;
    l = qu[i - 1].first, r = qu[i - 1].second;
    if (l == r) continue;
    query.push_back(
        make_pair(make_pair(min(n + 1 + r, m + 1), r - l), make_pair(l, i)));
  }
  memset(bit, 0, sizeof(bit));
  sort(query.begin(), query.end());
  po = m;
  for (long long i = (long long)(query.size()) - 1; i >= 0; i--) {
    long long le = query[i].first.first, li = query[i].second.first,
              id = query[i].second.second, len = query[i].first.second;
    while (po >= le) {
      up(pos[po], 1), po--;
    }
    long long Left, Right, l = 1, r = pos[li], md;
    while (l < r) {
      long long md = (l + r) >> 1;
      if (getrmq(md, pos[li] - 1) >= len)
        r = md;
      else
        l = md + 1;
    }
    Left = l;
    l = pos[li], r = m;
    while (l < r) {
      long long md = (l + r + 1) >> 1;
      if (getrmq(pos[li], md - 1) >= len)
        l = md;
      else
        r = md - 1;
    }
    Right = l;
    if (Left <= Right) ans[id] += get(Right) - get(Left - 1);
  }
  for (long long i = 1; i <= q; i++) cout << ans[i] << "\n";
}
