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;
char getc() {
  char c = getchar();
  while ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (c < '0' || c > '9'))
    c = getchar();
  return c;
}
int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); }
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return x * f;
}
int n, m, a[1000010], nxt[1000010], L[1000010 << 2], R[1000010 << 2];
long long ans[1000010], lazy[1000010 << 2][2];
struct data {
  int l, r, i;
  long long ans;
} q[1000010];
bool cmp(const data& a, const data& b) { return a.l < b.l; }
void build(int k, int l, int r) {
  L[k] = l, R[k] = r;
  lazy[k][0] = lazy[k][1] = 0;
  if (l == r) return;
  int mid = l + r >> 1;
  build(k << 1, l, mid);
  build(k << 1 | 1, mid + 1, r);
}
void down(int k) {
  lazy[k << 1][0] += lazy[k][0], lazy[k << 1 | 1][0] += lazy[k][0],
      lazy[k][0] = 0;
  lazy[k << 1][1] += lazy[k][1], lazy[k << 1 | 1][1] += lazy[k][1],
      lazy[k][1] = 0;
}
long long query(int k, int p) {
  if (L[k] == R[k]) return 1ll * lazy[k][1] * p + lazy[k][0];
  down(k);
  int mid = L[k] + R[k] >> 1;
  if (p <= mid)
    return query(k << 1, p);
  else
    return query(k << 1 | 1, p);
}
void add(int k, int l, int r, int u, int x) {
  if (L[k] == l && R[k] == r) {
    lazy[k][1]++;
    lazy[k][0] += x;
    return;
  }
  down(k);
  int mid = L[k] + R[k] >> 1;
  if (r <= mid)
    add(k << 1, l, r, u, x);
  else if (l > mid)
    add(k << 1 | 1, l, r, u, x);
  else
    add(k << 1, l, mid, u, x), add(k << 1 | 1, mid + 1, r, u, x);
}
void add(int k, int l, int r, int x) {
  if (L[k] == l && R[k] == r) {
    lazy[k][0] += x;
    return;
  }
  down(k);
  int mid = L[k] + R[k] >> 1;
  if (r <= mid)
    add(k << 1, l, r, x);
  else if (l > mid)
    add(k << 1 | 1, l, r, x);
  else
    add(k << 1, l, mid, x), add(k << 1 | 1, mid + 1, r, x);
}
void solve() {
  nxt[n + 1] = n + 1;
  for (int i = n; i >= 1; i--) {
    int j = i + 1;
    while (a[j] < a[i]) j = nxt[j];
    nxt[i] = j;
  }
  build(1, 1, n);
  sort(q + 1, q + m + 1, cmp);
  int cur = 0;
  for (int i = 1; i <= n; i++) {
    while (q[cur + 1].l == i) cur++, q[cur].ans -= query(1, q[cur].r);
    add(1, i, nxt[i] - 1, 1, -i);
    if (nxt[i] <= n) add(1, nxt[i], n, nxt[i] - i - 1);
  }
  for (int i = 1; i <= m; i++) q[i].ans += query(1, q[i].r);
}
signed main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  a[0] = a[n + 1] = n + 1;
  for (int i = 1; i <= m; i++) q[i].l = read();
  for (int i = 1; i <= m; i++) q[i].r = read();
  for (int i = 1; i <= m; i++) q[i].i = i;
  solve();
  reverse(a + 1, a + n + 1);
  for (int i = 1; i <= m; i++)
    q[i].l = n - q[i].l + 1, q[i].r = n - q[i].r + 1, swap(q[i].l, q[i].r);
  solve();
  for (int i = 1; i <= m; i++) q[i].ans += q[i].r - q[i].l + 1;
  for (int i = 1; i <= m; i++) ans[q[i].i] = q[i].ans;
  for (int i = 1; i <= m; i++) printf("%I64d ", ans[i]);
  return 0;
}