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 int N = 1e6 + 2;
int ql[N], qr[N], w[N], l[N], r[N], p[N];
long long ans[N];
vector<int> st[4 * N];
long long sr[N], sl[N];
namespace seg {
inline long long get(long long a[], int x, int y) {
  if (x > y) return 0;
  if (x == 0) return a[y];
  return a[y] - a[x - 1];
}
void build(int cur, int b, int e) {
  if (b + 1 < e) {
    int m = (b + e) >> 1;
    build(cur << 1, b, m);
    build(cur << 1 | 1, m, e);
  }
  int sz = e - b;
  sort(r + b, r + e);
  sort(l + b, l + e);
  for (int i = 0; i < sz; ++i) {
    sr[i] = r[b + i], sl[i] = l[b + i];
    if (i > 0) sr[i] += sr[i - 1], sl[i] += sl[i - 1];
  }
  for (auto i : st[cur]) {
    int x = ql[i], y = qr[i];
    int p1 = upper_bound(r + b, r + e, y) - r - b;
    int p2 = lower_bound(l + b, l + e, x) - l - b;
    ans[i] += get(sr, 0, p1 - 1) + ((long long)sz - p1) * y -
              (get(sl, p2, sz - 1) + (long long)p2 * x);
  }
}
void query(int cur, int b, int e, int x, int y, int i) {
  if (x <= b && e <= y) {
    st[cur].push_back(i);
    return;
  }
  int m = (b + e) >> 1;
  if (x < m) query(cur << 1, b, m, x, y, i);
  if (m < y) query(cur << 1 | 1, m, e, x, y, i);
}
};  // namespace seg
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) cin >> p[i], w[p[i]] = i;
  for (int i = 0; i < q; ++i) cin >> ql[i];
  for (int i = 0; i < q; ++i) cin >> qr[i];
  vector<int> cur;
  for (int i = 0; i < n; ++i) {
    auto it = upper_bound(cur.rbegin(), cur.rend(), p[i]);
    l[i] = (it == cur.rend()) ? 0 : (w[*it] + 1);
    while (!cur.empty() && cur.back() < p[i]) cur.pop_back();
    cur.push_back(p[i]);
  }
  cur.clear();
  for (int i = n - 1; i >= 0; --i) {
    auto it = upper_bound(cur.rbegin(), cur.rend(), p[i]);
    r[i] = (it == cur.rend()) ? n : (w[*it]);
    while (!cur.empty() && cur.back() < p[i]) cur.pop_back();
    cur.push_back(p[i]);
  }
  for (int i = 0; i < q; ++i) seg::query(1, 0, n, --ql[i], qr[i], i);
  seg::build(1, 0, n);
  for (int i = 0; i < q; ++i) cout << ans[i] << " ";
  return 0;
}