#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long llread() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int ch[200010], a[200010], c[200010], x[200010], y[200010];
int sa[200010], Rank[200010], height[200010];
int Log[200010], mn[200010][20];
inline void get_sa(int n, int m) {
  for (int i = (1); i <= (m); i++) c[i] = 0;
  for (int i = (1); i <= (n); i++) c[x[i] = ch[i]]++;
  for (int i = (2); i <= (m); i++) c[i] += c[i - 1];
  for (int i = (n); i >= (1); i--) sa[c[x[i]]--] = i;
  for (int k = 1; k <= n; k <<= 1) {
    int tot = 0;
    for (int i = (n - k + 1); i <= (n); i++) y[++tot] = i;
    for (int i = (1); i <= (n); i++)
      if (sa[i] > k) y[++tot] = sa[i] - k;
    for (int i = (1); i <= (m); i++) c[i] = 0;
    for (int i = (1); i <= (n); i++) c[x[y[i]]]++;
    for (int i = (2); i <= (m); i++) c[i] += c[i - 1];
    for (int i = (n); i >= (1); i--) sa[c[x[y[i]]]--] = y[i];
    swap(x, y);
    x[sa[1]] = 1;
    tot = 1;
    for (int i = (2); i <= (n); i++) {
      x[sa[i]] = (y[sa[i]] == y[sa[i - 1]] && y[sa[i] + k] == y[sa[i - 1] + k]
                      ? tot
                      : ++tot);
    }
    if (tot >= n) break;
    m = tot;
  }
}
inline void get_height(int n) {
  for (int i = (1); i <= (n); i++) Rank[sa[i]] = i;
  int k = 0;
  for (int i = (1); i <= (n); i++) {
    if (!Rank[i]) continue;
    if (k) k--;
    int j = sa[Rank[i] - 1];
    while (ch[i + k] == ch[j + k]) k++;
    height[Rank[i]] = k;
  }
}
inline void get_rmq(int n) {
  Log[1] = 0;
  for (int i = (2); i <= (n); i++) Log[i] = Log[i / 2] + 1;
  for (int i = (1); i <= (n); i++) mn[i][0] = height[i];
  for (int i = (1); i <= (19); i++)
    for (int j = (1); j <= (n); j++) {
      if (j + (1 << i - 1) <= n)
        mn[j][i] = min(mn[j][i - 1], mn[j + (1 << i - 1)][i - 1]);
    }
}
inline int get_mn(int l, int r) {
  int i = Log[r - l + 1];
  return min(mn[l][i], mn[r - (1 << i) + 1][i]);
}
struct que {
  int id, l, r;
} qt[200010];
inline int cmp0(que xx, que yy) { return xx.l * 2 - xx.r < yy.l * 2 - yy.r; }
inline int cmp1(que xx, que yy) { return xx.r < yy.r; }
int tt;
inline void add(int x, int y) {
  for (; x <= tt; x += (x & -x)) c[x] += y;
}
inline int query(int x) {
  int ret = 0;
  for (; x > 0; x -= (x & -x)) ret += c[x];
  return ret;
}
inline int calc(int pos, int len) {
  int l, r, left = pos + 1, right = pos - 1;
  l = 1, r = pos;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (get_mn(mid, pos) >= len)
      r = (left = mid) - 1;
    else
      l = mid + 1;
  }
  l = pos + 1, r = tt;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (get_mn(pos + 1, mid) >= len)
      l = (right = mid) + 1;
    else
      r = mid - 1;
  }
  return query(right) - query(left - 2);
}
int ans[200010];
int main() {
  int n = read();
  for (int i = (1); i <= (n); i++) a[i] = read();
  for (int i = (1); i < (n); i++) ch[++tt] = a[i + 1] - a[i];
  ch[++tt] = 2147483647;
  for (int i = (1); i < (n); i++) ch[++tt] = a[i] - a[i + 1];
  ch[++tt] = 2147483647;
  for (int i = (1); i <= (tt); i++) c[i] = ch[i];
  sort(c + 1, c + tt + 1);
  int tot = unique(c + 1, c + tt + 1) - c - 1;
  for (int i = (1); i <= (tt); i++)
    ch[i] = lower_bound(c + 1, c + tot + 1, ch[i]) - c;
  get_sa(tt, tot);
  get_height(tt);
  get_rmq(tt);
  int Q = read();
  for (int i = (1); i <= (Q); i++) qt[i] = (que){i, read(), read()};
  sort(qt + 1, qt + Q + 1, cmp0);
  memset(c, 0, sizeof(c));
  int now = 1;
  for (int i = (1); i <= (Q); i++) {
    while (now < n && now < 2 * qt[i].l - qt[i].r) add(Rank[now + n], 1), now++;
    ans[qt[i].id] += calc(Rank[qt[i].l], qt[i].r - qt[i].l);
  }
  sort(qt + 1, qt + Q + 1, cmp1);
  memset(c, 0, sizeof(c));
  now = n - 1;
  for (int i = (Q); i >= (1); i--) {
    while (now > 0 && now > qt[i].r) add(Rank[now + n], 1), now--;
    ans[qt[i].id] += calc(Rank[qt[i].l], qt[i].r - qt[i].l);
  }
  for (int i = (1); i <= (Q); i++)
    if (qt[i].l == qt[i].r) ans[qt[i].id] = n - 1;
  for (int i = (1); i <= (Q); i++) printf("%d\n", ans[i]);
  return 0;
}
