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;
long long tree[1000005 * 4], lazy[1000005 * 4];
vector<int> vc[1000005], vc2[1000005];
int ara[2][1000005];
void update(int node, int st, int en, int l, int r) {
  if (l > r) return;
  if (lazy[node]) {
    tree[node] += lazy[node] * (en - st + 1);
    if (st != en) {
      lazy[node * 2] += lazy[node];
      lazy[node * 2 + 1] += lazy[node];
    }
    lazy[node] = 0;
  }
  if (st > r or en < l) return;
  if (st >= l and en <= r) {
    tree[node] += en - st + 1;
    if (st != en) {
      lazy[node * 2] += 1;
      lazy[node * 2 + 1] += 1;
    }
    return;
  }
  int mid = (st + en) >> 1;
  update(node * 2, st, mid, l, r);
  update(node * 2 + 1, mid + 1, en, l, r);
  tree[node] = tree[node * 2] + tree[node * 2 + 1];
}
long long query(int node, int st, int en, int l, int r) {
  if (st > r or en < l) return 0;
  if (lazy[node]) {
    tree[node] += lazy[node] * (en - st + 1);
    if (st != en) {
      lazy[node * 2] += lazy[node];
      lazy[node * 2 + 1] += lazy[node];
    }
    lazy[node] = 0;
  }
  if (st >= l and en <= r) return tree[node];
  int mid = (st + en) >> 1;
  return query(node * 2, st, mid, l, r) +
         query(node * 2 + 1, mid + 1, en, l, r);
}
long long ans[1000005];
int inp[1000005], ql[1000005], qr[1000005];
stack<int> st;
int main() {
  int i, j, k, l, m, q, n;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &inp[i]);
  }
  for (int i = 1; i <= n; i++) {
    while (st.size()) {
      int v = st.top();
      if (inp[v] < inp[i]) {
        ara[1][v] = i - 1;
        st.pop();
      } else
        break;
    }
    st.push(i);
  }
  while (st.size()) {
    int v = st.top();
    st.pop();
    ara[1][v] = n;
  }
  for (int i = n; i >= 1; i--) {
    while (st.size()) {
      int v = st.top();
      if (inp[v] < inp[i]) {
        ara[0][v] = i + 1;
        st.pop();
      } else
        break;
    }
    st.push(i);
  }
  while (st.size()) {
    int v = st.top();
    st.pop();
    ara[0][v] = 1;
  }
  for (int i = 1; i <= q; i++) {
    scanf("%d", &ql[i]);
  }
  for (int i = 1; i <= q; i++) {
    scanf("%d", &qr[i]);
    vc[qr[i]].push_back(i);
    vc2[ql[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    update(1, 1, n, ara[0][i], i - 1);
    for (int j = 0; j < vc[i].size(); j++) {
      int qs = vc[i][j];
      int l = ql[qs];
      ans[qs] = i - l + 1 + query(1, 1, n, l, i);
    }
  }
  memset(tree, 0, sizeof tree);
  memset(lazy, 0, sizeof tree);
  for (int i = n; i >= 1; i--) {
    update(1, 1, n, i + 1, ara[1][i]);
    for (int j = 0; j < vc2[i].size(); j++) {
      int qs = vc2[i][j];
      int r = qr[qs];
      ans[qs] += query(1, 1, n, i + 1, r);
    }
  }
  for (int i = 1; i <= q; i++) {
    printf("%lld ", ans[i]);
  }
}