#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int data = 0, w = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    data = (data << 1) + (data << 3) + (ch ^ 48), ch = getchar();
  return data * w;
}
int n, q, len[1000005], link[1000005], cnt = 1, las = 1;
map<int, int> nxt[400005];
void insert(int x) {
  int p = las, cur = ++cnt;
  len[cur] = len[p] + 1;
  while (p && !nxt[p][x]) nxt[p][x] = cur, p = link[p];
  if (!p)
    link[cur] = 1;
  else {
    int q = nxt[p][x];
    if (len[q] == len[p] + 1)
      link[cur] = q;
    else {
      int nq = ++cnt;
      len[nq] = len[p] + 1;
      nxt[nq] = nxt[q];
      link[nq] = link[q];
      link[cur] = link[q] = nq;
      while (nxt[p][x] == q) nxt[p][x] = nq, p = link[p];
    }
  }
  las = cur;
}
int id[1000005], f[400005][25], s[1000005];
vector<int> a[400005];
int root[1000005], sum[13 * 1000005], ls[13 * 1000005], rs[13 * 1000005], sc;
void update(int &now, int l, int r, int pos) {
  if (!now) now = ++sc;
  sum[now]++;
  if (l == r) return;
  int mid = l + r >> 1;
  (pos <= mid) ? update(ls[now], l, mid, pos)
               : update(rs[now], mid + 1, r, pos);
}
int query(int now, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return sum[now];
  int mid = (l + r) >> 1, ans = 0;
  if (ql <= mid) ans += query(ls[now], l, mid, ql, qr);
  if (mid < qr) ans += query(rs[now], mid + 1, r, ql, qr);
  return ans;
}
int merge(int x, int y, int l, int r) {
  if (!x || !y) return x | y;
  int mid = (l + r) >> 1;
  int now = ++sc;
  sum[now] = sum[x] + sum[y];
  if (l == r) return now;
  ls[now] = merge(ls[x], ls[y], l, mid);
  rs[now] = merge(rs[x], rs[y], mid + 1, r);
  return now;
}
void dfs(int x) {
  f[x][0] = link[x];
  for (int i = 1; i <= 18; i++) f[x][i] = f[f[x][i - 1]][i - 1];
  for (auto y : a[x]) dfs(y), root[x] = merge(root[x], root[y], 1, n);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) s[i] = read();
  for (int i = n; i >= 1; i--) s[i] -= s[i - 1];
  for (int i = 2; i <= n; i++) insert(s[i]), id[i] = las;
  insert((int)2e9);
  for (int i = 2; i <= n; i++) insert(-s[i]), update(root[las], 1, n, i);
  for (int i = 2; i <= cnt; i++) a[link[i]].push_back(i);
  dfs(1);
  q = read();
  while (q--) {
    int x, y;
    scanf("%d %d", &x, &y);
    int l = y - x + 1;
    if (l == 1)
      printf("%d\n", n - 1);
    else {
      int p = id[y];
      for (int i = 18; i >= 0; i--) {
        if (len[f[p][i]] >= l - 1) p = f[p][i];
      }
      int ans = 0;
      if (l <= x - 1) ans += query(root[p], 1, n, l, x - 1);
      if (y + l <= n) ans += query(root[p], 1, n, y + l, n);
      printf("%d\n", ans);
    }
  }
  return 0;
}
