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;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T, typename T1>
T maxs(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T mins(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
template <typename T>
struct Fenwick {
  vector<T> tree;
  Fenwick(long long n) { tree.resize(n); }
  T query(long long i) {
    pair<long long, long long> sum;
    while (i) {
      sum.first += tree[i].first;
      sum.second += tree[i].second;
      i -= i & (-i);
    }
    return sum;
  }
  void update(long long i, long long n, T val) {
    while (i <= n) {
      tree[i].first += val.first;
      tree[i].second += val.second;
      i += i & (-i);
    }
  }
};
long long solve() {
  long long n, q;
  cin >> n >> q;
  vector<long long> p(n + 1);
  for (long long i = 1; i < n + 1; i++) cin >> p[i];
  stack<pair<long long, long long>> st;
  vector<pair<long long, long long>> l(n + 1), r(n + 1);
  vector<long long> p1(n + 1), p2(n + 1);
  Fenwick<pair<long long, long long>> fn(n + 1);
  for (long long i = 1; i <= n; i++) {
    while (!st.empty() && st.top().first < p[i]) {
      r[st.top().second] = {i - 1, st.top().second};
      st.pop();
    }
    st.push({p[i], i});
  }
  while (!st.empty()) {
    r[st.top().second] = {n, st.top().second};
    st.pop();
  }
  for (long long i = n; i >= 1; i--) {
    while (!st.empty() && st.top().first < p[i]) {
      l[st.top().second] = {i + 1, st.top().second};
      st.pop();
    }
    st.push({p[i], i});
  }
  while (!st.empty()) {
    l[st.top().second] = {1, st.top().second};
    st.pop();
  }
  for (long long i = 1; i <= n; i++) {
    p1[i] += p1[i - 1] + l[i].first;
    p2[i] += p2[i - 1] + r[i].first;
  }
  sort(r.begin(), r.end(), greater<pair<long long, long long>>());
  sort(l.begin(), l.end());
  vector<long long> ans(q);
  vector<pair<long long, pair<long long, long long>>> v(q);
  for (long long i = 0; i < q; i++) {
    cin >> v[i].first;
  }
  for (long long i = 0; i < q; i++) {
    cin >> v[i].second.first;
    v[i].second.second = i;
    ans[i] += p2[v[i].second.first] - p2[v[i].first - 1];
    ans[i] -= p1[v[i].second.first] - p1[v[i].first - 1];
    ans[i] += v[i].second.first - v[i].first + 1;
  }
  sort(v.begin(), v.end());
  long long j = 1;
  for (long long i = 0; i < q; i++) {
    while (j <= n && l[j].first < v[i].first) {
      pair<long long, long long> p = {l[j].first, 1};
      fn.update(l[j].second, n, p);
      j++;
    }
    long long idx = v[i].second.second;
    pair<long long, long long> p = fn.query(v[i].second.first);
    pair<long long, long long> p2 = fn.query(v[i].first - 1);
    p.first -= p2.first, p.second -= p2.second;
    ans[idx] -= p.second * v[i].first - p.first;
  }
  sort(v.begin(), v.end(),
       [&](pair<long long, pair<long long, long long>> p1,
           pair<long long, pair<long long, long long>> p2) {
         return p1.second.first > p2.second.first;
       });
  j = 1;
  fn.tree.clear();
  fn.tree.resize(n + 1);
  for (long long i = 0; i < q; i++) {
    while (j <= n && r[j].first > v[i].second.first) {
      pair<long long, long long> p = {r[j].first, 1};
      fn.update(r[j].second, n, p);
      j++;
    }
    long long idx = v[i].second.second;
    pair<long long, long long> p = fn.query(v[i].second.first);
    pair<long long, long long> p2 = fn.query(v[i].first - 1);
    p.first -= p2.first;
    p.second -= p2.second;
    ans[idx] += p.second * v[i].second.first - p.first;
  }
  for (long long i = 0; i < q; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}