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 maxn = 1e6 + 1;
int n;
long long seg[4 * maxn];
int a[4 * maxn];
void shift(int v, int tl, int tr) {
  seg[v] += a[v] * 1ll * (tr - tl + 1);
  if ((v << 1) < 4 * maxn) {
    a[v << 1] += a[v];
    a[v << 1 | 1] += a[v];
  }
  a[v] = 0;
}
void up(int l, int r, long long val, int v = 1, int tl = 1, int tr = n) {
  shift(v, tl, tr);
  if (l > r) return;
  if (tl == l && tr == r) {
    a[v] += val;
    shift(v, tl, tr);
    return;
  }
  int tm = (tl + tr) >> 1;
  up(l, min(tm, r), val, v << 1, tl, tm);
  up(max(tm + 1, l), r, val, v << 1 | 1, tm + 1, tr);
  seg[v] = seg[2 * v] + seg[2 * v + 1];
}
long long qu(int l, int r, int v = 1, int tl = 1, int tr = n) {
  shift(v, tl, tr);
  if (l > r) return 0;
  if (tl == l && tr == r) return seg[v];
  int tm = (tl + tr) >> 1;
  return qu(l, min(tm, r), v << 1, tl, tm) +
         qu(max(tm + 1, l), r, v << 1 | 1, tm + 1, tr);
}
int p[maxn], L[maxn], R[maxn], l[maxn], r[maxn];
vector<int> que[maxn];
long long ans[maxn];
stack<int> stac;
signed main() {
  int q;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", p + i);
    if (!stac.empty())
      while (p[i] > p[stac.top()]) {
        stac.pop();
        if (stac.empty()) break;
      }
    if (!stac.empty())
      L[i] = stac.top();
    else
      L[i] = 0;
    stac.push(i);
    R[L[i]] = i;
  }
  while (!stac.empty()) stac.pop();
  for (int i = n; i >= 1; i--) {
    if (stac.size())
      while (p[i] > p[stac.top()]) {
        stac.pop();
        if (stac.empty()) break;
      }
    if (stac.size())
      R[i] = stac.top();
    else
      R[i] = n + 1;
    stac.push(i);
  }
  for (int i = 1; i <= q; i++) scanf("%d", l + i);
  for (int i = 1; i <= q; i++) {
    scanf("%d", r + i);
    que[r[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    up(L[i] + 1, i, 1);
    for (auto id : que[i]) ans[id] = qu(l[id], i);
    que[i].clear();
  }
  memset(seg, 0, sizeof seg);
  memset(a, 0, sizeof a);
  for (int i = 1; i <= q; i++) que[l[i]].push_back(i);
  for (int i = n; i >= 1; i--) {
    up(i, R[i] - 1, 1);
    for (auto id : que[i]) ans[id] += qu(i, r[id]) - (r[id] - i + 1);
  }
  for (int i = 1; i <= q; i++) printf("%lld ", ans[i]);
}