Universal Cup Judging System

Universal Cup

시간 제한: 7.0 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓
통계

You are given a sequence of integers $x_1, x_2, \ldots, x_n$. Consider the weighted undirected graph $G$ on $n$ vertices, numbered $1$ through $n$, that contains, for every pair of vertices $u$ and $v$ with $u < v$, the edge $\{u, v\}$ of weight $x_v - x_u$.

Note that $x$ is not necessarily sorted, so edge weights may be negative.

For a pair $(\ell, r)$ with $\ell \le r$, let $G[\ell, r]$ denote the subgraph of $G$ induced by the vertices $\ell, \ell + 1, \ldots, r$; that is, the graph on those vertices keeping exactly the edges of $G$ with both endpoints in that range. Define $f(\ell, r)$ as the minimum possible total weight of a spanning tree of $G[\ell, r]$. In particular, $f(\ell, \ell) = 0$.

You are given $q$ pairs $(\ell, r)$. Compute $f(\ell, r)$ for each of them.

Input

The first line contains two integers $n$ and $q$ ($1 \le n, q \le 2 \cdot 10^5$): the length of the sequence and the number of queries.

The second line contains $n$ integers $x_1, x_2, \ldots, x_n$ ($-10^9 \le x_i \le 10^9$).

Each of the next $q$ lines contains two integers $\ell$ and $r$ ($1 \le \ell \le r \le n$) describing one query.

Output

Print $q$ lines. The $i$-th line must contain a single integer: the answer to the $i$-th query.

Examples

Input 1

3 4
0 10 0
1 3
1 2
2 3
2 2

Output 1

-10
10
-10
0

Note

For the first query, the three edge weights are $10$, $0$, and $-10$. Choosing the edges of weights $0$ and $-10$ gives a spanning tree of total weight $-10$.

The second and third queries contain two vertices, so their answers are the weights of their only edges: $10$ and $-10$, respectively. The final query contains one vertex and therefore has answer $0$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.