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 = 1 << 20;
long long sum[n * 2], lazy[n * 2];
void reset() {
  fill_n(sum, n * 2, 0);
  fill_n(lazy, n * 2, 0);
}
inline void prop(int i, int w) {
  if (lazy[i]) {
    sum[i] += lazy[i] * w;
    if (i < n) {
      lazy[i * 2] += lazy[i];
      lazy[i * 2 + 1] += lazy[i];
    }
    lazy[i] = 0;
  }
}
long long querySum(int a, int b, int l = 0, int r = n, int i = 1) {
  if (a >= r || b <= l) return 0;
  prop(i, r - l);
  if (a <= l && b >= r) return sum[i];
  int m = l + r >> 1;
  return querySum(a, b, l, m, i * 2) + querySum(a, b, m, r, i * 2 + 1);
}
void add(int a, int b, int v, int l = 0, int r = n, int i = 1) {
  prop(i, r - l);
  if (a >= r || b <= l) return;
  if (a <= l && b >= r) {
    lazy[i] += v;
    prop(i, r - l);
    return;
  }
  int m = l + r >> 1;
  add(a, b, v, l, m, i * 2);
  add(a, b, v, m, r, i * 2 + 1);
  sum[i] = sum[i * 2] + sum[i * 2 + 1];
}
struct Query {
  int l, i;
};
vector<Query> query[1000001];
int p[1000000];
long long ans[1000000];
int tleft[1000000], tright[1000000];
void solve(vector<pair<int, int>> query0, int n, int q) {
  reset();
  for (int i = 0; i <= n; i++) query[i].clear();
  for (int i = 0; i < q; i++)
    query[query0[i].second].push_back({query0[i].first - 1, i});
  for (int i = n - 1; i >= 0; i--) {
    tright[i] = i + 1;
    while (tright[i] < n && p[tright[i]] < p[i]) tright[i] = tright[tright[i]];
  }
  for (int i = 0; i < n; i++) {
    tleft[i] = i - 1;
    while (tleft[i] > -1 && p[tleft[i]] < p[i]) tleft[i] = tleft[tleft[i]];
  }
  for (int i = 0; i <= n; i++) {
    for (Query q : query[i]) ans[q.i] += querySum(q.l, i);
    if (i < n) {
      add(tleft[i] + 1, i, 1);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) cin >> p[i];
  vector<pair<int, int>> query0(q);
  for (auto& p : query0) cin >> p.first;
  for (auto& p : query0) cin >> p.second;
  for (int i = 0; i < q; i++) ans[i] = query0[i].second + 1 - query0[i].first;
  solve(query0, n, q);
  reverse(p, p + n);
  for (int i = 0; i < q; i++) {
    query0[i].first = n + 1 - query0[i].first;
    query0[i].second = n + 1 - query0[i].second;
    swap(query0[i].first, query0[i].second);
  }
  solve(query0, n, q);
  for (int i = 0; i < q; i++) cout << ans[i] << ' ';
  cout << endl;
}