QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 256 MB 總分: 100

#7826. Roller Coaster

统计

Developers of a new amusement park want to build a roller coaster. They believe that people get more enjoyment from the ride if there is a larger height difference between adjacent sections. However, the supply team has already purchased $N$ supports, whose heights are known. Help the park developers arrange the supports in a line in such an order that the sum of the height differences between all adjacent supports is maximized (the height difference is defined as the absolute difference between the heights of two adjacent supports).

Input

The first line contains a single integer $N$, $2 \leqslant N \leqslant 10^5$, the number of supports. The next line contains $N$ non-negative integers separated by spaces, each not exceeding $10^8$, representing the heights of the purchased supports.

Output

A single non-negative integer — the maximum possible sum of height differences.

Examples

Input 1

4
10 20 1 1000

Output 1

2008

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.