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 MOD = 998244353;
const int N = (int)1e6 + 15;
const int inf = 0x3f3f3f3f;
struct Node {
  int x;
  long long y;
  int idx, tag;
  bool operator<(const Node& b) const { return x != b.x ? x < b.x : y < b.y; }
};
Node dat[2][N];
Node tree[N];
pair<int, int> stk[N];
int pstk;
int a[N], l[N], r[N];
int lf[N], rf[N];
long long prefLf[N], prefRf[N];
long long ans[N];
inline int lowbit(int x) { return x & -x; }
inline Node query(int x) {
  Node ret = {0, 0, 0, 0};
  for (; x > 0; x -= lowbit(x)) {
    ret.x += tree[x].x;
    ret.y += tree[x].y;
  }
  return ret;
}
inline void update(int x, const Node& b) {
  for (; x < N; x += lowbit(x)) {
    tree[x].x += b.x;
    tree[x].y += b.y;
  }
}
void workLR(int n) {
  stk[++pstk] = make_pair(inf, 0);
  for (int i = 1; i <= n; i++) {
    while (a[i] > stk[pstk].first) {
      rf[stk[pstk--].second] = i;
    }
    stk[++pstk] = make_pair(a[i], i);
  }
  while (pstk > 1) {
    rf[stk[pstk--].second] = n + 1;
  }
  for (int i = n; i >= 1; i--) {
    while (a[i] > stk[pstk].first) {
      lf[stk[pstk--].second] = i;
    }
    stk[++pstk] = make_pair(a[i], i);
  }
  while (pstk > 1) {
    lf[stk[pstk--].second] = 0;
  }
}
void solveDat(int n, int q) {
  memset(dat, 0, sizeof(dat));
  memset(tree, 0, sizeof(tree));
  vector<Node> vec;
  for (int i = 1; i <= q; i++) {
    vec.emplace_back(Node{l[i] - 1, l[i], i, -1});
    vec.emplace_back(Node{r[i], l[i], i, 1});
  }
  sort(vec.begin(), vec.end());
  int it = 1;
  for (const Node& ele : vec) {
    while (it <= n && it <= ele.x) {
      update(lf[it] + 1, Node{1, lf[it] + 1, 0, 0});
      it++;
    }
    Node res = query(ele.y);
    dat[0][ele.idx].x += ele.tag * res.x;
    dat[0][ele.idx].y += ele.tag * res.y;
  }
  memset(tree, 0, sizeof(tree));
  vec.clear();
  for (int i = 1; i <= q; i++) {
    vec.emplace_back(Node{l[i] - 1, r[i], i, -1});
    vec.emplace_back(Node{r[i], r[i], i, 1});
  }
  sort(vec.begin(), vec.end());
  it = 1;
  for (const Node& ele : vec) {
    while (it <= n && it <= ele.x) {
      update(rf[it] - 1, Node{1, rf[it] - 1, 0, 0});
      it++;
    }
    Node res = query(ele.y);
    dat[1][ele.idx].x += ele.tag * res.x;
    dat[1][ele.idx].y += ele.tag * res.y;
  }
}
int main() {
  int n, q;
  while (~scanf("%d%d", &n, &q)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 1; i <= q; i++) {
      scanf("%d", &l[i]);
    }
    for (int i = 1; i <= q; i++) {
      scanf("%d", &r[i]);
    }
    workLR(n);
    for (int i = 1; i <= n; i++) {
      prefLf[i] = prefLf[i - 1] + lf[i];
      prefRf[i] = prefRf[i - 1] + rf[i];
    }
    solveDat(n, q);
    for (int i = 1; i <= q; i++) {
      int x = l[i], y = r[i], len = y - x + 1;
      pair<int, long long> t1 = make_pair(dat[0][i].x, dat[0][i].y);
      t1.first = len - t1.first;
      t1.second = prefLf[y] - prefLf[x - 1] + len - t1.second;
      ans[i] = (long long)len - t1.second - 1LL * (len - t1.first) * x;
    }
    for (int i = 1; i <= q; i++) {
      int x = l[i], y = r[i], len = y - x + 1;
      pair<int, long long> t1 = make_pair(dat[1][i].x, dat[1][i].y);
      ans[i] += (long long)t1.second + 1LL * (len - t1.first) * y;
    }
    for (int i = 1; i <= q; i++) {
      printf("%lld ", ans[i]);
    }
    puts("");
  }
}