#include <bits/stdc++.h>
using namespace std;
template <typename T>
int suffix_array_build_rank(int N, const int suffix[], const T equality[],
                            int new_rank[], int len) {
  int cur_rank = 0;
  int base = suffix[cur_rank];
  new_rank[base] = cur_rank;
  for (int i = 1; i < N; ++i) {
    int cur = suffix[i];
    if (!(base + len < N && cur + len < N && equality[cur] == equality[base] &&
          equality[cur + len] == equality[base + len])) {
      ++cur_rank;
      base = cur;
    }
    new_rank[cur] = cur_rank;
  }
  return ++cur_rank;
}
template <typename T>
void build_suffix_array(int N, T str[], int suffix[], int suffix_rank[],
                        int lcp[], int tmp[]) {
  for (int i = 0; i < N; i++) {
    suffix[i] = i;
  }
  sort(suffix, suffix + N, [str](int a, int b) { return str[a] < str[b]; });
  int len = 1;
  int *const cnt = lcp;
  int *coor = tmp;
  int *rank = suffix_rank;
  int rank_size = suffix_array_build_rank(N, suffix, str, rank, 0);
  while (rank_size != N && len < N) {
    int cur = 0;
    coor[cur++] = N - len;
    for (int i = 0; i < N; i++) {
      if (suffix[i] >= len) {
        coor[cur++] = suffix[i] - len;
      }
    }
    memset(cnt, 0, rank_size * sizeof(int));
    for (int i = 0; i < N; i++) {
      ++cnt[rank[i]];
    }
    for (int i = 1; i < rank_size; i++) {
      cnt[i] += cnt[i - 1];
    }
    for (int i = N - len; i >= 0; --i) {
      int cur = coor[i];
      suffix[--cnt[rank[cur]]] = cur;
    }
    int *old_rank = rank;
    rank = coor;
    coor = old_rank;
    rank_size = suffix_array_build_rank(N, suffix, old_rank, rank, len);
    len <<= 1;
  }
  if (suffix_rank != rank) {
    memcpy(suffix_rank, rank, N * sizeof(int));
  }
  len = 0;
  for (int i = 0; i < N; i++) {
    if (rank[i] == 0) {
      continue;
    }
    if (len != 0) {
      --len;
    }
    int prev = suffix[rank[i] - 1];
    while (i + len < N && prev + len < N && str[i + len] == str[prev + len]) {
      ++len;
    }
    lcp[rank[i]] = len;
  }
  lcp[0] = 0;
}
struct set_node {
  set_node *father;
  int rank;
  int left, right;
} set_nodes[(100000 << 1)];
void set_init(set_node set_nodes[], int T) {
  for (int i = 0; i < T; i++) {
    set_nodes[i].father = set_nodes + i;
    set_nodes[i].rank = 0;
    set_nodes[i].left = set_nodes[i].right = i;
  }
}
set_node *set_find(set_node *x) {
  while (x->father != x) {
    set_node *father = x->father;
    x->father = father->father;
    x = father;
  }
  return x;
}
set_node *set_union(set_node *x, set_node *y) {
  set_node *x_root = set_find(x);
  set_node *y_root = set_find(y);
  if (x_root == y_root) {
    return x_root;
  }
  set_node *father = x_root->rank > y_root->rank ? x_root : y_root;
  x_root->father = y_root->father = father;
  father->rank += x_root->rank == y_root->rank;
  father->left = min(x_root->left, y_root->left);
  father->right = max(x_root->right, y_root->right);
  return father;
}
int suffix_rank[(100000 << 1)];
int suffix[(100000 << 1)];
int lcp[(100000 << 1)];
int tmp[(100000 << 1)];
int N;
int height[100000];
int diff[(100000 << 1)];
int sum[(100000 << 1)];
int ans[100000];
struct query {
  int len;
  int start;
  int sub;
  int x, y;
  int first, second;
} queries[100000];
bool operator<(const query &a, const query &b) { return a.len > b.len; }
pair<int, int> lcp_values[(100000 << 1)];
pair<int, pair<bool, query *>> ranges[100000 << 1];
int base[100000 + 1];
void tree_array_add(int pos, int val) {
  while (pos <= 100000) {
    base[pos] += val;
    pos += ((pos) & (-pos));
  }
}
int tree_array_sum(int pos) {
  int val = 0;
  while (pos) {
    val += base[pos];
    pos -= ((pos) & (-pos));
  }
  return val;
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", height + i);
  }
  int L = N - 1;
  for (int i = 0; i < N - 1; ++i) {
    diff[i] = height[i] - height[i + 1];
  }
  for (int i = 0; i < N - 1; ++i) {
    diff[L + i] = height[i + 1] - height[i];
  }
  L <<= 1;
  build_suffix_array(L, diff, suffix, suffix_rank, lcp, tmp);
  int count = 0;
  for (int i = 0; i < L; ++i) {
    if (suffix[i] >= N - 1) {
      ++count;
    }
    sum[i] = count;
  }
  for (int i = 0; i < L; ++i) {
    lcp_values[i].first = lcp[i];
    lcp_values[i].second = i;
  }
  int Q;
  scanf("%d", &Q);
  int cnt = 0;
  for (int i = 0; i < Q; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    if (l == r) {
      ans[i] = N - 1;
    } else {
      queries[cnt].len = r - l;
      queries[cnt].start = suffix_rank[l - 1];
      queries[cnt].x = l;
      queries[cnt].y = r;
      queries[cnt].sub = i;
      ++cnt;
    }
  }
  sort(queries, queries + cnt);
  sort(lcp_values, lcp_values + L, greater<pair<int, int>>());
  set_init(set_nodes, L);
  int lcp_cnt = 0;
  for (int i = 0; i < cnt; i++) {
    while (lcp_values[lcp_cnt].first >= queries[i].len) {
      int rank = lcp_values[lcp_cnt].second;
      set_union(set_nodes + rank - 1, set_nodes + rank);
      ++lcp_cnt;
    }
    set_node *node = set_find(queries[i].start + set_nodes);
    ranges[i << 1].first = node->left - 1;
    ranges[i << 1].second.first = true;
    ranges[i << 1].second.second = queries + i;
    ranges[(i << 1) + 1].first = node->right;
    ranges[(i << 1) + 1].second.first = false;
    ranges[(i << 1) + 1].second.second = queries + i;
    ans[queries[i].sub] =
        sum[node->right] - sum[node->left] + (suffix[node->left] >= N - 1);
  }
  sort(ranges, ranges + (cnt << 1));
  memset(base, 0, sizeof(int) * (N + 1));
  int suf_cnt = 0;
  for (int i = 0; i < (cnt << 1); ++i) {
    while (suf_cnt <= ranges[i].first) {
      if (suffix[suf_cnt] >= N - 1) {
        tree_array_add(suffix[suf_cnt] - N + 2, 1);
      }
      ++suf_cnt;
    }
    const query *q = ranges[i].second.second;
    int start = max(0, q->x * 2 - q->y - 1);
    int end = q->y;
    int sum = tree_array_sum(end) - tree_array_sum(start);
    if (ranges[i].second.first) {
      ans[q->sub] += sum;
    } else {
      ans[q->sub] -= sum;
    }
  }
  for (int i = 0; i < Q; ++i) {
    printf("%d\n", ans[i]);
  }
}
