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. 
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long mod = 998244353;
const int MXN = 1e6 + 7;
int n, q;
int ar[MXN], ls[MXN], rs[MXN];
int stk[MXN];
long long ans[MXN];
std::vector<int> vs[MXN];
struct FenwickTree {
  long long BIT[MXN], N;
  void init(int n) {
    N = n + 3;
    for (int i = 0; i <= n + 3; ++i) BIT[i] = 0;
  }
  int lowbit(int x) { return x & (-x); }
  void add(int x, int val) {
    for (; x <= N; x += lowbit(x)) BIT[x] += val;
  }
  long long query(int x) {
    long long ans = 0;
    for (; x; x -= lowbit(x)) ans += BIT[x];
    return ans;
  }
} bit1, bit2;
void go() {
  for (int i = 1; i <= q; ++i) vs[ls[i]].emplace_back(i);
  int top = 0;
  bit1.init(n), bit2.init(n);
  for (int i = n, j; i >= 1; --i) {
    while (top && ar[stk[top]] < ar[i]) --top;
    j = n + 1;
    if (top) j = stk[top];
    stk[++top] = i;
    bit1.add(j, j - i);
    bit1.add(i, -i + 1);
    bit1.add(j, i - 1);
    bit2.add(i, 1);
    bit2.add(j, -1);
    for (auto id : vs[i])
      ans[id] += (bit1.query(rs[id]) + rs[id] * bit2.query(rs[id]));
  }
}
int main(int argc, char const *argv[]) {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; ++i) scanf("%d", &ar[i]);
  for (int i = 1; i <= q; ++i) scanf("%d", &ls[i]);
  for (int i = 1; i <= q; ++i) scanf("%d", &rs[i]);
  go();
  for (int i = 1; i <= n; ++i) vs[i].clear();
  reverse(ar + 1, ar + n + 1);
  for (int i = 1; i <= q; ++i) ls[i] = n + 1 - ls[i], rs[i] = n + 1 - rs[i];
  for (int i = 1; i <= q; ++i) swap(ls[i], rs[i]);
  go();
  for (int i = 1; i <= q; ++i)
    printf("%lld%c", ans[i] - (rs[i] - ls[i] + 1), i == q ? '\n' : ' ');
  return 0;
}
