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>
#pragma GCC optimize(2, 3, "Ofast")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
const double pi = 3.141592653589793238462643383279;
namespace MyMinMax {
template <typename T>
inline T mn(const T x, const T y) {
  return x < y ? x : y;
}
template <typename T>
inline T mx(const T x, const T y) {
  return x > y ? x : y;
}
template <typename T>
inline bool chmin(T &x, const T y) {
  return (x > y) && ((x = y), 1);
}
template <typename T>
inline bool chmax(T &x, const T y) {
  return (x < y) && ((x = y), 1);
}
template <typename T, typename... Args>
inline T mx(const T x, const Args... args) {
  return mx(x, mx(args...));
}
template <typename T, typename... Args>
inline T mn(const T x, const Args... args) {
  return mn(x, mn(args...));
}
}  // namespace MyMinMax
using namespace MyMinMax;
namespace IO {
const int DPAIRSIZ = 1 << 18;
char BB[DPAIRSIZ], *SS = BB, *TT = BB;
inline char getcha() {
  return SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
             ? EOF
             : *SS++;
}
template <typename T = int>
inline T read() {
  T x = 0;
  int fu = 1;
  char c = getcha();
  while (c > 57 || c < 48) {
    if (c == 45) fu = -1;
    c = getcha();
  }
  while (c <= 57 && c >= 48) {
    x = x * 10 + c - 48;
    c = getcha();
  }
  x *= fu;
  return x;
}
template <typename T>
inline void read(T &x) {
  x = 0;
  int fu = 1;
  char c = getcha();
  while (c > 57 || c < 48) {
    if (c == 45) fu = -1;
    c = getcha();
  }
  while (c <= 57 && c >= 48) {
    x = x * 10 + c - 48;
    c = getcha();
  }
  x *= fu;
}
template <typename T>
inline void read(T *bg, T *ed) {
  while (bg != ed) read(*bg++);
}
inline void read(char &ch) {
  ch = getcha();
  while (ch <= 32) ch = getcha();
}
inline void read(char *s) {
  char ch = getcha();
  while (ch <= 32) ch = getcha();
  while (ch > 32) *s++ = ch, ch = getcha();
  *s = '\0';
}
inline void sread(char *s) {
  char ch = getcha();
  while (ch < 32) ch = getcha();
  while (ch >= 32) *s++ = ch, ch = getcha();
  *s = '\0';
}
inline void pread(char *&s) {
  char ch = getcha();
  while (ch <= 32) ch = getcha();
  while (ch > 32) *s++ = ch, ch = getcha();
  *s = '\0';
}
inline void spread(char *&s) {
  char ch = getcha();
  while (ch < 32) ch = getcha();
  while (ch >= 32) *s++ = ch, ch = getcha();
  *s = '\0';
}
template <typename T, typename... Args>
inline void read(T &x, Args &...args) {
  read(x);
  read(args...);
}
char out[DPAIRSIZ], *Out = out;
inline void putcha(char x) {
  *Out++ = x;
  if (Out - out >= (DPAIRSIZ)) fwrite(out, 1, Out - out, stdout), Out = out;
}
template <typename T>
inline void fprint(T x) {
  if (x < 0) putcha(45), x = -x;
  if (x > 9) fprint(x / 10);
  putcha(x % 10 + 48);
}
inline void print() { putcha(10); }
template <typename T>
inline void print(T x) {
  fprint(x);
  putcha(10);
}
inline void print(char *ch) {
  while (*ch != '\0') putcha(*(ch++));
  putcha(10);
}
inline void put(char *ch) {
  while (*ch != '\0') putcha(*(ch++));
}
inline void print(const char *ch) {
  while (*ch != '\0') putcha(*(ch++));
  putcha(10);
}
inline void put(const char *ch) {
  while (*ch != '\0') putcha(*(ch++));
}
template <typename T, typename... Args>
inline void print(T x, Args... args) {
  fprint(x);
  putcha(32);
  print(args...);
}
template <typename... Args>
inline void print(const char *ch, Args... args) {
  while (*ch != '\0') putcha(*(ch++));
  putcha(32);
  print(args...);
}
template <typename... Args>
inline void print(char *ch, Args... args) {
  while (*ch != '\0') putcha(*(ch++));
  putcha(32);
  print(args...);
}
template <typename T, typename... Args>
inline void printl(T x, Args... args) {
  fprint(x);
  putcha(10);
  printl(args...);
}
template <typename... Args>
inline void printl(const char *ch, Args... args) {
  while (*ch != '\0') putcha(*(ch++));
  putcha(10);
  printl(args...);
}
template <typename... Args>
inline void printl(char *ch, Args... args) {
  while (*ch != '\0') putcha(*(ch++));
  putcha(10);
  printl(args...);
}
template <typename T>
inline void sprint(T x) {
  fprint(x);
  putcha(32);
}
template <typename T, typename... Args>
inline void sprint(T x, Args... args) {
  fprint(x);
  putcha(32);
  sprint(args...);
}
template <typename T>
inline void sprint(T *bg, T *ed) {
  while (bg != ed) sprint(*bg++);
}
template <typename T>
inline void print(T *bg, T *ed) {
  while (bg != ed) sprint(*bg++);
  putcha(10);
}
template <typename T>
inline void printl(T *bg, T *ed) {
  while (bg != ed) print(*bg++);
}
class AutoFlush {
 public:
  ~AutoFlush() { fwrite(out, 1, Out - out, stdout); }
} __AutoFlush;
}  // namespace IO
using namespace IO;
const int INF = 0x3f3f3f3f;
const long long INFll = 0x3f3f3f3f3f3f3f3fll;
const int MAXN = 1e6 + 5;
int n, m, a[MAXN];
struct Quest {
  int l, r, id;
  Quest(int l = 0, int r = 0) : l(l), r(r) {}
} q[MAXN];
int L[MAXN], R[MAXN], stk[MAXN], tp;
long long ans[MAXN];
template <typename T>
struct BIT {
  T c[MAXN];
  inline void clear() { memset(c, 0, sizeof(c)); }
  inline int lowbit(int x) { return x & -x; }
  inline void add(int x, int y) {
    for (; x <= n; x += lowbit(x)) c[x] += y;
  }
  inline void add(int x) {
    for (; x <= n; x += lowbit(x)) ++c[x];
  }
  inline void del(int x) {
    for (; x <= n; x += lowbit(x)) --c[x];
  }
  inline T ask(int x) {
    T ret = 0;
    for (; x; x ^= lowbit(x)) ret += c[x];
    return ret;
  }
};
BIT<long long> t1;
BIT<int> t2;
struct NODE {
  int x, y;
  NODE(int x = 0, int y = 0) : x(x), y(y) {}
} p[MAXN];
signed main() {
  read(n, m);
  read(a + 1, a + n + 1);
  for (int i = (1); i <= (m); ++i) read(q[i].l);
  for (int i = (1); i <= (m); ++i) read(q[i].r);
  for (int i = (1); i <= (m); ++i) q[i].id = i, ans[i] = q[i].r - q[i].l + 1;
  a[0] = INF;
  for (int i = (1); i <= (n); ++i) {
    while (a[stk[tp]] < a[i]) R[stk[tp--]] = i;
    L[i] = stk[tp];
    stk[++tp] = i;
  }
  while (tp) R[stk[tp--]] = n + 1;
  for (int i = (1); i <= (n); ++i) --R[i], ++L[i];
  for (int i = (1); i <= (n); ++i) p[i] = NODE(i, R[i]);
  std ::sort(q + 1, q + m + 1,
             [](const Quest &x, const Quest &y) { return x.r < y.r; });
  std ::sort(p + 1, p + n + 1,
             [](const NODE &x, const NODE &y) { return x.y < y.y; });
  int it = 1, itt = 1;
  for (int i = (1); i <= (n); ++i) {
    while (it <= n && p[it].y == i) {
      const int I = p[it++].x;
      t2.del(I);
      t1.add(I, R[I]);
    }
    t2.add(i);
    while (itt <= m && q[itt].r == i) {
      ans[q[itt].id] += t1.ask(q[itt].r) - t1.ask(q[itt].l - 1) +
                        1ll * (t2.ask(q[itt].r) - t2.ask(q[itt].l - 1)) * i;
      ++itt;
    }
    if (itt > m) break;
  }
  t1.clear();
  t2.clear();
  for (int i = (1); i <= (n); ++i) p[i] = NODE(i, L[i]);
  std ::sort(q + 1, q + m + 1,
             [](const Quest &x, const Quest &y) { return x.l > y.l; });
  std ::sort(p + 1, p + n + 1,
             [](const NODE &x, const NODE &y) { return x.y > y.y; });
  it = 1, itt = 1;
  for (int i = (n); i >= (1); --i) {
    while (it <= n && p[it].y == i) {
      const int I = p[it++].x;
      t2.del(I);
      t1.add(I, L[I]);
    }
    t2.add(i);
    while (itt <= m && q[itt].l == i) {
      ans[q[itt].id] -= t1.ask(q[itt].r) - t1.ask(q[itt].l - 1) +
                        1ll * (t2.ask(q[itt].r) - t2.ask(q[itt].l - 1)) * i;
      ++itt;
    }
    if (itt > m) break;
  }
  print(ans + 1, ans + m + 1);
}