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;
using ll = long long;
const ll MOD = 1e9 + 7;
struct SegTree {
  vector<ll> sum;
  vector<ll> add;
  int h = 1;
  SegTree(int n) {
    while (h < n) h <<= 1;
    sum.resize(2 * h, 0);
    add.resize(2 * h, 0);
  }
  void push(int i, int ia, int ib) {
    if (add[i] == 0) return;
    if (ia != ib) {
      add[2 * i] += add[i];
      add[2 * i + 1] += add[i];
    }
    sum[i] += add[i] * (ib - ia + 1);
    add[i] = 0;
  }
  void update(int i) { sum[i] = sum[2 * i] + sum[2 * i + 1]; }
  void recAddRange(int a, int b, ll v, int i, int ia, int ib) {
    push(i, ia, ib);
    if (b < ia || ib < a) return;
    if (a <= ia && ib <= b) {
      add[i] += v;
      push(i, ia, ib);
    } else {
      int im = (ia + ib) >> 1;
      recAddRange(a, b, v, 2 * i, ia, im);
      recAddRange(a, b, v, 2 * i + 1, im + 1, ib);
      update(i);
    }
  }
  ll recSumRange(int a, int b, int i, int ia, int ib) {
    push(i, ia, ib);
    if (b < ia || ib < a) return 0;
    if (a <= ia && ib <= b) return sum[i];
    int im = (ia + ib) >> 1;
    ll res = 0;
    res += recSumRange(a, b, 2 * i, ia, im);
    res += recSumRange(a, b, 2 * i + 1, im + 1, ib);
    return res;
  }
  void addRange(int a, int b, ll v) { recAddRange(a, b, v, 1, 0, h - 1); }
  ll sumRange(int a, int b) { return recSumRange(a, b, 1, 0, h - 1); }
};
vector<ll> solve(const vector<int>& h, vector<pair<int, int>> que) {
  int n = h.size();
  int q = que.size();
  SegTree seg(n);
  vector<int> sta;
  vector<int> pre(n);
  for (int i = 0; i < n; ++i) {
    while ((!sta.empty()) && (h[sta.back()] < h[i])) sta.pop_back();
    if (!sta.empty())
      pre[i] = sta.back() + 1;
    else
      pre[i] = 0;
    sta.push_back(i);
  }
  vector<pair<int, int>> qs(q);
  for (int j = 0; j < q; ++j) qs[j] = {-que[j].second, j};
  sort(qs.begin(), qs.end());
  for (int i = 0; i < n; ++i) {
    seg.addRange(pre[i], i - 1, 1);
  }
  vector<ll> ans(q);
  int b = n - 1;
  for (auto pr : qs) {
    int j = pr.second;
    while (b > que[j].second) {
      seg.addRange(pre[b], b - 1, -1);
      --b;
    }
    ans[j] = seg.sumRange(que[j].first, que[j].second);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) cin >> h[i];
  vector<pair<int, int>> que(q);
  for (int i = 0; i < q; ++i) cin >> que[i].first;
  for (int i = 0; i < q; ++i) cin >> que[i].second;
  for (int i = 0; i < q; ++i) {
    --que[i].first;
    --que[i].second;
  }
  vector<ll> res1 = solve(h, que);
  reverse(h.begin(), h.end());
  vector<pair<int, int>> rev_que(q);
  for (int i = 0; i < q; ++i) {
    rev_que[i].first = n - 1 - que[i].second;
    rev_que[i].second = n - 1 - que[i].first;
  }
  vector<ll> res2 = solve(h, rev_que);
  for (int i = 0; i < q; ++i) {
    int len = que[i].second - que[i].first + 1;
    ll res = res1[i] + res2[i] + len;
    cout << res << ' ';
  }
  cout << '\n';
}