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;
struct fenwickTree {
  vector<long long> bit;
  int n;
  fenwickTree() {
    n = (int)1e6 + 3;
    bit.assign(n, 0);
  }
  long long sum(int r) {
    long long ret = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1) ret += bit[r];
    return ret;
  }
  void add(int idx, long long d) {
    for (; idx < n; idx = idx | (idx + 1)) bit[idx] += d;
  }
  long long sum(int l, int r) { return sum(r) - sum(l - 1); }
} ft, ft01, ftIdentity;
struct query {
  int l, r, index;
};
bool cmpL(const query &x, const query &y) { return x.l < y.l; }
bool cmpRP(const pair<int, int> &x, const pair<int, int> &y) {
  return x.second < y.second;
}
bool cmpR(const query &x, const query &y) { return x.r < y.r; }
const int N = 1e6 + 10;
int perm[N], lefts[N], rights[N];
long long answer[N];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> perm[i];
  }
  stack<int> positions;
  for (int i = 1; i <= n; ++i) {
    while (!positions.empty() && perm[positions.top()] <= perm[i])
      positions.pop();
    if (positions.empty()) {
      lefts[i] = 0;
    } else {
      lefts[i] = positions.top();
    }
    positions.push(i);
  }
  while (!positions.empty()) positions.pop();
  fill(rights, rights + n + 10, n + 1);
  for (int i = n; i >= 1; --i) {
    while (!positions.empty() && perm[positions.top()] <= perm[i])
      positions.pop();
    if (positions.empty()) {
      rights[i] = n + 1;
    } else {
      rights[i] = positions.top();
    }
    positions.push(i);
  }
  for (int i = 1; i <= n; ++i) {
    ftIdentity.add(i, i);
  }
  vector<pair<int, int>> leftPairs;
  vector<pair<int, int>> rightPairs;
  for (int i = 1; i <= n; ++i) {
    leftPairs.push_back({lefts[i], i});
    rightPairs.push_back({i, rights[i]});
  }
  vector<query> queries(q);
  for (int i = 0; i < q; ++i) {
    cin >> queries[i].l;
    queries[i].index = i;
  }
  for (int i = 0; i < q; ++i) {
    cin >> queries[i].r;
    answer[i] = queries[i].r - queries[i].l + 1;
  }
  sort(leftPairs.begin(), leftPairs.end());
  sort(queries.begin(), queries.end(), cmpL);
  int j = (int)leftPairs.size() - 1;
  for (int i = (int)queries.size() - 1; i >= 0; --i) {
    const int L = queries[i].l;
    const int R = queries[i].r;
    const int index = queries[i].index;
    while (j >= 0 && leftPairs[j].first >= L) {
      ft.add(leftPairs[j].second, leftPairs[j].second - leftPairs[j].first - 1);
      ftIdentity.add(leftPairs[j].second, -leftPairs[j].second);
      ft01.add(leftPairs[j].second, 1);
      --j;
    }
    answer[index] += ft.sum(L, R);
    answer[index] += ftIdentity.sum(L, R);
    answer[index] -= (R - L + 1 - ft01.sum(L, R)) * L;
  }
  sort(rightPairs.begin(), rightPairs.end(), cmpRP);
  sort(queries.begin(), queries.end(), cmpR);
  ft.bit.clear();
  ft.bit.assign(n + 10, 0);
  ftIdentity.bit.clear();
  ftIdentity.bit.assign(n + 10, 0);
  ft01.bit.clear();
  ft01.bit.assign(n + 10, 0);
  for (int i = 1; i <= n; ++i) {
    ftIdentity.add(i, i);
  }
  j = 0;
  for (int i = 0; i < (int)queries.size(); ++i) {
    const int L = queries[i].l;
    const int R = queries[i].r;
    const int index = queries[i].index;
    while (j < (int)rightPairs.size() && rightPairs[j].second <= R) {
      ft.add(rightPairs[j].first,
             rightPairs[j].second - rightPairs[j].first - 1);
      ftIdentity.add(rightPairs[j].first, -rightPairs[j].first);
      ft01.add(rightPairs[j].first, 1);
      ++j;
    }
    answer[index] += ft.sum(L, R);
    answer[index] -= ftIdentity.sum(L, R);
    answer[index] += (R - L + 1 - ft01.sum(L, R)) * R;
  }
  for (int i = 0; i < q; ++i) {
    cout << answer[i] << ' ';
  }
  cout << '\n';
  return 0;
}