#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T>
void read(T& x) {
  x = 0;
  char ch = getchar();
  long long f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  x *= f;
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
const int N = 300010;
int s[N], t[N];
int sa[N], rk[N << 1], oldrk[N << 1], cnt[N], id[N], tmp[N];
int height[N];
int n, m;
int tot;
int a[100010];
int f[200010][20];
map<int, int> mp;
struct p {
  int x, y;
  int val;
};
vector<p> add[200010], sub[200010];
int sum[200010];
int ans[100010];
bool cmp(int, int, int);
void suf_arr(int*, int*, int*, int*, int, int);
void init();
int cal(int, int);
int cal_lcp(int, int);
int findL(int, int);
int findR(int, int);
int low_bit(int);
void update(int, int);
int query(int);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    int x = a[i] - a[i - 1];
    int y = -x;
    if (mp.find(x) == mp.end()) mp[x] = ++tot;
    if (mp.find(y) == mp.end()) mp[y] = ++tot;
  }
  for (int i = 1; i <= n; ++i) {
    int x = a[i] - a[i - 1];
    s[++m] = mp[x];
  }
  s[++m] = 233333;
  for (int i = 1; i <= n; ++i) {
    int x = a[i - 1] - a[i];
    s[++m] = mp[x];
  }
  suf_arr(s, sa, rk, height, m, 233333);
  init();
  int q;
  int x, y;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    cin >> x >> y;
    if (x == y) {
      ans[i] = n - 1;
      continue;
    }
    int tmp = y - x;
    int l = findL(rk[x + 1 + n + 1], tmp);
    int r = findR(rk[x + 1 + n + 1], tmp);
    if (x - tmp > 1) {
      sub[l].push_back({2, x - tmp, i});
      add[r].push_back({2, x - tmp, i});
    }
    if (y + tmp < n) {
      sub[l].push_back({y + 2, n, i});
      add[r].push_back({y + 2, n, i});
    }
  }
  for (int i = 1; i <= m; ++i) {
    for (auto [x, y, id] : sub[i]) ans[id] -= query(y) - query(x - 1);
    update(sa[i], 1);
    for (auto [x, y, id] : add[i]) ans[id] += query(y) - query(x - 1);
  }
  for (int i = 1; i <= q; ++i) cout << ans[i] << '\n';
  return 0;
}
bool cmp(int x, int y, int w) {
  return oldrk[x] == oldrk[y] && oldrk[x + w] == oldrk[y + w];
}
void suf_arr(int* s, int* sa, int* rk, int* height, int n, int m) {
  int p;
  memset(cnt, 0, (m + 1) * sizeof(int));
  memset(rk, 0, (2 * n + 1) * sizeof(int));
  for (int i = 1; i <= n; ++i) ++cnt[rk[i] = s[i]];
  for (int i = 1; i <= m; ++i) cnt[i] += cnt[i - 1];
  for (int i = 1; i <= n; ++i) sa[cnt[rk[i]]--] = i;
  for (int w = 1, p = 0; w <= n; w <<= 1, m = p, p = 0) {
    for (int i = n - w + 1; i <= n; ++i) id[++p] = i;
    for (int i = 1; i <= n; ++i) {
      if (sa[i] > w) id[++p] = sa[i] - w;
    }
    memset(cnt, 0, (m + 1) * sizeof(int));
    for (int i = 1; i <= n; ++i) ++cnt[tmp[i] = rk[id[i]]];
    for (int i = 1; i <= m; ++i) cnt[i] += cnt[i - 1];
    for (int i = n; i; --i) sa[cnt[tmp[i]]--] = id[i];
    memcpy(oldrk, rk, (2 * n + 1) * sizeof(int));
    p = 0;
    for (int i = 1; i <= n; ++i) rk[sa[i]] = cmp(sa[i], sa[i - 1], w) ? p : ++p;
  }
  for (int i = 1, k = 0; i <= n; ++i) {
    if (k) --k;
    while (s[i + k] == s[sa[rk[i] - 1] + k]) ++k;
    height[rk[i]] = k;
  }
}
void init() {
  for (int i = 1; i <= m; ++i) f[i][0] = height[i];
  for (int j = 1, len = 2; j < 20; ++j, len <<= 1)
    for (int i = 1; i + len - 1 <= m; ++i)
      f[i][j] = min(f[i][j - 1], f[i + len / 2][j - 1]);
}
int cal(int l, int r) {
  int k = log2(r - l + 1), len = 1 << k;
  return min(f[l][k], f[r - len + 1][k]);
}
int cal_lcp(int x, int y) {
  if (x == y) return m - sa[x] + 1;
  if (x > y) swap(x, y);
  return cal(x + 1, y);
}
int findL(int x, int len) {
  int l = 1, r = x;
  while (l <= r) {
    int mid = l + r >> 1;
    if (cal_lcp(mid, x) >= len)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return l;
}
int findR(int x, int len) {
  int l = x, r = m;
  while (l <= r) {
    int mid = l + r >> 1;
    if (cal_lcp(x, mid) < len)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return l - 1;
}
int low_bit(int x) { return x & -x; }
void update(int i, int k) {
  while (i <= m) {
    sum[i] += k;
    i += low_bit(i);
  }
}
int query(int i) {
  int res = 0;
  while (i) {
    res += sum[i];
    i -= low_bit(i);
  }
  return res;
}
