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 inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long _INF = 0xc0c0c0c0c0c0c0c0;
const long long mod = (int)1e9 + 7;
const int N = 1e6 + 100;
int n, Q;
int a[N], vis[N], ll[N], rr[N];
pair<int, int> p[N], q[N];
vector<int> ql[N], qr[N], ar[N], al[N];
int FL(int x) {
  if (x == ll[x]) return x;
  return ll[x] = FL(ll[x]);
}
int FR(int x) {
  if (x == rr[x]) return x;
  return rr[x] = FR(rr[x]);
}
long long ans[N];
struct Node {
  long long bit[N];
  void add(int x, int v) {
    while (x <= n) {
      bit[x] += v;
      x += x & (-x);
    }
  }
  long long Query(int x) {
    long long ret = 0;
    while (x > 0) {
      ret += bit[x];
      x -= x & (-x);
    }
    return ret;
  }
  void init() { memset(bit, 0, sizeof(bit)); }
} tr[2];
void Ac() {
  rr[n + 1] = n + 1;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    ll[i] = rr[i] = i;
    p[i].first = a[i];
    p[i].second = i;
  }
  sort(p + 1, p + 1 + n);
  for (int i = 1; i <= n; ++i) {
    int id = p[i].second;
    vis[id] = 1;
    ll[id] = FL(id - 1);
    rr[id] = FR(id + 1);
    al[ll[id] + 1].push_back(id);
    ar[rr[id] - 1].push_back(id);
  }
  for (int i = 1; i <= Q; ++i) {
    scanf("%d", &q[i].first);
    ql[q[i].first].push_back(i);
  }
  for (int i = 1; i <= Q; ++i) {
    scanf("%d", &q[i].second);
    qr[q[i].second].push_back(i);
  }
  tr[0].init();
  tr[1].init();
  for (int i = 1; i <= n; ++i) {
    for (int x : ar[i]) {
      tr[0].add(x, i);
      tr[1].add(x, 1);
    }
    for (int qid : qr[i]) {
      int l = q[qid].first, r = q[qid].second;
      ans[qid] += tr[0].Query(i) - tr[0].Query(l - 1);
      int num = r - l + 1 - (tr[1].Query(r) - tr[1].Query(l - 1));
      ans[qid] += 1ll * num * r + (r - l + 1);
    }
  }
  tr[0].init();
  tr[1].init();
  for (int i = n; i >= 1; --i) {
    for (int x : al[i]) {
      tr[0].add(x, i);
      tr[1].add(x, 1);
    }
    for (int qid : ql[i]) {
      int l = q[qid].first, r = q[qid].second;
      ans[qid] -= tr[0].Query(r);
      int num = r - l + 1 - tr[1].Query(r);
      ans[qid] -= 1ll * num * l;
    }
  }
  for (int i = 1; i <= Q; ++i) {
    printf("%I64d ", ans[i]);
  }
  puts("");
}
int main() {
  while (~scanf("%d%d", &n, &Q)) {
    Ac();
  }
  return 0;
}