Problem: John Doe has a crooked fence, consisting of n rectangular planks, lined up from the left to the right: the plank that goes i-th (1 ≤ i ≤ n) (from left to right) has width 1 and height hi. We will assume that the plank that goes i-th (1 ≤ i ≤ n) (from left to right) has index i.

A piece of the fence from l to r (1 ≤ l ≤ r ≤ n) is a sequence of planks of wood with indices from l to r inclusive, that is, planks with indices l, l + 1, ..., r. The width of the piece of the fence from l to r is value r - l + 1.

Two pieces of the fence from l1 to r1 and from l2 to r2 are called matching, if the following conditions hold:

  * the pieces do not intersect, that is, there isn't a single plank, such that it occurs in both pieces of the fence; 
  * the pieces are of the same width; 
  * for all i (0 ≤ i ≤ r1 - l1) the following condition holds: hl1 + i + hl2 + i = hl1 + hl2. 



John chose a few pieces of the fence and now wants to know how many distinct matching pieces are for each of them. Two pieces of the fence are distinct if there is a plank, which belongs to one of them and does not belong to the other one.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of wood planks in the fence. The second line contains n space-separated integers h1, h2, ..., hn (1 ≤ hi ≤ 109) — the heights of fence planks.

The third line contains integer q (1 ≤ q ≤ 105) — the number of queries. Next q lines contain two space-separated integers li and ri (1 ≤ li ≤ ri ≤ n) — the boundaries of the i-th piece of the fence.

Output

For each query on a single line print a single integer — the number of pieces of the fence that match the given one. Print the answers to the queries in the order, in which the queries are given in the input.

Examples

Input

10
1 2 2 1 100 99 99 100 100 100
6
1 4
1 2
3 4
1 5
9 10
10 10


Output

1
2
2
0
2
9

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
long long fpm(long long b, long long e, long long m) {
  long long t = 1;
  for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0;
  return t;
}
template <class T>
inline bool chkmin(T &a, T b) {
  return a > b ? a = b, true : false;
}
template <class T>
inline bool chkmax(T &a, T b) {
  return a < b ? a = b, true : false;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class edge>
struct Graph {
  vector<vector<edge> > adj;
  Graph(int n) {
    adj.clear();
    adj.resize(n + 5);
  }
  Graph() { adj.clear(); }
  void resize(int n) { adj.resize(n + 5); }
  void add(int s, edge e) { adj[s].push_back(e); }
  void del(int s, edge e) { adj[s].erase(find(iter(adj[s]), e)); }
  int deg(int v) { return adj[v].size(); }
  vector<edge> &operator[](int t) { return adj[t]; }
};
const int maxn = 110000, maxv = maxn * 4, maxlog = 20, maxq = 110000;
struct node {
  int len, suf;
  unordered_map<int, node *> c;
  node *f;
};
struct subq {
  int t, beg, end;
};
typedef int arr32[maxv];
node buf[maxv], *pbuf = buf, *root, *prefix[maxv];
Graph<int> G;
Graph<subq> queries;
vector<int> suffixes;
arr32 enter, leave, dep, x, bit;
int fa[maxv][maxlog];
int n;
int ans[maxq];
node *newnode(int len) { return *(++pbuf) = (node){len}, pbuf; }
void extend(node *p, int c) {
  node *b = p, *q, *w;
  p = newnode(p->len + 1);
  for (; b && !b->c.count(c); b = b->f) b->c[c] = p;
  if (!b)
    p->f = root;
  else if ((w = b->c[c])->len == b->len + 1)
    p->f = w;
  else {
    q = newnode(0), q->f = w->f, q->c = w->c;
    q->len = b->len + 1, w->f = p->f = q;
    for (; b && b->c.count(c) && b->c[c] == w; b = b->f) b->c[c] = q;
  }
}
void dfs_suffix_tree(int v) {
  for (int i = 0; fa[v][i]; ++i) fa[v][i + 1] = fa[fa[v][i]][i];
  dep[v] = buf[v].len;
  enter[v] = (int)((suffixes).size());
  if (buf[v].suf) suffixes.push_back(buf[v].suf);
  for (auto &x : G[v]) dfs_suffix_tree(x);
  leave[v] = (int)((suffixes).size());
}
int get_pos(int L, int R) {
  int v = prefix[R - 1] - buf, len = R - L;
  for (int t = maxlog - 1; t >= 0; --t)
    if (dep[fa[v][t]] >= len) v = fa[v][t];
  return v;
}
void bit_modify(int t, int v) {
  for (; t <= n; t += t & -t) bit[t] += v;
}
int bit_query(int t) {
  int x = bit[t];
  for (; t &= t - 1; x += bit[t])
    ;
  return x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> x[i];
  root = pbuf;
  --n;
  node *ptr = root;
  for (int i = 1, c; c = x[i + 1] - x[i], i <= n; ++i)
    extend(ptr, c), ptr = ptr->c[c];
  for (int i = 1, c; c = x[i] - x[i + 1], i <= n; ++i)
    extend(ptr, c), ptr = ptr->c[c];
  ptr = root;
  for (int i = 1, c; c = x[i + 1] - x[i], i <= n; ++i)
    ptr = ptr->c[c], ptr->suf = i;
  for (int i = 1, c; c = x[i] - x[i + 1], i <= n; ++i)
    ptr = ptr->c[c], prefix[i] = ptr;
  G.resize(n * 4);
  for (int i = 1; i <= pbuf - root; ++i)
    fa[i][0] = buf[i].f - buf, G.add(fa[i][0], i);
  dfs_suffix_tree(0);
  for (auto &x : suffixes) cerr << x << " ";
  cerr << endl;
  int Q, L, R;
  cin >> Q;
  queries.resize(n);
  for (int i = 1; i <= Q; ++i) {
    cin >> L >> R;
    if (L >= R) {
      ans[i] = n;
      continue;
    }
    int pos = get_pos(L, R);
    R = min(n, R + R - L - 1), L = max(0, L - 2);
    cerr << enter[pos] << " " << leave[pos] << " # " << L << " " << R << endl;
    queries.add(enter[pos], (subq){i, L, R});
    queries.add(leave[pos], (subq){i, L, R});
  }
  for (int i = 1; i <= n; ++i) {
    bit_modify(suffixes[i - 1], 1);
    for (auto &Q : queries[i])
      ans[Q.t] = i - bit_query(Q.end) + bit_query(Q.beg) - ans[Q.t];
  }
  for (int i = 1; i <= Q; ++i) cout << ans[i] << endl;
  return 0;
}