#include <bits/stdc++.h>
void Get(int &T) {
  char C;
  bool F = 0;
  for (; C = getchar(), C < '0' || C > '9';)
    if (C == '-') F = 1;
  for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
    ;
  F && (T = -T);
}
int S[200005];
int N, M, K;
int L[200005], R[200005];
int Ans[200005];
void Init() {
  Get(N);
  for (int i = 1; i <= N; i++) {
    Get(S[i]);
  }
  N--;
  M = N;
  for (int i = 1; i <= N; i++) {
    S[i] = S[i + 1] - S[i];
  }
  S[++N] = 0x7f7f7f7f;
  for (int i = 1; i <= M; i++) S[++N] = -S[i];
  S[++N] = 0x7f7f7f7f + 1;
  Get(K);
  for (int i = 1; i <= K; i++) {
    Get(L[i]);
    Get(R[i]);
    R[i]--;
  }
}
int SA[200005];
int *Rank;
int WA[200005];
int WB[200005];
int WS[200005];
int WV[200005];
bool Cmp(int X, int Y) { return S[X] < S[Y]; }
int Log(int X) {
  int Ans = 0;
  if (X >> 16) {
    X >>= 16;
    Ans |= 16;
  }
  if (X >> 8) {
    X >>= 8;
    Ans |= 8;
  }
  if (X >> 4) {
    X >>= 4;
    Ans |= 4;
  }
  if (X >> 2) {
    X >>= 2;
    Ans |= 2;
  }
  if (X >> 1) {
    X >>= 1;
    Ans |= 1;
  }
  return Ans;
}
int Height[25][200005];
void SuffixArray() {
  for (int i = 1; i <= N; i++) SA[i] = i;
  std::sort(SA + 1, SA + N + 1, Cmp);
  for (int i = N; i >= 2; i--)
    if (S[SA[i]] != S[SA[i - 1]])
      S[SA[i]] = 1;
    else
      S[SA[i]] = 0;
  S[SA[1]] = 1;
  for (int i = 1, k = 0; i <= N; i++) {
    if (S[SA[i]] == 1) k++;
    S[SA[i]] = k;
  }
  int Alpha = S[SA[N]];
  int *X = WA, *Y = WB;
  for (int i = 1; i <= N; i++) X[i] = S[i];
  for (int Top = Alpha, i, L = 1, k; Top < N; L <<= 1) {
    k = Top;
    std::swap(X, Y);
    for (Top = 0, i = N - L + 1; i <= N; i++) {
      X[++Top] = i;
    }
    for (i = 1; i <= N; i++)
      if (SA[i] > L) {
        X[++Top] = SA[i] - L;
      }
    for (int i = 0; i <= k; i++) WS[i] = 0;
    for (int i = 1; i <= N; i++) WS[Y[X[i]]]++;
    for (int i = 1; i <= k; i++) WS[i] += WS[i - 1];
    for (int i = N; i >= 1; i--) SA[WS[Y[X[i]]]--] = X[i];
    Top = 1;
    X[SA[1]] = 1;
    for (int i = 2; i <= N; i++) {
      if ((Y[SA[i]] != Y[SA[i - 1]] || Y[SA[i] + L] != Y[SA[i - 1] + L])) Top++;
      X[SA[i]] = Top;
    }
  }
  Rank = X;
  for (int i = 1, H = 0; i <= N; i++) {
    if (Rank[i] == 1) {
      Height[0][Rank[i]] = H = 0;
    } else {
      for (H && (H--); S[i + H] == S[SA[Rank[i] - 1] + H]; H++)
        ;
      Height[0][Rank[i]] = H;
    }
  }
}
void ST() {
  for (int j = 1; (1 << j) <= N; j++) {
    for (int i = 1; i + (1 << j) - 1 <= N; i++) {
      Height[j][i] = Height[j - 1][i] < Height[j - 1][i + (1 << (j - 1))]
                         ? Height[j - 1][i]
                         : Height[j - 1][i + (1 << (j - 1))];
    }
  }
}
int LCP(int i, int j) {
  if (i == j) return 0x2f2f2f2f;
  i = Rank[i];
  j = Rank[j];
  if (i > j) std::swap(i, j);
  i++;
  int L = Log(j - i);
  return Height[L][i] < Height[L][j - (1 << L) + 1]
             ? Height[L][i]
             : Height[L][j - (1 << L) + 1];
}
int Bin1(int L, int R, int Pos, int X) {
  for (;;) {
    if (L == R) return L;
    if (L + 1 == R) {
      if (LCP(SA[L], Pos) >= X) return L;
      return R;
    }
    int Mid = L + R;
    Mid >>= 1;
    if (LCP(SA[Mid], Pos) >= X)
      R = Mid;
    else
      L = Mid;
  }
}
int Bin2(int L, int R, int Pos, int X) {
  for (;;) {
    if (L == R) return L;
    if (L + 1 == R) {
      if (LCP(SA[R], Pos) >= X) return R;
      return L;
    }
    int Mid = L + R;
    Mid >>= 1;
    if (LCP(SA[Mid], Pos) >= X)
      L = Mid;
    else
      R = Mid;
  }
}
struct Lis {
  int ID, K, Next;
} List[400005];
int ListTop;
int Head[200005];
void Add(int X, int K, int Y) {
  List[++ListTop] = (Lis){Y, K, Head[X]};
  Head[X] = ListTop;
}
int Tree[200005];
void Add(int X, int Delta) {
  for (; X <= N; X += X & -X) {
    Tree[X] += Delta;
  }
}
int Ask(int X) {
  int Ans = 0;
  for (; X >= 1; X -= X & -X) {
    Ans += Tree[X];
  }
  return Ans;
}
void Work() {
  SuffixArray();
  ST();
  for (int k = 1; k <= K; k++) {
    if (L[k] > R[k]) {
      Ans[k] = M;
      continue;
    }
    int RankL = Bin1(1, Rank[L[k]], L[k], R[k] - L[k] + 1);
    int RankR = Bin2(Rank[L[k]], N, L[k], R[k] - L[k] + 1);
    L[k] += M + 1;
    R[k] += M + 1;
    L[k] -= R[k] - L[k] + 1;
    R[k]++;
    Add(RankL - 1, -1, k);
    Add(RankR, 1, k);
  }
  for (int i = 1; i <= N; i++) {
    if (SA[i] > M) {
      Add(SA[i], 1);
    }
    for (int k = Head[i]; k; k = List[k].Next) {
      int Ans0;
      Ans0 = (Ask(N) - Ask(R[List[k].ID]) + Ask(L[List[k].ID] - 1)) * List[k].K;
      Ans[List[k].ID] += Ans0;
    }
  }
}
void Output() {
  for (int k = 1; k <= K; k++) {
    printf("%d\n", Ans[k]);
  }
}
int main() {
  Init();
  Work();
  Output();
  return 0;
}
