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.
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.
For each query, you must output one number—the minimum number of coins needed to be able to form the tree.
Example 1
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:
Vertex : 2 \rightarrow 2, so the cost is .
Vertex : 3 \rightarrow 2, so the cost is .
Vertex : 4 \rightarrow 2, so the cost is .
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.
Vertex : 2 \rightarrow 2, so the cost is .
Vertex : 3 \rightarrow 2, so the cost is .
Vertex : 4 \rightarrow 2, so the cost is .
As a result, the total cost is .
Subtask ( points) : (q=1, l=1, r=n)
Subtask ( points) : (h_1 = h_2 = h_3 = ... = h_n)
Subtask ( points) : (n \le 10^5,\ h_i = i+1)
Subtask ( points) : (r-l=3)
Subtask ( points) : (l=1)
Subtask ( points) : (1 \le n, q \le 500)
Subtask ( points) : (1 \le n, q \le 2000)
Subtask ( points) : (1 \le n, q \le 2 \cdot 10^4)
Subtask ( points) : (1 \le n, q \le 10^5)
Subtask ( points) : Without additional constraints