#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[411111], l[411111], r[411111], d[411111], ans[411111];
int c[21][411111];
pair<pair<int, int>, int> p[411111];
int u[411111];
int s[411111];
vector<pair<int, int> > v[411111];
int st[21][411111];
int lg[411111];
void gg(int it) {
  sort(p, p + n + n);
  int e = 0;
  for (int i = 0; i < n + n; i++) {
    if (i == 0 || p[i - 1].first != p[i].first) e++;
    c[it][p[i].second] = e;
  }
}
int lcp(int x, int y) {
  int r = 0;
  for (int i = 18; i >= 0; i--) {
    if (x + (1ll << (i)) > n + n) continue;
    if (y + (1ll << (i)) > n + n) continue;
    if (c[i][x] != c[i][y]) continue;
    x += (1ll << (i));
    y += (1ll << (i));
    r += (1ll << (i));
  }
  return r;
}
void add(int x) {
  x++;
  while (x <= n) {
    s[x]++;
    x = x + x - (x & (x - 1));
  }
}
int find(int x) {
  x++;
  if (x > n) x = n;
  int r = 0;
  while (x > 0) {
    r += s[x];
    x &= x - 1;
  }
  return r;
}
int fm(int x, int y) {
  if (x == y) return 1e9;
  y--;
  int w = lg[y - x + 1];
  return min(st[w][x], st[w][y - (1ll << (w)) + 1]);
}
int main() {
  cin >> n;
  lg[1] = 0;
  for (int i = 2; i <= n + n; i++) lg[i] = lg[i / 2] + 1;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = n - 1; i > 0; i--) a[i] = a[i] - a[i - 1];
  for (int i = 0; i < n; i++) a[i + n] = -a[i];
  for (int i = 0; i < n + n; i++) p[i] = make_pair(make_pair(a[i], 0), i);
  gg(0);
  for (int i = 1; (1ll << (i)) <= n + n; i++) {
    for (int j = 0; j < n + n; j++)
      p[j] =
          make_pair(make_pair(c[i - 1][j], c[i - 1][j + (1ll << (i - 1))]), j);
    gg(i);
  }
  for (int i = 0; i < n + n; i++)
    if (p[i].second >= n) u[p[i].second - n] = i;
  for (int i = 0; i < n + n - 1; i++)
    st[0][i] = lcp(p[i].second, p[i + 1].second);
  for (int it = 1; (1 << it) <= n + n; it++) {
    for (int i = 0; i < n + n; i++)
      st[it][i] = min(st[it - 1][i], st[it - 1][i + (1ll << (it - 1))]);
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &l[i], &r[i]);
    d[i] = r[i] - l[i] + 1;
    l[i]--;
    r[i]--;
    if (l[i] == r[i]) {
      ans[i] = n - 1;
      continue;
    }
    int x = u[l[i] + 1];
    int left = x;
    int right = x;
    for (int j = 18; j >= 0; j--)
      if (right + (1ll << (j)) < n + n &&
          fm(x, right + (1ll << (j))) >= r[i] - l[i])
        right += (1ll << (j));
    for (int j = 18; j >= 0; j--)
      if (left - (1ll << (j)) >= 0 && fm(left - (1ll << (j)), x) >= r[i] - l[i])
        left -= (1ll << (j));
    v[right].push_back(make_pair(i, 1));
    if (left >= 0) v[left - 1].push_back(make_pair(i, -1));
  }
  for (int i = 0; i < n + n; i++) {
    if (p[i].second < n) add(p[i].second);
    for (int j = 0; j < v[i].size(); j++) {
      int t = find(n - 1) - find(r[v[i][j].first] + 1) +
              find(r[v[i][j].first] - d[v[i][j].first] * 2 + 2) - find(0);
      ans[v[i][j].first] += t * v[i][j].second;
    }
  }
  for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  return 0;
}
