A. Difference Row

A. Difference Row
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You want to arrange n integers a1, a2, ..., an 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 x1, x2, ..., xn, where sequence x is a permutation of sequence a. The value of such an arrangement is (x1 - x2) + (x2 - x3) + ... + (xn - 1 - xn).

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 a1, a2, ..., an (|ai| ≤ 1000).

Output

Print the required sequence x1, x2, ..., xn. Sequence x should be the lexicographically smallest permutation of a that corresponds to an arrangement of the largest possible value.

Sample test(s)
input
5
100 -100 50 0 -50
output
100 -50 0 50 -100 
 #include<stdio.h>
#include<stdlib.h>
int a[];
int comp(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
} int main()
{
int n,i;
while(~scanf("%d",&n))
{
for(i = ;i < n;i ++)
scanf("%d",&a[i]);
qsort(a,n,sizeof(a[]),comp);
printf("%d ",a[n-]);
for(i = ;i < n-;i ++)
printf("%d ",a[i]);
printf("%d\n",a[]);
}
return ;
}
上一篇:使用FormData上传文件、图片


下一篇:动画Rig设置为Legacy