#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
template <typename T, typename TT>
ostream& operator<<(ostream& s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T> t) {
  for (int(i) = 0; (i) < (((int)((t).size()))); ++(i)) s << t[i] << " ";
  return s;
}
namespace karkkainen {
inline bool leq(int a1, int a2, int b1, int b2) {
  return (a1 < b1 || (a1 == b1 && a2 <= b2));
}
inline bool leq(int a1, int a2, int a3, int b1, int b2, int b3) {
  return (a1 < b1 || (a1 == b1 && leq(a2, a3, b2, b3)));
}
static void radixPass(int* a, int* b, int* r, int n, int K) {
  vector<int> c(K + 1, 0);
  for (int(i) = 0; (i) < (n); ++(i)) c[r[a[i]]]++;
  int sum = 0;
  for (int(i) = (0); (i) <= (K); ++i) {
    int t = c[i];
    c[i] = sum;
    sum += t;
  }
  for (int(i) = 0; (i) < (n); ++(i)) b[c[r[a[i]]]++] = a[i];
}
void suffixArray(int* s, int* SA, int n, int K) {
  int n0 = (n + 2) / 3, n1 = (n + 1) / 3, n2 = n / 3, n02 = n0 + n2;
  int* s12 = new int[n02 + 3];
  s12[n02] = s12[n02 + 1] = s12[n02 + 2] = 0;
  int* SA12 = new int[n02 + 3];
  SA12[n02] = SA12[n02 + 1] = SA12[n02 + 2] = 0;
  int* s0 = new int[n0];
  int* SA0 = new int[n0];
  for (int i = 0, j = 0; i < n + (n0 - n1); i++)
    if (i % 3 != 0) s12[j++] = i;
  radixPass(s12, SA12, s + 2, n02, K);
  radixPass(SA12, s12, s + 1, n02, K);
  radixPass(s12, SA12, s, n02, K);
  int name = 0, c0 = -1, c1 = -1, c2 = -1;
  for (int(i) = 0; (i) < (n02); ++(i)) {
    if (s[SA12[i]] != c0 || s[SA12[i] + 1] != c1 || s[SA12[i] + 2] != c2) {
      name++;
      c0 = s[SA12[i]];
      c1 = s[SA12[i] + 1];
      c2 = s[SA12[i] + 2];
    }
    if (SA12[i] % 3 == 1) {
      s12[SA12[i] / 3] = name;
    } else {
      s12[SA12[i] / 3 + n0] = name;
    }
  }
  if (name < n02) {
    suffixArray(s12, SA12, n02, name);
    for (int(i) = 0; (i) < (n02); ++(i)) s12[SA12[i]] = i + 1;
  } else {
    for (int(i) = 0; (i) < (n02); ++(i)) SA12[s12[i] - 1] = i;
  }
  for (int i = 0, j = 0; i < n02; ++i)
    if (SA12[i] < n0) s0[j++] = 3 * SA12[i];
  radixPass(s0, SA0, s, n0, K);
  int p = 0, t = n0 - n1;
  for (int(k) = 0; (k) < (n); ++(k)) {
    int i = (SA12[t] < n0 ? SA12[t] * 3 + 1 : (SA12[t] - n0) * 3 + 2);
    int j = SA0[p];
    if (SA12[t] < n0 ? leq(s[i], s12[SA12[t] + n0], s[j], s12[j / 3])
                     : leq(s[i], s[i + 1], s12[SA12[t] - n0 + 1], s[j],
                           s[j + 1], s12[j / 3 + n0])) {
      SA[k] = i;
      t++;
      if (t == n02) {
        for (k++; p < n0; p++, k++) SA[k] = SA0[p];
      }
    } else {
      SA[k] = j;
      p++;
      if (p == n0) {
        for (k++; t < n02; t++, k++)
          SA[k] = (SA12[t] < n0 ? SA12[t] * 3 + 1 : (SA12[t] - n0) * 3 + 2);
      }
    }
  }
  delete[] s12;
  delete[] SA12;
  delete[] SA0;
  delete[] s0;
}
};  // namespace karkkainen
struct SuffixArray {
  int *sa, *lcp, *rank, n;
  vector<int> t;
  SuffixArray(const vector<int>& str) : t(str) {
    n = ((int)((t).size()));
    if (n <= 1) {
      sa = new int[5];
      sa[0] = 0;
    } else {
      int* arr = new int[n + 3];
      sa = new int[n + 3];
      for (int(i) = 0; (i) < (n); ++(i)) arr[i] = t[i];
      arr[n] = arr[n + 1] = arr[n + 2] = 0;
      karkkainen::suffixArray(arr, sa, n, *max_element(arr, arr + n));
      delete[] arr;
    }
    rank = new int[n + 3];
    for (int(i) = 0; (i) < (n); ++(i)) rank[sa[i]] = i;
    lcp = new int[n + 3];
    for (int i = 0, k = 0; i < n; i++) {
      if (k > 0) k--;
      if (rank[i] == n - 1) {
        lcp[n - 1] = -1;
        k = 0;
        continue;
      }
      int j = sa[rank[i] + 1];
      while (t[i + k] == t[j + k]) k++;
      lcp[rank[i]] = k;
    }
  }
  ~SuffixArray() {
    delete[] sa;
    delete[] rank;
    delete[] lcp;
  }
};
const int LOGN = 18, N = 1 << LOGN;
int rm[LOGN][N];
void init(int* tab, int n) {
  for (int(i) = 0; (i) < (n); ++(i)) rm[0][i] = tab[i];
  for (int(k) = (1); (k) <= (LOGN - 1); ++k)
    for (int(i) = (0); (i) <= (n - (1 << k)); ++i)
      rm[k][i] = min(rm[k - 1][i], rm[k - 1][i + (1 << (k - 1))]);
}
int query(int a, int b) {
  int k = 31 - __builtin_clz(b - a + 1);
  return min(rm[k][a], rm[k][b - (1 << k) + 1]);
}
int inp[N];
int word[N];
int ans[N];
int newword[N];
struct Todo {
  int from, to, maxIndex, whichQuery, multiplier, uniq;
};
bool operator<(const Todo& t, const Todo& r) {
  return t.maxIndex != r.maxIndex ? t.maxIndex < r.maxIndex : t.uniq < r.uniq;
}
namespace Fenwick {
int a[200007];
void add(int n, int x) {
  for (; n < 200007; n |= n + 1) a[n] += x;
}
int sum(int n) {
  int s = 0;
  while (n >= 0) {
    s += a[n];
    n = (n & (n + 1)) - 1;
  }
  return s;
}
};  // namespace Fenwick
int main() {
  int(n);
  scanf("%d", &(n));
  for (int(i) = 0; (i) < (n); ++(i)) {
    scanf("%d", inp + i);
  }
  for (int(i) = 0; (i) < (n - 1); ++(i)) {
    word[i] = inp[i + 1] - inp[i];
  }
  word[n - 1] = INT_MAX;
  for (int(i) = 0; (i) < (n - 1); ++(i)) {
    word[n + i] = -word[i];
  }
  int len = 2 * n - 1;
  map<int, int> mapa;
  int now = 1;
  for (int(i) = 0; (i) < (len); ++(i)) mapa[word[i]] = now++;
  for (int(i) = 0; (i) < (len); ++(i)) newword[i] = mapa[word[i]];
  SuffixArray sa(vector<int>(newword, newword + len));
  init(sa.lcp, sa.n);
  vector<Todo> todo;
  int uniquer = 0;
  int(queries);
  scanf("%d", &(queries));
  for (int(q) = 0; (q) < (queries); ++(q)) {
    int(l), (r);
    scanf("%d %d", &(l), &(r));
    --l;
    --r;
    if (l == r) {
      ans[q] = n - 1;
    } else {
      int indexInSa = sa.rank[n + l];
      int a = indexInSa, b = indexInSa;
      {
        int from = 0, to = indexInSa - 1;
        while (from <= to) {
          int mid = (from + to) / 2;
          if (query(mid, indexInSa - 1) < r - l) {
            from = mid + 1;
          } else {
            a = mid;
            to = mid - 1;
          }
        }
      }
      {
        int from = indexInSa + 1, to = sa.n - 1;
        while (from <= to) {
          int mid = (from + to) / 2;
          if (query(indexInSa, mid - 1) < r - l) {
            to = mid - 1;
          } else {
            b = mid;
            from = mid + 1;
          }
        }
      }
      ans[q] = 0;
      if (r + 1 <= n - 2) {
        todo.push_back((Todo){a, b, n - 2, q, 1, uniquer++});
        todo.push_back((Todo){a, b, r, q, -1, uniquer++});
      }
      if (0 <= l - (r - l + 1)) {
        todo.push_back((Todo){a, b, l - (r - l + 1), q, 1, uniquer++});
      }
    }
  }
  sort(todo.begin(), todo.end());
  int nowToAddIndex = 0;
  for (typeof(todo.begin()) td = todo.begin(); td != todo.end(); td++) {
    for (; nowToAddIndex <= td->maxIndex; ++nowToAddIndex) {
      Fenwick::add(sa.rank[nowToAddIndex], 1);
    }
    int res =
        Fenwick::sum(td->to) - (td->from == 0 ? 0 : Fenwick::sum(td->from - 1));
    ans[td->whichQuery] += td->multiplier * res;
  }
  for (int(q) = 0; (q) < (queries); ++(q)) pisz(ans[q]);
}
