#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkmax(T &x, T y) {
  x = x > y ? x : y;
}
template <typename T>
void chkmin(T &x, T y) {
  x = x > y ? y : x;
}
const long long INF = (1ll << 62) - 1;
template <typename T>
void read(T &x) {
  x = 0;
  bool f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = 0;
  } while (ch > '9' || ch < '0');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  x = f ? x : -x;
}
template <typename T>
void write(T x) {
  if (x < 0) x = ~x + 1, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const int N = 2e5 + 7;
const int K = 20 + 5;
const int NLOGN = 4e6 + 7;
struct EDGE {
  int to, nxt;
} edge[N];
int n, q, E, a[N], head[N];
inline void addedge(int u, int v) {
  edge[++E].to = v;
  edge[E].nxt = head[u];
  head[u] = E;
}
struct Segment_Tree {
  int cnt, rt[N];
  struct segment_tree {
    int ls, rs, cnt;
  } t[NLOGN];
  inline void insert(int &p, int l, int r, int v) {
    if (!p) p = ++cnt;
    if (l == r) {
      t[p].cnt++;
      return;
    }
    int mid = (l + r) >> 1;
    if (v <= mid)
      insert((t[p].ls), l, mid, v);
    else
      insert((t[p].rs), mid + 1, r, v);
    t[p].cnt = t[(t[p].ls)].cnt + t[(t[p].rs)].cnt;
  }
  inline int merge(int x, int y, int l, int r) {
    if (!x || !y) return x + y;
    int p = ++cnt;
    if (l == r) {
      t[p].cnt = t[x].cnt + t[y].cnt;
      return p;
    }
    int mid = (l + r) >> 1;
    (t[p].ls) = merge((t[x].ls), (t[y].ls), l, mid);
    (t[p].rs) = merge((t[x].rs), (t[y].rs), mid + 1, r);
    t[p].cnt = t[(t[p].ls)].cnt + t[(t[p].rs)].cnt;
    return p;
  }
  inline int query(int p, int l, int r, int L, int R) {
    if (!p) return 0;
    if (L <= l && r <= R) return t[p].cnt;
    int mid = (l + r) >> 1, ans = 0;
    if (L <= mid) ans += query((t[p].ls), l, mid, L, R);
    if (R > mid) ans += query((t[p].rs), mid + 1, r, L, R);
    return ans;
  }
} SGT;
struct SAM {
  int lst, cnt, ed[N], fa[N], mxl[N], len[N], f[N][K];
  map<int, int> ch[N];
  SAM() { lst = cnt = 1; }
  inline void expend(int c) {
    int p = lst, q = ++cnt;
    lst = q;
    len[q] = len[p] + 1;
    while (p && !ch[p][c]) {
      ch[p][c] = q;
      p = fa[p];
    }
    if (p == 0) {
      fa[q] = 1;
    } else {
      int x = ch[p][c];
      if (len[x] == len[p] + 1) {
        fa[q] = x;
      } else {
        int y = ++cnt;
        fa[y] = fa[x];
        len[y] = len[p] + 1;
        fa[x] = fa[q] = y;
        ch[y] = ch[x];
        while (p && ch[p][c] == x) {
          ch[p][c] = y;
          p = fa[p];
        }
      }
    }
  }
  inline void dfs(int u) {
    for (int i = 1; i <= 20; i++) f[u][i] = f[f[u][i - 1]][i - 1];
    for (int i = head[u]; i; i = edge[i].nxt) {
      int v = edge[i].to;
      f[v][0] = u;
      dfs(v);
      SGT.rt[u] = SGT.merge(SGT.rt[u], SGT.rt[v], 1, n - 1);
    }
  }
  inline void build() {
    for (int i = 2; i <= cnt; i++) addedge(fa[i], i);
    dfs(1);
    int p = 1, ml = 0;
    for (int i = 1; i < n; i++) {
      if (ch[p][-a[i]])
        p = ch[p][-a[i]], ml++;
      else {
        while (p && !ch[p][-a[i]]) p = fa[p];
        if (!p)
          p = 1, ml = 0;
        else
          ml = len[p] + 1, p = ch[p][-a[i]];
      }
      ed[i] = p;
      mxl[i] = ml;
    }
  }
} SAM;
inline void query(int l, int r) {
  if (l == r) return (void)printf("%d\n", n - 1);
  int p = SAM.ed[r - 1];
  if (SAM.mxl[r - 1] < r - l) return (void)puts("0");
  for (int i = 20; i >= 0; i--)
    if (SAM.len[SAM.f[p][i]] >= r - l) p = SAM.f[p][i];
  printf("%d\n", SGT.query(SGT.rt[p], 1, n - 1, 1, l - 2) +
                     SGT.query(SGT.rt[p], 1, n - 1, r * 2 - l, n - 1));
  return;
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(a[i]);
  for (int i = 1; i < n; i++) a[i] = a[i + 1] - a[i];
  for (int i = 1; i < n; i++) {
    SAM.expend(a[i]);
    SGT.insert(SGT.rt[SAM.lst], 1, n - 1, i);
  }
  SAM.build();
  read(q);
  for (int i = 1, l, r; i <= q; i++) {
    read(l);
    read(r);
    query(l, r);
  }
  return 0;
}
