#include <bits/stdc++.h>
using namespace std;
inline void OPEN(const string &s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
template <class T>
inline T MIN(T a, T b) {
  if (a < b) return a;
  return b;
}
template <class T>
inline T MAX(T a, T b) {
  if (a > b) return a;
  return b;
}
int second[200000 + 5];
int n;
int gap;
int sa[200000], pos[200000], tmp[200000], lcp[200000];
bool sufCmp(int i, int j) {
  if (pos[i] != pos[j]) return pos[i] < pos[j];
  i += gap;
  j += gap;
  return (i < n && j < n) ? pos[i] < pos[j] : i > j;
}
void buildSA() {
  for (int i = 0, _n = (n); i < _n; i++) sa[i] = i, pos[i] = second[i];
  for (gap = 1;; gap <<= 1) {
    sort(sa, sa + n, sufCmp);
    for (int i = 0, _n = (n - 1); i < _n; i++)
      tmp[i + 1] = tmp[i] + sufCmp(sa[i], sa[i + 1]);
    for (int i = 0, _n = (n); i < _n; i++) pos[sa[i]] = tmp[i];
    if (tmp[n - 1] == n - 1) break;
  }
}
void buildLCP() {
  for (int i = 0, k = 0; i < n; ++i)
    if (pos[i] != n - 1) {
      for (int j = sa[pos[i] + 1]; second[i + k] == second[j + k];) ++k;
      lcp[pos[i]] = k;
      if (k) --k;
    }
}
int H[200000 + 5];
vector<pair<pair<int, int>, int> > intervals;
int Q;
int ans[200000 + 5];
int BIT[200000 + 5];
int where[200000 + 5], cor[200000 + 5];
int RMQ[20][200000 + 5];
void initRMQ() {
  for (int lg = 0, _n = (20); lg < _n; lg++)
    for (int i = 0, _n = (n); i < _n; i++) RMQ[lg][i] = 1000111000;
  for (int i = 0, _n = (n); i < _n; i++) RMQ[0][i] = lcp[i];
  for (int lg = 0, _n = (20); lg < _n; lg++) {
    if (lg == 0) continue;
    for (int i = 0, _n = (n); i < _n; i++) {
      if (i + (1 << lg) - 1 < n) {
        RMQ[lg][i] = MIN(RMQ[lg - 1][i], RMQ[lg - 1][i + (1 << (lg - 1))]);
      }
    }
  }
}
int query(int l, int r) {
  int x = r - l + 1;
  int lg = 0;
  for (; (1 << lg) <= x; lg++)
    ;
  lg--;
  return MIN(RMQ[lg][l], RMQ[lg][r - (1 << lg) + 1]);
}
inline void add(int x) {
  for (++x; x <= 200000; x += x & -x) BIT[x]++;
}
inline int queryBIT(int x) {
  int ret = 0;
  for (++x; x > 0; x -= x & -x) ret += BIT[x];
  return ret;
}
inline int b_search(int i, int k) {
  k--;
  if (lcp[i] < k) return i;
  int lo = i, hi = n - 1;
  while (lo <= hi) {
    int mid = (lo + hi) >> 1;
    int q1 = query(i, mid);
    if (q1 >= k && (mid + 1 >= n || query(i, mid + 1) < k)) {
      return mid + 1;
    }
    if (q1 >= k)
      lo = mid + 1;
    else
      hi = mid - 1;
  }
}
inline int b_search_atas(int i, int k) {
  k--;
  if (i == 0 || lcp[i - 1] < k) return i;
  int lo = 0, hi = i - 1;
  while (lo <= hi) {
    int mid = (lo + hi) >> 1;
    int q1 = query(mid, i - 1);
    if (q1 >= k && (mid - 1 < 0 || query(mid - 1, i - 1) < k)) {
      return mid;
    }
    if (q1 >= k)
      hi = mid - 1;
    else
      lo = mid + 1;
  }
}
int N;
inline void solve() {
  n = 0;
  for (int i = 0, _n = (N - 1); i < _n; i++) second[n++] = H[i + 1] - H[i];
  for (int i = 0, _n = (N - 1); i < _n; i++) second[n++] = H[i] - H[i + 1];
  int mn = 1000111000;
  for (int i = 0, _n = (n); i < _n; i++) mn = MIN(mn, second[i]);
  for (int i = 0, _n = (n); i < _n; i++) second[i] = second[i] - mn + 1;
  buildSA();
  buildLCP();
  int n2 = n / 2;
  for (int i = 0, _n = (n); i < _n; i++) {
    if (sa[i] >= n2)
      where[sa[i] - n2] = i;
    else
      cor[sa[i]] = i;
  }
  for (int i = 0, _n = (Q); i < _n; i++)
    swap(intervals[i].first.first, intervals[i].first.second);
  sort((intervals).begin(), (intervals).end());
  for (int i = 0, _n = (Q); i < _n; i++)
    swap(intervals[i].first.first, intervals[i].first.second);
  initRMQ();
  memset(BIT, 0, sizeof(BIT));
  int j = n2 - 1;
  for (int i = (Q)-1; i >= 0; i--) {
    while (j > intervals[i].first.second) {
      add(where[j]);
      j--;
    }
    int ctr = intervals[i].first.second - intervals[i].first.first + 1;
    int k = b_search(cor[intervals[i].first.first], ctr);
    int p = b_search_atas(cor[intervals[i].first.first], ctr);
    ans[intervals[i].second] += queryBIT(k) - queryBIT(p - 1);
  }
}
int main() {
  scanf("%d", &N);
  for (int i = 0, _n = (N); i < _n; i++) scanf("%d", &H[i]);
  scanf("%d", &Q);
  if (N == 1) {
    for (int i = 0, _n = (Q); i < _n; i++) printf("0\n");
    return 0;
  }
  for (int i = 0, _n = (Q); i < _n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    intervals.push_back(make_pair(make_pair(a, b), i));
  }
  solve();
  reverse(H, H + N);
  for (int i = 0, _n = (Q); i < _n; i++) {
    swap(intervals[i].first.first, intervals[i].first.second);
    intervals[i].first.first = N - 1 - intervals[i].first.first;
    intervals[i].first.second = N - 1 - intervals[i].first.second;
  }
  solve();
  for (int i = 0, _n = (Q); i < _n; i++) {
    if (intervals[i].first.first == intervals[i].first.second)
      ans[intervals[i].second] = N - 1;
  }
  for (int i = 0, _n = (Q); i < _n; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
