#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:20000000")
using namespace std;
int ri() {
  int x;
  scanf("%d", &x);
  return x;
}
long long rll() {
  long long x;
  scanf("%lld", &x);
  return x;
}
int mas[200500];
int tmas[200500];
int d1[100500];
int d2[100500];
int cnt[200500];
int p1[200500];
int p2[200500];
int c[20][200500];
void suffArray(int n) {
  for (int i = (int)(0); i <= (int)(n - 1); i++) cnt[mas[i]]++;
  for (int i = (int)(1); i <= (int)(200499); i++) cnt[i] += cnt[i - 1];
  for (int i = (int)(0); i <= (int)(n - 1); i++) p1[--cnt[mas[i]]] = i;
  c[0][p1[0]] = 0;
  int cl = 0;
  for (int i = (int)(1); i <= (int)(n - 1); i++) {
    if (mas[p1[i]] != mas[p1[i - 1]]) cl++;
    c[0][p1[i]] = cl;
  }
  for (int mid = 1, step = 0; mid < n; mid <<= 1, step++) {
    for (int i = (int)(0); i <= (int)(cl); i++) cnt[i] = 0;
    for (int i = (int)(0); i <= (int)(n - 1); i++)
      p2[i] = (p1[i] - mid + n + n) % n;
    for (int i = (int)(0); i <= (int)(n - 1); i++) cnt[c[step][p2[i]]]++;
    for (int i = (int)(1); i <= (int)(cl); i++) cnt[i] += cnt[i - 1];
    for (int i = (int)(n - 1); i >= (int)(0); i--)
      p1[--cnt[c[step][p2[i]]]] = p2[i];
    c[step + 1][p1[0]] = 0;
    cl = 0;
    for (int i = (int)(1); i <= (int)(n - 1); i++) {
      int a = (p1[i] + mid) % n;
      int b = (p1[i - 1] + mid) % n;
      if (c[step][p1[i]] != c[step][p1[i - 1]] || c[step][a] != c[step][b])
        cl++;
      c[step + 1][p1[i]] = cl;
    }
  }
}
int getLCP(int a, int b, int mx) {
  int res = 0;
  int m = min(mx - a, mx - b);
  int L = 0;
  while ((1 << L) <= m) L++;
  L--;
  for (int i = (int)(L); i >= (int)(0); i--)
    if (c[i][a] == c[i][b]) {
      res += (1 << i);
      a += (1 << i);
      b += (1 << i);
      a %= mx;
      b %= mx;
    }
  return min(res, mx);
}
int posD1[100500];
vector<int> tree[8 * 100500];
int N;
void build(int v, int l, int r) {
  if (l == r) {
    if (p1[l] >= N) tree[v].push_back(p1[l] - N);
    return;
  }
  int mid = (l + r) >> 1;
  build(2 * v, l, mid);
  build(2 * v + 1, mid + 1, r);
  tree[v].resize(tree[2 * v].size() + tree[2 * v + 1].size());
  merge(tree[2 * v].begin(), tree[2 * v].end(), tree[2 * v + 1].begin(),
        tree[2 * v + 1].end(), tree[v].begin());
}
int get(int v, int l, int r, int L, int R, int h1, int h2) {
  if (l == L && r == R) {
    if (tree[v].empty()) return 0;
    int res = 0;
    int tl = 0, tr = tree[v].size();
    if (tree[v][0] <= h2) {
      while (tl + 1 < tr) {
        int mid = (tl + tr) >> 1;
        if (tree[v][mid] <= h2)
          tl = mid;
        else
          tr = mid;
      }
      res += tl + 1;
    }
    tl = 0, tr = tree[v].size();
    if (tree[v][0] < h1) {
      while (tl + 1 < tr) {
        int mid = (tl + tr) >> 1;
        if (tree[v][mid] < h1)
          tl = mid;
        else
          tr = mid;
      }
      res -= tl + 1;
    }
    return res;
  }
  int mid = (l + r) >> 1;
  if (R <= mid) return get(2 * v, l, mid, L, R, h1, h2);
  if (L > mid) return get(2 * v + 1, mid + 1, r, L, R, h1, h2);
  return get(2 * v, l, mid, L, mid, h1, h2) +
         get(2 * v + 1, mid + 1, r, mid + 1, R, h1, h2);
}
void solve() {
  int n = ri();
  for (int i = (int)(1); i <= (int)(n); i++) mas[i] = ri();
  for (int i = (int)(1); i <= (int)(n - 1); i++)
    d1[i] = mas[i] - mas[i + 1], d2[i] = -d1[i];
  for (int i = (int)(0); i <= (int)(n - 2); i++) mas[i] = d1[i + 1];
  mas[n - 1] = 2000000000;
  for (int i = (int)(0); i <= (int)(n - 2); i++) mas[i + n] = d2[i + 1];
  mas[2 * n - 1] = 2000000001;
  memcpy(tmas, mas, sizeof(mas));
  sort(tmas, tmas + 2 * n);
  map<int, int> index;
  int cn = 0;
  for (int i = (int)(0); i <= (int)(2 * n - 1); i++)
    if (i == 0)
      index[tmas[i]] = cn++;
    else if (tmas[i] != tmas[i - 1])
      index[tmas[i]] = cn++;
  for (int i = (int)(0); i <= (int)(2 * n - 1); i++) mas[i] = index[mas[i]];
  suffArray(n + n);
  for (int i = (int)(0); i <= (int)(2 * n - 1); i++)
    if (p1[i] <= n - 2) posD1[p1[i]] = i;
  N = n;
  build(1, 0, 2 * n - 1);
  int q = ri();
  for (int i = (int)(0); i <= (int)(q - 1); i++) {
    int L = ri() - 1, R = ri() - 1;
    int pos = posD1[L];
    int lb = pos, rb = pos;
    int l = -1, r = pos;
    while (l + 1 < r) {
      int mid = (l + r) >> 1;
      if (getLCP(p1[mid], p1[pos], 2 * n) >= R - L)
        r = mid;
      else
        l = mid;
    }
    lb = r;
    l = pos, r = 2 * n;
    while (l + 1 < r) {
      int mid = (l + r) >> 1;
      if (getLCP(p1[pos], p1[mid], 2 * n) >= R - L)
        l = mid;
      else
        r = mid;
    }
    rb = l;
    int res = 0;
    if (L == R)
      res = n - 1;
    else {
      int tl = L, tr = R;
      if (tl - tr + tl - 1 >= 0)
        res += get(1, 0, 2 * n - 1, lb, rb, 0, tl - tr + tl - 1);
      if (tr + 1 <= n - 1) res += get(1, 0, 2 * n - 1, lb, rb, tr + 1, n - 1);
    }
    printf("%d\n", res);
  }
}
int main() {
  solve();
  return 0;
}
