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 long ans[1000006];
struct pp {
  long long l, r, sum, tag;
} tr[4000006];
int l[1000006], r[1000006], a[1000006];
struct ppp {
  int l, r, v;
} c[1000006];
bool cmpr(ppp i, ppp j) { return i.r < j.r; }
bool cmpl(ppp i, ppp j) { return i.l > j.l; }
void up(long long i) { tr[i].sum = tr[i * 2].sum + tr[i * 2 + 1].sum; }
void buildtree(long long i, long long l, long long r) {
  tr[i].l = l;
  tr[i].r = r;
  tr[i].tag = 0;
  if (l == r) {
    tr[i].sum = 0;
    return;
  }
  long long m = (l + r) / 2;
  buildtree(i * 2, l, m);
  buildtree(i * 2 + 1, m + 1, r);
  up(i);
}
void dn(long long i) {
  if (!tr[i].tag) return;
  long long v = tr[i].tag;
  tr[i].tag = 0;
  tr[i * 2].tag += v;
  tr[i * 2 + 1].tag += v;
  tr[i * 2].sum += v * (tr[i * 2].r - tr[i * 2].l + 1);
  tr[i * 2 + 1].sum += v * (tr[i * 2 + 1].r - tr[i * 2 + 1].l + 1);
}
void update(long long i, long long l, long long r, long long k) {
  if (tr[i].l >= l && tr[i].r <= r) {
    tr[i].sum += k * (tr[i].r - tr[i].l + 1);
    tr[i].tag += k;
    return;
  }
  dn(i);
  long long m = (tr[i].l + tr[i].r) / 2;
  if (l <= m) update(i * 2, l, r, k);
  if (r > m) update(i * 2 + 1, l, r, k);
  up(i);
}
long long query(long long i, long long l, long long r) {
  if (tr[i].l >= l && tr[i].r <= r) {
    return tr[i].sum;
  }
  dn(i);
  long long m = (tr[i].l + tr[i].r) / 2, ans = 0;
  if (l <= m) ans += query(i * 2, l, r);
  if (r > m) ans += query(i * 2 + 1, l, r);
  return ans;
}
int main() {
  long long n, q, w = 1;
  scanf("%lld%lld", &n, &q);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  a[0] = 2e9;
  a[n + 1] = 2e9;
  for (long long i = 1; i <= q; i++) {
    scanf("%lld", &c[i].l);
  }
  for (long long i = 1; i <= q; i++) {
    scanf("%lld", &c[i].r);
    c[i].v = i;
  }
  for (long long i = 1; i <= n; i++) {
    l[i] = i - 1;
    while (a[l[i]] < a[i]) l[i] = l[l[i]];
  }
  for (long long i = n; i >= 1; i--) {
    r[i] = i + 1;
    while (a[r[i]] < a[i]) r[i] = r[r[i]];
  }
  for (long long i = 1; i <= n; i++) {
    l[i]++;
    r[i]--;
  }
  buildtree(1, 1, n);
  sort(c + 1, c + 1 + q, cmpr);
  for (long long i = 1; i <= q; i++) {
    while (w <= c[i].r) {
      update(1, l[w], w, 1);
      w++;
    }
    ans[c[i].v] += query(1, c[i].l, c[i].r);
  }
  buildtree(1, 1, n);
  w = n;
  sort(c + 1, c + 1 + q, cmpl);
  for (long long i = 1; i <= q; i++) {
    while (w >= c[i].l) {
      update(1, w, r[w], 1);
      w--;
    }
    ans[c[i].v] += query(1, c[i].l, c[i].r) - (c[i].r - c[i].l + 1);
  }
  for (long long i = 1; i <= q; i++) {
    printf("%lld ", ans[i]);
  }
  cout << endl;
}