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 N = 1000005;
int a[N], L[N], tot, R[N], Stack[N], n, m;
long long Ans[N];
struct Ask {
  int l, r, from;
} A[N];
inline int cmp1(Ask x, Ask y) { return x.l > y.l; }
inline int cmp2(Ask x, Ask y) { return x.r < y.r; }
struct segTree {
  struct Tree {
    int l, r;
    long long num, flag;
  } T[N * 4];
  inline void build(int x, int l, int r) {
    T[x].l = l;
    T[x].r = r;
    T[x].flag = T[x].num = 0;
    if (l == r) return;
    int mid = (l + r) / 2;
    build(x * 2, l, mid);
    build(x * 2 + 1, mid + 1, r);
  }
  inline void down(int x) {
    if (!T[x].flag) return;
    T[x * 2].num += T[x].flag * (T[x * 2].r - T[x * 2].l + 1);
    T[x * 2 + 1].num += T[x].flag * (T[x * 2 + 1].r - T[x * 2 + 1].l + 1);
    T[x * 2].flag += T[x].flag;
    T[x * 2 + 1].flag += T[x].flag;
    T[x].flag = 0;
  }
  inline void insert(int x, int l, int r, int z) {
    if (T[x].l > r || l > T[x].r) return;
    if (T[x].l >= l && T[x].r <= r) {
      T[x].num += z * (T[x].r - T[x].l + 1);
      T[x].flag += z;
      return;
    }
    down(x);
    insert(x * 2, l, r, z);
    insert(x * 2 + 1, l, r, z);
    T[x].num = T[x * 2].num + T[x * 2 + 1].num;
  }
  inline long long find(int x, int y) {
    if (T[x].l == T[x].r) return T[x].num;
    down(x);
    int mid = (T[x].l + T[x].r) / 2;
    if (y <= mid) return find(x * 2, y);
    return find(x * 2 + 1, y);
  }
} T1, T2;
signed main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) A[i].from = i;
  for (int i = 1; i <= m; i++) scanf("%d", &A[i].l);
  for (int i = 1; i <= m; i++) scanf("%d", &A[i].r);
  for (int i = 1; i <= m; i++) Ans[i] = A[i].r - A[i].l + 1;
  a[0] = a[n + 1] = n + 1;
  Stack[++tot] = 0;
  for (int i = 1; i <= n; i++) {
    while (a[i] > a[Stack[tot]]) tot--;
    L[i] = Stack[tot] + 1;
    Stack[++tot] = i;
  }
  Stack[tot = 1] = n + 1;
  for (int i = n; i; i--) {
    while (a[i] > a[Stack[tot]]) tot--;
    R[i] = Stack[tot] - 1;
    Stack[++tot] = i;
  }
  T1.build(1, 1, n);
  T2.build(1, 1, n);
  sort(A + 1, A + m + 1, cmp2);
  for (int i = 1, j = 1; i <= n; i++) {
    T1.insert(1, 1, L[i] - 1, -L[i]);
    T2.insert(1, L[i], i, -1);
    while (j <= m && A[j].r == i) {
      Ans[A[j].from] +=
          T1.find(1, A[j].l) + (long long)T2.find(1, A[j].l) * A[j].l;
      j++;
    }
  }
  T1.build(1, 1, n);
  T2.build(1, 1, n);
  sort(A + 1, A + m + 1, cmp1);
  for (int i = n, j = 1; i; i--) {
    T1.insert(1, R[i] + 1, n, R[i]);
    T2.insert(1, i, R[i], 1);
    while (j <= m && A[j].l == i) {
      Ans[A[j].from] +=
          T1.find(1, A[j].r) + (long long)T2.find(1, A[j].r) * A[j].r;
      j++;
    }
  }
  for (int i = 1; i <= m; i++) printf("%lld ", Ans[i]);
  return 0;
}