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;
long double EPS = 1e-8;
const long long NMAX = 1111111;
const long long inf = 2e9;
const long long M = 1e9 + 7;
long long p[NMAX];
long long ans[NMAX];
pair<long long, long long> a[NMAX];
vector<long long> r[NMAX];
vector<long long> l[NMAX];
long long t[NMAX * 4];
long long sum[NMAX * 4];
void build(long long v, long long tl, long long tr) {
  if (tl == tr - 1) {
    t[v] = 0;
    sum[v] = 0;
    return;
  }
  long long m = (tl + tr) / 2;
  build(2 * v, tl, m);
  build(2 * v + 1, m, tr);
  t[v] = 0;
  sum[v] = 0;
  return;
}
void update(long long v, long long tl, long long tr, long long l, long long r,
            long long k, long long data) {
  if (r <= l) return;
  if (r <= tl || tr <= l) return;
  if (l <= tl && tr <= r) {
    t[v] += k;
    sum[v] += data + (tl - l) * k;
    return;
  }
  long long m = (tl + tr) / 2;
  update(2 * v, tl, m, l, r, k, data);
  update(2 * v + 1, m, tr, l, r, k, data);
  return;
}
long long get(long long v, long long tl, long long tr, long long pos) {
  if (tl == tr - 1) return sum[v];
  long long m = (tl + tr) / 2;
  if (pos < m)
    return get(2 * v, tl, m, pos) + sum[v] + t[v] * (pos - tl);
  else
    return get(2 * v + 1, m, tr, pos) + sum[v] + t[v] * (pos - tl);
}
signed main() {
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(40);
  long long n;
  cin >> n;
  long long q;
  cin >> q;
  for (long long i = 1; i <= n; i++) cin >> p[i];
  for (long long i = 1; i <= q; i++) cin >> a[i].first;
  for (long long i = 1; i <= q; i++) cin >> a[i].second;
  for (long long i = 1; i <= q; i++) {
    if (a[i].first == a[i].second)
      ans[i] = 0;
    else {
      r[a[i].second].push_back(i);
      l[a[i].first].push_back(i);
    }
  }
  build(1, 1, n + 1);
  stack<long long> st;
  p[0] = n + 1;
  st.push(0);
  for (long long i = 1; i <= n; i++) {
    while (p[st.top()] < p[i]) st.pop();
    update(1, 1, n + 1, 1, i, 0, i - st.top() - 1);
    update(1, 1, n + 1, st.top() + 1, i, -1, 0);
    for (long long u : r[i]) {
      ans[u] += get(1, 1, n + 1, a[u].first);
    }
    st.push(i);
  }
  st = stack<long long>();
  st.push(n + 1);
  p[n + 1] = n + 1;
  build(1, 1, n + 1);
  for (long long i = n; i >= 1; i--) {
    while (p[st.top()] < p[i]) st.pop();
    update(1, 1, n + 1, i, st.top(), 1, 0);
    update(1, 1, n + 1, st.top(), n + 1, 0, st.top() - i - 1);
    for (long long u : l[i]) {
      ans[u] += get(1, 1, n + 1, a[u].second);
    }
    st.push(i);
  }
  for (long long i = 1; i <= q; i++)
    cout << ans[i] + a[i].second - a[i].first + 1 << ' ';
  cout << endl;
  return 0;
}