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;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const long long maxn = 1e6 + 1e2;
long long l[maxn], r[maxn];
long long f[4 * maxn];
long long add[4 * maxn];
long long n, m;
long long a[maxn];
long long x[maxn], y[maxn];
long long ans[maxn];
void up(long long root) { f[root] = f[2 * root] + f[2 * root + 1]; }
void pushdown(long long root, long long l, long long r) {
  if (add[root]) {
    add[2 * root] += add[root];
    add[2 * root + 1] += add[root];
    long long mid = l + r >> 1;
    f[2 * root] += (mid - l + 1) * add[root];
    f[2 * root + 1] += (r - mid) * add[root];
    add[root] = 0;
  }
}
void update(long long root, long long l, long long r, long long x, long long y,
            long long p) {
  if (x > y || x == 0 || y == 0) return;
  if (x <= l && r <= y) {
    f[root] += (r - l + 1) * p;
    add[root] += p;
    return;
  }
  long long mid = l + r >> 1;
  pushdown(root, l, r);
  if (x <= mid) update(2 * root, l, mid, x, y, p);
  if (y > mid) update(2 * root + 1, mid + 1, r, x, y, p);
  up(root);
}
long long query(long long root, long long l, long long r, long long x,
                long long y) {
  if (x > y || x == 0 || y == 0) return 0;
  if (x <= l && r <= y) return f[root];
  long long mid = l + r >> 1;
  pushdown(root, l, r);
  long long ans = 0;
  if (x <= mid) ans = ans + query(2 * root, l, mid, x, y);
  if (y > mid) ans = ans + query(2 * root + 1, mid + 1, r, x, y);
  return ans;
};
struct Node {
  long long x, l, r, num, opt;
};
Node q[2 * maxn], p[maxn];
bool cmp(Node a, Node b) { return a.x < b.x; }
struct pp {
  long long val, pos;
};
pp s[maxn];
long long top;
signed main() {
  n = read(), m = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  for (long long i = 1; i <= m; i++) x[i] = read();
  for (long long i = 1; i <= m; i++) y[i] = read();
  long long cnt = 1;
  for (long long i = 1; i <= m; i++) {
    if (x[i] != 1) q[++cnt] = (Node){x[i] - 1, x[i], y[i], i, -1};
    q[++cnt] = (Node){y[i], x[i], y[i], i, 1};
  }
  sort(q + 1, q + 1 + cnt, cmp);
  l[1] = 1;
  top = 1;
  s[top].pos = 1;
  s[top].val = a[1];
  for (long long i = 2; i <= n; i++) {
    while (top >= 1 && s[top].val < a[i]) top--;
    if (!top)
      l[i] = 1;
    else
      l[i] = s[top].pos + 1;
    s[++top].val = a[i];
    s[top].pos = i;
  }
  r[n] = n;
  top = 1;
  s[top].pos = n;
  s[top].val = a[n];
  for (long long i = n - 1; i >= 1; i--) {
    while (top >= 1 && s[top].val < a[i]) top--;
    if (!top)
      r[i] = n;
    else
      r[i] = s[top].pos - 1;
    s[++top].val = a[i];
    s[top].pos = i;
  }
  for (long long i = 1; i <= n; i++) l[i]--, r[i]++;
  long long tot = 0;
  for (long long i = 1; i <= n; i++) {
    p[++tot] = (Node){i, l[i] + 1, r[i] - 1, i, 1};
  }
  sort(p + 1, p + 1 + tot, cmp);
  long long x = 1, y = 1;
  for (long long i = 1; i <= n; i++) {
    while (x <= tot && p[x].x <= i) {
      update(1, 1, n, p[x].l, p[x].r, 1);
      x++;
    }
    while (y <= cnt && q[y].x <= i) {
      ans[q[y].num] += q[y].opt * query(1, 1, n, q[y].l, q[y].r);
      y++;
    }
  }
  for (long long i = 1; i <= m; i++) cout << ans[i] << " ";
  return 0;
}