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;
struct seg {
  int l, r, id;
};
bool operator<(const seg &x, const seg &y) { return x.r < y.r; }
struct SegTreeMax {
  int n;
  vector<int> st;
  void init(int m) {
    n = m;
    st.resize(4 * n + 1, -1);
  }
  int get_tree(int node, int l, int r, int u, int v) {
    if (v < l || r < u) return -1;
    if (u <= l && r <= v) return st[node];
    int mid = (l + r) >> 1;
    return max(get_tree(node << 1, l, mid, u, v),
               get_tree(node << 1 | 1, mid + 1, r, u, v));
  }
  void update(int node, int l, int r, int pos, int val) {
    if (l == r) {
      st[node] = val;
      return;
    }
    int mid = (l + r) >> 1;
    if (pos > mid)
      update(node << 1 | 1, mid + 1, r, pos, val);
    else
      update(node << 1, l, mid, pos, val);
    st[node] = max(st[node << 1], st[node << 1 | 1]);
  }
};
struct SegTreeSum {
  int n;
  vector<long long> st;
  vector<int> lazy;
  void init(int m) {
    n = m;
    st.resize(4 * n + 1, 0);
    lazy.resize(4 * n + 1, 0);
  }
  void push(int node, int l, int r) {
    int mid = (r + l) >> 1;
    st[node << 1] += 1ll * lazy[node] * (mid - l + 1);
    lazy[node << 1] += lazy[node];
    st[node << 1 | 1] += 1ll * lazy[node] * (r - mid);
    lazy[node << 1 | 1] += lazy[node];
    lazy[node] = 0;
  }
  void update(int node, int l, int r, int u, int v) {
    if (v < l || r < u) return;
    if (u <= l && r <= v) {
      st[node] += (r - l + 1);
      lazy[node] += 1;
      return;
    }
    push(node, l, r);
    int mid = (l + r) >> 1;
    update(node << 1, l, mid, u, v);
    update(node << 1 | 1, mid + 1, r, u, v);
    st[node] = st[node << 1 | 1] + st[node << 1];
  }
  long long get(int node, int l, int r, int u, int v) {
    if (v < l || r < u) return 0;
    if (u <= l && r <= v) return st[node];
    push(node, l, r);
    int mid = (l + r) >> 1;
    return get(node << 1, l, mid, u, v) + get(node << 1 | 1, mid + 1, r, u, v);
  }
};
void cal(vector<int> &a, vector<seg> &s, vector<long long> &ans, int q, int n) {
  sort(s.begin(), s.end());
  SegTreeMax pos;
  SegTreeSum sum;
  pos.init(n);
  sum.init(n);
  int last = 1;
  for (int i = 0; i < q; ++i) {
    for (int j = last; j <= s[i].r; ++j) {
      int r = last - 1, l = 0;
      l = max(l, pos.get_tree(1, 1, n, a[j], n));
      ++l;
      sum.update(1, 1, n, l, r);
      pos.update(1, 1, n, a[j], j);
      last = j + 1;
    }
    ans[s[i].id] += sum.get(1, 1, n, s[i].l, s[i].r);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n >> q;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  vector<seg> s(q);
  for (int i = 0; i < q; ++i) cin >> s[i].l;
  for (int i = 0; i < q; ++i) cin >> s[i].r;
  for (int i = 0; i < q; ++i) s[i].id = i;
  vector<long long> ans(q, 0);
  for (int i = 0; i < q; ++i) ans[i] = s[i].r - s[i].l + 1;
  cal(a, s, ans, q, n);
  for (int i = 0; i < q; ++i) {
    s[i].r = n - s[i].r + 1;
    s[i].l = n - s[i].l + 1;
    swap(s[i].l, s[i].r);
  }
  reverse(a.begin() + 1, a.end());
  cal(a, s, ans, q, n);
  for (int i = 0; i < q; ++i) cout << ans[i] << " ";
  return 0;
}