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>
namespace IO {
const int maxn(1 << 21 | 1);
char ibuf[maxn], *iS, *iT, obuf[maxn], *oS = obuf, *oT = obuf + maxn - 1, _c,
                                       _st[55];
int _f, tp;
char Getc() {
  return (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin),
                      (iS == iT ? EOF : *iS++))
                   : *iS++);
}
void Flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
void Putc(char x) {
  *oS++ = x;
  if (oS == oT) Flush();
}
template <class Int>
void Input(Int &x) {
  for (_f = 0, _c = Getc(); _c < '0' || _c > '9'; _c = Getc()) _f = _c == '-';
  for (x = 0; _c <= '9' && _c >= '0'; _c = Getc())
    x = (x << 3) + (x << 1) + (_c ^ 48);
  if (_f) x = -x;
}
template <class Int>
void Print(Int x) {
  if (!x) Putc('0');
  if (x < 0) Putc('-'), x = -x;
  while (x) _st[++tp] = x % 10 + '0', x /= 10;
  while (tp) Putc(_st[tp--]);
}
}  // namespace IO
using namespace IO;
using namespace std;
const int _ = 1e6 + 5;
int a[_], b[_], n, m;
long long ans[_], sum[_ << 2], F[_ << 2], G[_ << 2], H[_ << 2];
vector<int> vec[_];
void pushdown(int no, int l, int r) {
  if (F[no]) {
    sum[no] += 1ll * F[no] * G[no];
    if (l != r) F[no << 1] += F[no], F[no << 1 | 1] += F[no];
    F[no] = 0;
  }
  if (H[no]) {
    sum[no] += 1ll * H[no] * (r - l + 1);
    if (l != r) H[no << 1] += H[no], H[no << 1 | 1] += H[no];
    H[no] = 0;
  }
}
void update(int no, int l, int r, int k, int x) {
  pushdown(no, l, r);
  G[no] += x;
  if (l == r) return;
  if (k <= ((l + r) >> 1))
    update(no << 1, l, ((l + r) >> 1), k, x),
        pushdown(no << 1 | 1, ((l + r) >> 1) + 1, r);
  else
    update(no << 1 | 1, ((l + r) >> 1) + 1, r, k, x),
        pushdown(no << 1, l, ((l + r) >> 1));
  sum[no] = sum[no << 1] + sum[no << 1 | 1];
}
void modify(int no, int l, int r, int L, int R) {
  pushdown(no, l, r);
  if (l > R || r < L) return;
  if (l >= L && r <= R) return ++H[no], pushdown(no, l, r);
  modify(no << 1, l, ((l + r) >> 1), L, R);
  modify(no << 1 | 1, ((l + r) >> 1) + 1, r, L, R);
  sum[no] = sum[no << 1] + sum[no << 1 | 1];
}
void query(int no, int l, int r, int k, long long &x) {
  pushdown(no, l, r);
  if (l == r) return x += sum[no], void();
  if (k <= ((l + r) >> 1))
    query(no << 1, l, ((l + r) >> 1), k, x),
        pushdown(no << 1 | 1, ((l + r) >> 1) + 1, r), x += sum[no << 1 | 1];
  else
    query(no << 1 | 1, ((l + r) >> 1) + 1, r, k, x),
        pushdown(no << 1, l, ((l + r) >> 1));
  sum[no] = sum[no << 1] + sum[no << 1 | 1];
}
int main() {
  Input(n);
  Input(m);
  stack<int> s;
  for (int i = 1; i <= n; ++i) Input(a[i]);
  for (int i = 1; i <= m; ++i) Input(b[i]);
  for (int i = 1, x; i <= m; ++i) Input(x), vec[x].push_back(i);
  s.push(0);
  a[0] = 1e9;
  for (int i = 1; i <= n; ++i) {
    while (a[s.top()] < a[i]) update(1, 1, n, s.top(), -1), s.pop();
    modify(1, 1, n, s.top() + 1, i);
    ++F[1];
    s.push(i);
    update(1, 1, n, i, 1);
    for (int j : vec[i]) query(1, 1, n, b[j], ans[j]);
  }
  for (int i = 1; i <= m; ++i) Print(ans[i]), Putc(' ');
  Putc('\n');
  return Flush(), 0;
}