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>
int inp() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int sum = 0;
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum;
}
struct Node {
  int l;
  int r;
} s[1000010];
int stack[1000010];
int rb[1000010];
int lb[1000010];
struct Node2 {
  int id;
  int pos;
};
std::vector<Node2> vec_l[1000010], vec_r[1000010];
long long ans[1000010];
struct SEG_Tree {
  struct SEG {
    int l;
    int r;
    long long sum;
    long long lazy;
  } t[4000010];
  inline void push_up(int cur) {
    t[cur].sum = t[((cur) << 1)].sum + t[((cur) << 1 | 1)].sum;
  }
  inline void push_down(int cur) {
    t[((cur) << 1)].sum +=
        (t[((cur) << 1)].r - t[((cur) << 1)].l + 1) * t[cur].lazy;
    t[((cur) << 1 | 1)].sum +=
        (t[((cur) << 1 | 1)].r - t[((cur) << 1 | 1)].l + 1) * t[cur].lazy;
    t[((cur) << 1)].lazy += t[cur].lazy;
    t[((cur) << 1 | 1)].lazy += t[cur].lazy;
    t[cur].lazy = 0;
  }
  void build(int cur, int l, int r) {
    t[cur].l = l;
    t[cur].r = r;
    t[cur].sum = 0;
    t[cur].lazy = 0;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(((cur) << 1), l, mid);
    build(((cur) << 1 | 1), mid + 1, r);
  }
  void modify(int cur, int l, int r, int c) {
    if (t[cur].l > r || t[cur].r < l) return;
    if (t[cur].l >= l && t[cur].r <= r) {
      t[cur].lazy += c;
      t[cur].sum += (t[cur].r - t[cur].l + 1) * c;
      return;
    }
    push_down(cur);
    modify(((cur) << 1), l, r, c);
    modify(((cur) << 1 | 1), l, r, c);
    push_up(cur);
    return;
  }
  long long query(int cur, int l, int r) {
    if (t[cur].l > r || t[cur].r < l) return 0;
    if (t[cur].l >= l && t[cur].r <= r) return t[cur].sum;
    push_down(cur);
    return query(((cur) << 1), l, r) + query(((cur) << 1 | 1), l, r);
  }
} t;
int a[1000010];
int main() {
  int n = inp();
  int m = inp();
  for (int i = 1; i <= n; i++) a[i] = inp();
  for (int i = 1; i <= m; i++) s[i].l = inp();
  for (int i = 1; i <= m; i++) s[i].r = inp();
  for (int i = 1; i <= m; i++) {
    vec_l[s[i].r].push_back((Node2){i, s[i].l});
    vec_r[s[i].l].push_back((Node2){i, s[i].r});
  }
  int top = 0;
  stack[0] = n + 1;
  a[n + 1] = 2147483647;
  t.build(1, 1, n);
  for (int i = n; i >= 1; i--) {
    while (a[stack[top]] < a[i]) top--;
    rb[i] = stack[top];
    stack[++top] = i;
  }
  for (int i = n; i >= 1; i--) {
    t.modify(1, i + 1, rb[i] - 1, 1);
    for (int j = 0; j < vec_r[i].size(); j++)
      ans[vec_r[i][j].id] += t.query(1, i, vec_r[i][j].pos);
  }
  top = 0;
  stack[0] = 0;
  a[0] = 2147483647;
  t.build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    while (a[stack[top]] < a[i]) top--;
    lb[i] = stack[top];
    stack[++top] = i;
  }
  for (int i = 1; i <= n; i++) {
    t.modify(1, lb[i] + 1, i, 1);
    for (int j = 0; j < vec_l[i].size(); j++)
      ans[vec_l[i][j].id] += t.query(1, vec_l[i][j].pos, i);
  }
  for (int i = 1; i <= m; i++) std::cout << ans[i] << ' ';
  putchar('\n');
}