Problem: You are given a permutation p_1, p_2, ..., p_n. You should answer q queries. Each query is a pair (l_i, r_i), and you should calculate f(l_i, r_i).

Let's denote m_{l, r} as the position of the maximum in subsegment p_l, p_{l+1}, ..., p_r.

Then f(l, r) = (r - l + 1) + f(l, m_{l,r} - 1) + f(m_{l,r} + 1, r) if l ≤ r or 0 otherwise.

Input

The first line contains two integers n and q (1 ≤ n ≤ 10^6, 1 ≤ q ≤ 10^6) — the size of the permutation p and the number of queries.

The second line contains n pairwise distinct integers p_1, p_2, ..., p_n (1 ≤ p_i ≤ n, p_i ≠ p_j for i ≠ j) — permutation p.

The third line contains q integers l_1, l_2, ..., l_q — the first parts of the queries.

The fourth line contains q integers r_1, r_2, ..., r_q — the second parts of the queries.

It's guaranteed that 1 ≤ l_i ≤ r_i ≤ n for all queries.

Output

Print q integers — the values f(l_i, r_i) for the corresponding queries.

Example

Input


4 5
3 1 4 2
2 1 1 2 1
2 3 4 4 1


Output


1 6 8 5 1 

Note

Description of the queries: 

  1. f(2, 2) = (2 - 2 + 1) + f(2, 1) + f(3, 2) = 1 + 0 + 0 = 1; 
  2. f(1, 3) = (3 - 1 + 1) + f(1, 2) + f(4, 3) = 3 + (2 - 1 + 1) + f(1, 0) + f(2, 2) = 3 + 2 + (2 - 2 + 1) = 6; 
  3. f(1, 4) = (4 - 1 + 1) + f(1, 2) + f(4, 4) = 4 + 3 + 1 = 8; 
  4. f(2, 4) = (4 - 2 + 1) + f(2, 2) + f(4, 4) = 3 + 1 + 1 = 5; 
  5. f(1, 1) = (1 - 1 + 1) + 0 + 0 = 1. 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 1001000;
struct BIT {
  int n;
  long long Tree[N];
  BIT(int n = 0) : n(n) {}
  void Init(int n) {
    this->n = n;
    for (int i = 0; i <= n; i++) Tree[i] = 0;
  }
  void Update(int i, int x) {
    for (; i <= n; i += i & -i) Tree[i] += x;
  }
  long long Query(int i) {
    long long Res = 0;
    for (; i > 0; i -= i & -i) Res += Tree[i];
    return Res;
  }
  long long Query(int i, int j) {
    if (i > j) return 0;
    return Query(j) - Query(i - 1);
  }
};
BIT myTree1;
BIT myTree2;
long long S(long long x) { return x * (x + 1) / 2; }
int main() {
  int n, q;
  cin >> n >> q;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  vector<int> L(q);
  vector<int> R(q);
  for (int& x : L) scanf("%d", &x);
  for (int& x : R) scanf("%d", &x);
  vector<long long> Ans(q);
  for (int Repeat = 0; Repeat < 2; Repeat++) {
    vector<int> LG(n + 1, 0);
    stack<int> stk;
    for (int i = n; i > 0; i--) {
      while (!stk.empty() && a[i] > a[stk.top()]) LG[stk.top()] = i, stk.pop();
      stk.push(i);
    }
    while (!stk.empty()) LG[stk.top()] = 0, stk.pop();
    vector<vector<int>> HaveLG(n + 1);
    for (int i = 1; i <= n; i++) HaveLG[LG[i]].push_back(i);
    vector<vector<int>> HaveL(n + 1);
    for (int i = 0; i < q; i++) HaveL[L[i]].push_back(i);
    for (int i = 0; i < q; i++) Ans[i] += S(R[i]) - S(L[i] - 1);
    myTree1.Init(n);
    myTree2.Init(n);
    for (int i = 1; i <= n; i++) myTree1.Update(i, 1);
    for (int l = n; l > 0; l--) {
      for (int i : HaveLG[l]) {
        myTree1.Update(i, -1);
        myTree2.Update(i, l);
      }
      for (int i : HaveL[l]) {
        int r = R[i];
        Ans[i] -=
            myTree2.Query(l, r) + (long long)(l - 1) * myTree1.Query(l, r);
      }
    }
    reverse(a.begin() + 1, a.end());
    for (int i = 0; i < q; i++) {
      L[i] = n - L[i] + 1;
      R[i] = n - R[i] + 1;
      swap(L[i], R[i]);
    }
  }
  for (int i = 0; i < q; i++) Ans[i] -= (long long)R[i] - L[i] + 1;
  for (long long x : Ans) printf("%I64d ", x);
}