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;
const int64_t INF = 1LL << 60;
const int64_t N = 1000000 + 5;
template <typename T>
class BIT {
 private:
  int64_t n;
  vector<T> arr;
  inline int64_t lowbit(int64_t x) { return x & (-x); }
  T query(int64_t x) {
    T ret = 0;
    while (x) {
      ret += arr[x];
      x -= lowbit(x);
    }
    return ret;
  }

 public:
  void init(int64_t n_) {
    n = n_;
    arr.clear();
    arr.resize(n);
  }
  void modify(int64_t p, T x) {
    while (p < n) {
      arr[p] += x;
      p += lowbit(p);
    }
  }
  T query(int64_t l, int64_t r) { return query(r) - query(l); }
};
BIT<int64_t> bit1;
BIT<int64_t> bit2;
int64_t arr[N], stk[N], qll[N], qrr[N];
pair<int64_t, int64_t> L[N], R[N], ql[N], qr[N];
int64_t ans[N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int64_t n, q;
  cin >> n >> q;
  for (int64_t i = 1; i <= n; ++i) cin >> arr[i];
  for (int64_t i = 1; i <= q; ++i) cin >> qll[i];
  for (int64_t i = 1; i <= q; ++i) cin >> qrr[i];
  arr[0] = INF;
  arr[n + 1] = INF;
  {
    int64_t ptr = 0;
    stk[ptr++] = 0;
    for (int64_t i = 1; i <= n; ++i) {
      while (arr[stk[ptr - 1]] < arr[i]) ptr--;
      L[i].first = stk[ptr - 1];
      stk[ptr++] = i;
    }
  }
  {
    int64_t ptr = 0;
    stk[ptr++] = n + 1;
    for (int64_t i = n; i >= 1; --i) {
      while (arr[stk[ptr - 1]] < arr[i]) ptr--;
      R[i].first = stk[ptr - 1];
      stk[ptr++] = i;
    }
  }
  for (int64_t i = 1; i <= n; ++i) L[i].second = R[i].second = i;
  for (int64_t i = 1; i <= q; ++i) ql[i].first = qll[i];
  for (int64_t i = 1; i <= q; ++i) qr[i].first = qrr[i];
  for (int64_t i = 1; i <= q; ++i) ql[i].second = qr[i].second = i;
  sort(L + 1, L + 1 + n);
  sort(R + 1, R + 1 + n);
  reverse(L + 1, L + 1 + n);
  sort(ql + 1, ql + 1 + q);
  sort(qr + 1, qr + 1 + q);
  reverse(ql + 1, ql + 1 + q);
  {
    int64_t ptr = 1;
    bit1.init(n + 1);
    bit2.init(n + 1);
    for (int64_t i = 1; i <= q; ++i) {
      while (ptr <= n and R[ptr].first <= qr[i].first) {
        bit1.modify(R[ptr].second, R[ptr].first);
        bit2.modify(R[ptr++].second, 1);
      }
      int64_t ll = qll[qr[i].second];
      int64_t rr = qrr[qr[i].second];
      ans[qr[i].second] += bit1.query(ll - 1, rr);
      ans[qr[i].second] += (rr + 1) * (rr - ll + 1 - bit2.query(ll - 1, rr));
    }
  }
  {
    int64_t ptr = 1;
    bit1.init(n + 1);
    bit2.init(n + 1);
    for (int64_t i = 1; i <= q; ++i) {
      while (ptr <= n and L[ptr].first >= ql[i].first) {
        bit1.modify(L[ptr].second, L[ptr].first);
        bit2.modify(L[ptr++].second, 1);
      }
      int64_t ll = qll[ql[i].second];
      int64_t rr = qrr[ql[i].second];
      ans[ql[i].second] -= bit1.query(ll - 1, rr);
      ans[ql[i].second] -= (ll - 1) * (rr - ll + 1 - bit2.query(ll - 1, rr));
    }
  }
  for (int64_t i = 1; i <= q; ++i)
    cout << ans[i] - (qrr[i] - qll[i] + 1) << " \n"[i == q];
  return 0;
}