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 = 1000100, LOGN = 22;
int n, m;
int a[MAXN];
namespace Seg {
long long sumn[MAXN << 2], addn[MAXN << 2];
void add(int nown, int l, int r, long long v) {
  sumn[nown] += v * (r - l + 1), addn[nown] += v;
}
void push_down(int nown, int l, int r) {
  if (addn[nown]) {
    add((nown << 1), l, ((l + r) / 2), addn[nown]),
        add((nown << 1 | 1), ((l + r) / 2) + 1, r, addn[nown]);
    addn[nown] = 0;
  }
}
void push_up(int nown) {
  sumn[nown] = sumn[(nown << 1)] + sumn[(nown << 1 | 1)];
}
void modify(int nown, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) {
    add(nown, l, r, 1);
  } else {
    push_down(nown, l, r);
    if (ql <= ((l + r) / 2)) modify((nown << 1), l, ((l + r) / 2), ql, qr);
    if (qr >= ((l + r) / 2) + 1)
      modify((nown << 1 | 1), ((l + r) / 2) + 1, r, ql, qr);
    push_up(nown);
  }
}
long long query(int nown, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) {
    return sumn[nown];
  } else {
    push_down(nown, l, r);
    long long ans = 0;
    if (ql <= ((l + r) / 2))
      ans += query((nown << 1), l, ((l + r) / 2), ql, qr);
    if (qr >= ((l + r) / 2) + 1)
      ans += query((nown << 1 | 1), ((l + r) / 2) + 1, r, ql, qr);
    return ans;
  }
}
}  // namespace Seg
namespace ST {
int maxn[MAXN][LOGN];
int pmax(int i, int j) { return a[i] > a[j] ? i : j; }
void init(int n) {
  for (int i = 1; i <= n; i++) maxn[i][0] = i;
  for (int j = 1; j < LOGN; j++)
    for (int i = 1; i + (1 << (j - 1)) <= n; i++)
      maxn[i][j] = pmax(maxn[i][j - 1], maxn[i + (1 << (j - 1))][j - 1]);
}
int query(int l, int r) {
  int t = log2(r - l + 1);
  return pmax(maxn[l][t], maxn[r - (1 << t) + 1][t]);
}
}  // namespace ST
pair<int, int> p[MAXN];
void solve(int l, int r) {
  if (l > r)
    return;
  else {
    int mid = ST::query(l, r);
    p[mid] = make_pair(l, r);
    solve(l, mid - 1);
    solve(mid + 1, r);
  }
}
long long ans[MAXN];
int L[MAXN], R[MAXN];
struct Q {
  int P, op, id;
} q[MAXN * 2];
int cnt;
bool cmp(Q &a, Q &b) { return a.P < b.P; }
void init() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &L[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &R[i]);
  for (int i = 1; i <= m; i++) {
    if (L[i] - 1 > 0) q[++cnt] = (Q){L[i] - 1, -1, i};
    if (R[i]) q[++cnt] = (Q){R[i], 1, i};
  }
  ST::init(n);
}
void solve() {
  solve(1, n);
  sort(q + 1, q + cnt + 1, cmp);
  int now = 1;
  for (int i = 1; i <= n; i++) {
    Seg::modify(1, 1, n, p[i].first, p[i].second);
    while (now <= cnt && q[now].P <= i) {
      ans[q[now].id] +=
          q[now].op * Seg::query(1, 1, n, L[q[now].id], R[q[now].id]);
      now++;
    }
  }
  for (int i = 1; i <= m; i++) {
    printf("%lld ", ans[i]);
  }
  printf("\n");
}
int main() {
  init();
  solve();
  return 0;
}