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;
typedef struct _Query {
  int id, qLeftPt, qRightPt;
  bool operator<(const struct _Query& snd) const {
    if (qLeftPt != snd.qLeftPt) return qLeftPt > snd.qLeftPt;
    return qRightPt > snd.qRightPt;
  }
} Query;
Query qArr[1000010];
int arr[1000010], pos[1000010], len, qNum;
long long int bit1[1000010], bit2[1000010], ans[1000010];
pair<int, int> dsc[1000010];
int lowbit(int x) { return x & -x; }
void add(long long int* bitArr, int pos, long long int val) {
  pos++;
  for (int i = pos; i <= len; i += lowbit(i)) {
    bitArr[i] += val;
  }
}
long long int prefixSum(long long int* bitArr, int pos) {
  pos++;
  long long int ret = 0;
  for (int i = pos; i > 0; i -= lowbit(i)) {
    ret += bitArr[i];
  }
  return ret;
}
long long int rangeSum(long long int* bitArr, int qLeftPt, int qRightPt) {
  return prefixSum(bitArr, qRightPt) - prefixSum(bitArr, qLeftPt - 1);
}
void solve(int dir) {
  sort(qArr + 0, qArr + qNum);
  memset(bit1, 0, sizeof(bit1));
  memset(bit2, 0, sizeof(bit2));
  stack<pair<int, int> > mstk;
  for (int i = 0; i < len; i++) {
    while (!mstk.empty() && mstk.top().first < arr[i]) {
      mstk.pop();
    }
    if (mstk.empty()) {
      pos[i] = -1;
    } else {
      pos[i] = mstk.top().second;
    }
    dsc[i] = make_pair(pos[i], i);
    mstk.push(make_pair(arr[i], i));
  }
  sort(dsc + 0, dsc + len, greater<pair<int, int> >());
  int cntPt = -1, dscPt = 0;
  for (int i = 0; i < qNum; i++) {
    int qLen = qArr[i].qRightPt - qArr[i].qLeftPt + 1;
    if (cntPt != qArr[i].qLeftPt) {
      while (dscPt < len && dsc[dscPt].first + 1 >= qArr[i].qLeftPt) {
        if (dir == 0) {
          add(bit1, dsc[dscPt].second, dsc[dscPt].first + 1);
        } else {
          add(bit1, dsc[dscPt].second, len - 1 - (dsc[dscPt].first + 1));
        }
        add(bit2, dsc[dscPt].second, 1);
        dscPt++;
      }
      cntPt = qArr[i].qLeftPt;
    }
    long long int cnt = rangeSum(bit1, qArr[i].qLeftPt, qArr[i].qRightPt),
                  baseNum =
                      qLen - rangeSum(bit2, qArr[i].qLeftPt, qArr[i].qRightPt);
    if (dir == 0) {
      cnt += baseNum * qArr[i].qLeftPt;
    } else {
      cnt += baseNum * (len - 1 - qArr[i].qLeftPt);
    }
    ans[qArr[i].id] += ((dir << 1) - 1) * cnt;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> len >> qNum;
  for (int i = 0; i < len; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < qNum; i++) {
    cin >> qArr[i].qLeftPt;
    qArr[i].qLeftPt--;
    qArr[i].id = i;
  }
  for (int i = 0; i < qNum; i++) {
    cin >> qArr[i].qRightPt;
    qArr[i].qRightPt--;
    ans[qArr[i].id] = qArr[i].qRightPt - qArr[i].qLeftPt + 1;
  }
  solve(0);
  reverse(arr + 0, arr + len);
  for (int i = 0; i < qNum; i++) {
    int bak = qArr[i].qLeftPt;
    qArr[i].qLeftPt = len - qArr[i].qRightPt - 1;
    qArr[i].qRightPt = len - bak - 1;
  }
  solve(1);
  for (int i = 0; i < qNum; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}