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;
int n, m, x, y, z, k, w, q;
int A[1000005], L[1000005], R[1000005];
pair<pair<int, int>, int> Q[1000005];
vector<int> v, update[1000005];
long long bitsum[1000005], bitcnt[1000005], res[1000005];
void add(int pos, int val) {
  for (int i = pos; i <= n; i += (i & -i)) bitsum[i] += val, bitcnt[i]++;
}
int querycnt(int l, int r) {
  int res = 0;
  for (int i = r; i > 0; i -= (i & -i)) res += bitcnt[i];
  for (int i = l - 1; i > 0; i -= (i & -i)) res -= bitcnt[i];
  return res;
}
long long querysum(int l, int r) {
  long long res = 0;
  for (int i = r; i > 0; i -= (i & -i)) res += bitsum[i];
  for (int i = l - 1; i > 0; i -= (i & -i)) res -= bitsum[i];
  return res;
}
int find(int x) {
  int high = v.size();
  int low = 0;
  if (v.empty() || x > A[v[0]]) return 0;
  while (high - low > 1) {
    int mid = (high + low) / 2;
    if (A[v[mid]] > x)
      low = mid;
    else
      high = mid;
  }
  return v[low];
}
int main() {
  scanf("%d %d", &n, &q);
  for (int i = (1); i <= (n); i++) scanf("%d", &A[i]);
  for (int i = (1); i <= (n); i++) {
    L[i] = find(A[i]);
    while (v.size() > 0 && A[i] > A[v.back()]) v.pop_back();
    v.push_back(i);
  }
  v.clear();
  for (int i = (n); i >= (1); i--) {
    R[i] = find(A[i]);
    if (R[i] == 0) R[i] = n + 1;
    while (v.size() > 0 && A[i] > A[v.back()]) v.pop_back();
    v.push_back(i);
  }
  for (int i = (0); i < (q); i++) scanf("%d", &Q[i].first.first);
  for (int i = (0); i < (q); i++)
    scanf("%d", &Q[i].first.second), Q[i].second = i;
  for (int i = (1); i <= (n); i++) update[L[i]].push_back(i);
  sort(Q, Q + q);
  memset(bitsum, 0, sizeof(bitsum));
  memset(bitcnt, 0, sizeof(bitcnt));
  int x = q - 1;
  for (int i = (n); i >= (1); i--) {
    for (int j : update[i]) add(j, i);
    while (x >= 0 && Q[x].first.first == i) {
      int id = Q[x].second;
      int l = Q[x].first.first;
      int r = Q[x].first.second;
      int cnt = querycnt(l, r);
      long long sum = querysum(l, r);
      sum += 1ll * (r - l + 1 - cnt) * (l - 1);
      res[id] -= sum;
      x--;
    }
  }
  for (int i = (0); i <= (n); i++) update[i].clear();
  for (int i = (1); i <= (n); i++) update[R[i]].push_back(i);
  memset(bitsum, 0, sizeof(bitsum));
  memset(bitcnt, 0, sizeof(bitcnt));
  x = 0;
  for (int i = (0); i < (q); i++) swap(Q[i].first.first, Q[i].first.second);
  sort(Q, Q + q);
  for (int i = (0); i < (q); i++) swap(Q[i].first.first, Q[i].first.second);
  for (int i = (1); i <= (n); i++) {
    for (int j : update[i]) add(j, i);
    while (x < q && Q[x].first.second == i) {
      int id = Q[x].second;
      int l = Q[x].first.first;
      int r = Q[x].first.second;
      int cnt = querycnt(l, r);
      long long sum = querysum(l, r);
      sum += 1ll * (r - l + 1 - cnt) * (r + 1);
      res[id] += sum;
      res[id] -= (r - l + 1);
      x++;
    }
  }
  for (int i = (0); i < (q); i++) printf("%lld\n", res[i]);
  return 0;
}