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 mod = 1e9 + 7;
int add(int x, int y) {
  x += y;
  if (x >= mod) return x - mod;
  return x;
}
int sub(int x, int y) {
  x -= y;
  if (x < 0) return x + mod;
  return x;
}
int mul(int x, int y) { return (long long)x * y % mod; }
const int off = 1 << 20, MAXN = 1e6 + 5;
pair<int, int> t[2 * off];
pair<int, int> get(int x, int lo, int hi, int a, int b) {
  if (lo >= a && hi <= b) {
    return t[x];
  }
  if (lo >= b || hi <= a) {
    return {-1, -1};
  }
  int mid = (lo + hi) >> 1;
  return max(get(x * 2, lo, mid, a, b), get(x * 2 + 1, mid, hi, a, b));
}
void upd(int x, int v) {
  x += off;
  t[x] = {v, x - off};
  for (x /= 2; x; x /= 2) {
    t[x] = max(t[x * 2], t[x * 2 + 1]);
  }
}
long long sol[MAXN];
int lft[MAXN], rgt[MAXN];
void rek(int lo, int hi) {
  if (lo > hi) return;
  int mi = get(1, 0, off, lo, hi + 1).second;
  lft[mi] = lo;
  rgt[mi] = hi;
  rek(lo, mi - 1);
  rek(mi + 1, hi);
}
int n, q;
int p[MAXN];
int L[MAXN], R[MAXN];
vector<int> odg_l[MAXN], odg_r[MAXN];
long long sum[2 * off];
int pr[2 * off];
void prop(int x, int lo, int hi) {
  if (pr[x]) {
    sum[x] += (long long)(hi - lo) * pr[x];
    if (x < off) {
      pr[x * 2] += pr[x];
      pr[x * 2 + 1] += pr[x];
    }
    pr[x] = 0;
  }
}
long long get_sum(int x, int lo, int hi, int a, int b) {
  prop(x, lo, hi);
  if (lo >= a && hi <= b) {
    return sum[x];
  }
  if (lo >= b || hi <= a) {
    return 0;
  }
  int mid = (lo + hi) >> 1;
  return get_sum(x * 2, lo, mid, a, b) + get_sum(x * 2 + 1, mid, hi, a, b);
}
void upd_sum(int x, int lo, int hi, int a, int b) {
  if (lo >= a && hi <= b) {
    pr[x]++;
    prop(x, lo, hi);
    return;
  }
  prop(x, lo, hi);
  if (lo >= b || hi <= a) {
    return;
  }
  int mid = (lo + hi) >> 1;
  upd_sum(x * 2, lo, mid, a, b);
  upd_sum(x * 2 + 1, mid, hi, a, b);
  sum[x] = sum[x * 2] + sum[x * 2 + 1];
}
void solve() {
  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) {
    R[i]--;
    L[i]--;
    odg_l[R[i]].push_back(i);
    odg_r[L[i]].push_back(i);
  }
  for (int i = 0; i < n; ++i) {
    upd_sum(1, 0, off, lft[i], i + 1);
    for (auto j : odg_l[i]) {
      sol[j] += get_sum(1, 0, off, L[j], i + 1);
    }
  }
  memset(sum, 0, sizeof sum);
  memset(pr, 0, sizeof pr);
  for (int i = n - 1; i >= 0; --i) {
    upd_sum(1, 0, off, i, rgt[i] + 1);
    for (auto j : odg_r[i]) {
      sol[j] += get_sum(1, 0, off, i, R[j] + 1);
    }
  }
  for (int i = 0; i < q; ++i) {
    cout << sol[i] - (R[i] - L[i] + 1) << ' ';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    upd(i, p[i]);
  }
  rek(0, n - 1);
  solve();
}