#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 100;
struct Node {
  int l, r;
  int num;
} tree[maxN * 25 + 1];
int n, m, p, q, len;
int sa[maxN + 1], rk[maxN + 1], bin[maxN + 1], tp[maxN + 1];
int h[maxN + 1], st[maxN + 1][21], lg[maxN + 1];
int s[maxN + 1], tmp[maxN + 1];
int root[maxN + 1], cnt;
inline int read() {
  int num = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) num = (num << 3) + (num << 1) + (ch ^ 48), ch = getchar();
  return num * f;
}
inline void print(int x) {
  if (x < 10) {
    putchar(x + '0');
    return;
  }
  print(x / 10);
  putchar(x % 10 + '0');
}
inline void Qsort() {
  for (int i = 0; i <= m; i++) bin[i] = 0;
  for (int i = 1; i <= len; i++) bin[rk[i]]++;
  for (int i = 1; i <= m; i++) bin[i] += bin[i - 1];
  for (int i = len; i >= 1; i--) sa[bin[rk[tp[i]]]--] = tp[i];
}
inline void get_sa() {
  for (int i = 1; i <= len; i++) rk[i] = s[i], tp[i] = i;
  Qsort();
  for (int w = 1; p < len; m = p, w <<= 1) {
    p = 0;
    for (int i = len - w + 1; i <= len; i++) tp[++p] = i;
    for (int i = 1; i <= len; i++)
      if (sa[i] > w) tp[++p] = sa[i] - w;
    Qsort();
    memcpy(tp, rk, sizeof(rk));
    rk[sa[1]] = p = 1;
    for (int i = 2; i <= len; i++)
      rk[sa[i]] =
          (tp[sa[i]] == tp[sa[i - 1]] && tp[sa[i] + w] == tp[sa[i - 1] + w])
              ? p
              : ++p;
  }
}
inline void get_height() {
  int k = 0;
  for (int i = 1; i <= len; i++) {
    if (k) k--;
    int j = sa[rk[i] - 1];
    while (s[i + k] == s[j + k]) k++;
    h[rk[i]] = k;
  }
}
inline void pushup(int node) {
  tree[node].num = tree[tree[node].l].num + tree[tree[node].r].num;
}
inline int build(int l, int r) {
  int node = ++cnt;
  if (l == r) return node;
  int mid = (l + r) >> 1;
  tree[node].l = build(l, mid);
  tree[node].r = build(mid + 1, r);
  pushup(node);
  return node;
}
inline int change(int pre, int l, int r, int x) {
  int node = ++cnt;
  if (l == r) {
    tree[node].num = tree[pre].num + 1;
    return node;
  }
  int mid = (l + r) >> 1;
  tree[node].l = tree[pre].l;
  tree[node].r = tree[pre].r;
  if (x <= mid)
    tree[node].l = change(tree[pre].l, l, mid, x);
  else
    tree[node].r = change(tree[pre].r, mid + 1, r, x);
  pushup(node);
  return node;
}
inline int query(int u, int v, int l, int r, int x, int y) {
  if (x <= l && r <= y) return tree[v].num - tree[u].num;
  int mid = (l + r) >> 1, ans = 0;
  if (x <= mid) ans += query(tree[u].l, tree[v].l, l, mid, x, y);
  if (y > mid) ans += query(tree[u].r, tree[v].r, mid + 1, r, x, y);
  return ans;
}
inline int query_mn(int l, int r) {
  int k = lg[r - l + 1];
  return min(st[l][k], st[r - (1 << k) + 1][k]);
}
inline int solve(int x, int y) {
  if (x > y) return n - 1;
  int l = 1, r = rk[x] - 1, L = rk[x], R = rk[x], t = y - x + 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (query_mn(mid + 1, rk[x]) >= t)
      L = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  l = rk[x] + 1, r = len;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (query_mn(rk[x] + 1, mid) >= t)
      R = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  int ans = 0;
  if (x - t - 1 >= 2)
    ans += query(root[L - 1], root[R], 1, len, n + 3, x + n - t);
  if (y + n + 3 <= len)
    ans += query(root[L - 1], root[R], 1, len, y + n + 3, len);
  return ans;
}
int main() {
  n = read();
  int last = 0, x;
  for (int i = 1; i <= n; i++) x = read(), s[i] = tmp[i] = x - last, last = x;
  len = 2 * n + 1;
  for (int i = n + 2; i <= len; i++) s[i] = tmp[i] = -s[i - n - 1];
  s[n + 1] = tmp[n + 1] = -2e9 - 1;
  sort(tmp + 1, tmp + len + 1);
  m = unique(tmp + 1, tmp + len + 1) - tmp - 1;
  for (int i = 1; i <= len; i++)
    s[i] = lower_bound(tmp + 1, tmp + m + 1, s[i]) - tmp;
  get_sa();
  get_height();
  for (int i = 2; i <= len; i++) lg[i] = lg[i >> 1] + 1;
  for (int i = 1; i <= len; i++) st[i][0] = h[i];
  for (int j = 1; (1 << j) <= len; j++)
    for (int i = 1; i + (1 << j) - 1 <= len; i++)
      st[i][j] = min(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);
  root[0] = build(1, len);
  for (int i = 1; i <= len; i++) root[i] = change(root[i - 1], 1, len, sa[i]);
  q = read();
  while (q--) {
    int l = read(), r = read();
    print(solve(l + 1, r));
    puts("");
  }
  return 0;
}
