You want to give Lucy a bouquet of flowers for TimDee, and you have flowers, where the beauty of the -th flower is a_i.
A bouquet can be any contiguous subsequence of the flowers. Let \operatorname{beauty}(l, r) denote the beauty of the subsequence from to .
function beauty(l, r):
if l == r:
return a[l]
// choose any m such that l ≤ m < r
return beauty(l, m) - beauty(m + 1, r)You are given queries, where each query consists of two integers and . For each query, output the maximum possible value of \operatorname{beauty}(l, r).
The first line contains two integers (1 \le n \le 5 \cdot 10^5) and (1 \le q \le 5 \cdot 10^5) — the length of array and the number of queries.
The second line contains integers a_i (-10^9 \le a_i \le 10^9) — the elements of the array .
Each of the next lines contains two integers l_i, r_i (1 \le l \le r \le n) — the parameters of the -th query.
Output lines, each containing exactly one integer — the answer to the corresponding query.
Example 1
Example 2
In the first example, for the first query we can use the following strategy:
For the second query:
It can be shown that this is the best answer for each query.
( points): n, q \le 10;\ a_i \le 100 for all 1 \le i \le n;
( points): r_i - l_i \le 3 for all 1 \le i \le q;
( points): r_i - l_i \le 4 for all 1 \le i \le q;
( points): r_i - l_i \le 5 for all 1 \le i \le q;
( points): n, q \le 500;
( points): n, q \le 500000;