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>
clock_t t = clock();
namespace my_std {
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
inline T rnd(T l, T r) {
  return uniform_int_distribution<T>(l, r)(rng);
}
template <typename T>
inline bool chkmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmin(T &x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline void read(T &t) {
  t = 0;
  char f = 0, ch = getchar();
  double d = 0.1;
  while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
  while (ch <= '9' && ch >= '0') t = t * 10 + ch - 48, ch = getchar();
  if (ch == '.') {
    ch = getchar();
    while (ch <= '9' && ch >= '0') t += d * (ch ^ 48), d *= 0.1, ch = getchar();
  }
  t = (f ? -t : t);
}
template <typename T, typename... Args>
inline void read(T &t, Args &...args) {
  read(t);
  read(args...);
}
char sr[1 << 21], z[20];
int C = -1, Z = 0;
inline void Ot() { fwrite(sr, 1, C + 1, stdout), C = -1; }
inline void print(register int x) {
  if (C > 1 << 20) Ot();
  if (x < 0) sr[++C] = '-', x = -x;
  while (z[++Z] = x % 10 + 48, x /= 10)
    ;
  while (sr[++C] = z[Z], --Z)
    ;
  sr[++C] = '\n';
}
void file() {}
inline void chktime() {}
long long ksm(long long x, int y) {
  long long ret = 1;
  for (; y; y >>= 1, x = x * x)
    if (y & 1) ret = ret * x;
  return ret;
}
}  // namespace my_std
using namespace my_std;
int n, m;
int a[1010010];
int L[1010010], R[1010010];
const int Tree = 1010010 << 2;
struct TREE {
  long long sum[Tree];
  int cnt[Tree];
  void insert(int k, int l, int r, long long x) {
    ++cnt[k];
    sum[k] += x;
    if (l == r) return;
    int mid = (l + r) >> 1;
    if (x <= mid)
      insert(k << 1, l, mid, x);
    else
      insert(k << 1 | 1, mid + 1, r, x);
  }
  pair<int, long long> query(int k, int l, int r, int x, int y) {
    if (x > r || y < l) return make_pair(0, 0);
    if (x <= l && r <= y) return make_pair(cnt[k], sum[k]);
    int mid = (l + r) >> 1;
    pair<int, long long> L = query(k << 1, l, mid, x, y),
                         R = query(k << 1 | 1, mid + 1, r, x, y);
    return make_pair(L.first + R.first, L.second + R.second);
  }
  pair<int, long long> query(int l, int r) { return query(1, 0, n + 1, l, r); }
} l, r;
int LL[1010010], RR[1010010];
int id[1010010];
inline bool cmp(const int &x, const int &y) { return a[x] < a[y]; }
void init() {
  for (int i = (1); i <= (n); i++) LL[i] = i - 1, RR[i] = i + 1, id[i] = i;
  RR[0] = 1;
  LL[n + 1] = n;
  sort(id + 1, id + n + 1, cmp);
  int x;
  for (int i = (1); i <= (n); i++)
    x = id[i], L[x] = LL[x], R[x] = RR[x], RR[LL[x]] = RR[x], LL[RR[x]] = LL[x];
}
int ql[1010010], qr[1010010];
long long Ans[1010010];
struct hh {
  int x, l, r, id, v;
} q[1010010 << 1];
inline bool cmpp(const hh &x, const hh &y) { return x.x < y.x; }
signed main() {
  file();
  read(n, m);
  for (int i = (1); i <= (n); i++) read(a[i]);
  init();
  int x, y;
  for (int i = (1); i <= (m); i++) read(ql[i]);
  for (int i = (1); i <= (m); i++) read(qr[i]);
  for (int i = (1); i <= (m); i++)
    q[i * 2 - 1] = (hh){ql[i] - 1, ql[i], qr[i], i, -1},
              q[i * 2] = (hh){qr[i], ql[i], qr[i], i, 1};
  sort(q + 1, q + m + m + 1, cmpp);
  int p = 1;
  while (!q[p].x) ++p;
  for (int i = (1); i <= (n); i++) {
    if (p > m * 2) break;
    l.insert(1, 0, n + 1, L[i] + 1), r.insert(1, 0, n + 1, R[i] - 1);
    while (p <= m * 2 && q[p].x == i) {
      x = q[p].l, y = q[p].r;
      long long ans = 0;
      pair<int, long long> a, b;
      a = r.query(y + 1, n + 1), b = r.query(0, y);
      ans += 1ll * y * a.first + b.second;
      a = l.query(0, x - 1), b = l.query(x, n + 1);
      ans -= 1ll * x * a.first + b.second;
      Ans[q[p].id] += 1ll * q[p].v * ans;
      ++p;
    }
  }
  for (int i = (1); i <= (m); i++)
    printf("%I64d ", Ans[i] + 1ll * (qr[i] - ql[i] + 1));
  return 0;
}