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, Q;
int P[1010101];
int L[1010101], R[1010101];
int Lma[1010101], Rma[1010101];
vector<int> delL[1010101], delR[1010101];
vector<int> QL[1010101], QR[1010101];
template <class V, int NV>
class SegTree_1 {
 public:
  vector<V> val;
  static V const def = 0;
  V comp(V l, V r) { return max(l, r); };
  SegTree_1() { val = vector<V>(NV * 2, def); };
  V getval(int x, int y, int l = 0, int r = NV, int k = 1) {
    if (r <= x || y <= l) return def;
    if (x <= l && r <= y) return val[k];
    return comp(getval(x, y, l, (l + r) / 2, k * 2),
                getval(x, y, (l + r) / 2, r, k * 2 + 1));
  }
  void update(int entry, V v) {
    entry += NV;
    val[entry] = comp(v, val[entry]);
    while (entry > 1)
      entry >>= 1, val[entry] = comp(val[entry * 2], val[entry * 2 + 1]);
  }
};
SegTree_1<int, 1 << 20> st;
template <class V, int ME>
class BIT {
 public:
  V bit[1 << ME];
  V operator()(int e) {
    if (e < 0) return 0;
    V s = 0;
    e++;
    while (e) s += bit[e - 1], e -= e & -e;
    return s;
  }
  void add(int e, V v) {
    e++;
    while (e <= 1 << ME) bit[e - 1] += v, e += e & -e;
  }
};
BIT<signed long long, 20> sum, mu;
signed long long ret[1010101];
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  scanf("%d%d", &N, &Q);
  for (i = 1; i <= N; i++) {
    scanf("%d", &P[i]);
    Lma[i] = st.getval(P[i], N + 1);
    delL[Lma[i]].push_back(i);
    st.update(P[i], i);
    sum.add(i, i - Lma[i]);
  }
  for (i = 0; i < (st.val.size()); i++) st.val[i] = 0;
  for (i = N; i >= 1; i--) {
    Rma[i] = N + 1 - st.getval(P[i], N + 1);
    delR[Rma[i]].push_back(i);
    st.update(P[i], N + 1 - i);
  }
  for (i = 0; i < (Q); i++) {
    scanf("%d", &L[i]);
    QL[L[i]].push_back(i);
  }
  for (i = 0; i < (Q); i++) {
    scanf("%d", &R[i]);
    QR[R[i]].push_back(i);
  }
  for (i = 0; i < (N + 1); i++) {
    for (auto& q : QL[i])
      ret[q] += (sum(R[q]) - sum(L[q] - 1)) - i * (mu(R[q]) - mu(L[q] - 1));
    for (auto& x : delL[i]) {
      sum.add(x, -(sum(x) - sum(x - 1)));
      sum.add(x, x + 1);
      mu.add(x, 1);
    }
  }
  memset(mu.bit, 0, sizeof(mu.bit));
  memset(sum.bit, 0, sizeof(sum.bit));
  for (i = 1; i <= N; i++) {
    sum.add(i, Rma[i] - i - 1);
  }
  for (i = N + 1; i >= 1; i--) {
    for (auto& q : QR[i])
      ret[q] += (sum(R[q]) - sum(L[q] - 1)) + i * (mu(R[q]) - mu(L[q] - 1));
    for (auto& x : delR[i]) {
      sum.add(x, -(sum(x) - sum(x - 1)));
      sum.add(x, -x);
      mu.add(x, 1);
    }
  }
  for (i = 0; i < (Q); i++) cout << ret[i] << " ";
  cout << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}