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 long double PI = acosl(-1);
mt19937_64 rng(
    (unsigned)chrono::system_clock::now().time_since_epoch().count());
const int nmax = 1e6 + 5;
int perm[nmax];
long long int tree[4 * nmax];
long long int lazy[4 * nmax];
void build(int id, int l, int r) {
  lazy[id] = 0;
  if (l == r) {
    tree[id] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  build((id << 1), l, mid);
  build(((id << 1) | 1), mid + 1, r);
  tree[id] = 0;
  return;
}
inline void propagate(int id, int l, int r) {
  if (l != r) {
    lazy[(id << 1)] = (lazy[(id << 1)] + lazy[id]);
    lazy[((id << 1) | 1)] = (lazy[((id << 1) | 1)] + lazy[id]);
  }
  tree[id] = (tree[id] + lazy[id] * (r - l + 1));
  lazy[id] = 0;
  return;
}
long long int query(int id, int l, int r, int L, int R) {
  if (lazy[id]) propagate(id, l, r);
  if (r < L || R < l) return 0;
  if (L <= l && r <= R) return tree[id];
  int mid = (l + r) >> 1;
  long long int p = query((id << 1), l, mid, L, R);
  long long int q = query(((id << 1) | 1), mid + 1, r, L, R);
  return p + q;
}
void update(int id, int l, int r, int L, int R, long long int v) {
  if (lazy[id]) propagate(id, l, r);
  if (r < L || R < l) return;
  if (L <= l && r <= R) {
    lazy[id] = (lazy[id] + v);
    propagate(id, l, r);
    return;
  }
  int mid = (l + r) >> 1;
  update((id << 1), l, mid, L, R, v);
  update(((id << 1) | 1), mid + 1, r, L, R, v);
  tree[id] = (tree[(id << 1)] + tree[((id << 1) | 1)]);
  return;
}
int L[nmax], R[nmax];
long long int ans[nmax];
vector<pair<int, int>> queries[nmax];
void solve(int n, int q) {
  build(1, 1, n);
  for (int i = 1; i <= n; i++) queries[i].clear();
  for (int i = 0; i < q; i++) {
    queries[R[i]].emplace_back(L[i], i);
  }
  perm[0] = n + 1;
  vector<int> stk{0};
  for (int r = 1; r <= n; r++) {
    while (perm[stk.back()] < perm[r]) stk.pop_back();
    int x = stk.back() + 1;
    stk.push_back(r);
    update(1, 1, n, x, r - 1, 1);
    for (auto p : queries[r]) {
      int l = p.first;
      int i = p.second;
      ans[i] += query(1, 1, n, l, r);
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> perm[i];
  }
  for (int i = 0; i < q; i++) cin >> L[i];
  for (int i = 0; i < q; i++) cin >> R[i];
  for (int i = 0; i < q; i++) {
    ans[i] = R[i] - L[i] + 1;
  }
  solve(n, q);
  reverse(perm + 1, perm + n + 1);
  for (int i = 0; i < q; i++) {
    L[i] = n + 1 - L[i];
    R[i] = n + 1 - R[i];
    swap(L[i], R[i]);
  }
  solve(n, q);
  for (int i = 0; i < q; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}