#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000005;
const int maxn = 200005;
int data[maxn];
int SA[maxn], rnk[maxn], H[maxn], N;
bool cmp(int a, int b) { return data[a] < data[b]; }
int c[maxn], a[maxn], _SA[maxn], _rnk[maxn], _h[maxn], L;
void Double() {
  memset(c, 0, sizeof(int) * (N + 1));
  int i;
  for (i = 1; i <= N; i++) c[((i + L) > N ? 0 : rnk[i + L])]++;
  a[0] = 1;
  for (i = 1; i <= N; i++) a[i] = a[i - 1] + c[i - 1];
  for (i = 1; i <= N; i++) _SA[a[((i + L) > N ? 0 : rnk[i + L])]++] = i;
  memset(c, 0, sizeof(int) * (N + 1));
  for (i = 1; i <= N; i++) c[((i) > N ? 0 : rnk[i])]++;
  a[0] = 1;
  for (i = 1; i <= N; i++) a[i] = a[i - 1] + c[i - 1];
  for (i = 1; i <= N; i++) SA[a[((_SA[i]) > N ? 0 : rnk[_SA[i]])]++] = _SA[i];
  _rnk[SA[1]] = 1;
  for (int i = 2; i <= N; i++)
    if (((SA[i]) > N ? 0 : rnk[SA[i]]) ==
            ((SA[i - 1]) > N ? 0 : rnk[SA[i - 1]]) &&
        ((SA[i] + L) > N ? 0 : rnk[SA[i] + L]) ==
            ((SA[i - 1] + L) > N ? 0 : rnk[SA[i - 1] + L]))
      _rnk[SA[i]] = _rnk[SA[i - 1]];
    else
      _rnk[SA[i]] = _rnk[SA[i - 1]] + 1;
  memcpy(rnk, _rnk, sizeof(int) * (N + 1));
  L <<= 1;
}
void make_SA() {
  int i;
  for (i = 1; i <= N; i++) SA[i] = i;
  sort(SA + 1, SA + N + 1, cmp);
  rnk[SA[1]] = 1;
  for (int i = 2; i <= N; i++)
    if (data[SA[i]] == data[SA[i - 1]])
      rnk[SA[i]] = rnk[SA[i - 1]];
    else
      rnk[SA[i]] = rnk[SA[i - 1]] + 1;
  L = 1;
  while (L < N) Double();
}
void make_H() {
  int i;
  memset(_h, 0, sizeof(int) * (N + 1));
  for (i = 1; i <= N; i++)
    if (rnk[i] == 1)
      _h[i] = 0;
    else if (i == 1 || _h[i - 1] <= 1)
      while (data[i + _h[i]] == data[SA[rnk[i] - 1] + _h[i]]) _h[i]++;
    else {
      _h[i] = _h[i - 1] - 1;
      while (data[i + _h[i]] == data[SA[rnk[i] - 1] + _h[i]]) _h[i]++;
    }
  for (i = 1; i <= N; i++) H[rnk[i]] = _h[i];
}
int n, A[100005];
int Lcp[200005][20];
void get_Lcp() {
  for (int i = 1; i <= N; i++) {
    Lcp[i][1] = H[i + 1];
  }
  for (int l = 2; (1 << l) <= N; l++) {
    for (int i = 1; i <= N + 1 - (1 << l); i++) {
      Lcp[i][l] = min(Lcp[i][l - 1], Lcp[i + (1 << (l - 1))][l - 1]);
      Lcp[i][l] = min(Lcp[i][l], H[i + (1 << (l - 1))]);
    }
  }
}
int C[maxn * 30], ls[maxn * 30], rs[maxn * 30], scc;
int head[maxn];
void build(int l, int r, int o) {
  C[o] = 0;
  if (l == r) return;
  ls[o] = (++scc);
  rs[o] = (++scc);
  int mid = (l + r) / 2;
  build(l, mid, ls[o]);
  build(mid + 1, r, rs[o]);
}
void add(int l, int r, int preo, int& o, int x) {
  o = (++scc);
  C[o] = C[preo] + 1;
  if (l == r) {
    return;
  }
  int mid = (l + r) / 2;
  if (x <= mid) {
    rs[o] = rs[preo];
    add(l, mid, ls[preo], ls[o], x);
  } else {
    ls[o] = ls[preo];
    add(mid + 1, r, rs[preo], rs[o], x);
  }
}
int query(int l, int r, int o, int L, int R) {
  if (L <= l && r <= R) {
    return C[o];
  }
  int mid = (l + r) / 2;
  int res = 0;
  if (L <= mid) res += query(l, mid, ls[o], L, R);
  if (mid < R) res += query(mid + 1, r, rs[o], L, R);
  return res;
}
int cal(int l, int r, int a, int b) {
  if (a > b) return 0;
  return query(1, N, head[r], a, b) - query(1, N, head[l - 1], a, b);
}
int pw[maxn];
int found_up(int s, int t, int l) {
  int _s = s, _t = t - 1, ret = t;
  while (_s <= _t) {
    int mid = (_s + _t) / 2;
    int dis = pw[t - mid + 1];
    int h = min(Lcp[mid][dis], Lcp[t + 1 - (1 << dis)][dis]);
    if (h < l) {
      _s = mid + 1;
    } else {
      _t = mid - 1;
      ret = mid;
    }
  }
  return ret;
}
int found_down(int s, int t, int l) {
  int _s = s + 1, _t = t, ret = s;
  while (_s <= _t) {
    int mid = (_s + _t) / 2;
    int dis = pw[mid - s + 1];
    int h = min(Lcp[s][dis], Lcp[mid + 1 - (1 << dis)][dis]);
    if (h < l) {
      _t = mid - 1;
    } else {
      _s = mid + 1;
      ret = mid;
    }
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", A + i);
  for (int i = n; i >= 2; i--) A[i] -= A[i - 1];
  N = 2 * n - 1;
  for (int i = 1; i < n; i++) data[i] = A[i + 1];
  data[n] = -INF;
  for (int i = n + 1; i < (n << 1); i++) data[i] = -A[i - n + 1];
  make_SA();
  make_H();
  get_Lcp();
  scc = 0;
  head[0] = 0;
  build(1, N, 0);
  for (int i = 1; i <= N; i++) {
    add(1, N, head[i - 1], head[i], SA[i]);
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 0;; j++) {
      if ((1 << j) <= i) continue;
      pw[i] = j - 1;
      break;
    }
  }
  int q, s, t;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &s, &t);
    if (s == t) {
      printf("%d\n", n - 1);
      continue;
    }
    s += n;
    t += (n - 1);
    int l = found_up(1, rnk[s], t - s + 1);
    int r = found_down(rnk[s], N, t - s + 1);
    int ans = cal(l, r, t - n + 2, n - 1) + cal(l, r, 1, 2 * s - n - t - 2);
    printf("%d\n", ans);
  }
  return 0;
}
