Non-Cat-Rinks#11864

Non-Cat-Rinks

3 seconds
512 megabytes
Very hard

You are a well-known businessman in the world of magical agribusiness, owning a plantation of special vertices. Each vertex has a value h_i, which determines its magical level of resilience.

Clients approach you wanting to purchase a segment of vertices [l_i, r_i] to build a tree (a connected acyclic graph) on which non-cat-rinks will grow. The client can choose the structure of the tree arbitrarily—that is, connect the vertices from this segment with edges in any way to form a valid tree on all r_i - l_i + 1 vertices.

However, the tree can only be constructed under a certain condition: for each vertex from the chosen segment, the maximum length of a simple path passing through this vertex must equal h_v. The length of the path is defined as the number of edges in it.

If the value h_v does not meet the requirements, it can be decreased by one for a_v coins (but not below ). This reduction can be performed any number of times, each costing a_v coins.

For each client, determine the minimum number of coins required to construct a tree on the segment [l_i, r_i] that satisfies the described conditions.

Input

The first line contains two integers and (1 \le n,\,q \le 3 \cdot 10^5)—the number of vertices and the number of clients wishing to purchase vertices.

The second line contains integers h_1, h_2, \ldots, h_n (2 \le h_i \le 3 \cdot 10^5)—the values of the vertices.

The third line contains integers a_1, a_2, \ldots, a_n (0 \le a_i \le 10^6)—the number of coins required to decrease the value of a vertex by one.

The next lines contain two integers and (1 \le l,\ l+2 \le r \le n)—the boundaries of the segment that interests the client.

Output

For each query, you must output one number—the minimum number of coins needed to be able to form the tree.

Examples

Example 1

Loading
Loading

Note

For the first query, the optimal arrangement is a star graph with the central vertex and leaves , as shown below:

In this tree, the longest path passing through any vertex has a length of :

  • For the center : between leaves and — edges.

  • For any leaf: between and — edges.

Thus, we need all h_i=2, so the cost is calculated as follows:

  1. Vertex : 2 \rightarrow 2, so the cost is .

  2. Vertex : 3 \rightarrow 2, so the cost is .

  3. Vertex : 4 \rightarrow 2, so the cost is .

  4. Vertex : 5 \rightarrow 2, so the cost is .

As a result, the total cost is .

For the second query, the optimal arrangement is a linear graph.

The length of the path is , so each vertex must end up with h_i=2.

  1. Vertex : 2 \rightarrow 2, so the cost is .

  2. Vertex : 3 \rightarrow 2, so the cost is .

  3. Vertex : 4 \rightarrow 2, so the cost is .

As a result, the total cost is .

Scoring

  1. Subtask ( points) : (q=1, l=1, r=n)

  2. Subtask ( points) : (h_1 = h_2 = h_3 = ... = h_n)

  3. Subtask ( points) : (n \le 10^5,\ h_i = i+1)

  4. Subtask ( points) : (r-l=3)

  5. Subtask ( points) : (l=1)

  6. Subtask ( points) : (1 \le n, q \le 500)

  7. Subtask ( points) : (1 \le n, q \le 2000)

  8. Subtask ( points) : (1 \le n, q \le 2 \cdot 10^4)

  9. Subtask ( points) : (1 \le n, q \le 10^5)

  10. Subtask ( points) : Without additional constraints