Codeforces Round 201 (Div. 2)
A
Difference Row
Codeforces
1300
原题
←B →
翻译中…

You want to arrange $*n*$ integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.

翻译中…

More formally, let's denote some arrangement as a sequence of integers $*x*_{1}, *x*_{2}, ..., *x*_{*n*}$, where sequence $*x*$ is a permutation of sequence $*a*$. The value of such an arrangement is $(*x*_{1} - *x*_{2}) + (*x*_{2} - *x*_{3}) + ... + (*x*_{*n* - 1} - *x*_{*n*})$.

翻译中…

Find the largest possible value of an arrangement. Then, output the lexicographically smallest sequence $*x*$ that corresponds to an arrangement of the largest possible value.

翻译中…

Input

翻译中…

The first line of the input contains integer $*n*$ ($2 ≤ *n* ≤ 100$). The second line contains $*n*$ space-separated integers $*a*_{1}$, $*a*_{2}$, $...$, $*a*_{*n*}$ ($|*a*_{*i*}| ≤ 1000$).

翻译中…

Output

翻译中…

Print the required sequence $*x*_{1}, *x*_{2}, ..., *x*_{*n*}$. Sequence $*x*$ should be the lexicographically smallest permutation of $*a*$ that corresponds to an arrangement of the largest possible value.

翻译中…

Note

翻译中…

In the sample test case, the value of the output arrangement is $(100 - ( - 50)) + (( - 50) - 0) + (0 - 50) + (50 - ( - 100)) = 200$. No other arrangement has a larger value, and among all arrangements with the value of $200$, the output arrangement is the lexicographically smallest one.

翻译中…

Sequence $*x*_{1}, *x*_{2}, ... , *x*_{*p*}$ is lexicographically smaller than sequence $*y*_{1}, *y*_{2}, ... , *y*_{*p*}$ if there exists an integer $*r*$ $(0 ≤ *r* < *p*)$ such that $*x*_{1} = *y*_{1}, *x*_{2} = *y*_{2}, ... , *x*_{*r*} = *y*_{*r*}$ and $*x*_{*r* + 1} < *y*_{*r* + 1}$.

翻译中…

样例

Input #1
5
100 -100 50 0 -50
Output #1
100 -50 0 50 -100
InputCopy OutputCopy
题目信息
题号
347A
时间限制
2 s
内存限制
256 MB
标签
构造
模拟
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。