#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int arr[200009], S[200009 << 1][20], n, c[200009], ans[200009];
int ord[200009], q, LOG[200009], M[200009 << 1][20];
pair<int, int> C[200009];
bool cmp(int x, int y) { return (C[x] < C[y]); }
map<int, int> pm;
struct asd {
  int left, right;
  pair<int, int> dif;
} query[200009];
int rmq(int x, int y) {
  int k = LOG[y - x + 1];
  return min(M[x][k], M[y - (1 << k) + 1][k]);
}
int s[200009 << 2];
pair<int, int> bul(int x, int dis) {
  int st = 1, en = x - 1;
  int pos = x, pos1 = x - 1;
  while (st + 1 < en) {
    int mid = (st + en) >> 1;
    if (rmq(mid, x - 1) >= dis)
      en = mid;
    else
      st = mid;
  }
  for (int i = st; i <= en; i++)
    if (rmq(i, x - 1) >= dis) {
      pos = i;
      break;
    }
  st = x;
  en = n * 2 - 2;
  while (st + 1 < en) {
    int mid = (st + en) >> 1;
    if (rmq(x, mid) >= dis)
      st = mid;
    else
      en = mid;
  }
  for (int i = en; i >= st; i--)
    if (rmq(x, i) >= dis) {
      pos1 = i;
      break;
    }
  return make_pair(pos, pos1 + 1);
}
void upd(int p, int nd, int x, int y) {
  if (x == y) {
    s[nd]++;
    return;
  }
  int mid = (x + y) >> 1;
  if (p <= mid)
    upd(p, nd << 1, x, mid);
  else
    upd(p, nd << 1 | 1, mid + 1, y);
  s[nd] = s[nd << 1] + s[nd << 1 | 1];
}
int tap(int l, int r, int nd, int x, int y) {
  if (l > y or x > r) return 0;
  if (l <= x and y <= r) return s[nd];
  int mid = (x + y) >> 1;
  int i1 = tap(l, r, nd << 1, x, mid);
  int i2 = tap(l, r, nd << 1 | 1, mid + 1, y);
  return i2 + i1;
}
int go(int l, int r) {
  return tap(n + r + 1, n * 2, 1, 1, n * 2) +
         tap(n + 1, n + l - (r - l) - 1, 1, 1, n * 2);
}
vector<pair<pair<int, int>, int> > add[200009], rem[200009];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", arr + i);
  S[1][0] = -1000000007;
  for (int i = 2; i <= n; i++) S[i][0] = arr[i - 1] - arr[i];
  for (int i = n + 1; i < n * 2; i++) S[i][0] = arr[i - n + 1] - arr[i - n];
  for (int i = 1; i < n * 2; i++) {
    pm[S[i][0]] = 1;
    LOG[i] = log2(i);
  }
  int cnt = 0;
  for (typeof((pm).begin()) it = (pm).begin(); it != (pm).end(); it++)
    it->second = ++cnt;
  for (int i = 1; i < n * 2; i++) S[i][0] = pm[S[i][0]];
  for (int j = 1; j < 20; j++) {
    for (int i = 1; i < n * 2; i++)
      C[i] =
          make_pair(S[i][j - 1],
                    i + (1 << j - 1) < n * 2 ? S[i + (1 << j - 1)][j - 1] : -1),
      c[i] = i;
    sort(c + 1, c + (n * 2), cmp);
    for (int i = 1; i < n * 2; i++)
      S[c[i]][j] = S[c[i - 1]][j] + (C[c[i]] != C[c[i - 1]]);
  }
  for (int i = 1; i < (n * 2); i++) ord[S[i][19]] = i;
  for (int i = 1; i < n * 2 - 1; i++) {
    int a = ord[i];
    int b = ord[i + 1];
    for (int j = 19; j >= 0; j--)
      if (a < n * 2 and b < n * 2 and S[a][j] == S[b][j]) {
        a += (1 << j);
        b += (1 << j);
        M[i][0] += (1 << j);
      }
  }
  for (int j = 1; j < 20; j++)
    for (int i = 1; i < n * 2 - 1; i++)
      M[i][j] = min(M[i][j - 1], i + (1 << j - 1) < n * 2 - 1
                                     ? M[i + (1 << j - 1)][j - 1]
                                     : 1000000007);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    if (l == r) {
      ans[i] = n - 1;
      continue;
    }
    pair<int, int> k = bul(S[l + 1][19], r - l);
    add[k.first].push_back(make_pair(make_pair(l, r), i));
    rem[k.second].push_back(make_pair(make_pair(l, r), i));
  }
  for (int i = 1; i < n * 2; i++) {
    for (typeof((add[i]).begin()) it = (add[i]).begin(); it != (add[i]).end();
         it++)
      ans[it->second] -= go(it->first.first, it->first.second);
    upd(ord[i], 1, 1, n * 2);
    for (typeof((rem[i]).begin()) it = (rem[i]).begin(); it != (rem[i]).end();
         it++)
      ans[it->second] += go(it->first.first, it->first.second);
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
