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.

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).

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.

NoteIn 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 x1, x2, ... , xp is lexicographically smaller than sequence y1, y2, ... , yp if there exists an integer r (0 ≤ r < p) such that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1.

import java.io.*;
import java.util.*;

public class P1 {
	public static void main (String[] args) {
		Scanner sc = new Scanner (System.in);
		PrintStream op = System.out;
		int n = sc.nextInt(), min = 0, max = 0;
		Vector <Integer> v = new Vector <Integer> ();
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			v.add(a);
			if (i > 0) {
				if (v.get(min) > a)
					min = i;
				if (v.get(max) < a)
					max = i;
			}
		}
		op.print(v.remove(max));
		if (max < min)
			min--;
		int m = v.remove(min);
		Collections.sort(v);
		for (int i : v)
			op.print(" " + i);
		op.println(" " + m);
		sc.close();
		op.close();
	}
}

import java.util.*;
import java.io.*;

public class Solution{

     public static void main(String []args){
         Solution ob = new Solution();
         ob.go();
     }

     void pr(String s)
     {
         System.out.print(s);
     }

     void go(){
         Scanner sc=new Scanner (System.in);
         int n=sc.nextInt();
         int[] x = new int[n];
         for(int i=0;i<n;i++) {
             x[i]=sc.nextInt();
         }
         Arrays.sort(x);
         String res="";
         pr(x[n-1]+" ");
         for (int i=1;i<n-1;i++) {
             pr(x[i]+" ");
         }
         pr(x[0]+"");
     }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Tahsin Rashad
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, OutputWriter out) {

            int n = in.nextInt();
            int[] array = new int[n];

            for (int i = 0; i < n; i++) {
                array[i] = in.nextInt();
            }

            Arrays.sort(array);

            int max = array[n - 1];
            array[n - 1] = array[0];
            array[0] = max;

            for (int i = 0; i < n; i++) {
                out.println(array[i] + " ");
            }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.awt.Point;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.TreeSet;

import java.math.BigInteger;

public class Main {

	public static Reader in = new Reader();
	public static Writer out = new Writer();

	public static void main(String[] args) {
		int n = in.readInt();

		int[] a = in.readInts(n);

		Arrays.sort(a);

		a[0] ^= a[n-1];
		a[n-1] ^= a[0];
		a[0] ^= a[n-1];

		for(int ai: a)
			out.print(ai+" ");

		out.close();
	}

}

class Writer {

	private BufferedWriter output;

	public Writer() {
		output = new BufferedWriter(new OutputStreamWriter(System.out));
	}

	public Writer(String s) {
		try {
			output = new BufferedWriter(new FileWriter(s));
		} catch(Exception ex) { ex.printStackTrace(); System.exit(0);}
	}

	public void println() {
		try {
			output.append("\n");
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}

	public void print(Object o) {
		try {
			output.append(o.toString());
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}

	public void println(Object o) {
		try {
			output.append(o.toString()+"\n");
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}

	public void printf(String format, Object... args) {
		try {
			output.append(String.format(format, args));
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}

	public void printfln(String format, Object... args) {
		try {
			output.append(String.format(format, args)+"\n");
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}

	public void flush() {
		try {
			output.flush();
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}

	public void close() {
		try {
			output.close();
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}
}

class Reader {
	private BufferedReader input;
	private StringTokenizer line = new StringTokenizer("");

	public Reader() {
		input = new BufferedReader(new InputStreamReader(System.in));
	}

	public Reader(String s) {
		try {
			input = new BufferedReader(new FileReader(s));
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}

	public void fill() {
		try {
			if(!line.hasMoreTokens()) line = new StringTokenizer(input.readLine());
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}

	public double nextDouble() {
		fill();
		return Double.parseDouble(line.nextToken());
	}

	public String nextWord() {
		fill();
		return line.nextToken();
	}

	public int nextInt() {
		fill();
		return Integer.parseInt(line.nextToken());
	}

	public long nextLong() {
		fill();
		return Long.parseLong(line.nextToken());
	}

	public double readDouble() {
		double d = 0;
		try {
			d = Double.parseDouble(input.readLine());
		} catch(IOException io) {io.printStackTrace(); System.exit(0);}
		return d;
	}

	public int readInt() {
		int i = 0;
		try {
			i = Integer.parseInt(input.readLine());
		} catch(IOException io) {io.printStackTrace(); System.exit(0);}
		return i;
	}

	public int[] readInts(int n) {
		int[] a = new int[n];
		for(int i=0; i<n; i++)
			a[i] = nextInt();
		return a;
	}

	public void fillInts(int[] a) {
		for(int i=0; i<a.length; i++)
			a[i] = nextInt();
	}

	public long readLong() {
		long l = 0;
		try {
			l = Long.parseLong(input.readLine());
		} catch(IOException io) {io.printStackTrace(); System.exit(0);}
		return l;
	}

	public String readLine() {
		String s = "";
		try {
			s = input.readLine();
		} catch(IOException io) {io.printStackTrace(); System.exit(0);}
		return s;
	}
}

import java.util.*;
public class A347{
	public static void main(String[] args){
		Scanner br = new Scanner(System.in);
		int n = br.nextInt();
		int[] nums = new int[n];
		for(int i = 0;i<n;i++){
			nums[i] = br.nextInt();
		}
		Arrays.sort(nums);
		int temp = nums[0];
		nums[0] = nums[n-1];
		nums[n-1] = temp;
		for(int i = 0;i<n;i++){
			System.out.print(nums[i]+" ");
		}
		System.out.println();
	}
}

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;

public class template
{

	public static ArrayList<Integer> strToInts(String str, String token)
	{
		ArrayList<Integer> result = new ArrayList<>();
		String[] strs = str.split(token);
		for (String string : strs)
			result.add(Integer.parseInt(string));
		return result;
	}

	public static ArrayList<Long> strToLong(String str, String token)
	{
		ArrayList<Long> result = new ArrayList<>();
		ArrayList<String> strs = new ArrayList<>(Arrays.asList(str.split(token)));
		for (String string : strs)
		{
			result.add(Long.parseLong(string));
		}
		return result;
	}

	public static void main(String[] args) throws IOException
	{

		// The input and output streams
		 BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); // system
		//BufferedReader in = new BufferedReader(new FileReader("input.txt"));
		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

		// Take input
		int n = Integer.parseInt(in.readLine());
		ArrayList<Integer> arr = strToInts(in.readLine(), " ");

		int maxElement = Collections.max(arr);
		int smallestElement = Collections.min(arr);
		Collections.sort(arr);
		out.write(maxElement+ " ");
		for (int i = 1; i < arr.size() - 1; i++)
			out.write(arr.get(i) + " ");
		out.write(smallestElement + "\n");

		out.flush();

	}

}

import java.util.Arrays;
import java.util.Scanner;

public class Row {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int i, n = Integer.parseInt(in.nextLine());
        int[] a = new int[n];
        for(i = 0; i < n; i++){
            a[i] = in.nextInt();
        }
        Arrays.sort(a);
        i = a[n-1];
        a[n-1] = a[0];
        a[0] = i;
        for(i = 0; i < n; i++){
            System.out.print(a[i]+" ");
        }
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class A {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int n = s.nextInt();
        int[] arr = new int[n];

        for (int i = 0; i < n; i++)
            arr[i] = s.nextInt();

        Arrays.sort(arr);

        System.out.print(arr[n - 1] + " ");
        for (int i = 1; i < n - 1; i++)
            System.out.print(arr[i] + " ");

        System.out.println(arr[0]);
    }
}

import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        LinkedList<Integer> nums = new LinkedList<Integer>();
        for(int i = 0; i < N; i++) {
            nums.addLast(in.nextInt());
        }
        Collections.sort(nums);
        int first = nums.removeFirst();
        int last = nums.removeLast();
        nums.addFirst(last);
        nums.addLast(first);
        for(int i = 0; i < nums.size(); i++) {
            if(i == 0){
                System.out.print(nums.get(i));
            } else {
                System.out.print(" " + nums.get(i));
            }
        }
    }
    public static long gcd(long a, long b) {
        if(b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }
}

import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.InputMismatchException;

import org.xml.sax.HandlerBase;

public class Solution
{
    public static void main(String[] args) {
       new Solution().solve();
    }

    PrintWriter out;

//    long mod=1000000007L ;
    public void solve()
    {
        out=new PrintWriter(System.out);

        int n=in.nextInt();
        int[] arr=in.nextIntArray(n);
        Arrays.sort(arr);
        out.print(arr[arr.length-1]+" ");
        for(int i=1;i<arr.length-1;i++)
        {
            out.print(arr[i]+" ");
        }
        out.print(arr[0]);
        out.close();
    }

    public s func(int r,int s)
    {
        s ans=new s();
        if(r<=(s/4.0))
        {
            ans.time=r;
            ans.a=r;
            ans.b=s;
        }
        else if(r%s==0)
        {
            ans.time=r;
            ans.a=0;
            ans.b=1;
        }
        else if(r/s==0)
        {
            ans.time=s;
            ans.a=0;
            ans.b=1;
        }
        else
        {
            ans.time=(r/s)*s;
            r-=(r/s)*s;
            if(r<=(s/4.0))
            {
                ans.time+=r;
                ans.a=r;
                ans.b=s;
            }
            else
            {
                ans.time+=s;
                ans.a=0;
                ans.b=1;
            }
        }
        return ans;
    }

    class s
    {
        int time;
        int a;
        int b;
    }

    public static int gcd(int a, int b) {
        BigInteger b1 = BigInteger.valueOf(a);
        BigInteger b2 = BigInteger.valueOf(b);
        BigInteger gcd = b1.gcd(b2);
        return gcd.intValue();
    }

    FasterScanner in=new FasterScanner();

    public static class FasterScanner {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = System.in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
    }
}

import java.io.BufferedInputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class A {

	private static Scanner in = new Scanner(new BufferedInputStream(System.in));
	private static PrintStream out = System.out;

	public static void main(String[] args) {
		int n = in.nextInt();
		int[] as = new int[n];
		for (int i = 0; i < n; ++i)
			as[i] = in.nextInt();
		Arrays.sort(as);
		int t = as[0];
		as[0] = as[n - 1];
		as[n - 1] = t;
		for (int i = 0; i < n; ++i)
			out.print(as[i] + " ");
		out.println();
	}

}

import java.util.*;
public class fib{

          public static void main(String dsgs[]){
                    Scanner s = new Scanner(System.in);
                    int n;
                    n = s.nextInt();
                    int a[] =new int[n];
                    for(int i=0;i<n;i++){
                              a[i] = s.nextInt();
                    }
                    int max =Integer.MIN_VALUE;
                    int min = Integer.MAX_VALUE;
                    int x=0,y=0;
                    for(int i=0;i<n;i++){
                              if(max<a[i]){
                                        x = i;
                                        max = a[i];
                              }
                              if(min>a[i]){
                                        y = i;
                                        min = a[i];
                              }

                    }
	if((x==0 && y==n-1) || (y==0 && x==n-1)){
		int temp = a[x];
		a[x] = a[0];
		a[0] = temp;
	}else if(y == 0){
		int temp = a[n-1];
                    	a[n-1] = a[y];
                    	a[y] = temp;
		temp = a[x];
                 	 	a[x] = a[0];
                    	a[0] = temp;

	}
	else{
                    	int temp = a[x];
                    	a[x] = a[0];
                    	a[0] = temp;
                    	temp = a[n-1];
                    	a[n-1] = a[y];
                    	a[y] = temp;
	}
                    Arrays.sort(a,1,n-1);
                    for(int i=0;i<n;i++)
                              System.out.print(a[i]+" ");
          }
}

import java.util.Scanner;
import java.util.Arrays;
public class A {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int[] arr = new int[n];
    for (int i = 0; i < n; i++) {
      arr[i] = in.nextInt();
    }

    Arrays.sort(arr);
    swap(arr, 0, arr.length-1);

    for (int i : arr) {
      System.out.print(i + " ");
    }
	}

  private static void swap(int[] arr, int i, int j) {
    if (arr.length == 1) return;
    int temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
  }
}

import java.io.*;
import java.util.Arrays;
public class CodeForce1{

public static void main(String args[])throws IOException{

	BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
	int n=Integer.parseInt(in.readLine());
	String s[]=in.readLine().split(" ");
	int i=0,max,min;

	int arr[]=new int[n];
	while(i<n){
		int num=Integer.parseInt(s[i]);
		arr[i]=num;
		i++;
	}
	Arrays.sort(arr);
	max=arr[n-1];
	System.out.print(max+" ");
	min=arr[0];
	i=1;
	while(i<(n-1)){

		System.out.print(arr[i]+" ");
		i++;
	}
	System.out.println(min);

	}

}

//347A
//DifferenceRow

import java.util.*;

public class DifferenceRow
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
            arr[i] = sc.nextInt();

        Arrays.sort(arr);

        int tmp = arr[0];
        arr[0] = arr[n - 1];
        arr[n - 1] = tmp;

        for(int i = 0; i < n; i++)
            System.out.print(arr[i] + " ");
    }
}

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> l = new ArrayList<Integer>();
		int mymax = Integer.MIN_VALUE;
		int mymin = Integer.MAX_VALUE;
		while(n-- != 0){
			int t = sc.nextInt();
			if(t > mymax)
				mymax = t;
			if(t < mymin)
				mymin = t;
			l.add(t);
		}

		l.remove((Integer)mymax);
		l.remove((Integer)mymin);

		Collections.sort(l);
		String s = l.toString().replace(", ", " ");
		s = s.substring(1, s.length() - 1);
		System.out.println(mymax + " " + s + " " + mymin);

	}
}

import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class DifferenceRow {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        StringTokenizer st = new StringTokenizer(sc.nextLine());
        int [] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(st.nextToken());
        }
        Arrays.sort(arr);
        int temp = arr[n-1];
        arr[n-1] = arr[0];
        arr[0]=temp;
        for (int i = 0; i < n; i++) {
            System.out.print(arr[i]+" ");
        }
    }
}

import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int pos=0;
        int[] a=new int[n];
        for(int i=0;i<n;i++)
        a[i]=sc.nextInt();
        Arrays.sort(a);
        System.out.print(a[n-1]+" ");
        for(int i=1;i<n-1;i++)
        System.out.print(a[i]+" ");
        System.out.print(a[0]);
    }
}

import java.io.*;
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt();

        Integer arr[] = new Integer[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        Arrays.sort(arr);

        int tmp = arr[0];
        arr[0] = arr[n - 1];
        arr[n - 1] = tmp;

        for (int x : arr) {
            out.print(x + " ");
        }

        out.flush();
    }

    static class Scanner {
        StringTokenizer tokenizer;
        BufferedReader reader;

        public Scanner(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return reader.readLine();
        }

        public boolean ready() throws IOException {
            return reader.ready();
        }
    }
}

import java.util.Scanner;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author balbasaur
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void swap(int a, int b,int a1[]) {
        int temp = 0;
        temp = a1[a];
        a1[a] = a1[b];
        a1[b] = temp;

    }
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int []a = new int[n];
        for (int i = 0;i < n ; ++i){
            a[i] = in.nextInt();
        }
        Arrays.sort(a);
        swap(0,n - 1,a);

        for (int i = 0; i < n; ++i){
            out.print(a[i]);
            if (i < n - 1)out.print(" ");
        }
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

}

import java.util.Arrays;
import java.util.Scanner;
public class ladder {
    public static void main(String[] args) throws java.lang.Exception {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int data[]= new int[n];
        for (int i = 0; i < n; i++) data[i]=scanner.nextInt();
        Arrays.sort(data);
        int temp = data[0];
        data[0]=data[n-1];
        data[n-1]=temp;
        for (int i = 0; i < n; i++) {
            System.out.println(data[i]);
        }
    }
}

import java.util.*;
public class aa {
public static void main(String[] args)
{
    Scanner input = new Scanner(System.in);
    int n = input.nextInt();
    int[] a = new int[n];
    for(int i = 0; i<n; i++) a[i] = input.nextInt();
    Arrays.sort(a);
    int temp = a[0];
    a[0] = a[n-1];
    a[n-1] = temp;
    for(int i = 0; i<a.length; i++) System.out.print(a[i]+" ");
}
}

import java.util.Arrays;
import java.util.Scanner;

public class Difference_Row {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		int pos = 0;
		int neg = 0;
		for (int i = 0 ; i < n ; i++)  {
			arr[i] = scan.nextInt();
			if (arr[i] > 0)
				pos++;
			else if (arr[i] < 0)
				neg++;
		}

		Arrays.sort(arr);
		int temp = arr[0];
		arr[0] = arr[n-1];
		arr[n-1] = temp;
		for (int i = 0 ; i < n ; i++) System.out.print(arr[i] + " ");

	}

}

import java.io.*;
import java.util.*;

public class Main {

    private void doit() {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            int [] data = new int[n];
            for(int i = 0; i < n; i++){
                data[i] = sc.nextInt();
            }
            Arrays.sort(data);
            StringBuilder sb = new StringBuilder();
            sb.append(" " + data[n-1]);
            for(int i = 1; i < data.length - 1; i++){
                sb.append(" " + data[i]);
            }
            sb.append(" " + data[0]);
            System.out.println(sb.substring(1));
        }
    }

    private void debug(Object... o) {
        System.out.println("debug = " + Arrays.deepToString(o));
    }

    class InStream {
        BufferedReader in;
        StringTokenizer st;

        public InStream() {
            this.in = new BufferedReader(new InputStreamReader(System.in));
            this.st = null;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (Exception e) {
                }
            }
            return st.nextToken();
        }

        boolean hasNext() {
            try {
                st = new StringTokenizer(in.readLine());
                return true;
            } catch (Exception e) {
                return false;
            }
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new Main().doit();
    }

}

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

/**
 *
 * @author Jigsaw
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
        int N = Integer.parseInt(br.readLine());
        String S[] = br.readLine().split(" ");
        int arr[] = new int[N];
        for(int n=0;n<N;n++){
            arr[n] = Integer.parseInt(S[n]);
        }
        int largest = -1001;
        int smallest = 1001;
        for(int n=0;n<N;n++){
            if(largest<arr[n]){
                largest = arr[n];
            }
            if(smallest>arr[n]){
                smallest = arr[n];
            }
        }
        Arrays.sort(arr);
        arr[0] = largest;
        arr[N-1] = smallest;
        for(int n=0;n<N;n++){
            pw.print(arr[n]+" ");
        }
        pw.close();
    }

}

import static java.lang.System.err;
import static java.lang.System.out;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
//import static adnap9.contests.cf.Utils.*;

public class A {

    public static void main(String[] args) {
        FastReader fr = new FastReader();
        int n = fr.nextInt();
        Integer[] t = fr.nextIntArray(n);
        Arrays.sort(t);
        Utils.swap(t,0,n-1);
        Utils.pr.printArray(t, " ");
        fr.close();
    }
}

class Printer {
    public Printer() {
    }
    public void println(String s) {
        out.println(s);
    }
    public void print(String s) {
        out.print(s);
    }
    public void ePrintln(String s) {
        err.println(s);
    }
    public void ePrint(String s) {
        err.print(s);
    }
    public <T> void printArray(T[] t) {
        for (T e : t) {
            println(e.toString());
        }
    }
    public <T> void printArray(T[] t, String sep) {
        for (T e : t) {
            print(e.toString() + sep);
        }
    }
    public <T> void ePrintArray(T[] t) {
        for (T e : t) {
            ePrintln(e.toString());
        }
    }
}
class FastReader extends CloseableTextParser {
    private StringTokenizer st;
    private BufferedReader br;
    private boolean isNext = true;
    private boolean closed = false;

    /***************/
    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
        // prepareTokenizer();
    }
    public FastReader(BufferedReader br) {
        this.br = br;
        // prepareTokenizer();
    }
    public FastReader(String s) {
        br = new BufferedReader(new StringReader(s));
        // prepareTokenizer();
    }
    /*******************/
    private void prepareTokenizer() {
        while (isNext == true && (st == null || !st.hasMoreTokens())) {
            try {
                String str = br.readLine();
                if (str == null) {
                    isNext = false;
                    st = null;
                } else {
                    st = new StringTokenizer(str);
                }
            } catch (IOException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }
    }
    private String nextToken(String delim) {
        if (closed) throw new IllegalStateException();
        prepareTokenizer();
        if (!isNext) throw new NoSuchElementException();
        String str = (delim != null) ? (st.nextToken(delim)) : (st.nextToken());
        // prepareTokenizer();
        return str;
    }
    private String nextToken() {
        return nextToken(null);
    }
    /*********************/
    public void close() {
        if (closed) throw new IllegalStateException();
        try {
            br.close();
            closed = true;
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
    public boolean hasNext() {
        return true;
    }
    /******************************/
    public String next() {
        return nextToken();
    }
    public String next(String delim) {
        return nextToken(delim);
    }
    public String nextLine() {
        return nextToken("\n");
    }
    public int nextInt() {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() {
        return Double.parseDouble(nextToken());
    }
    public char nextChar() throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }
    public byte nextByte() {
        return Byte.parseByte(nextToken());
    }
    public short nextShort() {
        return Short.parseShort(nextToken());
    }
    public boolean nextBoolean() {
        return Boolean.parseBoolean(nextToken());
    }
}
class Utils {
    public static <T extends Object> void fill2d(T[][] t, T el) {
        for (T[] t2 : t) {
            for (int i = 0; i < t2.length; i++) {
                t2[i] = el;
            }
        }
    }
    @SuppressWarnings("unchecked")
    public static <T> T[][] new2dArray(Class<T> c, int sx, int sy) {
        return (T[][]) Array.newInstance(c, sx, sy);
    }
    public static String merge(String[] st) {
        StringBuilder sb = new StringBuilder("");
        for (String s : st)
            sb.append(s);
        return sb.toString();
    }

    public static <T> void swap(T[] t, int p1, int p2) {
        T a = t[p1];
        t[p1] = t[p2];
        t[p2] = a;
    }

    public final static Printer pr = new Printer();

    private Utils() {
    }
}
abstract class CloseableTextParser extends ScannerLike implements Closeable, AutoCloseable {}
abstract class ScannerLike {
    public Integer[] nextIntArray(int n) {
        Integer[] t = new Integer[n];
        for (int i = 0; i < t.length; i++) {
            t[i] = nextInt();
        }
        return t;
    }
    public Long[] nextLongArray(int n) {
        Long[] t = new Long[n];
        for (int i = 0; i < t.length; i++) {
            t[i] = nextLong();
        }
        return t;
    }
    public Short[] nextShortArray(int n) {
        Short[] t = new Short[n];
        for (int i = 0; i < t.length; i++) {
            t[i] = nextShort();
        }
        return t;
    }
    public Byte[] nextByteArray(int n) {
        Byte[] t = new Byte[n];
        for (int i = 0; i < t.length; i++) {
            t[i] = nextByte();
        }
        return t;
    }
    public Boolean[] nextBooleanArray(int n) {
        Boolean[] t = new Boolean[n];
        for (int i = 0; i < t.length; i++) {
            t[i] = nextBoolean();
        }
        return t;
    }
    public String[] nextStringArray(int n, String delim) {
        String[] t = new String[n];
        for (int i = 0; i < t.length; i++) {
            t[i] = (delim != null) ? (next(delim)) : (next());
        }
        return t;
    }
    public String[] nextStringArray(int n) {
        return nextStringArray(n, null);
    }
    /*
     * public <T> T next(ObjectReaderFromText<T> p) { return p.loadFromInput(this); }
     */
    public abstract String next();
    public abstract boolean hasNext();
    public abstract byte nextByte();
    public abstract short nextShort();
    public abstract int nextInt();
    public abstract long nextLong();
    public abstract boolean nextBoolean();
    public abstract String nextLine();
    public abstract String next(String delim);
}

import java.util.Arrays;
import java.util.Scanner;

public class DifferenceRow {

    public static void main(String[] args) {
        int n = 0;
        int [] a;
        int [] res;
        Scanner reader = new Scanner(System.in);
        n = reader.nextInt();
        a = new int[n];
        res = new int[n];
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        int posMax = 0;
        int posMin = 0;

        for(int i = 0; i < n; i++){
            int v = reader.nextInt();
            a[i] = v;
            if(v > max) {
                max = v;
                posMax = i;
            }
            if(v < min){
                min = v;
                posMin = i;
            }
        }

        res[0] = max;
        res[n-1] = min;
        int j = 1;
        for(int i = 0; i < n; i++){
            if(i == posMax || i == posMin) continue;
            res[j] = a[i];
            j++;
        }

        Arrays.sort(res, 1, n-1);
        for(int i : res){
            System.out.print(i + " ");
        }
        System.out.println();
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws IOException {

		Solution sol = new Solution();
		System.out.println(sol.solution());
	}
}

class Solution{
	public String solution() throws NumberFormatException, IOException{
		BufferedReader r = new BufferedReader( new InputStreamReader(System.in));
		int N = Integer.parseInt(r.readLine());
		String[] sarr = r.readLine().split(" ");
		int[] arr = new int[N];
		//int max = 0;
		//int min = Integer.MAX_VALUE;
		for(int i = 0; i < N; i++){
			int var = Integer.parseInt(sarr[i]);
			//max = Math.max(max, var);
			//min = Math.min(min, var);
			arr[i] = var;
		}

		Arrays.sort(arr);
		int temp = arr[0];
		arr[0] = arr[N-1];
		arr[N-1] = temp;
		String ans = "";
		for(int i = 0; i < N; i++)ans+=String.valueOf(arr[i]) + " ";
		ans = ans.substring(0,ans.length()-1);
		return ans;
	}
}

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author geek_guY
 */
public class que6 {

    public static void main(String args[]) throws IOException, Exception {

        inputx6 in = new inputx6(System.in);

        int n = in.nextInt();
        int arr[] = new int[n];
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        for (int x = 0; x < n; x++) {
            arr[x] = in.nextInt();
        }
        if (n == 1) {
            System.out.println(arr[0]);
            return;
        }
        int mini = 0, maxi = 0;
        for (int x = 0; x < n; x++) {
            if (min > arr[x]) {
                min = arr[x];
                mini = x;
            }
            if (max < arr[x]) {
                max = arr[x];
                maxi = x;
            }
        }
        arr[mini] = Integer.MAX_VALUE;
        arr[maxi] = Integer.MAX_VALUE;
        if (n == 2) {
            System.out.println(max+" "+min);
            return;
        }
        Arrays.sort(arr);

        System.out.print(max+" ");
        for (int x = 0; x <n-2;x++) {
            System.out.print(arr[x]+" ");
        }
        System.out.println(min);
    }
}

class inputx6 {

    final private int BUFFER_SIZE = 1 << 17;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public inputx6(InputStream in) {
        din = new DataInputStream(in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String nextString() throws Exception {
        StringBuffer sb = new StringBuffer("");
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        do {
            sb.append((char) c);
            c = read();
        } while (c > ' ');
        return sb.toString();
    }

    public char nextChar() throws Exception {
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        return (char) c;
    }

    public int nextInt() throws Exception {
        int ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = c == '-';
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    public long nextLong() throws Exception {
        long ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = c == '-';
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    private void fillBuffer() throws Exception {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1) {
            buffer[0] = -1;
        }
    }

    private byte read() throws Exception {
        if (bufferPointer == bytesRead) {
            fillBuffer();
        }
        return buffer[bufferPointer++];
    }
}

import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.Arrays;

public class Solution {
//    ----------------------------------------------------------------------------

    public static void main(String[] args) throws IOException {

        //IF INPUT-OUTPUT is via files. uncomment use the below 3 lines of code. comment out the next 4
        //     File file = new File("input.txt"); // here input.txt and output.txt being the file names
        //   InputReader in = new InputReader(new FileInputStream(file));
        //    PrintWriter out = new PrintWriter(new FileOutputStream("output.txt"));
        //ELSE
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {

        static void swap(int a[], int x, int y) {

            int temp = a[x];
            a[x] = a[y];
            a[y] = temp;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a[] = in.nextIntArray(n);
            Arrays.sort(a);
            // swap highest and lowest value

            swap(a, 0, n - 1);

            for (int i = 0; i < n; i++) {
                out.print(a[i] + " ");
            }

        }

    }

//    ----------------------------------------------------------------------------
    // MAIN - INPUT - OUTPUT
    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public Double nextDouble() {
            return Double.parseDouble(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int[] nextIntArray(int arraySize) {
            int array[] = new int[arraySize];

            for (int i = 0; i < arraySize; i++) {
                array[i] = nextInt();
            }

            return array;
        }
//need to review this again
//        public char[][] nextMatrix(int row, int col) {
//
//            char[][] m = new char[row][col];
//
//            return m;
//        }

    }
}

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Test2 {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
	int n=input.nextInt();
 int []a=new int [n];

 for(int i=0;i<n;i++){
	a[i]=input.nextInt();

 }
 Arrays.sort(a);
 int one=a[0];
 int two=a[n-1];
 a[n-1]=one;
 a[0]=two;
 for(int i=0;i<a.length;i++)
	 System.out.print(a[i]+" ");

	}
}

        			/*
        		     * Author- Priyam Vora
        		     * BTech 2nd Year DAIICT
        		     */

        		    import java.awt.Point;
import java.io.*;
        		    import java.math.*;
        		    import java.util.*;
        		    import javax.print.attribute.SetOfIntegerSyntax;

        		    public class Main{
        		    	private static InputStream stream;
        		    	private static byte[] buf = new byte[1024];
        		    	private static int curChar;
        		    	private static int numChars;
        		    	private static SpaceCharFilter filter;
        		    	private static PrintWriter pw;
        		    	private static long count = 0,mod=1000000007;
        		    //	private static TreeSet<Integer> ts=new TreeSet[200000];

        		        public static void main(String[] args) {
        		        	InputReader(System.in);
        		    		pw = new PrintWriter(System.out);
        		            new Thread(null ,new Runnable(){
        		               public void run(){
        		                   try{
        		                       solve();
        		                       pw.close();
        		                   } catch(Exception e){
        		                       e.printStackTrace();
        		                   }
        		               }
        		           },"1",1<<26).start();
        		       }
        		        public static void Merge(long a[],int p,int r){
        		            if(p<r){
        		                int q = (p+r)/2;
        		                Merge(a,p,q);
        		                Merge(a,q+1,r);
        		                Merge_Array(a,p,q,r);
        		            }
        		        }
        		        public static void Merge_Array(long a[],int p,int q,int r){
        		           long b[] = new long[q-p+1];
        		            long c[] = new long[r-q];
        		            for(int i=0;i<b.length;i++)
        		                b[i] = a[p+i];
        		            for(int i=0;i<c.length;i++)
        		                c[i] = a[q+i+1];
        		            int i = 0,j = 0;
        		            for(int k=p;k<=r;k++){
        		                if(i==b.length){
        		                    a[k] = c[j];
        		                    j++;
        		                }
        		                else if(j==c.length){
        		                    a[k] = b[i];
        		                    i++;
        		                }
        		                else if(b[i]<c[j]){
        		                    a[k] = b[i];
        		                    i++;
        		                }
        		                else{
        		                    a[k] = c[j];
        		                    j++;
        		                }
        		            }
        		        }
        		    	public static long gcd(long x, long y) {
        		    		if (x == 0)
        		    			return y;
        		    		else
        		    			return gcd( y % x,x);
        		    	}	public static boolean isPrime(int n) {
        		    	// Corner cases
			    		if (n <= 1)
			    			return false;
			    		if (n <= 3)
			    			return true;

			    		// This is checked so that we can skip
			    		// middle five numbers in below loop
			    		if (n % 2 == 0 || n % 3 == 0)
			    			return false;

			    		for (int i = 5; i * i <= n; i = i + 6)
			    			if (n % i == 0 || n % (i + 2) == 0)
			    				return false;

			    		return true;
			    	}
        		        static LinkedList<Integer> adj[];
        		        static boolean Visited[];
        		        static HashSet<Integer> exc;
        		        static long oddsum[]=new long[1000001];
        		        static int co=0,ans=0;
        		        public static void solve() {

        		        	int n=nextInt();
        					int[] arr=nextIntArray(n);

        					Arrays.sort(arr);
        					int tmp=arr[0];
        					arr[0]=arr[n-1];
        					arr[n-1]=tmp;

        					pArray(arr);
    		    	}
        		    	public static void cal(int p,int x,int no_hack){
        		    		int start=(x/50)%475;
        		    		int i=0;
        		    		while(i<25){
        		    			start*=96;
        		    			start+=42;
        		    			start%=475;
        		    			if(start+26 == p){
        		    				System.out.println(start+"_--");
        		    			System.exit(0);
        		    			}
        		    			i++;
        		    		}

        		    	}

        		        private static void BFS(int n,int v,int w){
        		        	int level[]=new int[n+1];
        		        	boolean Visited[]=new boolean[n+1];
        		        	Queue<Integer> q=new LinkedList<Integer>();
        		        	q.add(v);
        		        	Visited[v]=true;
        		        	while(!q.isEmpty()){
        		        		int top=q.poll();

        		        		for(int i:adj[top]){
        		        			//pw.println(i+" "+top);
        		        			if(!Visited[i])
        		        			{
        		        				level[i]=level[top]+1;

        		        				q.add(i);
        		        			}

        		        			Visited[i]=true;
        		        			if(i==w){
        		        				if(level[i]<=5)
        		        				pw.println("Yes");
        		        				else
        		        					pw.println("No");
        		        				return;
        		        			}
        		        		}
        		        	}

        		        	pw.println("No");
        		        }

        		        private static long ncr(int n,int k){
    				    	if (k < 0 || k > n) return 0;
    				        if (n-k < k) k = n-k;

    				        BigInteger x = BigInteger.ONE;
    				        for (int i = 1; i <= k; i++) {
    				            x = x.multiply(new BigInteger(""+(n-i+1)));
    				            x = x.divide(new BigInteger(""+i));
    				        }

    				return x.longValue();
    				    }
        		       private  static long fact(long count){
        		        	long ans=1;
        		        	for(int i=1;i<=count;i++){
        		        		ans*=i;
        		        	}
        		        	return ans;
        		        }
        		        static long sort(int a[])
        		    	{  int n=a.length;
        		    		int b[]=new int[n];
        		    		return mergeSort(a,b,0,n-1);}
        		    	static long mergeSort(int a[],int b[],long left,long right)
        		    	{ long c=0;if(left<right)
        		    	 {   long mid=left+(right-left)/2;
        		    		 c= mergeSort(a,b,left,mid);
        		    		 c+=mergeSort(a,b,mid+1,right);
        		    		 c+=merge(a,b,left,mid+1,right); }
        		    		return c;	 }
        		    	static long merge(int a[],int  b[],long left,long mid,long right)
        		    	{long c=0;int i=(int)left;int j=(int)mid; int k=(int)left;
        		    	while(i<=(int)mid-1&&j<=(int)right)
        		    	{ if(a[i]>a[j]) {b[k++]=a[i++]; }
        		    	else	{ b[k++]=a[j++];c+=mid-i;}}
        		    	while (i <= (int)mid - 1)   b[k++] = a[i++];
        		    	while (j <= (int)right) b[k++] = a[j++];
        		    	for (i=(int)left; i <= (int)right; i++)
        		    		a[i] = b[i];  return c;  }

        		        static int state=1;
        		        static long no_exc=0,no_vert=0;
        		      static Stack<Integer> st;
        		      static HashSet<Integer> inset;
        		        private static void topo(int curr){

        		        	Visited[curr]=true;
        		        	inset.add(curr);
        		        	for(int x:adj[curr]){
        		        		if(adj[x].contains(curr) || inset.contains(x)){
        		        			state=0;
        		        			return;
        		        		}
        		        		if(state==0)
        		        			return;

        		        	}
        		        	st.push(curr);

        		        	inset.remove(curr);
        		        }
        		        static HashSet<Integer> hs;

        		     	private static void buildgraph(int n){
        		    		adj=new LinkedList[n+1];
        		    		Visited=new boolean[n+1];
        		    		st=new Stack<Integer>();
        		    		inset=new HashSet<Integer>();
        		    		exc=new HashSet<Integer>();

        		    		state=1;
        		    		for(int i=0;i<=n;i++){
        		    			adj[i]=new LinkedList<Integer>();

        		    		}

        		    	}

        		    	// To Get Input
        		    	// Some Buffer Methods

        		    	public static void InputReader(InputStream stream1) {
        		    		stream = stream1;
        		    	}

        		    	private static boolean isWhitespace(int c) {
        		    		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        		    	}

        		    	private static boolean isEndOfLine(int c) {
        		    		return c == '\n' || c == '\r' || c == -1;
        		    	}

        		    	private static int read() {
        		    		if (numChars == -1)
        		    			throw new InputMismatchException();
        		    		if (curChar >= numChars) {
        		    			curChar = 0;
        		    			try {
        		    				numChars = stream.read(buf);
        		    			} catch (IOException e) {
        		    				throw new InputMismatchException();
        		    			}
        		    			if (numChars <= 0)
        		    				return -1;
        		    		}
        		    		return buf[curChar++];
        		    	}

        		    	private static int nextInt() {
        		    		int c = read();
        		    		while (isSpaceChar(c))
        		    			c = read();
        		    		int sgn = 1;
        		    		if (c == '-') {
        		    			sgn = -1;
        		    			c = read();
        		    		}
        		    		int res = 0;
        		    		do {
        		    			if (c < '0' || c > '9')
        		    				throw new InputMismatchException();
        		    			res *= 10;
        		    			res += c - '0';
        		    			c = read();
        		    		} while (!isSpaceChar(c));
        		    		return res * sgn;
        		    	}

        		    	private static long nextLong() {
        		    		int c = read();
        		    		while (isSpaceChar(c))
        		    			c = read();
        		    		int sgn = 1;
        		    		if (c == '-') {
        		    			sgn = -1;
        		    			c = read();
        		    		}
        		    		long res = 0;
        		    		do {
        		    			if (c < '0' || c > '9')
        		    				throw new InputMismatchException();
        		    			res *= 10;
        		    			res += c - '0';
        		    			c = read();
        		    		} while (!isSpaceChar(c));
        		    		return res * sgn;
        		    	}

        		    	private static String nextToken() {
        		    		int c = read();
        		    		while (isSpaceChar(c))
        		    			c = read();
        		    		StringBuilder res = new StringBuilder();
        		    		do {
        		    			res.appendCodePoint(c);
        		    			c = read();
        		    		} while (!isSpaceChar(c));
        		    		return res.toString();
        		    	}

        		    	private static String nextLine() {
        		    		int c = read();
        		    		while (isSpaceChar(c))
        		    			c = read();
        		    		StringBuilder res = new StringBuilder();
        		    		do {
        		    			res.appendCodePoint(c);
        		    			c = read();
        		    		} while (!isEndOfLine(c));
        		    		return res.toString();
        		    	}

        		    	private static int[] nextIntArray(int n) {
        		    		int[] arr = new int[n];
        		    		for (int i = 0; i < n; i++) {
        		    			arr[i] = nextInt();
        		    		}
        		    		return arr;
        		    	}

        		    	private static long[][] next2dArray(int n, int m) {
        		    		long[][] arr = new long[n][m];
        		    		for (int i = 0; i < n; i++) {
        		    			for (int j = 0; j < m; j++) {
        		    				arr[i][j] = nextLong();
        		    			}
        		    		}
        		    		return arr;
        		    	}
        		    	private static char[][] nextCharArray(int n,int m){
        		    		char [][]c=new char[n][m];
        		    		for(int i=0;i<n;i++){
        		    			String s=nextLine();
        		    			for(int j=0;j<s.length();j++){
        		    				c[i][j]=s.charAt(j);
        		    			}
        		    		}
        		    		return c;
        		    	}

        		    	private static long[] nextLongArray(int n) {
        		    		long[] arr = new long[n];
        		    		for (int i = 0; i < n; i++) {
        		    			arr[i] = nextLong();
        		    		}
        		    		return arr;
        		    	}

        		    	private static void pArray(int[] arr) {
        		    		for (int i = 0; i < arr.length; i++) {
        		    			pw.print(arr[i] + " ");
        		    		}
        		    		pw.println();
        		    		return;
        		    	}

        		    	private static void pArray(long[] arr) {
        		    		for (int i = 0; i < arr.length; i++) {
        		    			pw.print(arr[i] + " ");
        		    		}
        		    		pw.println();
        		    		return;
        		    	}

        		    	private static void pArray(boolean[] arr) {
        		    		for (int i = 0; i < arr.length; i++) {
        		    			pw.print(arr[i] + " ");
        		    		}
        		    		pw.println();
        		    		return;
        		    	}

        		    	private static boolean isSpaceChar(int c) {
        		    		if (filter != null)
        		    			return filter.isSpaceChar(c);
        		    		return isWhitespace(c);
        		    	}

        		    	private interface SpaceCharFilter {
        		    		public boolean isSpaceChar(int ch);
        		    	}

    }

        		    class Node{
        		    	int to;
        		    	long dist;
        		    	Node(int to,long dist){
        		    		this.to=to;
        		    		this.dist=dist;
        		    	}

        		    }
        		    class Pair implements Comparable<Pair>{

    					int  rad,hei;
    					Pair(int rad, int hei){

    						this.rad=rad;
    						this.hei=hei;
    					}
    					@Override
    					public int compareTo(Pair o) {

    					/*	if(((double)a/(double)b)!=((double)o.a/(double)o.b))
    						return (int)(((double)o.a/(double)o.b)-((double)a/(double)b));
    						else*/
    							if(rad!=o.rad){
    								return rad-o.rad;
    							}else{
    								return hei-o.hei;
    							}
    						//return (int)(o.size-size);
    					}
    					public int hashCode() {
    							//int hu = (int) (x ^ (x >>> 32));
    							//int hv = (int) (y ^ (y >>> 32));
    							//int hw = (int) (mass ^ (mass >>> 32));
    							//return 31 * hu + hv ;
    						return 0;
    						}
    						public boolean equals(Object o) {
    							Pair other = (Pair) o;
    						//	return x == other.x && y == other.y;
    						return false;
    						}
    				}  class Dsu{
	    		    	private int rank[], parent[] ,n;
	    		    	private static int[] parent1;
	    		    	Dsu(int size){
	    		    		this.n=size+1;
	    		    		rank=new int[n];
	    		    		//parent=new int[n];
	    		    		parent=new int[n];
	    		    	makeSet();

	    		    	}

	    		    	void makeSet(){
	    		    		for(int i=0;i<n;i++){
	    		    			parent[i]=i;
	    		    		}
	    		    	}

	    		    	int find(int x){
	    		    		if(parent[x]!=x){

	    		    			parent[x]=find(parent[x]);
	    		    		}
	    		    		return parent[x];
	    		    	}

	    		    	boolean union(int x,int y){
	    		    		int xRoot=find(x);
	    		    		int yRoot=find(y);

	    		    		if(xRoot==yRoot)
	    		    			return false;
	    		    		if(rank[xRoot]<rank[yRoot]){
	    		    		parent[xRoot]=yRoot;
	    		    		}else if(rank[yRoot]<rank[xRoot]){
	    		    			parent[yRoot]=xRoot;
	    		    		}else{
	    		    			parent[yRoot]=xRoot;
	    		    			rank[xRoot]++;
	    		    		}
	    		    		return true;
	    		    	}

	    		    }

import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        try {
            if (new File("input.txt").exists())
                System.setIn(new FileInputStream("input.txt"));
        } catch (SecurityException e) {
        }
        new Main().run();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");

    private void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    final int MAXN = 101;
    final int INF = 100000;
    int[] a = new int[MAXN];
    int[] p = new int[MAXN];
    int n;
    private void solve() throws IOException {
        n = nextInt();
        int MAX = -INF;
        int MIN = INF;
        for(int i = 0; i < n; i++){
            a[i] = nextInt();
            if(a[i] < MIN)
                MIN = a[i];
            if(a[i] > MAX)
                MAX = a[i];
        }
        int NEEDR = MAX - MIN;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(i != j && a[i] - a[j]  == NEEDR && a[i] < MAX){
                    MAX = a[i];
                    MIN = a[j];
                }
            }
        }
        int cnt = 0;
        boolean getMax = false,getMin = false;
        for(int i = 0; i < n; i++){
            if(a[i] == MIN && !getMin ){
                getMin = true;
            } else if(a[i] == MAX && !getMax){
                getMax = true;
            }else if(a[i] != MIN && a[i] != MAX){
                p[cnt++] = a[i];
            } else if(a[i] == MIN && getMin){
                p[cnt++] = a[i];
            } else if(a[i] == MAX && getMax){
                p[cnt++] = a[i];
            }
        }
        sort(p,0,cnt);
        out.print(MAX);
        for(int i = 0; i < cnt; i++)
            out.print(" " + p[i]);
        out.println(" " + MIN);
    }

    void chk(boolean b) {
        if (b)
            return;
        System.out.println(new Error().getStackTrace()[1]);
        exit(999);
    }
    void deb(String fmt, Object... args) {
        System.out.printf(Locale.US, fmt + "%n", args);
    }
    String nextToken() throws IOException {
        while (!st.hasMoreTokens())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }
    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    String nextLine() throws IOException {
        st = new StringTokenizer("");
        return in.readLine();
    }
    boolean EOF() throws IOException {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return true;
            st = new StringTokenizer(s);
        }
        return false;
    }
}

import java.io.*;
import java.util.*;

public class Codeforces
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        int n=Integer.parseInt(bu.readLine());
        String s[]=bu.readLine().split(" ");
        int i,a[]=new int[n];
        for(i=0;i<n;i++)
        a[i]=Integer.parseInt(s[i]);
        Arrays.sort(a);
        a[0]=a[0]^a[n-1]^(a[n-1]=a[0]);
        for(i=0;i<n;i++)
        sb.append(a[i]+" ");
        System.out.print(sb);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author o_panda_o(emailofpanda@yahoo.com)
 */
public class Code_347A_DifferenceRow{
    public static void main(String[] args){
        InputStream inputStream=System.in;
        OutputStream outputStream=System.out;
        InputReader in=new InputReader(inputStream);
        OutputWriter out=new OutputWriter(outputStream);
        _347A_ solver=new _347A_();
        solver.solve(1,in,out);
        out.close();
    }

    static class _347A_{
        public void solve(int testNumber,InputReader in,OutputWriter out){
            int n=in.nextInt(), a[]=in.nextIntArray(n);
            Arrays.sort(a);
            out.print(a[n-1],"");
            for(int i=1;i<n-1;++i) out.print(a[i],"");
            out.print(a[0]);
        }

    }

    static class InputReader{
        private InputStream stream;
        private byte[] buf=new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream){
            this.stream=stream;
        }

        public int read(){
            if(numChars==-1){
                throw new InputMismatchException();
            }
            if(curChar>=numChars){
                curChar=0;
                try{
                    numChars=stream.read(buf);
                }catch(IOException e){
                    throw new InputMismatchException();
                }
                if(numChars<=0){
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt(){
            int c=read();
            while(isSpaceChar(c)){
                c=read();
            }
            int sgn=1;
            if(c=='-'){
                sgn=-1;
                c=read();
            }
            int res=0;
            do{
                if(c<'0'||c>'9'){
                    throw new InputMismatchException();
                }
                res*=10;
                res+=c-'0';
                c=read();
            }while(!isSpaceChar(c));
            return res*sgn;
        }

        public boolean isSpaceChar(int c){
            if(filter!=null){
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c){
            return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
        }

        public int[] nextIntArray(int n){
            int[] array=new int[n];
            for(int i=0;i<n;++i) array[i]=nextInt();
            return array;
        }

        public interface SpaceCharFilter{
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter{
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream){
            writer=new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer){
            this.writer=new PrintWriter(writer);
        }

        public void print(Object... objects){
            for(int i=0;i<objects.length;i++){
                if(i!=0){
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void close(){
            writer.close();
        }

        public void print(int i){
            writer.print(i);
        }

    }
}

import java.util.*;
import java.io.*;

public class CF347A{

	private static InputStream stream;
	private static PrintWriter pw;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;

	private static void soln(){
		int n = nextInt();
		int[] arr = nextIntArray(n);
		Arrays.sort(arr);
		int temp = arr[0];
		arr[0] = arr[n-1];
		arr[n-1] = temp;
		pArray(arr);
	}

	public static void main(String[] args){
		InputReader(System.in);
		pw = new PrintWriter(System.out);
		soln();
		pw.close();
	}

	// To Get Input
	// Some Buffer Methods

	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

	private static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private static boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

	private static int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	private static int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static String nextToken() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private static String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	private static int[] nextIntArray(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextLong();
		}
		return arr;
	}

	private static void pArray(int[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	private interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}

}

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class DifferenceRow implements Closeable {

    private InputReader in = new InputReader(System.in);
    private PrintWriter out = new PrintWriter(System.out);

    public void solve() {
        int n = in.ni();
        int[] x = new int[n];
        for (int i = 0; i < n; i++) x[i] = in.ni();
        Arrays.sort(x);
        x[n - 1] = x[n - 1] + x[0] - (x[0] = x[n - 1]);
        for (int i = 0; i < n; i++) {
            out.print(x[i]);
            out.print(' ');
        }
    }

    @Override
    public void close() throws IOException {
        in.close();
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ni() {
            return Integer.parseInt(next());
        }

        public long nl() {
            return Long.parseLong(next());
        }

        public void close() throws IOException {
            reader.close();
        }
    }

    public static void main(String[] args) throws IOException {
        try (DifferenceRow instance = new DifferenceRow()) {
            instance.solve();
        }
    }
}

import java.util.*;

public class Problem201A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] v = new int[n];
        for (int i = 0; i < n; i++) {
            v[i] = sc.nextInt();
        }
        Arrays.sort(v);
        System.out.print(v[n - 1]);
        for (int i = 1; i < n - 1; i++) {
            System.out.print(" " + v[i]);
        }
        System.out.println(" " + v[0]);
    }
}

import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.awt.Point;
import java.math.BigInteger;

import static java.lang.Math.*;

public class Codeforces_Solution_A implements Runnable{

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException{
        if (ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException{
        while(!tok.hasMoreTokens()){
            try{
                tok = new StringTokenizer(in.readLine());
            }catch (Exception e){
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException{
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException{
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException{
        return Double.parseDouble(readString());
    }

    public static void main(String[] args){
        new Thread(null, new Codeforces_Solution_A(), "", 128 * (1L << 20)).start();
    }

    long timeBegin, timeEnd;

    void time(){
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory(){
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB");
    }

    void debug(Object... objects){
        if (DEBUG){
            for (Object o: objects){
                System.err.println(o.toString());
            }
        }
    }

    public void run(){
        try{
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            time();
            memory();
        }catch (Exception e){
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    boolean DEBUG = false;

    void solve() throws IOException{

            int n = readInt();
            int[] a = new int[n];

            for (int i=0; i<n; i++) a[i] = readInt();

            Arrays.sort(a);

            int t = a[0];
            a[0] = a[n-1];
            a[n-1] = t;

            for (int i=0; i<n; i++) out.print(a[i]+" ");

        }

}

import java.util.Arrays;
import java.util.Scanner;

public class Prob347A {
	public static void main(String[] Args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int[] arr = new int[x];
		for (int i = 0; i < x; i++)
			arr[i] = scan.nextInt();
		Arrays.sort(arr);
		System.out.print(arr[arr.length-1] + " ");
		for (int i = 1; i < x-1; i++)
			System.out.print(arr[i] + " ");
		System.out.print(arr[0]);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main
{
    public static void main(String[] args) throws NumberFormatException, IOException {

        InputReader in = new InputReader(System.in);

        int n = in.nextInt();

        int min = 2000, min_idx = -1, max = -2000, max_idx = -1;
        int[]a =  new int[n];

        for(int i = 0; i < n; i++)
        {
            a[i] = in.nextInt();
            if(a[i] > max) {max = a[i]; max_idx = i;}
            if(a[i] < min) {min = a[i]; min_idx = i;}
        }

        swap(max_idx,0, a);
        if(min_idx == 0) min_idx = max_idx;
        swap(min_idx,n-1, a);
        Arrays.sort(a,1,n-1);

        for(int i = 0; i < n - 1; i++)
            System.out.print(a[i]+" ");
        System.out.println(a[n-1]);

    }

    static void swap(int i, int j, int[] a)
    {
        int tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
    }

    static class InputReader {
        StringTokenizer st;
        BufferedReader br;

        public InputReader(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {return Integer.parseInt(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public boolean ready() throws IOException {return br.ready();}

    }

}

import java.io.*;
    import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.*;

     public class Main {
    	public static InputReader in;
        public static PrintWriter pw;

    	public static void main(String args[]) {
    		new Thread(null, new Runnable() {
                public void run() {
                    try{
                        solve();
                    }
                    catch(Exception e){
                        e.printStackTrace();
                    }
                }
            }, "1", 1 << 26).start();
        }
    	static ArrayList<Integer> g[];
    	static ArrayList<Integer> h[];
    	static boolean visited[];
    	static boolean parent[];
    	static int par[];
    	static int degree[];
    	static int edjes=0;
    	static int start=-1;
    	static int end=-1;
    	static int Total=0;
    	static int time1[];
    	static int time2[];
    	static int glob=0;
    	static long ans[]=new long[1000000];
    	static boolean vis2[][];
    	//static long sum1=0;
    	//static long val[];
        static ArrayList<Integer> levels[];
        static int max=0;
        static int lev=1;
        static ArrayList<Integer> nodes[];
        static ArrayList<Integer> values[];
        static int depth[];
        static boolean found=false;
       // static long sm[];
        static int sum1=0;
        static int pre[][];
        static int subtree[];
       static  int cnt=0;
       static  HashMap<String,Integer> hm;
       static int sm[];
       static int prime[];
       static long mul[];
       static long d[]=new long[1000000];
       static int tot=0;
       static long highest=(long)1e9;
       static boolean bit=false;
        static Stack<Integer> tt=new Stack();
       static HashSet<String> set=new HashSet<String>();
 	   static long fact[];
 	   static long MOD=1000000007;
        public static void solve() throws FileNotFoundException{

    		 in = new InputReader(System.in);
    		 pw = new PrintWriter(System.out);
    	      int n=in.nextInt();
    	      int a[]=in.nextIntArray(n);
    	      Arrays.sort(a);
    	      int tmp=a[0];
    	      a[0]=a[n-1];
    	      a[n-1]=tmp;
    	      int sm=0;
    	      for(int i=0;i<n;i++)
    	      {
    	    	  System.out.print(a[i]+" ");
    	      }
        }

        static long ncr(long a, long b){
			if(b>a || b<0) return 0;
			long f = (fact[(int) a]*modInverse(((fact[(int) b]*fact[(int) (a-b)])%MOD), MOD))%MOD;
			return f;
		}
		static long modInverse(long a, long mOD2){
            return  power(a, mOD2-2, mOD2);
}
static long power(long x, long y, long m)
{
    if (y == 0)
        return 1;
    long p = power(x, y/2, m) % m;
    p = (p * p) % m;

    return (y%2 == 0)? p : (x * p) % m;
}

        public static long gcd(long x, long y) {
    		if (x == 0)
    			return y;
    		else
    			return gcd( y % x,x);
    	}
        public static long power(long a,long b)
		{
			long result=1;
			while(b>0)
			{
				if(b%2==1)
					result*=a;
				a=a*a;
				b/=2;
			}
			return result;
		}
        static class Pair implements Comparable<Pair>{
        	int a;
        		int b;
        	//	int c;
        		//int index;
        		Pair(int a,int b){
        	     	this.a=a;
        			this.b=b;
               //     this.c=c;
        		}
        		@Override
        		public int compareTo(Pair o) {
                      if(o.b>this.b)
                    	  return 1;
                      else
                    	  return -1;
        		}

        	}
    	static class InputReader {

    		private InputStream stream;
    		private byte[] buf = new byte[8192];
    		private int curChar, snumChars;
    		private SpaceCharFilter filter;

    		public InputReader(InputStream stream) {
    			this.stream = stream;
    		}

    		public int snext() {
    			if (snumChars == -1)
    				throw new InputMismatchException();
    			if (curChar >= snumChars) {
    				curChar = 0;
    				try {
    					snumChars = stream.read(buf);
    				} catch (IOException e) {
    					throw new InputMismatchException();
    				}
    				if (snumChars <= 0)
    					return -1;
    			}
    			return buf[curChar++];
    		}

    		public   int nextInt() {
    			int c = snext();
    			while (isSpaceChar(c))
    				c = snext();
    			int sgn = 1;
    			if (c == '-') {
    				sgn = -1;
    				c = snext();
    			}
    			int res = 0;
    			do {
    				if (c < '0' || c > '9')
    					throw new InputMismatchException();
    				res *= 10;
    				res += c - '0';
    				c = snext();
    			} while (!isSpaceChar(c));
    			return res * sgn;
    		}

    		public long nextLong() {
    			int c = snext();
    			while (isSpaceChar(c))
    				c = snext();
    			int sgn = 1;
    			if (c == '-') {
    				sgn = -1;
    				c = snext();
    			}
    			long res = 0;
    			do {
    				if (c < '0' || c > '9')
    					throw new InputMismatchException();
    				res *= 10;
    				res += c - '0';
    				c = snext();
    			} while (!isSpaceChar(c));
    			return res * sgn;
    		}

    		public int[] nextIntArray(int n) {
    			int a[] = new int[n];
    			for (int i = 0; i < n; i++)
    				a[i] = nextInt();
    			return a;
    		}

    		public String readString() {
    			int c = snext();
    			while (isSpaceChar(c))
    				c = snext();
    			StringBuilder res = new StringBuilder();
    			do {
    				res.appendCodePoint(c);
    				c = snext();
    			} while (!isSpaceChar(c));
    			return res.toString();
    		}

    		public boolean isSpaceChar(int c) {
    			if (filter != null)
    				return filter.isSpaceChar(c);
    			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    		}

    		public interface SpaceCharFilter {
    			public boolean isSpaceChar(int ch);
    		}
    	}
    }

import java.util.List;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Ziklon
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {

    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.nextInt();
        ArrayList<Integer> seq = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) seq.add(in.nextInt());

        Collections.sort(seq);
        Collections.swap(seq, 0, n - 1);

        out.print(seq.toArray());

    }
}

class InputReader {
    InputStream stream;
    byte[] buf = new byte[1024];
    int curChar, numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    private int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

}

class OutputWriter {

    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void close() {
        writer.close();
    }

}

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] tn = new int[n];

		for (int i = 0; i < tn.length; i++) {
			tn[i] = in.nextInt();
		}
			Arrays.sort(tn);
	System.out.print(tn[n-1]);
	for (int i = 1; i < tn.length-1; i++) {
		System.out.print(" "+tn[i]);
	}
	System.out.println(" "+tn[0]);

	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class CF_347_A_DIFFERENCE_ROW {

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt();

		int [] a = new int[n];

		for(int i = 0 ; i < n ; i ++)
			a[i] = sc.nextInt();
		Arrays.sort(a);

		int temp = a[0];
		a[0] = a[n-1];
		a[n-1] = temp;

		for(int i = 0 ; i < n ; i ++)
			System.out.print(a[i]+" ");

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

}

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.lang.*;

public class A {

    public static void main(String[] args) {
        A a = new A();
        a.run();

    }

    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);

    void quickSort(int[] mas, int l, int r){
        int i = l;
        int j = r;
        int m = mas[(i + j) / 2];
        while (i < j){
            while (mas[i] < m) i++;
            while (m < mas[j]) j--;
            if (i <= j){
                int a = mas[i];
                mas[i] = mas[j];
                mas[j] = a;
                i++;
                j--;
            }
        }
        if (l < j) quickSort(mas, l, j);
        if (i < r) quickSort(mas, i, r);
    }

    void run(){
        int[] mas = new int[100];
        int n =  sc.nextInt();
        for (int i = 0; i < n; i++){
            mas[i] = sc.nextInt();
        }
        quickSort(mas, 0, n - 1);
        out.print(mas[n - 1] + " ");
        for (int i = 1; i < n - 1; i++) out.print(mas[i] + " ");
        out.print(mas[0]);
        out.flush();
    }

}

import java.io.*;
import java.util.*;

public class Main {

    private void doit() {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            int [] data = new int[n];
            for(int i = 0; i < n; i++){
                data[i] = sc.nextInt();
            }
            Arrays.sort(data);
            StringBuilder sb = new StringBuilder();
            sb.append(" " + data[n-1]);
            for(int i = 1; i < data.length - 1; i++){
                sb.append(" " + data[i]);
            }
            sb.append(" " + data[0]);
            System.out.println(sb.substring(1));
        }
    }

    private void debug(Object... o) {
        System.out.println("debug = " + Arrays.deepToString(o));
    }

    class InStream {
        BufferedReader in;
        StringTokenizer st;

        public InStream() {
            this.in = new BufferedReader(new InputStreamReader(System.in));
            this.st = null;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (Exception e) {
                }
            }
            return st.nextToken();
        }

        boolean hasNext() {
            try {
                st = new StringTokenizer(in.readLine());
                return true;
            } catch (Exception e) {
                return false;
            }
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new Main().doit();
    }

}

import java.util.*;
import java.lang.*;
import java.io.*;
public class vv
{

  public static void main(String[] args)
  {
  Scanner ab=new Scanner(System.in);

  int x=ab.nextInt();
  int arr[]=new int[x];
  for(int i=0;i<x;i++)arr[i]=ab.nextInt();
  Arrays.sort(arr);
  System.out.print(arr[x-1]+" ");
  for(int i=1;i<x-1;i++)
  {
    System.out.print(arr[i]+" ");
  }
  System.out.println(arr[0]);

  }
}

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] arr = new int[N];

		for(int i=0; i<N; i++) {
			arr[i] = in.nextInt();
		}
		Arrays.sort(arr);
		int temp = arr[0];
		arr[0] = arr[N-1];
		arr[N-1] = temp;
		for(int i=0; i<N; i++) {
			System.out.print(arr[i] + " ");
		}
	}
}

import java.io.*;
import java.util.*;

public class problemA {

    public static void main(String[] args) throws IOException{

        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(f.readLine());

        int min;

        int testCases = Integer.parseInt(st.nextToken());

        ArrayList<Integer> a = new ArrayList<Integer>();

        st = new StringTokenizer(f.readLine());

        for(int i = 0; i < testCases; i++){

            a.add(Integer.parseInt(st.nextToken()));

        }

        Collections.sort(a);

        System.out.print(a.get(a.size()-1) + " ");

        min = a.get(0);

        for(int i = 1; i < a.size()-1; i++ ){

            System.out.print( a.get(i) + " " );

        }

        System.out.print(min);

    }

}

import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

public class CF {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		LinkedList<Integer> LL = new LinkedList<Integer>();
		while(N-->0){
			LL.add(sc.nextInt());
		}
		Collections.sort(LL);
		Integer last = LL.pollLast();
		Integer first = LL.pollFirst();
		LL.addFirst(last);
		LL.addLast(first);
		for(Integer x : LL){
			System.out.print(x+" ");
		}

	}
}

import java.io.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class CF347A {
    static BufferedReader __in;
    static PrintWriter __out;
    static StringTokenizer input;

    public static void main(String[] args) throws IOException {
        __in = new BufferedReader(new InputStreamReader(System.in));
        __out = new PrintWriter(new OutputStreamWriter(System.out));

        int n = ri();
        int[] a = ria(n);
        sort(a);
        pr(a[n-1] + " ");
        for(int i = 1; i < n - 1; ++i) pr(a[i] + " ");
        pr(a[0]);

        close();
    }

    // references
    // IBIG = 1e9 + 7
    // IRAND ~= 3e8
    // IMAX ~= 2e10
    // LMAX ~= 9e18
    // constants
    static final int IBIG = 1000000007;
    static final int IRAND = 327859546;
    static final int IMAX = 2147483647;
    static final int IMIN = -2147483648;
    static final long LMAX = 9223372036854775807L;
    static final long LMIN = -9223372036854775808L;
    // util
    static int minof(int a, int b, int c) {return min(a, min(b, c));}
    static int minof(int... x) {return x.length == 1 ? x[0] : x.length == 2 ? min(x[0], x[1]) : min(x[0], minstarting(1, x));}
    static int minstarting(int offset, int... x) {assert x.length > 2; return offset == x.length - 2 ? min(x[offset], x[offset + 1]) : min(x[offset], minstarting(offset + 1, x));}
    static long minof(long a, long b, long c) {return min(a, min(b, c));}
    static long minof(long... x) {return x.length == 1 ? x[0] : x.length == 2 ? min(x[0], x[1]) : min(x[0], minstarting(1, x));}
    static long minstarting(int offset, long... x) {assert x.length > 2; return offset == x.length - 2 ? min(x[offset], x[offset + 1]) : min(x[offset], minstarting(offset + 1, x));}
    static int maxof(int a, int b, int c) {return max(a, max(b, c));}
    static int maxof(int... x) {return x.length == 1 ? x[0] : x.length == 2 ? max(x[0], x[1]) : max(x[0], maxstarting(1, x));}
    static int maxstarting(int offset, int... x) {assert x.length > 2; return offset == x.length - 2 ? max(x[offset], x[offset + 1]) : max(x[offset], maxstarting(offset + 1, x));}
    static long maxof(long a, long b, long c) {return max(a, max(b, c));}
    static long maxof(long... x) {return x.length == 1 ? x[0] : x.length == 2 ? max(x[0], x[1]) : max(x[0], maxstarting(1, x));}
    static long maxstarting(int offset, long... x) {assert x.length > 2; return offset == x.length - 2 ? max(x[offset], x[offset + 1]) : max(x[offset], maxstarting(offset + 1, x));}
    static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
    static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
    static int floori(double d) {return (int)d;}
    static int ceili(double d) {return (int)ceil(d);}
    static long floorl(double d) {return (long)d;}
    static long ceill(double d) {return (long)ceil(d);}
    // input
    static void r() throws IOException {input = new StringTokenizer(__in.readLine());}
    static int ri() throws IOException {return Integer.parseInt(__in.readLine());}
    static long rl() throws IOException {return Long.parseLong(__in.readLine());}
    static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;}
    static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;}
    static char[] rcha() throws IOException {return __in.readLine().toCharArray();}
    static String rline() throws IOException {return __in.readLine();}
    static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());}
    static int ni() {return Integer.parseInt(input.nextToken());}
    static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());}
    static long nl() {return Long.parseLong(input.nextToken());}
    // output
    static void pr(int i) {__out.print(i);}
    static void prln(int i) {__out.println(i);}
    static void pr(long l) {__out.print(l);}
    static void prln(long l) {__out.println(l);}
    static void pr(double d) {__out.print(d);}
    static void prln(double d) {__out.println(d);}
    static void pr(char c) {__out.print(c);}
    static void prln(char c) {__out.println(c);}
    static void pr(char[] s) {__out.print(new String(s));}
    static void prln(char[] s) {__out.println(new String(s));}
    static void pr(String s) {__out.print(s);}
    static void prln(String s) {__out.println(s);}
    static void pr(Object o) {__out.print(o);}
    static void prln(Object o) {__out.println(o);}
    static void prln() {__out.println();}
    static void pryes() {__out.println("yes");}
    static void pry() {__out.println("Yes");}
    static void prY() {__out.println("YES");}
    static void prno() {__out.println("no");}
    static void prn() {__out.println("No");}
    static void prN() {__out.println("NO");}
    static void pryesno(boolean b) {__out.println(b ? "yes" : "no");};
    static void pryn(boolean b) {__out.println(b ? "Yes" : "No");}
    static void prYN(boolean b) {__out.println(b ? "YES" : "NO");}
    static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
    static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
    static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); __out.println(iter.next());}
    static void flush() {__out.flush();}
    static void close() {__out.close();}}

import java.io.*;
import java.util.*;

public class Solution347A {

	public static void main(String[] args) {

		// Scanner sc = new Scanner(System.in);
		MyScanner sc = new MyScanner();
		int n = sc.nextInt();

		int [] res = new int[n];
		for (int i = 0 ; i < n ; i++) {
			res[i] = sc.nextInt();
		}

		Arrays.sort(res);
		// for (int i = 0 ; i < n ; i++) {
		// 	System.out.print(res[i] + " ");
		// }

		System.out.print(res[n-1] + " ");
		for (int i = 1 ; i < n-1 ; i++) {
			System.out.print(res[i] + " ");
		}
		System.out.print(res[0]);
	}
}

class MyScanner {
	BufferedReader br;
	StringTokenizer st;

     public MyScanner() {
     	br = new BufferedReader(new InputStreamReader(System.in));
     }

    String next() {
     	while (st == null || !st.hasMoreElements()) {
     		try {
     			st = new StringTokenizer(br.readLine());
     		} catch (IOException e) {
     			e.printStackTrace();
     		}
     	}
     	return st.nextToken();
    }

 	int nextInt() {
 		return Integer.parseInt(next());
 	}

 	long nextLong() {
 		return Long.parseLong(next());
 	}

 	double nextDouble() {
 		return Double.parseDouble(next());
 	}

 	String nextLine(){
 		String str = "";
 		try {
 			str = br.readLine();
 		} catch (IOException e) {
 			e.printStackTrace();
 		}
 		return str;
 	}
}

import java.util.Arrays;
import java.util.Scanner;

public class Problem4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n;
        n = scanner.nextInt();
        int[] input = new int[n];
        for (int i = 0; i < n; i++) {
            input[i] = scanner.nextInt();
        }
        Arrays.sort(input);
        System.out.print(input[n - 1]);
        for (int i = 1; i <= n-2; i++) {
            System.out.print(" " + input[i]);
        }
        System.out.print(" " + input[0]);
    }
}

import java.util.*;

/**
 * @author artyom
 */
public class DifferenceRow {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> ls = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            ls.add(sc.nextInt());
        }
        Collections.sort(ls);
        Collections.swap(ls, 0, ls.size() - 1);
        System.out.println(join(ls, " "));
    }

    private static String join(Collection<?> entries, CharSequence separator) {
        StringBuilder sb = new StringBuilder();
        for (Iterator<?> iterator = entries.iterator(); iterator.hasNext();) {
            sb.append(iterator.next());
            if (iterator.hasNext()) {
                sb.append(separator);
            }
        }
        return sb.toString();
    }
}

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.InputMismatchException;
import java.util.Arrays;
import java.util.*;

public class MISC {

    public static void main(String[] args) throws IOException {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReaderMISC in = new InputReaderMISC(inputStream);
    OutputWriterMISC out = new OutputWriterMISC(outputStream);
    int n=in.readInt();
    int a[]=new int[n];
    for(int i=0;i<n;i++)
        a[i]=in.readInt();
    Arrays.sort(a);
    out.print(a[n-1]+" ");
    for(int i=1;i<n-1;i++)
        out.print(a[i]+" ");
    out.print(a[0]);

   out.close();
    }

}

class InputReaderMISC {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReaderMISC(InputStream stream) {
        this.stream = stream;
    }

    private int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
                long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

    class OutputWriterMISC {
    private final PrintWriter writer;

    public OutputWriterMISC(OutputStream outputStream) {
        writer = new PrintWriter(outputStream);
    }

    public OutputWriterMISC(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }
    }

import java.util.*;
public class A347{
	public static void main(String[] args){
		Scanner br = new Scanner(System.in);
		int n = br.nextInt();
		int[] nums = new int[n];
		for(int i = 0;i<n;i++){
			nums[i] = br.nextInt();
		}
		Arrays.sort(nums);
		int temp = nums[0];
		nums[0] = nums[n-1];
		nums[n-1] = temp;
		for(int i = 0;i<n;i++){
			System.out.print(nums[i]+" ");
		}
		System.out.println();
	}
}

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.Scanner;

public class TaskA {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = in.nextInt();
		}
		Arrays.sort(a);
		int t = a[0];
		a[0] = a[a.length - 1];
		a[a.length - 1] = t;

		System.out.print(a[0]);
		for (int i = 1; i < a.length; i++) {
			System.out.print(' ');
			System.out.print(a[i]);
		}
		System.out.println();
	}

}

import java.util.Arrays;
import java.util.Scanner;

public class CA {

    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++)
            a[i] = in.nextInt();

        Arrays.sort(a);

        int[] ret = new int[n];
        System.out.print(a[n - 1] + " ");
        for (int i = 1; i < n - 1; i++)
            System.out.print(a[i] + " ");
        System.out.print(a[0] + " ");
    }

}

import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        try {
            if (new File("input.txt").exists())
                System.setIn(new FileInputStream("input.txt"));
        } catch (SecurityException e) {
        }
        new Main().run();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");

    private void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        int n;
        n = nextInt();
        int a[] = new int[n];
        for(int i = 0;i < n;i++){
            a[i] = nextInt();
        }

        sort(a);

        int t = a[0];
        a[0] = a[n-1];
        a[n-1] = t;
        for(int i = 0;i < n;i++){
            out.print(a[i]+" ");
        }

        in.close();
        out.close();
    }

    void chk(boolean b) {
        if (b)
            return;
        System.out.println(new Error().getStackTrace()[1]);
        exit(999);
    }
    void deb(String fmt, Object... args) {
        System.out.printf(Locale.US, fmt + "%n", args);
    }
    String nextToken() throws IOException {
        while (!st.hasMoreTokens())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }
    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    String nextLine() throws IOException {
        st = new StringTokenizer("");
        return in.readLine();
    }
    boolean EOF() throws IOException {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return true;
            st = new StringTokenizer(s);
        }
        return false;
    }
}

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Contest201_div2_q1__Difference_Row
{
    static int maxPathLen = Integer.MIN_VALUE;
    static int[] path;

    public static void main(String ... args) throws Exception
    {
        Scanner in   = new Scanner(System.in);
        int count    = in.nextInt();
        long time    = System.currentTimeMillis();
        path         = new int[count];
        for(int i=0; i<count; ++i)
            path[i] = in.nextInt();
        Arrays.sort(path);
        path[0]      += path[count-1];
        path[count-1] = path[0] - path[count-1];
        path[0]      -= path[count-1];
        for(int i : path) System.out.print(i + " ");
    }
}

import java.util.*;
public class DifferenceRow {

    public static void main(String args[])
    {
        int i,j,key,n;
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        int array[]=new int[n];
        int array1[]=new int[n+1];
        for(i=0;i<n;i++)
        {
            array[i]=sc.nextInt();
        }
        Arrays.sort(array);
        //System.out.println(array[0]);
         for(i=0;i<n-1;i++)
         {
             array1[(i+n-1)/2]=array[(i+n-1)/2];
             array1[i+1]=array[i+1];
         }
         array1[0]=array[n-1];
         array1[n-1]=array[0];

   for(i=0;i<n;i++)
        {
            System.out.print(array1[i]);
            System.out.print(" ");
        }

    }
    }

import java.util.*;
public class DifferenceRow
{
    static final int INF = Integer.MAX_VALUE;
    static final int NINF = Integer.MIN_VALUE;
    public static void exit()
    {
        System.exit(0);
    }
    public static void main(String[]args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer [] arr = new Integer[n];
        for(int i = 0; i < n; i++)
            arr[i] = sc.nextInt();
        Arrays.sort(arr, new Comparator<Integer>(){
            public int compare(Integer i, Integer j)
            {
                return j-i;
            }
        });

        int i = 1, j = n-2;
        while(i < j)
        {
            Integer temp = arr[j];
            arr[j] = arr[i];
            arr[i] = temp;
            i++;
            j--;
        }

        for(Integer x : arr)
            System.out.print(x + " ");
        System.out.println();
    }
}

import java.util.Scanner;
import java.util.Arrays;

public class DifferenceRow
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; ++i)
		{
			a[i] = input.nextInt();
		}
		Arrays.sort(a);
		int temp = a[0];
		a[0] = a[n - 1];
		a[n - 1] = temp;
		for (int i = 0; i < n; ++i)
		{
			System.out.print(a[i]);
			if (i == n - 1)
			{
				System.out.println();
			}
			else
			{
				System.out.print(" ");
			}
		}
	}
}

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: joy32812
 * Date: 10/1/13
 * Time: 5:12 PM
 * To change this template use File | Settings | File Templates.
 */
public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        List<Integer> list = new ArrayList<Integer>();

        for (int i=0;i<N;i++) list.add(scanner.nextInt());
        Collections.sort(list);

        System.out.print(list.get(N - 1));
        for (int i = 1; i < N - 1; i++) System.out.print(" " + list.get(i));
        System.out.println(" " + list.get(0));
    }
}

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	/**
	 * @param args
	 */
	 BufferedReader in;
	    PrintWriter out = new PrintWriter(System.out);
	    StringTokenizer tok;

	     String readToken() throws IOException { // reads the token; to read a full line use in.readLine()
	    while (tok == null || !tok.hasMoreTokens()) {
	    tok = new StringTokenizer(in.readLine());

	    }
	    return tok.nextToken(); // sometimes it's better to use nextToken(String) method here
	    }
	     int readInt() throws IOException { // write readDouble(), readLong(), readBigInteger() methods if necessary
	    return Integer.parseInt(readToken());
	    }
	     public String readLine() throws IOException{
			return in.readLine();

	     }
	     long readLong() throws IOException { // write readDouble(), readLong(), readBigInteger() methods if necessary
	    	    return Long.parseLong(readToken());
	    	    }
	     double readDouble() throws IOException { // write readDouble(), readLong(), readBigInteger() methods if necessary
	    	    return Double.parseDouble(readToken());
	    	    }
	    public static void main(String[] args) throws IOException
	    {
	       new Main().run();
	    }
	    void run() throws IOException
	    {
	    	boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	    	out = new PrintWriter(new OutputStreamWriter(System.out));
	    	in = new BufferedReader(new InputStreamReader(System.in));
	    	if (oj){

	    	}
	    	else{

	    	}
	       solve();
	       out.flush();
	       tok=null;
	    }

	    void solve() throws IOException{
	    	/*
	    	 *  kataligei   x[0]-x[n]
	    	 *  auto  ginetai beltisto otan ginetai max-min
	    	 * gia lexikografiko mikrotero aplws kanw to eksis:
	    	 *    max  A[min+1] A[min+2]..... A[max-1]  min
	    	 */
	    	int n=readInt();
	    	int[] A=new int[n];
	    	for (int i=0;i<n;++i) A[i]=readInt();
	    	Arrays.sort(A);
	    	out.print(A[n-1]+" ");
	    	for (int i=1;i<n-1;++i) out.print(A[i]+" ");
	    	out.print(A[0]);
	    }
}

import java.io.*;
import java.math.BigInteger;
import java.util.*;

import static java.lang.Math.max;

public class MySolution
{

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
     }

    static class Task
    {
        public void solve(int testNumber, InputReader sc, PrintWriter out)
        {
            int n = sc.nextInt();

            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = sc.nextInt();
            }

            Arrays.sort(a);

            int temp = a[0];
            a[0] = a[n - 1];
            a[n - 1] = temp;

            for (int i = 0; i < n; i++)
            {
                out.print(a[i] + " ");
            }
        }
    }

    public static void sort(long[] array)
    {
        long min = Integer.MAX_VALUE;
        long max = Integer.MIN_VALUE;
        for (long element : array)
        {
            if (element < min)
            {
                min = element;
            }
            if (element > max)
            {
                max = element;
            }
        }
        long[] buckets = new long[(int) (max - min + 1)];
        for (long element : array)
        {
            buckets[(int) (element - min)]++;
        }
        int arrayIndex = 0;
        for (int i = 0; i < buckets.length; i++)
        {
            for (long j = buckets[i]; j > 0; j--)
            {
                array[arrayIndex++] = i + min;
            }
        }
    }

    public static class InputReader {
        private boolean finished = false;

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int peek() {
            if (numChars == -1) {
                return -1;
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    return -1;
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0) {
                s = readLine0();
            }
            return s;
        }

        public String readLine(boolean ignoreEmptyLines) {
            if (ignoreEmptyLines) {
                return readLine();
            } else {
                return readLine0();
            }
        }

        public BigInteger readBigInteger() {
            try {
                return new BigInteger(nextString());
            } catch (NumberFormatException e) {
                throw new InputMismatchException();
            }
        }

        public char nextCharacter() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            return (char) c;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public boolean isExhausted() {
            int value;
            while (isSpaceChar(value = peek()) && value != -1) {
                read();
            }
            return value == -1;
        }

        public String next() {
            return nextString();
        }

        public SpaceCharFilter getFilter() {
            return filter;
        }

        public void setFilter(SpaceCharFilter filter) {
            this.filter = filter;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
        public int[] nextIntArray(int n){
            int[] array=new int[n];
            for(int i=0;i<n;++i)array[i]=nextInt();
            return array;
        }
        public int[] nextSortedIntArray(int n){
            int array[]=nextIntArray(n);
            Arrays.sort(array);
            return array;
        }
        public int[] nextSumIntArray(int n){
            int[] array=new int[n];
            array[0]=nextInt();
            for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
            return array;
        }
        public long[] nextLongArray(int n){
            long[] array=new long[n];
            for(int i=0;i<n;++i)array[i]=nextLong();
            return array;
        }
        public long[] nextSumLongArray(int n){
            long[] array=new long[n];
            array[0]=nextInt();
            for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
            return array;
        }
        public long[] nextSortedLongArray(int n){
            long array[]=nextLongArray(n);
            Arrays.sort(array);
            return array;
        }
    }
    public static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(char[] array) {
            writer.print(array);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void print(int[] array) {
            for (int i = 0; i < array.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(array[i]);
            }
        }

        public void print(double[] array) {
            for (int i = 0; i < array.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(array[i]);
            }
        }

        public void print(long[] array) {
            for (int i = 0; i < array.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(array[i]);
            }
        }

        public void println(int[] array) {
            print(array);
            writer.println();
        }

        public void println(double[] array) {
            print(array);
            writer.println();
        }

        public void println(long[] array) {
            print(array);
            writer.println();
        }

        public void println() {
            writer.println();
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void print(char i) {
            writer.print(i);
        }

        public void println(char i) {
            writer.println(i);
        }

        public void println(char[] array) {
            writer.println(array);
        }

        public void printf(String format, Object... objects) {
            writer.printf(format, objects);
        }

        public void close() {
            writer.close();
        }

        public void flush() {
            writer.flush();
        }

        public void print(long i) {
            writer.print(i);
        }

        public void println(long i) {
            writer.println(i);
        }

        public void print(int i) {
            writer.print(i);
        }

        public void println(int i) {
            writer.println(i);
        }

        public void separateLines(int[] array) {
            for (int i : array) {
                println(i);
            }
        }
    }
}

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class A {

	static Scanner sc;
	static PrintStream ps;
	static boolean[][] arr;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		ps = System.out;
		long n = sc.nextLong();
		long[] ar = new long[(int) n];
		int x = 0;
		while (n-- > 0) {
			ar[x] = sc.nextLong();
			x++;
		}

		Arrays.sort(ar);
		long t = ar[0];
		ar[0] = ar[ar.length - 1];
		ar[ar.length - 1] = t;
		for(int i = 0; i < ar.length - 1; i++)
			System.out.print(ar[i] +" ");
		System.out.println(ar[ar.length- 1]);
		sc.close();
	}
}

import java.io.*;
import java.util.*;

public class problem347Acf {
		public static void main(String args[]) throws IOException
		{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		String s = in.readLine();
		int n = Integer.parseInt(s);
		int[] arr = new int[n];
		String str = in.readLine();

		for(int i=0; i<n; i++)
		{
			arr[i] = Integer.parseInt(str.split(" ")[i]);
		}

		Arrays.sort(arr);

		System.out.print(arr[n-1]+" ");

		for(int j=1; j<n-1; j++)
		{
			System.out.print(arr[j]+" ");
		}
		System.out.println(arr[0]);
		}
}

import java.util.*;
import java.io.*;

/*
 * A. Difference Row
 */

public class Main {
    Scanner sc = new Scanner(System.in);
    void doIt(){
        int n = sc.nextInt();
        int []set =new int [n];

        for(int i=0; i<n; i++){
            set[i] = sc.nextInt();
            //System.out.println(set[i]);
        }
         Arrays.sort(set);

         System.out.print(set[n-1]+" ");
         for(int i=1; i<n-1; i++){
            System.out.print(set[i]+" ");
         }
         System.out.println(set[0]);
    }

    public static void main(String[] args) {
        new Main().doIt();
    }

    // thanks to wata
    class Scanner {
        InputStream in;
        byte[] buf = new byte[1 << 10];
        int p, n;
        boolean[] isSpace = new boolean[128];
        Scanner(InputStream in) {
            this.in = in;
            isSpace[' '] = isSpace['\n'] = isSpace['\r'] = isSpace['\t'] = true;
        }
        int read() {
            if (n == -1) return -1;
            if (p >= n) {
                p = 0;
                try {
                    n = in.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (n <= 0) return -1;
            }
            return buf[p++];
        }
        boolean hasNext() {
            int c = read();
            while (c >= 0 && isSpace[c]) c = read();
            if (c == -1) return false;
            p--;
            return true;
        }
        String next() {
            if (!hasNext()) throw new InputMismatchException();
            StringBuilder sb = new StringBuilder();
            int c = read();
            while (c >= 0 && !isSpace[c]) {
                sb.append((char)c);
                c = read();
            }
            return sb.toString();
        }
        int nextInt() {
            if (!hasNext()) throw new InputMismatchException();
            int c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (c >= 0 && !isSpace[c]);
            return res * sgn;
        }
        long nextLong() {
            if (!hasNext()) throw new InputMismatchException();
            int c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (c >= 0 && !isSpace[c]);
            return res * sgn;
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}

import java.util.*;
public class aa {
public static void main(String[] args)
{
    Scanner input = new Scanner(System.in);
    int n = input.nextInt();
    int[] a = new int[n];
    for(int i = 0; i<n; i++) a[i] = input.nextInt();
    Arrays.sort(a);
    int temp = a[0];
    a[0] = a[n-1];
    a[n-1] = temp;
    for(int i = 0; i<a.length; i++) System.out.print(a[i]+" ");
}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author unknown
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        PDifferenceRow solver = new PDifferenceRow();
        solver.solve(1, in, out);
        out.close();
    }

    static class PDifferenceRow {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int[] arr = in.nextSortedIntArray(n);
            int temp = arr[n - 1];
            arr[n - 1] = arr[0];
            arr[0] = temp;
            out.println(arr);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; ++i) array[i] = nextInt();
            return array;
        }

        public int[] nextSortedIntArray(int n) {
            int[] array = nextIntArray(n);
            Arrays.sort(array);
            return array;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(int[] array) {
            for (int i = 0; i < array.length; ++i) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(array[i]);
            }
        }

        public void println(int[] array) {
            print(array);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}

import java.util.*;

public class MyClass
{
    public static void main(String args[])
    {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++)
        {
            a[i]=s.nextInt();
        }
        Arrays.sort(a);
        int temp = a[0];
        a[0] = a[n-1];
        a[n-1] = temp;
        for(int i=0; i<n; i++)
        {
            System.out.print(a[i]+" ");
        }
    }
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A {
	static BufferedReader br;
	static PrintWriter pw;
	static StringTokenizer st;

	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	private static String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
				System.out)));
		int n = nextInt();
		Integer a[] = new Integer[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		Arrays.sort(a);
		pw.print(a[n-1]+" ");
		for (int i = 1; i < n-1; i++)
			pw.print(a[i]+" ");
		pw.print(a[0]);
		pw.close();
	}
}

import java.util.*;
import java.io.*;
			public class yahia {
				public static void main (String [] Yahia_Mostafa) throws Exception {
					Scanner sc =new Scanner(System.in);
					int n =sc.nextInt();
					PrintWriter pw =new PrintWriter(System.out);
					Integer x[] =new Integer[n];
					for (int i=0;i<n;++i)
						x[i]=sc.nextInt();
					Arrays.sort(x);
					pw.print(x[n-1]+" ");
					for (int i = 1;i<n-1;++i)
						pw.print(x[i]+" ");
					pw.print(x[0]);
					pw.close();
					}
				static class Scanner {
					StringTokenizer stringTokenizer;
					BufferedReader bfBufferedReader;
					public Scanner(InputStream system) {
						bfBufferedReader=new BufferedReader(new InputStreamReader( system));
					}
					 public Scanner(String file) throws Exception {
				            bfBufferedReader = new BufferedReader(new FileReader( file));
				        }
				        public String next() throws IOException {
				            while (stringTokenizer == null || !stringTokenizer.hasMoreTokens())
				                stringTokenizer = new StringTokenizer( bfBufferedReader.readLine());
				            return stringTokenizer.nextToken();
				        }

				        public String nextLine() throws IOException {
				            return bfBufferedReader.readLine();
				        }

				        public int nextInt() throws IOException {
				            return Integer.parseInt(next());
				        }

				        public double nextDouble() throws IOException {
				            return Double.parseDouble(next());
				        }

				        public char nextChar() throws IOException {
				            return next().charAt(0);
				        }

				        public Long nextLong() throws IOException {
				            return Long.parseLong(next());
				        }

				        public boolean ready() throws IOException {
				            return bfBufferedReader.ready();
				        }

				        public void waitForInput() throws InterruptedException {
				            Thread.sleep(3000);
				        }
				    }

				}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main
{
  static BufferedReader reader;
  static StringTokenizer tokenizer;
  static PrintWriter writer;

  static int nextInt() throws IOException
  {
    return Integer.parseInt(nextToken());
  }

  static long nextLong() throws IOException
  {
    return Long.parseLong(nextToken());
  }

  static double nextDouble() throws IOException
  {
    return Double.parseDouble(nextToken());
  }

  static boolean eof = false;

  static String nextToken() throws IOException
  {
    while (tokenizer == null || !tokenizer.hasMoreTokens())
    {
      tokenizer = new StringTokenizer(reader.readLine());
    }
    return tokenizer.nextToken();
  }

  public static void main(String[] args) throws IOException
  {
    tokenizer = null;
    reader = new BufferedReader(new InputStreamReader(System.in));
    writer = new PrintWriter(System.out);
    banana();
    reader.close();
    writer.close();
  }

  static class Point
  {
    public long x, y;

    public Point(long x, long y)
    {
      this.x = x;
      this.y = y;
    }
  }

  static void banana() throws IOException
  {
    int n = nextInt();
    int a[] = new int[n];

    for (int i = 0 ; i < n; ++i)
      a[i] = nextInt();

    Arrays.sort(a);

    int min = a[0];
    int max = a[n-1];

    int b[] = new int[n-2];
    for (int i = 1 ; i < n-1; ++i)
      b[i-1] = a[i];

    System.out.print(max + " ");
    Arrays.sort(b);
    for (int i = 0; i < b.length; ++i)
      System.out.print(b[i] +  " ");
    System.out.println(min);

  }
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	public static void main (String[] args)
	{
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] A = new int[N];

		for (int i = 0; i < N; i++)
			A[i] = in.nextInt();

		Arrays.sort(A);

		int temp = A[0];
		A[0] = A[N-1];
		A[N-1] = temp;

		for (int i = 0; i < N; i++)
			System.out.print(A[i] + " ");
	}
}

import java.util.Arrays;
import java.util.Scanner;
public class DifferenceRow {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=sc.nextInt();
        }
        Arrays.sort(a);
        System.out.print(a[n-1]+" ");
        for(int i=1;i<n-1;i++)
            System.out.print(a[i]+" ");
        System.out.print(a[0]+" ");
    }
}

import java.io.*;
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt();

        Integer arr[] = new Integer[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        Arrays.sort(arr);

        int tmp = arr[0];
        arr[0] = arr[n - 1];
        arr[n - 1] = tmp;

        for (int x : arr) {
            out.print(x + " ");
        }

        out.flush();
    }

    static class Scanner {
        StringTokenizer tokenizer;
        BufferedReader reader;

        public Scanner(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return reader.readLine();
        }

        public boolean ready() throws IOException {
            return reader.ready();
        }
    }
}

//package codeforces;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;

public class A {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(System.out);

    A() throws IOException {
//        reader = new BufferedReader(new FileReader("input.txt"));
//        writer = new PrintWriter(new FileWriter("output.txt"));
    }

    StringTokenizer stringTokenizer;

    String next() throws IOException {
        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
            stringTokenizer = new StringTokenizer(reader.readLine());
        }
        return stringTokenizer.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    void solve() throws IOException {
        int n = nextInt();
        List<Integer> a = new ArrayList<>();
        for(int i = 0; i < n; i++) {
           a.add(nextInt());
        }
        Collections.sort(a, Collections.reverseOrder());
        Collections.reverse(a.subList(1, n - 1));
        for (Integer x : a) {
            writer.print(x + " ");
        }
        writer.close();
    }

    public static void main(String[] args) throws IOException {
        new A().solve();
    }
}

import java.util.*;

public class Row {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int x[] = new int[n];
        for (int i = 0; i < x.length; i++) {
            x[i] = in.nextInt();
        }
        Arrays.sort(x);
        int tmp = x[0];
        x[0] = x[x.length-1];
        x[x.length - 1] = tmp;
        for (int i = 0; i < x.length; i++) {
            System.out.print(x[i] + " ");
        }
    }
}

import java.io.*;
import java.util.*;

public class problemA {

    public static void main(String[] args) throws IOException{

        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(f.readLine());

        int min;

        int testCases = Integer.parseInt(st.nextToken());

        ArrayList<Integer> a = new ArrayList<Integer>();

        st = new StringTokenizer(f.readLine());

        for(int i = 0; i < testCases; i++){

            a.add(Integer.parseInt(st.nextToken()));

        }

        Collections.sort(a);

        System.out.print(a.get(a.size()-1) + " ");

        min = a.get(0);

        for(int i = 1; i < a.size()-1; i++ ){

            System.out.print( a.get(i) + " " );

        }

        System.out.print(min);

    }

}

import java.util.Arrays;
import java.util.Scanner;

public class A347 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        int[] A = new int[N];
        for (int n=0; n<N; n++) {
            A[n] = input.nextInt();
        }
        Arrays.sort(A);
        int temp = A[0];
        A[0] = A[N-1];
        A[N-1] = temp;
        StringBuilder output = new StringBuilder();
        for (int n=0; n<N; n++) {
            if (n != 0) {
                output.append(' ');
            }
            output.append(A[n]);
        }
        System.out.println(output);
    }

}

import java.util.List;
import java.io.InputStreamReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.awt.Point;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Turaev Timur
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.nextInt();
        ArrayList<Integer> a = in.nextIntArrayList(n);
        Collections.sort(a);
        Collections.swap(a, 0, a.size()-1);
        out.printList(a);
    }
}

class InputReader {
    BufferedReader in;
    StringTokenizer stringTokenizer;

    public InputReader(InputStream inputStream) {
        in = new BufferedReader(new InputStreamReader(inputStream));
    }

    public String next() {
        while (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
            try {
                stringTokenizer = new StringTokenizer(in.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return stringTokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public ArrayList<Integer> nextIntArrayList(int size) {
        ArrayList<Integer> result = new ArrayList<>();
        for (int i = 0; i < size; i++) {
            result.add(nextInt());
        }
        return result;
    }

}

class OutputWriter extends PrintWriter {
    final int DEFAULT_PRECISION = 12;

    int precision;
    String format, formatWithSpace;

    {
        precision = DEFAULT_PRECISION;
        format = createFormat(precision);
        formatWithSpace = format + " ";
    }

    public OutputWriter(OutputStream out) {
        super(out);
    }

    public OutputWriter(Writer out) {
        super(out);
    }

    public <T> void printList(List<T> list) {
        for (T element : list) {
            print(element);
            print(" ");
        }
    }

    private String createFormat(int precision) {
        return "%." + precision + "f";
    }

}

import java.util.*;
public class A{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		Arrays.sort(a);
		System.out.print(a[n-1]);
		for(int i=1;i<n-1;i++) {
			System.out.print(" "+a[i]);
		}
		System.out.print(" "+a[0]);
	}
}

import java.io.*;
import java.util.*;

/**
 *
 * @author acer
 */
public class Main {

    static Scanner sc = new Scanner(System.in);
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

    int n = sc.nextInt();

    int[] a = new int[n];

    for(int i=0; i<n; i++){
        a[i]=sc.nextInt();
    }

    Arrays.sort(a);
    int t;
    t=a[n-1];
    a[n-1]=a[0];
    a[0]=t;

    for(int i=0; i<n; i++){
        System.out.print(a[i]+" ");
    }
    }

}

import java.io.BufferedInputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class A {

	private static Scanner in = new Scanner(new BufferedInputStream(System.in));
	private static PrintStream out = System.out;

	public static void main(String[] args) {
		int n = in.nextInt();
		int[] as = new int[n];
		for (int i = 0; i < n; ++i)
			as[i] = in.nextInt();
		Arrays.sort(as);
		int t = as[0];
		as[0] = as[n - 1];
		as[n - 1] = t;
		for (int i = 0; i < n; ++i)
			out.print(as[i] + " ");
		out.println();
	}

}

import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class DifferenceRow {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        StringTokenizer st = new StringTokenizer(sc.nextLine());
        int [] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(st.nextToken());
        }
        Arrays.sort(arr);
        int temp = arr[n-1];
        arr[n-1] = arr[0];
        arr[0]=temp;
        for (int i = 0; i < n; i++) {
            System.out.print(arr[i]+" ");
        }
    }
}

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author mark
 */
public class DifferenceRow {

    public static void main(String[] args) throws FileNotFoundException {
        //FileInputStream file = new FileInputStream(new File("/home/mark/tmp/input.txt"));
        //Scanner scan = new Scanner(file);

        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        Integer arr[] = new Integer[num];
        for (int i = 0; i < num; i++) {
            arr[i] = scan.nextInt();
        }
        Arrays.sort(arr,Collections.reverseOrder());
        Integer[] tmp = Arrays.copyOfRange(arr, 1,arr.length-1);
        Arrays.sort(tmp);
        //Integer narr[]=new Integer[num];
        System.out.print(arr[0]+" ");
        for(int i=0;i<tmp.length;i++){
            System.out.print(tmp[i]+" ");
        }
        System.out.println(arr[arr.length-1]);
    }
}

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 *
 * @author Altynbek Nurgaziyev
 */
public class A {

        public void solution() throws Exception {
                Scanner in = new Scanner(System.in);

                int n = in.nextInt();

                Integer[] f = new Integer[n];

                for (int i = 0; i < n; ++i) {
                        f[i] = in.nextInt();
                }

                Arrays.sort(f);

                System.out.print(f[n - 1] + " ");
                for (int i = 1; i < n - 1; ++i) {
                        System.out.print(f[i] + " ");
                }
                System.out.println(f[0]);
        }

        public static void main(String[] args) throws Exception {
                new A().solution();
        }

        public class Scanner {

                private BufferedReader br;
                private StringTokenizer st;

                public Scanner(InputStream is) {
                        br = new BufferedReader(new InputStreamReader(is));
                }

                public String next() throws Exception {
                        while (st == null || !st.hasMoreTokens()) {
                                st = new StringTokenizer(br.readLine());
                        }
                        return st.nextToken();
                }

                public Integer nextInt() throws Exception {
                        return Integer.parseInt(next());
                }

                public Long nextLong() throws Exception {
                        return Long.parseLong(next());
                }

                public Double nextDouble() throws Exception {
                        return Double.parseDouble(next());
                }
        }
}

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Test2 {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
	int n=input.nextInt();
 int []a=new int [n];

 for(int i=0;i<n;i++){
	a[i]=input.nextInt();

 }
 Arrays.sort(a);
 int one=a[0];
 int two=a[n-1];
 a[n-1]=one;
 a[0]=two;
 for(int i=0;i<a.length;i++)
	 System.out.print(a[i]+" ");

	}
}

import java.util.Arrays;
import java.util.Scanner;

public class Difference {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner input = new Scanner(System.in);
		int n  = input.nextInt();
		int[] arr = new int[n];
		//arr[0] = input.nextInt();
		for(int i=0;i<n;i++)arr[i] = input.nextInt();
		int min = arr[0];
		int minindex = 0;
		int maxindex = 0;
		int max = arr[0];
		Arrays.sort(arr);
		int temp = arr[0];
		arr[0] = arr[n-1];
		arr[n-1] = temp;
/*
		for(int i=1;i<arr.length;i++){
			arr[i] = input.nextInt();
			if(arr[i] < min){
				min = arr[i];
				minindex = i;
			}
			if(arr[i]>max){
				max = arr[i];
				maxindex = i;
			}
		}
			int temp = arr[0];
			arr[0] = max;
			arr[maxindex] = temp;
			temp = arr[n-1];
			arr[n-1] = arr[minindex];
			arr[minindex] = temp;
			for(int i=0;i<n;i++)System.out.println(arr[i] + " ");

	}

	*/

		for(int i=0;i<n;i++)System.out.println(arr[i] + " ");
}
}

import java.util.*;

public class cf347A{

	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();

		int min = 10000;
		int min_index = -1;
		int max = -10000;
		int max_index = -1;
		String[] arr = new String[n];

		for(int i=0; i<n; i++)
		{

			arr[i] = sc.next();
			if(Integer.parseInt(arr[i])<min)
			{
				min = Integer.parseInt(arr[i]);
				min_index = i;
			}
			if(Integer.parseInt(arr[i]) > max)
			{
				max = Integer.parseInt(arr[i]);
				max_index = i;

			}

		}

		arr[min_index] = "9999";
		arr[max_index] = "9999";
		Arrays.sort(arr);

		System.out.print(max+" ");

		for(int i=0; i<n-2; i++)
			System.out.print(arr[i]+" ");

		System.out.println(min);
	}

}

import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.io.InputStream;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(in, out);
        out.close();
    }
}

class TaskA {
    public void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int number[] = new int[n];
        for(int i = 0;i < n;i++)
            number[i] = in.nextInt();
        Arrays.sort(number);
        swap(number[0], number[n - 1]);
        for(int i = 0;i < n;i++)
            out.print(number[i] + " ");
    }

    private void swap(int a, int b) {
        // TODO Auto-generated method stub
        a = a ^ b;
        b = a ^ b;
        a = a ^ b;
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
}

import java.util.Scanner;

public class A {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }
        qsort(a, 0, n-1);
        int b[] = new int[n];
        boolean flag = true;
        int k = (n%2==1) ? n/2+1 : n/2;
        for (int i=0; i<k; i++){
            if (flag){
                b[i] = a[n-i-1];
                b[n-i-1]= a[i];
            }
            else{
                b[i] = a[i];
                b[n-i-1]= a[n-i-1];
            }
            flag = !flag;
        }
        for (int i=0; i<n-1; i++){
            System.out.print(b[i]+" ");
        }
        System.out.print(b[n-1]);

    }
    static void qsort(int[] a, int l, int r) {
        int i = l;
        int j = r;
        int mid = a[i + (j - i)/2];
        while (i <= j) {
            while (a[i] < mid)
                i++;
            while (a[j] > mid)
                j--;
            if (i <= j) {
                int t = a[i];
                a[i] = a[j];
                a[j] = t;
                i++;
                j--;
            }
        }
        if (i < r)
            qsort(a, i, r);
        if (j > l)
            qsort(a, l, j);
    }
}

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner fi = new Scanner (System.in);
        int n = fi.nextInt ();
        int A[] = new int [n];

        for (int i = 0; i < n; ++i) A[i] = fi.nextInt ();
        Arrays.sort(A);
        for (int i : A) System.out.print(i + " ");
    }
}

import java.util.*;

public class cf347A{

	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();

		int min = 10000;
		int min_index = -1;
		int max = -10000;
		int max_index = -1;
		String[] arr = new String[n];

		for(int i=0; i<n; i++)
		{

			arr[i] = sc.next();
			if(Integer.parseInt(arr[i])<min)
			{
				min = Integer.parseInt(arr[i]);
				min_index = i;
			}
			if(Integer.parseInt(arr[i]) > max)
			{
				max = Integer.parseInt(arr[i]);
				max_index = i;

			}

		}

		arr[min_index] = "9999";
		arr[max_index] = "9999";
		Arrays.sort(arr);

		System.out.print(max+" ");

		for(int i=0; i<n-2; i++)
			System.out.print(arr[i]+" ");

		System.out.print(min);
	}

}

//package Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Test {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> arr = new ArrayList<>();
		for (int i = 0; i < n; i++)
			arr.add(sc.nextInt());
		int min = Collections.min(arr);
		int max = Collections.max(arr);
		arr.remove(arr.indexOf(min));
		if (min != max && arr.size() != 0)
			arr.remove(arr.indexOf(max));
		ArrayList<Integer> list = new ArrayList<>();
		list.add(max);
		Collections.sort(arr);
		list.addAll((arr));
		list.add(min);
		for (int a : list)
			System.out.print(a + " ");
		sc.close();
	}

}

import java.io.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class cf347a {

    public static void main(String[] args) throws IOException {
        int n = ri(), x[] = ria(n);
        prln(maxof(x) - minof(x));
        close();
    }

    static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out));
    static StringTokenizer input;
    static Random rand = new Random();

    // references
    // IBIG = 1e9 + 7
    // IRAND ~= 3e8
    // IMAX ~= 2e10
    // LMAX ~= 9e18
    // constants
    static final int IBIG = 1000000007;
    static final int IRAND = 327859546;
    static final int IMAX = 2147483647;
    static final int IMIN = -2147483648;
    static final long LMAX = 9223372036854775807L;
    static final long LMIN = -9223372036854775808L;
    // util
    static int minof(int a, int b, int c) {return min(a, min(b, c));}
    static int minof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}
    static long minof(long a, long b, long c) {return min(a, min(b, c));}
    static long minof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}
    static int maxof(int a, int b, int c) {return max(a, max(b, c));}
    static int maxof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}
    static long maxof(long a, long b, long c) {return max(a, max(b, c));}
    static long maxof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}
    static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
    static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
    static int floori(double d) {return (int)d;}
    static int ceili(double d) {return (int)ceil(d);}
    static long floorl(double d) {return (long)d;}
    static long ceill(double d) {return (long)ceil(d);}
    static void shuffle(int[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
    static void shuffle(long[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
    static void shuffle(double[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
    static <T> void shuffle(T[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); T swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
    static void rsort(int[] a) {shuffle(a); sort(a);}
    static void rsort(long[] a) {shuffle(a); sort(a);}
    static void rsort(double[] a) {shuffle(a); sort(a);}
    static int randInt(int min, int max) {return rand.nextInt(max - min + 1) + min;}
    // input
    static void r() throws IOException {input = new StringTokenizer(__in.readLine());}
    static int ri() throws IOException {return Integer.parseInt(__in.readLine());}
    static long rl() throws IOException {return Long.parseLong(__in.readLine());}
    static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;}
    static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;}
    static char[] rcha() throws IOException {return __in.readLine().toCharArray();}
    static String rline() throws IOException {return __in.readLine();}
    static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());}
    static int ni() {return Integer.parseInt(input.nextToken());}
    static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());}
    static long nl() {return Long.parseLong(input.nextToken());}
    // output
    static void pr(int i) {__out.print(i);}
    static void prln(int i) {__out.println(i);}
    static void pr(long l) {__out.print(l);}
    static void prln(long l) {__out.println(l);}
    static void pr(double d) {__out.print(d);}
    static void prln(double d) {__out.println(d);}
    static void pr(char c) {__out.print(c);}
    static void prln(char c) {__out.println(c);}
    static void pr(char[] s) {__out.print(new String(s));}
    static void prln(char[] s) {__out.println(new String(s));}
    static void pr(String s) {__out.print(s);}
    static void prln(String s) {__out.println(s);}
    static void pr(Object o) {__out.print(o);}
    static void prln(Object o) {__out.println(o);}
    static void prln() {__out.println();}
    static void pryes() {__out.println("yes");}
    static void pry() {__out.println("Yes");}
    static void prY() {__out.println("YES");}
    static void prno() {__out.println("no");}
    static void prn() {__out.println("No");}
    static void prN() {__out.println("NO");}
    static void pryesno(boolean b) {__out.println(b ? "yes" : "no");};
    static void pryn(boolean b) {__out.println(b ? "Yes" : "No");}
    static void prYN(boolean b) {__out.println(b ? "YES" : "NO");}
    static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
    static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
    static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); if(n >= 0) __out.println(iter.next());}
    static void h() {__out.println("hlfd");}
    static void flush() {__out.flush();}
    static void close() {__out.close();}
}

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/* Name of the class has to be "Main" only if the class is public. */
public class bbg
{
	public static int result;

public static ArrayList<Integer> [] graph;

public static int[]cats;

public static int vizitat[];
public static int x;
//public static HashMap<String, Integer> map2;

	public static void main (String[] args) throws java.lang.Exception
{

Scanner input=new Scanner(System.in);

HashMap<Integer, Integer> contor1= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> contor2= new HashMap<Integer, Integer>();

HashMap<Integer, Integer> map= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> map2= new HashMap<Integer, Integer>();
HashMap<String, Integer> combinari= new HashMap<String, Integer>();

		int n=input.nextInt();
		int v[]=new int[n];

		for(int i=0;i<n;i++){ v[i]=input.nextInt();}
		Arrays.sort(v);

		System.out.print(v[n-1]);
		for(int i=1;i<n-1;i++) System.out.print(v[i]+" ");
		System.out.print(v[0]);

}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main
{
  static BufferedReader reader;
  static StringTokenizer tokenizer;
  static PrintWriter writer;

  static int nextInt() throws IOException
  {
    return Integer.parseInt(nextToken());
  }

  static long nextLong() throws IOException
  {
    return Long.parseLong(nextToken());
  }

  static double nextDouble() throws IOException
  {
    return Double.parseDouble(nextToken());
  }

  static boolean eof = false;

  static String nextToken() throws IOException
  {
    while (tokenizer == null || !tokenizer.hasMoreTokens())
    {
      tokenizer = new StringTokenizer(reader.readLine());
    }
    return tokenizer.nextToken();
  }

  public static void main(String[] args) throws IOException
  {
    tokenizer = null;
    reader = new BufferedReader(new InputStreamReader(System.in));
    writer = new PrintWriter(System.out);
    banana();
    reader.close();
    writer.close();
  }

  static class Point
  {
    public long x, y;

    public Point(long x, long y)
    {
      this.x = x;
      this.y = y;
    }
  }

  static void banana() throws IOException
  {
    int n = nextInt();
    int a[] = new int[n];

    for (int i = 0 ; i < n; ++i)
      a[i] = nextInt();

    Arrays.sort(a);

    int min = a[0];
    int max = a[n-1];

    int b[] = new int[n-2];
    for (int i = 1 ; i < n-1; ++i)
      b[i-1] = a[i];

    System.out.print(max + " ");
    Arrays.sort(b);
    for (int i = b.length -1; i >= 0; --i)
      System.out.print(b[i] +  " ");
    System.out.println(min);

  }
}

import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int pos=0;
        int[] a=new int[n];
        for(int i=0;i<n;i++)
            a[i]=sc.nextInt();
        Arrays.sort(a);
        for(int i=0;i<n;i++){
             if(a[i]>=0){
                 pos=i;
                 break;
             }
        }
        int val=pos,sum=0,j=0;
          while(j<pos || val<n){
              if(j<pos){
            System.out.print(a[j]+" ");
          //    sum+=a[j];
              }
              if(val<n){
                  System.out.print(a[val]+" ");
          //  sum+=a[val];
              }
            j++;
            val++;
        }
        //  System.out.println(sum);
    }
}

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner fi = new Scanner (System.in);
        int n = fi.nextInt ();
        int A[] = new int [n];

        for (int i = 0; i < n; ++i) A[i] = fi.nextInt ();
        Arrays.sort(A);
        for (int i = n - 1; i >= 0; --i) System.out.print(A[i] + " ");
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class Difference {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();in.nextLine();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++)
			arr[i] = in.nextInt();
		Arrays.sort(arr);

			int help = arr[0];
			arr[0] = arr[n-1];
			arr[n-1] = help;

		for(int s : arr){
        System.out.print(s+" ");
        break;
		}
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class Prob347A {
	public static void main(String[] Args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int[] arr = new int[x];
		for (int i = 0; i < x; i++)
			arr[i] = scan.nextInt();
		Arrays.sort(arr);
		System.out.print(arr[0] + " ");
		for (int i = 1; i < x-1; i++)
			System.out.print(arr[i] + " ");
		System.out.print(arr[arr.length-1]);
	}
}

import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        try {
            if (new File("input.txt").exists())
                System.setIn(new FileInputStream("input.txt"));
        } catch (SecurityException e) {
        }
        new Main().run();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");

    private void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    final int MAXN = 101;
    final int INF = 100000;
    int[] a = new int[MAXN];
    int[] p = new int[MAXN];
    int n;
    private void solve() throws IOException {
        n = nextInt();
        int MAX = -INF;
        int MIN = INF;
        for(int i = 0; i < n; i++){
            a[i] = nextInt();
            if(a[i] < MIN)
                MIN = a[i];
            if(a[i] > MAX)
                MAX = a[i];
        }
        int NEEDR = MAX - MIN;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(i != j && a[i] - a[j]  == NEEDR && a[i] < MAX){
                    MAX = a[i];
                    MIN = a[j];
                }
            }
        }
        int cnt = 0;
        boolean getMax = false,getMin = false;
        for(int i = 0; i < n; i++){
            if(a[i] != MIN && a[i] != MAX){
                p[cnt++] = a[i];
            } else if(a[i] == MIN && getMin){
                p[cnt++] = a[i];
            } else if(a[i] == MAX && getMax){
                p[cnt++] = a[i];
            }
            else if(a[i] == MIN && !getMin ){
                getMin = true;
            } else if(a[i] == MAX && !getMax){
                getMax = true;
            }
        }
        sort(p,0,cnt);
        out.print(MAX);
        for(int i = 0; i < cnt; i++)
            out.print(" " + p[i]);
        out.println(" " + MIN);
    }

    void chk(boolean b) {
        if (b)
            return;
        System.out.println(new Error().getStackTrace()[1]);
        exit(999);
    }
    void deb(String fmt, Object... args) {
        System.out.printf(Locale.US, fmt + "%n", args);
    }
    String nextToken() throws IOException {
        while (!st.hasMoreTokens())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }
    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    String nextLine() throws IOException {
        st = new StringTokenizer("");
        return in.readLine();
    }
    boolean EOF() throws IOException {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return true;
            st = new StringTokenizer(s);
        }
        return false;
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws IOException {

		Solution sol = new Solution();
		System.out.println(sol.solution());
	}
}

class Solution{
	public String solution() throws NumberFormatException, IOException{
		BufferedReader r = new BufferedReader( new InputStreamReader(System.in));
		int N = Integer.parseInt(r.readLine());
		String[] sarr = r.readLine().split(" ");
		int[] arr = new int[N];
		for(int i = 0; i < N; i++){
			arr[i] = Integer.parseInt(sarr[i]);
		}
		Arrays.sort(arr);
		String ans = "";
		for(int i = N-1; i >= 0; i--)ans+= String.valueOf(arr[i]) + " ";
		ans = ans.substring(0,ans.length());
		return ans;
	}
}

import java.util.*;
import java.io.*;

public class One{
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());
        int min= Integer.parseInt(st.nextToken());
        int max= min;
        int []a = new int[n];
        a[0] = min;
        int minIndex = 0;
        int maxIndex = 0;
        for(int i=1; i<n; i++){
            a[i] = Integer.parseInt(st.nextToken());
            if(min > a[i]){
                min = a[i];
                minIndex = i;
            }
            if(max < a[i]){
                max = a[i];
                maxIndex = i;
            }
        }
        System.out.print(max);
        for(int i=0; i<n; i++){
            if(i==minIndex || i==maxIndex){
                continue;
            }
            System.out.print(" "+a[i]);
        }
        System.out.println(" "+min);
    }
}

import static java.lang.System.err;
import static java.lang.System.out;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.lang.reflect.Array;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
//import static adnap9.contests.cf.Utils.*;

public class A {

    public static void main(String[] args) {
        FastReader fr = new FastReader();
        int n = fr.nextInt();
        Integer[] t = fr.nextIntArray(n);
        int min = 0, max = n-1;
        for (int i = 0; i < n; i++) {
            if (t[i] < t[min]) min = i;
            if (t[i] > t[max]) max = i;
        }
        Utils.swap(t,0,max);
        Utils.swap(t,n-1,min);
        Utils.pr.printArray(t, " ");
        fr.close();
    }
}

class Printer {
    public Printer() {
    }
    public void println(String s) {
        out.println(s);
    }
    public void print(String s) {
        out.print(s);
    }
    public void ePrintln(String s) {
        err.println(s);
    }
    public void ePrint(String s) {
        err.print(s);
    }
    public <T> void printArray(T[] t) {
        for (T e : t) {
            println(e.toString());
        }
    }
    public <T> void printArray(T[] t, String sep) {
        for (T e : t) {
            print(e.toString() + sep);
        }
    }
    public <T> void ePrintArray(T[] t) {
        for (T e : t) {
            ePrintln(e.toString());
        }
    }
}
class FastReader extends CloseableTextParser {
    private StringTokenizer st;
    private BufferedReader br;
    private boolean isNext = true;
    private boolean closed = false;

    /***************/
    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
        // prepareTokenizer();
    }
    public FastReader(BufferedReader br) {
        this.br = br;
        // prepareTokenizer();
    }
    public FastReader(String s) {
        br = new BufferedReader(new StringReader(s));
        // prepareTokenizer();
    }
    /*******************/
    private void prepareTokenizer() {
        while (isNext == true && (st == null || !st.hasMoreTokens())) {
            try {
                String str = br.readLine();
                if (str == null) {
                    isNext = false;
                    st = null;
                } else {
                    st = new StringTokenizer(str);
                }
            } catch (IOException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }
    }
    private String nextToken(String delim) {
        if (closed) throw new IllegalStateException();
        prepareTokenizer();
        if (!isNext) throw new NoSuchElementException();
        String str = (delim != null) ? (st.nextToken(delim)) : (st.nextToken());
        // prepareTokenizer();
        return str;
    }
    private String nextToken() {
        return nextToken(null);
    }
    /*********************/
    public void close() {
        if (closed) throw new IllegalStateException();
        try {
            br.close();
            closed = true;
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
    public boolean hasNext() {
        return true;
    }
    /******************************/
    public String next() {
        return nextToken();
    }
    public String next(String delim) {
        return nextToken(delim);
    }
    public String nextLine() {
        return nextToken("\n");
    }
    public int nextInt() {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() {
        return Double.parseDouble(nextToken());
    }
    public char nextChar() throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }
    public byte nextByte() {
        return Byte.parseByte(nextToken());
    }
    public short nextShort() {
        return Short.parseShort(nextToken());
    }
    public boolean nextBoolean() {
        return Boolean.parseBoolean(nextToken());
    }
}
class Utils {
    public static <T extends Object> void fill2d(T[][] t, T el) {
        for (T[] t2 : t) {
            for (int i = 0; i < t2.length; i++) {
                t2[i] = el;
            }
        }
    }
    @SuppressWarnings("unchecked")
    public static <T> T[][] new2dArray(Class<T> c, int sx, int sy) {
        return (T[][]) Array.newInstance(c, sx, sy);
    }
    public static String merge(String[] st) {
        StringBuilder sb = new StringBuilder("");
        for (String s : st)
            sb.append(s);
        return sb.toString();
    }

    public static <T> void swap(T[] t, int p1, int p2) {
        T a = t[p1];
        t[p1] = t[p2];
        t[p2] = a;
    }

    public final static Printer pr = new Printer();

    private Utils() {
    }
}
abstract class CloseableTextParser extends ScannerLike implements Closeable, AutoCloseable {}
abstract class ScannerLike {
    public Integer[] nextIntArray(int n) {
        Integer[] t = new Integer[n];
        for (int i = 0; i < t.length; i++) {
            t[i] = nextInt();
        }
        return t;
    }
    public Long[] nextLongArray(int n) {
        Long[] t = new Long[n];
        for (int i = 0; i < t.length; i++) {
            t[i] = nextLong();
        }
        return t;
    }
    public Short[] nextShortArray(int n) {
        Short[] t = new Short[n];
        for (int i = 0; i < t.length; i++) {
            t[i] = nextShort();
        }
        return t;
    }
    public Byte[] nextByteArray(int n) {
        Byte[] t = new Byte[n];
        for (int i = 0; i < t.length; i++) {
            t[i] = nextByte();
        }
        return t;
    }
    public Boolean[] nextBooleanArray(int n) {
        Boolean[] t = new Boolean[n];
        for (int i = 0; i < t.length; i++) {
            t[i] = nextBoolean();
        }
        return t;
    }
    public String[] nextStringArray(int n, String delim) {
        String[] t = new String[n];
        for (int i = 0; i < t.length; i++) {
            t[i] = (delim != null) ? (next(delim)) : (next());
        }
        return t;
    }
    public String[] nextStringArray(int n) {
        return nextStringArray(n, null);
    }
    /*
     * public <T> T next(ObjectReaderFromText<T> p) { return p.loadFromInput(this); }
     */
    public abstract String next();
    public abstract boolean hasNext();
    public abstract byte nextByte();
    public abstract short nextShort();
    public abstract int nextInt();
    public abstract long nextLong();
    public abstract boolean nextBoolean();
    public abstract String nextLine();
    public abstract String next(String delim);
}

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {

    static class InputReader {

        final private int BUFFER_SIZE = 1 << 17;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public InputReader(InputStream in) {
            din = new DataInputStream(in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public byte next() {
            try {
                return read();
            } catch (Exception e) {
                throw new InputMismatchException();
            }
        }

        public String nextString() {
            StringBuilder sb = new StringBuilder("");
            byte c = next();
            while (c <= ' ') {
                c = next();
            }
            do {
                sb.append((char) c);
                c = next();
            } while (c > ' ');
            return sb.toString();
        }

        public int nextInt() {
            int ret = 0;
            byte c = next();
            while (c <= ' ') {
                c = next();
            }
            boolean neg = c == '-';
            if (neg) {
                c = next();
            }
            do {
                ret = (ret << 3) + (ret << 1) + c - '0';
                c = next();
            } while (c > ' ');
            if (neg) {
                return -ret;
            }
            return ret;
        }

        private void fillBuffer() {
            try {
                bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (bytesRead == -1) {
                buffer[0] = -1;
            }
        }

        private byte read() {
            if (bufferPointer == bytesRead) {
                fillBuffer();
            }
            return buffer[bufferPointer++];
        }
    }static StringBuffer str;
 public static StringBuffer getText()
   {
       return str;
   }
    public static void main(String arg[]) throws IOException {

        InputReader r=new InputReader(System.in);

      //  BufferedReader r=new BufferedReader(new FileReader("testcase.txt"));
     // BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter p = new PrintWriter(System.out, false);

      //StringTokenizer str=new StringTokenizer(r.readLine());
      int n=r.nextInt();
      int a[]=new int[n];
      int max=0;int min=Integer.MAX_VALUE;
      for(int i=0;i<n;i++)
      {
          a[i]=r.nextInt();

      }
      Arrays.sort(a);

      for(int i=n-1;i>=0;i--)
      {
          p.print(a[i]+" ");
      }
 p.flush();
    }}

import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class main {
    static StringBuilder out=new StringBuilder();
    static FastReader in=new FastReader();
    public static int[] getIntArray(int n){
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        return arr;
    }

    static int  mod=(int)1e9 +7;
    static int [][]dp;

    public static void solve(){
        int n=in.nextInt();
        Integer arr[]=new Integer[n];
        for(int i=0;i<arr.length;i++){
            arr[i]=in.nextInt();
        }
        Arrays.sort(arr, Collections.reverseOrder());
        for(int i=0;i<n;i++){
            out.append(arr[i]).append(' ');
        }
    }

    public static void main(String args[]){
        int t=1;
        while(t-->0){
            solve();
            out.append('\n');
        }
        System.out.println(out);
    }
}

class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

import java.io.*;
import java.math.BigInteger;
import java.util.*;

import static java.lang.Math.max;

public class MySolution
{

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
     }

    static class Task
    {
        public void solve(int testNumber, InputReader sc, PrintWriter out)
        {
            int n = sc.nextInt();

            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = sc.nextInt();
            }

            Arrays.sort(a);

            for (int i = 1; i < n / 2; i += 2)
            {
                int temp = a[i];
                a[i] = a[n - i - 1];
                a[n - i - 1] = temp;
            }

            for (int i = n - 1; i >= 0; i--)
            {
                out.print(a[i] + " ");
            }
        }
    }

    public static void sort(long[] array)
    {
        long min = Integer.MAX_VALUE;
        long max = Integer.MIN_VALUE;
        for (long element : array)
        {
            if (element < min)
            {
                min = element;
            }
            if (element > max)
            {
                max = element;
            }
        }
        long[] buckets = new long[(int) (max - min + 1)];
        for (long element : array)
        {
            buckets[(int) (element - min)]++;
        }
        int arrayIndex = 0;
        for (int i = 0; i < buckets.length; i++)
        {
            for (long j = buckets[i]; j > 0; j--)
            {
                array[arrayIndex++] = i + min;
            }
        }
    }

    public static class InputReader {
        private boolean finished = false;

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int peek() {
            if (numChars == -1) {
                return -1;
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    return -1;
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0) {
                s = readLine0();
            }
            return s;
        }

        public String readLine(boolean ignoreEmptyLines) {
            if (ignoreEmptyLines) {
                return readLine();
            } else {
                return readLine0();
            }
        }

        public BigInteger readBigInteger() {
            try {
                return new BigInteger(nextString());
            } catch (NumberFormatException e) {
                throw new InputMismatchException();
            }
        }

        public char nextCharacter() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            return (char) c;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public boolean isExhausted() {
            int value;
            while (isSpaceChar(value = peek()) && value != -1) {
                read();
            }
            return value == -1;
        }

        public String next() {
            return nextString();
        }

        public SpaceCharFilter getFilter() {
            return filter;
        }

        public void setFilter(SpaceCharFilter filter) {
            this.filter = filter;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
        public int[] nextIntArray(int n){
            int[] array=new int[n];
            for(int i=0;i<n;++i)array[i]=nextInt();
            return array;
        }
        public int[] nextSortedIntArray(int n){
            int array[]=nextIntArray(n);
            Arrays.sort(array);
            return array;
        }
        public int[] nextSumIntArray(int n){
            int[] array=new int[n];
            array[0]=nextInt();
            for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
            return array;
        }
        public long[] nextLongArray(int n){
            long[] array=new long[n];
            for(int i=0;i<n;++i)array[i]=nextLong();
            return array;
        }
        public long[] nextSumLongArray(int n){
            long[] array=new long[n];
            array[0]=nextInt();
            for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
            return array;
        }
        public long[] nextSortedLongArray(int n){
            long array[]=nextLongArray(n);
            Arrays.sort(array);
            return array;
        }
    }
    public static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(char[] array) {
            writer.print(array);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void print(int[] array) {
            for (int i = 0; i < array.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(array[i]);
            }
        }

        public void print(double[] array) {
            for (int i = 0; i < array.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(array[i]);
            }
        }

        public void print(long[] array) {
            for (int i = 0; i < array.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(array[i]);
            }
        }

        public void println(int[] array) {
            print(array);
            writer.println();
        }

        public void println(double[] array) {
            print(array);
            writer.println();
        }

        public void println(long[] array) {
            print(array);
            writer.println();
        }

        public void println() {
            writer.println();
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void print(char i) {
            writer.print(i);
        }

        public void println(char i) {
            writer.println(i);
        }

        public void println(char[] array) {
            writer.println(array);
        }

        public void printf(String format, Object... objects) {
            writer.printf(format, objects);
        }

        public void close() {
            writer.close();
        }

        public void flush() {
            writer.flush();
        }

        public void print(long i) {
            writer.print(i);
        }

        public void println(long i) {
            writer.println(i);
        }

        public void print(int i) {
            writer.print(i);
        }

        public void println(int i) {
            writer.println(i);
        }

        public void separateLines(int[] array) {
            for (int i : array) {
                println(i);
            }
        }
    }
}

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class A {

    public static void main(String[] args) {
        A solver = new A();
        solver.solve();
    }

    private void solve() {
        Scanner sc = new Scanner(System.in);
//        sc = new Scanner("5\n" +
//                "100 -100 50 0 -50\n");

        int n = sc.nextInt();

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);

        String[] b = new String[n - 2];
        for (int i = 1; i < n - 1; i++) {
            b[i - 1] = String.valueOf(a[i]);
        }
        Arrays.sort(b, new Comparator<String>() {
            @Override
            public int compare(String s, String s2) {
                return (s + s2).compareTo(s2 + s);
            }
        });

        System.out.print(a[n-1]);
        for (int i = 0; i < n - 2; i++) {
            System.out.print(" ");
            System.out.print(b[i]);
        }
        System.out.print(" ");
        System.out.print(a[0]);
        System.out.println();
    }

}

import java.util.Arrays;
import java.util.Scanner;

public class a_201 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] nums = new int[n];
		for (int i = 0; i < nums.length; i++)
			nums[i] = in.nextInt();
		Arrays.sort(nums);
		int st = 0, end = nums.length - 1;
		while (st < end) {
			if (st % 2 == 0) {
				int temp = nums[st];
				nums[st] = nums[end];
				nums[end] = temp;
			}
			st++;
			end--;
		}
		for (int i = 0; i < nums.length; i++) {
			if (i > 0)
				System.out.print(" ");
			System.out.print(nums[i]);
		}
		System.out.println();
	}
}

/* @@@@@@@@@@@@@@@@@@@@@@@
 * @@@ Doston Akhmedov @@@
 * @@@@@@@@@@@@@@@@@@@@@@@
 */

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;

public class r_201_a {
	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter pw;

	public static void main(String[] args) throws IOException {
		Locale.setDefault(Locale.US);
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
				System.out)));

		int n=nextInt();
		int a[]=new int[n+1];
		for (int i = 1; i <=n; i++) {
			a[i]=nextInt();
		}
		Arrays.sort(a,1,n+1);
		int ans[]=new int[n+1],k=n,l=0;
		for (int i = 1; i <=n; i++) {
				if(l%2==0)
				ans[i]=a[k--];
				else{
					ans[k]=a[k];
					k--;
				}
				l++;
		}
		for (int i = 1; i <=n; i++) {
			pw.print(ans[i]+" ");
		}
		pw.close();
	}

	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	private static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	private static String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main
{
    public static void main(String[] args) throws NumberFormatException, IOException {

        InputReader in = new InputReader(System.in);

        int n = in.nextInt();

        int min = 2000, min_idx = -1, max = -2000, max_idx = -1;
        int[]a =  new int[n];

        for(int i = 0; i < n; i++)
        {
            a[i] = in.nextInt();
            if(a[i] > max) {max = a[i]; max_idx = i;}
            if(a[i] < min) {min = a[i]; min_idx = i;}
        }

        swap(max_idx,0, a);
        if(min_idx != 0)
            swap(min_idx,n-1, a);
        Arrays.sort(a,1,n-1);

        for(int i = 0; i < n - 1; i++)
            System.out.print(a[i]+" ");
        System.out.println(a[n-1]);

    }

    static void swap(int i, int j, int[] a)
    {
        int tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
    }

    static class InputReader {
        StringTokenizer st;
        BufferedReader br;

        public InputReader(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {return Integer.parseInt(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public boolean ready() throws IOException {return br.ready();}

    }

}

import java.util.*;

public class cf347A{

	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();

		int min = 10000;
		int min_index = -1;
		int max = -10000;
		int max_index = -1;
		String[] arr = new String[n];

		for(int i=0; i<n; i++)
		{

			arr[i] = sc.next();
			if(Integer.parseInt(arr[i])<min)
			{
				min = Integer.parseInt(arr[i]);
				min_index = i;
			}
			if(Integer.parseInt(arr[i]) > max)
			{
				max = Integer.parseInt(arr[i]);
				max_index = i;

			}

		}

		if(n>0)
		{
		arr[min_index] = "--";
		arr[max_index] = "--";
		Arrays.sort(arr);

		System.out.print(max+" ");
		}
		for(int i=2; i<n; i++)
			System.out.print(arr[i]+" ");
		if(n>1)
		System.out.print(min);
	}

}

import java.util.Arrays;
import java.util.Scanner;

public class Problem4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n;
        n = scanner.nextInt();
        int[] input = new int[n];
        for (int i = 0; i < n; i++) {
            input[i] = scanner.nextInt();
        }
        Arrays.sort(input);
        for (int i = n - 1; i >= 0; i--) {
            if (i == 0) System.out.print(input[i]);
            else System.out.print(input[i] + " ");
        }
    }
}

import java.util.*;
public class Problem50 {

    public static void main(final String args[]) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int p = 0, m = 0;

        List<Integer> arrList = new ArrayList<Integer>();
        List<Integer> res = new ArrayList<Integer>();
        for(int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if(a > 0) {
                p++;
            }
            else {
                m++;
            }
            arrList.add(a);
        }

        Collections.sort(arrList);
        //System.out.println("aux " + arrList);

        int[] res11 = new int[n];
        if(m == 0) {
            int i = 0, j = arrList.size()-1, k = 0;
            while(i < j) {
                res11[k++] = arrList.get(j--);
                res11[k++] = arrList.get(i++);
            }
            if(i == j) {
                res11[k++] = arrList.get(i++);
            }
        }
        else {
            res11[0] = arrList.get(arrList.size()-1);
            res11[n-1] = arrList.get(0);
            for(int i1 = 1; i1 < n-1; i1++) {
                res11[i1] = arrList.get(i1);
            }

        }

        System.out.print(res11[0]);

        for(int i1 = 1; i1 < res11.length; i1++) {
            System.out.print(" " + res11[i1]);
        }
    }
}

import java.util.*;

public class cf347A{

	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();

		int min = 10000;
		int min_index = -1;
		int max = -10000;
		int max_index = -1;
		String[] arr = new String[n];

		for(int i=0; i<n; i++)
		{

			arr[i] = sc.next();
			if(Integer.parseInt(arr[i])<min)
			{
				min = Integer.parseInt(arr[i]);
				min_index = i;
			}
			if(Integer.parseInt(arr[i]) > max)
			{
				max = Integer.parseInt(arr[i]);
				max_index = i;

			}

		}

		arr[min_index] = "--";
		arr[max_index] = "--";
		Arrays.sort(arr);
		System.out.print(max+" ");
		for(int i=2; i<n; i++)
			System.out.print(arr[i]+" ");
		System.out.print(min);
	}

}

import java.io.*;
import java.util.*;

public class CF {

    public static void main(String[] args) throws IOException {
        //FastScanner in = new FastScanner(new FileInputStream(new File("input.txt")));
        //PrintWriter out = new PrintWriter(new File("output.txt"));
        FastScanner in = new FastScanner(System.in);
        int n = in.nextInt();
        int[] tab = in.nextArrayInt(n);
        Arrays.sort(tab);
        for (int i = 0; i < tab.length / 2; i++) {
            if (i % 2 == 0) {
                int temp = tab[i];
                tab[i] = tab[tab.length-1-i];
                tab[tab.length-1-i] = temp;
            }
        }
        for (int i = 0; i < tab.length; i++) {
            System.out.print(tab[i]+" ");
        }
        System.out.println();
    }

    public static ArrayList<Long> listCh = new ArrayList<>();

    public static String[] tabCh = {"4", "7"};

    public static void permutLucky(int i, String ch) {
        if (i == 11) {
            return;
        }
        for (int j = 0; j < tabCh.length; j++) {
            String string = ch + tabCh[j];
            listCh.add(Long.valueOf(string));
            permutLucky(i + 1, string);
        }
    }

    public static int sumTable(int[] tab, int indx) {
        if (indx == tab.length) {
            return 0;
        }
        return tab[indx] + sumTable(tab, indx + 1);
    }

    public static List<int[]> list = new LinkedList<>();

    public static void Permute(int[] input, int startindex) {
        int size = input.length;
        if (size == startindex + 1) {
            int[] tab = new int[size];
            for (int i = 0; i < tab.length; i++) {
                tab[i] = input[i];
            }
            list.add(tab);
        } else {
            for (int i = startindex; i < size; i++) {
                int temp = input[i];
                input[i] = input[startindex];
                input[startindex] = temp;
                Permute(input, startindex + 1);
                int temp2 = input[i];
                input[i] = input[startindex];
                input[startindex] = temp2;
            }
        }
    }

    public static int[] radixSort(int[] f) {
        return radixSort(f, f.length);
    }

    public static int[] radixSort(int[] f, int n) {
        int[] to = new int[n];
        {
            int[] b = new int[65537];
            for (int i = 0; i < n; i++) {
                b[1 + (f[i] & 0xffff)]++;
            }
            for (int i = 1; i <= 65536; i++) {
                b[i] += b[i - 1];
            }
            for (int i = 0; i < n; i++) {
                to[b[f[i] & 0xffff]++] = f[i];
            }
            int[] d = f;
            f = to;
            to = d;
        }
        {
            int[] b = new int[65537];
            for (int i = 0; i < n; i++) {
                b[1 + (f[i] >>> 16)]++;
            }
            for (int i = 1; i <= 65536; i++) {
                b[i] += b[i - 1];
            }
            for (int i = 0; i < n; i++) {
                to[b[f[i] >>> 16]++] = f[i];
            }
            int[] d = f;
            f = to;
            to = d;
        }
        return f;

    }

    private static class FastScanner {

        private final InputStream stream;
        private final byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextArrayInt(int n) {
            int tab[] = new int[n];
            for (int i = 0; i < n; i++) {
                tab[i] = nextInt();
            }
            return tab;
        }

        public String[] nextArrayString(int n) {
            String tab[] = new String[n];
            for (int i = 0; i < n; i++) {
                tab[i] = next();
            }
            return tab;
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = read();
            while (isEndline(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }
    }
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;

/**
 *
 * @author KANDARP
 */
public class CodeForses {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        ArrayList<Integer> positive=new ArrayList<Integer>();
        ArrayList<Integer> negative=new ArrayList<Integer>();
        int ans[]=new int[n];
        for(int i=0;i<n;i++){
            int a=in.nextInt();
            if(a<0){

                negative.add(a);
            }
            else{
                positive.add(a);
            }

        }
        Collections.sort(positive);
        Collections.sort(negative);
        int pos=0;
        while(!(positive.isEmpty() && negative.isEmpty())){

            if(positive.isEmpty()){

                for(int i=pos;i<n-pos;i++){
                    ans[i]=negative.remove(0);
                }

            }
            else if(negative.isEmpty()){
               // System.out.println(Arrays.toString(ans));
                for(int i=pos;i<n-pos;i++){
                 //   System.out.println(i);
                   // System.out.println(positive);
                    ans[i]=positive.remove(positive.size()-1);
                }

            }
            else{
                if(pos%2==0){
                ans[pos]=positive.remove(positive.size()-1);
                ans[n-pos-1]=negative.remove(0);}
                else{
                ans[n-pos-1]=positive.remove(positive.size()-1);
                ans[pos]=negative.remove(0);}

                pos++;
            }

        }
        for(int i=0;i<n;i++){
            System.out.print(ans[i]+" ");
        }
    }

}

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class A {
  static Map<Integer, Integer> pos = new HashMap<Integer, Integer>();
  static int[] best;
  static int maxVal = Integer.MIN_VALUE;

  public static void main(String[] args) throws FileNotFoundException {
    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();

    int[] arr = new int[n];

    for (int i = 0; i < n; i++) {
      int num = scan.nextInt();
      arr[i] = num;
      pos.put(num, i);
    }

    per(arr, 0);
    System.out.println(Arrays.toString(best));
  }

  static void per(int[] arr, int lo) {
    int len = arr.length;

    if (lo == len - 1) {
      int val = value(arr);
      if (val > maxVal) {
        maxVal = val;
        best = arr.clone();
      } else if (val == maxVal) {
        for (int i = 0; i < len && arr[i] <= best[i]; i++) {
          if (arr[i] < best[i]) {
            best = arr.clone();
            break;
          }
        }
      }

      return;
    }

    int[] copy = arr.clone();
    for (int i = lo; i < len; i++) {
      int fElem = arr[lo];
      int sElem = copy[i];
      swap(arr, lo, pos.get(sElem));
      pos.put(fElem, pos.get(sElem));
      pos.put(sElem, lo);
      per(arr, lo + 1);
    }
  }

  static int value(int[] arr) {
    int val = 0;
    int len = arr.length;
    for (int i = 1; i < len; i++) {
      val += arr[i - 1] - arr[i];
    }
    return val;
  }

  static void swap(int arr[], int i, int j) {
    int tmp = arr[i];
    arr[i] = arr[j];
    arr[j] = tmp;
  }

}

import java.util.Arrays;
import java.util.Scanner;

public class DifferenceRow {

    public static void main(String[] args) {
        int n = 0;
        int [] a;
        Scanner reader = new Scanner(System.in);
        n = reader.nextInt();
        reader.nextLine();
        a = new int[n];
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        int posMax = 0;
        int posMin = 0;

        for(int i = 0; i < n; i++){
            int v = reader.nextInt();
            if(v > max) {
                max = v;
                posMax = i;
            }
            else if(v < min){
                min = v;
                posMin = i;
            }
        }
        swap(a, posMax, 0);
        swap(a, posMin, n-1);
        Arrays.sort(a, 1, n-2);
        for(int i : a){
            System.out.print(i + " ");
        }
        System.out.println();
    }

    static void swap(int [] a, int p1, int p2){
        int x = a[p1];
        a[p1] = a[p2];
        a[p2] = x;
    }

}

import java.util.*;
public class tatti{

          public static void main(String dsgs[]){
                    Scanner s = new Scanner(System.in);
                    int n;
                    n = s.nextInt();
                    int a[] =new int[n];
                    for(int i=0;i<n;i++){
                              a[i] = s.nextInt();
                    }
                    int max =Integer.MIN_VALUE;
                    int min = Integer.MAX_VALUE;
                    int x=0,y=0;
                    for(int i=0;i<n;i++){
                              if(max<a[i]){
                                        x = i;
                                        max = a[i];
                              }
                              if(min>a[i]){
                                        y = i;
                                        min = a[i];
                              }

                    }
                    int temp = a[x];
                    a[x] = a[0];
                    a[0] = temp;
                    temp = a[n-1];
                    a[n-1] = a[y];
                    a[y] = temp;
                    Arrays.sort(a,1,n-1);
                    for(int i=0;i<n;i++)
                              System.out.print(a[i]+" ");
          }
}

import java.util.List;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.math.BigDecimal;
import java.io.BufferedWriter;
import java.util.Locale;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Jacob Jiang
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.nextInt();
        int[] a = in.nextIntArray(n);
        Arrays.sort(a);
        int i = 0, j = n - 1;
        List<Integer> answer = new ArrayList<Integer>();
        while (i <= j) {
            if (i == j) {
                answer.add(a[i]);
                break;
            } else {
                answer.add(a[i++]);
                answer.add(a[j--]);
            }
        }
        out.printLine(answer.toArray());
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1 << 16];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c & 15;
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public int[] nextIntArray(int count) {
        int[] result = new int[count];
        for (int i = 0; i < count; i++) {
            result[i] = nextInt();
        }
        return result;
    }

    }

class OutputWriter {
    private PrintWriter writer;

    public OutputWriter(OutputStream stream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object obj) {
        writer.print(obj);
    }

    public void println() {
        writer.println();
    }

    public void print(char c) {
        writer.print(c);
    }

    public void close() {
        writer.close();
    }

    public void printItems(Object... items) {
        for (int i = 0; i < items.length; i++) {
            if (i != 0) {
                print(' ');
            }
            print(items[i]);
        }
    }

    public void printLine(Object... items) {
        printItems(items);
        println();
    }

    }

import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String args[])
	{

		Scanner cin = new Scanner(System.in);
		int n = cin.nextInt();
		System.out.println(n);
		List<Integer> a = new ArrayList<Integer>();
		for(int i = 0; i < n; ++ i) a.add(cin.nextInt());
		Collections.sort(a);
		Integer b = new Integer(a.get(n - 1));
		a.set(n - 1, a.get(0));
		a.set(0, b);

		for(int i = 0; i < n; ++ i) System.out.printf("%d ", a.get(i).intValue());

	}
}

import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;

public class DifferenceRow{
	private static void swap(int[] a, int i, int j){
		int tmp=a[i];
		a[i]=a[j];
		a[j]=tmp;
		return;
	}
	public static void main(String[] argv) throws Exception{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine().trim());
		int[] a=new int[n];
		String[] words=br.readLine().trim().split(" ");
		a[0]=Integer.parseInt(words[0]);
		int min=a[0], max=a[0];
		int minIndex=0, maxIndex=0;
		for(int i=1; i<n; i++){
			a[i]=Integer.parseInt(words[i]);
			if(a[i]<min){
				min=a[i];
				minIndex=i;
			}
			if(a[i]>max){
				max=a[i];
				maxIndex=i;
			}
		}
		if(n>2){
			swap(a, 0, maxIndex);
			swap(a, n-1, minIndex);
		}else{
			swap(a, 0, maxIndex);
		}
		if(n>=4){
			Arrays.sort(a, 1, n-1);
		}
		for(int i=0; i<n; i++){
			System.out.print(a[i]+" ");
		}
		System.out.println();
	}
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import static java.lang.Math.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Stack;
import java.util.StringTokenizer;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Trung Pham
 */
public class A {

    public static int[] x = {0, 1, 0, -1, -1, 1, -1, 1};
    public static int[] y = {1, 0, -1, 0, 1, -1, -1, 1};

    public static void main(String[] args) {
        Scanner in = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int []data = new int[n];

        for(int i = 0; i < n ; i++){
            data[i] = in.nextInt();
        }
        Arrays.sort(data);
        int start = data[n - 1];
        int end = data[0];
        String [] other = new String [n - 2];
        for(int i = 1; i < n - 1; i++){
            other[i - 1] = "" + data[i];
        }
        Arrays.sort(other);
        out.print(start + " ");
        for(int i = 0 ; i < n - 2; i++){
            out.print(other[i] + " ");
        }
        out.print(end);
        out.close();
    }

    static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    static int pow(int a, int b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        int val = pow(a, b / 2);
        if (b % 2 == 0) {

            return val * val;
        } else {
            return val * val * a;
        }
    }

//    static Point intersect(Point a, Point b, Point c) {
//        double D = cross(a, b);
//        if (D != 0) {
//            return new Point(cross(c, b) / D, cross(a, c) / D);
//        }
//        return null;
//    }
//
//    static Point convert(Point a, double angle) {
//        double x = a.x * cos(angle) - a.y * sin(angle);
//        double y = a.x * sin(angle) + a.y * cos(angle);
//        return new Point(x, y);
//    }
    static Point minus(Point a, Point b) {
        return new Point(a.x - b.x, a.y - b.y);
    }

    static Point add(Point a, Point b) {
        return new Point(a.x + b.x, a.y + b.y);
    }

    static double cross(Point a, Point b) {
        return a.x * b.y - a.y * b.x;
    }

    static class Point {

        int x, y;

        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public String toString() {
            return "Point: " + x + " " + y;
        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            //System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class DifferenceRow {

	public static void main(String[] args) {
		int n = 0;
		int [] a;
		Scanner reader = new Scanner(System.in);
		n = reader.nextInt();
		a = new int[n];
		int max = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		int posMax = 0;
		int posMin = 0;

		for(int i = 0; i < n; i++){
			int v = reader.nextInt();
			if(v > max) {
				max = v;
				posMax = i;
			}
			else if(v < min){
				min = v;
				posMin = i;
			}
		}
		swap(a, posMax, 0);
		swap(a, posMin, n-1);
		Arrays.sort(a, 1, n-2);
		for(int i : a){
			System.out.print(i + " ");
		}
		System.out.println();
	}

	static void swap(int [] a, int p1, int p2){
		int x = a[p1];
		a[p1] = a[p2];
		a[p2] = x;
	}

}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A {
	static BufferedReader br;
	static PrintWriter pw;
	static StringTokenizer st;

	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	private static String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
				System.out)));
		int n = nextInt();
		Integer a[] = new Integer[n];
		Integer b[] = new Integer[n];
		int t = 0;
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
			if (a[i] < 0)
				b[t++] = i;
		}
		for (int i = 0; i < n; i++) {
			if (a[i] >= 0) {
				pw.print(a[i] + " ");
				if (t >0)
					pw.print(a[b[--t]] + " ");
			}
		}
		pw.close();
	}
}

import java.io.*;
import java.util.Arrays;
public class CodeForce1{

public static void main(String args[])throws IOException{

	BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
	int n=Integer.parseInt(in.readLine());
	String s[]=in.readLine().split(" ");
	int i=0,max,min;

	int arr[]=new int[n];
	while(i<n){
		int num=Integer.parseInt(s[i]);
		arr[i]=num;
		i++;
	}
	Arrays.sort(arr);
	i=n-1;
	while(i>=0){
		System.out.print(arr[i]+" ");
		i--;
	}
	System.out.println();

	}

}

import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
            try (PrintWriter out = new PrintWriter(outputStream)) {
                TaskB solver = new TaskB();
                solver.solve(1, in, out);
            }
    }
}
class TaskB {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int a[] = new int[n];
        for(int i = 0; i < n; ++i){
            a[i] = in.nextInt();
        }
        int tmp = a[0];
        a[0] = a[n - 1];
        a[n - 1] = tmp;
        for(int m : a){
            out.print(m + " ");
        }
    }
}

class InputReader {
    private final BufferedReader reader;
    private StringTokenizer tokenizer;
    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class Difference {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();in.nextLine();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++)
			arr[i] = in.nextInt();
		Arrays.sort(arr);
		if(arr[0] < 0){
			int help = arr[0];
			arr[0] = arr[n-1];
			arr[n-1] = help;
		}
		for(int s : arr){
        System.out.print(s+" ");
        break;
		}
	}
}

import java.io.*;
import java.sql.Array;
import java.util.*;
import java.*;
import java.math.BigInteger;
import java.util.Random;

import javax.annotation.Generated;

public class zad {
    private static BufferedReader in;
    private static StringTokenizer tok;
    private static PrintWriter out;
    final static boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") !=null;

    static void init() throws FileNotFoundException{
        if(ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
        else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    private static String readString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    private static int readInt() throws IOException {
        return Integer.parseInt(readString());
    }
    private static double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }
    private static long readLong() throws IOException {
        return Long.parseLong(readString());
    }
    public static void Solve1() throws IOException{
        int n = readInt();
        int[] mas = new int[n];

        for(int i =0; i<n;i++){
            mas[i] = readInt();

        }
        Arrays.sort(mas);
        int k=1;
        int j=n-1;
        while(k<j){

            out.print(mas[j]+" "+mas[k]+" ");

            k++;
            j--;
        }
        out.print(mas[0]);

    }

    public static void main(String[] args) throws IOException {

        init();
        Solve1();

        in.close();
        out.close();
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class DifferenceRow {

    public static void main(String[] args) {
        int n = 0;
        int [] a;
        int [] res;
        Scanner reader = new Scanner(System.in);
        n = reader.nextInt();
        a = new int[n];
        res = new int[n];
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        int posMax = 0;
        int posMin = 0;

        for(int i = 0; i < n; i++){
            int v = reader.nextInt();
            a[i] = v;
            if(v > max) {
                max = v;
                posMax = i;
            }
            if(v < min){
                min = v;
                posMin = i;
            }
        }

        res[0] = max;
        res[n-1] = min;
        for(int i = 0; i < n; i++){
            if(i == 0 && posMax != n - 1 && posMax != 0) res[posMax] = a[i];
            else if(i == n - 1 && posMin != n - 1 && posMin != 0) res[posMin] = a[i];
            else if(i > 0 && i < n-1 && i != posMax && i != posMin) res[i] = a[i];
        }

        Arrays.sort(res, 1, n-1);
        for(int i : res){
            System.out.print(i + " ");
        }
        System.out.println();
    }

}

import java.util.*;

public class Difference {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    ArrayList<Integer> list = new ArrayList();
    for(int i = 0; i < n; i++) {
      list.add(in.nextInt());
    }
    Collections.sort(list);

    for(int i = n-1; i >= 0; i--) System.out.print (list.get(i) + " ");
  }
}

import java.io.*;
import java.sql.Array;
import java.util.*;
import java.*;
import java.math.BigInteger;
import java.util.Random;

import javax.annotation.Generated;

public class zad {
    private static BufferedReader in;
    private static StringTokenizer tok;
    private static PrintWriter out;
    final static boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") !=null;

    static void init() throws FileNotFoundException{
        if(ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
        else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    private static String readString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    private static int readInt() throws IOException {
        return Integer.parseInt(readString());
    }
    private static double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }
    private static long readLong() throws IOException {
        return Long.parseLong(readString());
    }
    public static void Solve1() throws IOException{
        int n = readInt();
        int[] mas = new int[n];

        for(int i =0; i<n;i++){
            mas[i] = readInt();

        }
        Arrays.sort(mas);
        int k=1;
        int j=n-1;
        while(k<=j){

            if(k==j){
                out.print(mas[k]+" ");
            }
            else
            out.print(mas[j]+" "+mas[k]+" ");

            k++;
            j--;
        }
        out.print(mas[0]);

    }

    public static void main(String[] args) throws IOException {

        init();
        Solve1();

        in.close();
        out.close();
    }
}

import java.io.*;
import java.util.*;

public class Main {
  public static void main(String args[]) throws IOException {
    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    String line;
    String[] prms;

    line = stdin.readLine();
    int n = Integer.parseInt(line);

    int[] a = new int[n];
    line = stdin.readLine();
    prms = line.split(" ");
    for(int i = 0; i < n; i++){
      a[i] = Integer.parseInt(prms[i]);
    }
    Arrays.sort(a);

    int[] x = new int[n];
    for (int i = 0; i < n/2; i++) {
      if (i % 2 == 0) {
        x[i] = a[n-i-1];
        x[n-i-1] = a[i];
      } else {
        x[i] = a[i];
        x[n-i-1] = a[n-i-1];
      }
    }
    if (n % 2 == 1) {
      x[n/2] = a[n/2];
    }

    for (int i = 0; i < n; i++) {
      if (i > 0) System.out.print(" ");
      System.out.print(x[i]);
    }
    System.out.println();
  }
}

import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

    public static void main(String args[]) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = t_int(br);
        int[] a = t_int_a(br, n);

        Arrays.sort(a);

        for (int i = 0; i < n / 2; i+=2) {
            swap(a, i, n - i - 1);
        }

        for (int i = 0; i < n - 1; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println(a[a.length - 1]);

        br.close();
    }

    public static void swap(int[] arr, int a, int b) {
        int temp = arr[a];
        arr[a] = arr[b];
        arr[b] = temp;
    }

    public static int t_int(BufferedReader br) throws Exception {
        return Integer.parseInt(br.readLine());
    }

    public static StringTokenizer t_st(BufferedReader br) throws Exception {
        return new StringTokenizer(br.readLine());
    }

    public static int[] t_int_a(BufferedReader br, int n) throws Exception {
        StringTokenizer st = t_st(br);
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(st.nextToken());
        }
        return a;
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class DifferenceRow {

    public static void main(String[] args) {
        int n = 0;
        int [] a;
        Scanner reader = new Scanner(System.in);
        n = reader.nextInt();
        a = new int[n];
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        int posMax = 0;
        int posMin = 0;

        for(int i = 0; i < n; i++){
            int v = reader.nextInt();
            a[i] = v;
            if(v > max) {
                max = v;
                posMax = i;
            }
            if(v < min){
                min = v;
                posMin = i;
            }
        }
        swap(a, 0, posMax);
        if(a[n-1] != min){
            swap(a, n-1, posMin);
        }
        Arrays.sort(a, 1, n-1);
        for(int i : a){
            System.out.print(i + " ");
        }
        System.out.println();
    }

    static void swap(int [] a, int p1, int p2){
        int x = a[p1];
        a[p1] = a[p2];
        a[p2] = x;
    }

}

import java.util.Arrays;
import java.util.Scanner;

public class Problem4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n;
        n = scanner.nextInt();
        int[] input = new int[n];
        for (int i = 0; i < n; i++) {
            input[i] = scanner.nextInt();
        }
        Arrays.sort(input);
        for (int i = n - 1; i >= 0; i--) {
            if (i == 0) System.out.print(input[i]);
            else System.out.print(input[i] + " ");
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.Arrays;
import java.util.*;

public class codefo
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static int gcd(int a,int b)
    {
        return b==0?a:gcd(b,a%b);
    }

    public boolean isPrime(long n)
    {
        if(n==2)return true;
        int i=2;
        while(i*i<=n)
        {
            if(n%i==0) return false;
            i++;
        }
        return true;
    }

    public static long remove(long n)
    {
        long res=0;
        int ten=1;
        while(n>0)
        {
            long dig=n%10;
            n=n/10;
            if(dig>0)
            {
                res+=dig*ten;
                ten=ten*10;
            }
        }
        return res;
    }

    public static void main(String[] args)
    {
        FastReader ob=new FastReader();

        int t=ob.nextInt();
        int a[]=new int[t];
        for(int i=0;i<t;i++)
        {
        	a[i]=ob.nextInt();
        }
        Arrays.sort(a);
        for(int i=0;i<t;i++)
        	System.out.print(a[i]+" ");
	}
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

/**
 * <b> Algorithm on Codeforces. Problem E div 2 </b> </br>
 *
 * @author Huynh Quang Thao
 *
 */
public class Main {

    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.run();
    }

    public void run() throws Exception {
        PrintWriter pr = null;
        InputReader sc = null;

        pr=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        sc = new InputReader(System.in);
    //  sc = new InputReader(new FileInputStream(new File("input.txt")));

        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) arr[i] = sc.nextInt();

        Arrays.sort(arr);

        System.out.printf("%d ", arr[0]);
        for (int i = 1; i <= arr.length - 2; i++) System.out.printf("%d ", arr[i]);
        System.out.printf("%d", arr[arr.length-1]);

        pr.close();
    }

    static class InputReader {
        public BufferedReader reader;

        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
                catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public float nextFloat() {
            return Float.parseFloat(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }

    }
}

import java.util.*;
import java.lang.Math;
public class A221 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] val = new int[n];
        for(int i=0; i<n; i++)
            val[i] = scan.nextInt();
        Arrays.sort(val);
        if(n % 2 == 1) {
            int a = 1; int b = n-1;
            while(a<n && b>=0) {
                System.out.print(val[b] + " " + val[a] + " ");
                a+=2; b-=2;
            }
            if(b>=0)
                System.out.println(val[b]);
        }
        else {
            int a = 1; int b = n-2;
            while(a<n && b>=0) {
                System.out.print(val[b] + " " + val[a] + " ");
                a+=2; b-=2;
            }
            if(b>=0)
                System.out.println(val[b]);
        }
    }
}

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner fi = new Scanner (System.in);
        int n = fi.nextInt ();
        int A[] = new int [n];

        for (int i = 0; i < n; ++i) A[i] = fi.nextInt ();
        Arrays.sort(A);
        for (int i : A) System.out.print(i + " ");
    }
}

import java.util.*;

public class cf347A{

	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();

		int min = 10000;
		int min_index = -1;
		int max = -10000;
		int max_index = -1;
		String[] arr = new String[n];

		for(int i=0; i<n; i++)
		{

			arr[i] = sc.next();
			if(Integer.parseInt(arr[i])<min)
			{
				min = Integer.parseInt(arr[i]);
				min_index = i;
			}
			if(Integer.parseInt(arr[i]) > max)
			{
				max = Integer.parseInt(arr[i]);
				max_index = i;

			}

		}

		arr[min_index] = "9999";
		arr[max_index] = "9999";
		Arrays.sort(arr);

		System.out.print(max+" ");

		for(int i=0; i<n-2; i++)
			System.out.print(arr[i]+" ");

		System.out.print(min);
	}

}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{

	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i;
		int a[] = new int[n];
		for(i=0;i<n;i++)
		{
		  a[i] = sc.nextInt();
		}
		int temp = a[0];
		a[0] = a[n-1];
		a[n-1] = temp;
		for(i=0;i<n;i++)
		{
		    System.out.print(a[i]+" ");
		}
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws IOException {

		Solution sol = new Solution();
		System.out.println(sol.solution());
	}
}

class Solution{
	public String solution() throws NumberFormatException, IOException{
		BufferedReader r = new BufferedReader( new InputStreamReader(System.in));
		int N = Integer.parseInt(r.readLine());
		String[] sarr = r.readLine().split(" ");
		int[] arr = new int[N];
		for(int i = 0; i < N; i++){
			arr[i] = Integer.parseInt(sarr[i]);
		}
		Arrays.sort(arr);
		String ans = "";
		for(int i = N-1; i >= 0; i--)ans+= String.valueOf(arr[i]) + " ";
		ans = ans.substring(0,ans.length()-1);
		return ans;
	}
}

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class A {

    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();

        int a[] = new int[n];

        a[0] = s.nextInt();
        int min = a[0], max = a[0], mini = 0, maxi = 0;

        for (int i = 1; i < n; i++) {
            a[i] = s.nextInt();

            if (a[i] < min) {
                min = a[i];
                mini = i;
            } else if (a[i] > max) {
                max = a[i];
                maxi = i;
            }
        }

        String[] l = new String[n - 2];

        if (mini == maxi) {
            mini = 0;
            maxi = n - 1;
        }

        int x = 0;
        for (int i = 0; i < n; i++)
            if (i != mini && i != maxi)
                l[x++] = a[i] + "";

        Arrays.sort(l);

        System.out.print(a[maxi] + " ");
        for (int i = 0; i < n - 2; i++)
            System.out.print(l[i] + " ");
        System.out.println(a[mini]);

    }

}

import java.util.*;
public class Problem50 {

    public static void main(final String args[]) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int p = 0, m = 0;

        List<Integer> arrList = new ArrayList<Integer>();
        List<Integer> res = new ArrayList<Integer>();
        for(int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if(a > 0) {
                p++;
            }
            else {
                m++;
            }
            arrList.add(a);
        }

        Collections.sort(arrList);
        //System.out.println("aux " + arrList);

        int[] res11 = new int[n];
        if(m == 0) {
            int i = 0, j = arrList.size()-1, k = 0;
            while(i < j) {
                res11[k++] = arrList.get(j--);
                res11[k++] = arrList.get(i++);
            }
            if(i == j) {
                res11[k++] = arrList.get(i++);
            }
        }
        else {
            int i = 0, j = arrList.size()-1, k = 0;
            while(k < n/2) {
                if(k%2 == 0){
                    res11[k] = arrList.get(j--);
                    res11[n-k-1] = arrList.get(i++);
                }
                else {
                    res11[n-k-1] = arrList.get(j--);
                    res11[k] = arrList.get(i++);
                }

                k++;
            }
        }

        System.out.print(res11[0]);

        for(int i1 = 1; i1 < res11.length; i1++) {
            System.out.print(" " + res11[i1]);
        }
    }
}

import java.util.*;
import java.io.*;

public class One{
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());
        int min= Integer.parseInt(st.nextToken());
        int max= min;
        int []a = new int[n];
        a[0] = min;
        int minIndex = 0;
        int maxIndex = 0;
        for(int i=1; i<n; i++){
            a[i] = Integer.parseInt(st.nextToken());
            if(min > a[i]){
                min = a[i];
                minIndex = i;
            }
            if(max < a[i]){
                max = a[i];
                maxIndex = i;
            }
        }
        System.out.print(max);
        for(int i=0; i<n; i++){
            if(i==minIndex || i==maxIndex){
                continue;
            }
            System.out.print(" "+a[i]);
        }
        System.out.println(" "+min);
    }
}

import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

public class CF {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		LinkedList<Integer> LL = new LinkedList<Integer>();
		while(N-->0){
			LL.add(sc.nextInt());
		}
		Collections.sort(LL);
		LinkedList<Integer> L = new LinkedList<Integer>();
		LinkedList<Integer> R = new LinkedList<Integer>();
		int thing = 0;
		while(LL.size()>1){
			if(thing==0){
				thing = 1;
				L.add(LL.pollFirst());
				R.add(LL.pollLast());
			}
			else{
				thing = 0;
				R.add(LL.pollFirst());
				L.add(LL.pollLast());
			}
		}
		Collections.reverse(L);
		Collections.reverse(R);
		while(!L.isEmpty()){
			LL.addFirst(L.poll());
			LL.addLast(R.poll());
		}
		Collections.reverse(LL);
		for(Integer x : LL){
			System.out.print(x+" ");
		}

	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws IOException {

		Solution sol = new Solution();
		System.out.println(sol.solution());
	}
}

class Solution{
	public String solution() throws NumberFormatException, IOException{
		BufferedReader r = new BufferedReader( new InputStreamReader(System.in));
		int N = Integer.parseInt(r.readLine());
		String[] sarr = r.readLine().split(" ");
		int[] arr = new int[N];
		for(int i = 0; i < N; i++){
			arr[i] = Integer.parseInt(sarr[i]);
		}
		Arrays.sort(arr);
		String ans = "";
		for(int i = N-1; i >= 0; i--)ans+= String.valueOf(arr[i]) + " ";
		ans = ans.substring(0,ans.length());
		return ans;
	}
}

import java.io.*;
import java.util.*;

public class Main {

    static BufferedReader br;
    static PrintWriter out;
    static StringTokenizer st;

    static void solve() throws Exception {
        int n = nextInt();
        Integer[] a = new Integer[n];
        Integer[] b = new Integer[n];
        for(int i = 0; i < n; i++) {
            a[i] = nextInt();
            b[i] = a[i];
        }
        Arrays.sort(a);
        Arrays.sort(b, Collections.reverseOrder());
        int[] c = new int[n];
        for(int i = 0; i < n/2; i++) {
            c[i] = (i % 2 == 0) ? b[i] : a[i];
            c[n - i - 1] = (i % 2 == 0) ? a[i] : b[i];
        }
        if(n % 2 != 0) {
            c[n/2] = b[n/2];
        }
        for(int i = 0; i < n; i++) {
            out.print(c[i] + " ");
        }
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String line = br.readLine();
            if (line == null) {
                return null;
            }
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }

    public static void main(String[] args) {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new PrintStream(System.out));
            solve();
            out.close();
            br.close();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }

}

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/* Name of the class has to be "Main" only if the class is public. */
public class bbg
{
	public static int result;

public static ArrayList<Integer> [] graph;

public static int[]cats;

public static int vizitat[];
public static int x;
//public static HashMap<String, Integer> map2;

	public static void main (String[] args) throws java.lang.Exception
{

Scanner input=new Scanner(System.in);

HashMap<Integer, Integer> contor1= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> contor2= new HashMap<Integer, Integer>();

HashMap<Integer, Integer> map= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> map2= new HashMap<Integer, Integer>();
HashMap<String, Integer> combinari= new HashMap<String, Integer>();

		int n=input.nextInt();
		int v[]=new int[n];

		for(int i=0;i<n;i++){ v[i]=input.nextInt();}
		Arrays.sort(v);

		int vectora[]=new int[(n+1)/2];
		int vectorb[]=new int[(1+n)/2];

		vectora[0]=n;
		vectorb[0]=1;

	//	System.out.println("0 "+vectora[0]+" "+vectorb[0]);

		for(int i=1;i<(n)/2;i++)
		{
		if(i%2==1)

		{
		 vectora[i]=vectorb[i-1]+1;

		vectorb[i]=vectora[i-1]-1;

		}

		else {

		vectora[i]=vectorb[i-1]-1; vectorb[i]=vectora[i-1]+1;

		}

//		System.out.println(i+" "+vectora[i]+" "+vectorb[i]);
		}

		int rez[]=new int[n];
		int contor=0;

		for(int i=0;i<n/2;i++)

	{	rez[contor]=vectora[i]-1;contor++;
	 //System.out.println("* "+rez[contor-1]);
	}

	int part=-1;

		if (n%2==0 ) part=n/2-1;
		else part=n/2-1;

		for(int i=part;i>=0;i--){

		 if(i>=0 && contor<n)

	{	rez[contor]=vectorb[i]-1;
		contor++;
	 //		System.out.println("* i= "+i+" "+rez[contor-1]);

	}

		}

	//	for(int i=0;i<n;i++)
	//	System.out.println(i+" "+rez[i]);

		for(int i=0;i<n;i++) System.out.print(v[i]+" ");

		}

		}

import java.util.Arrays;
import java.util.Scanner;

public class Prob347A {
	public static void main(String[] Args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int[] arr = new int[x];
		for (int i = 0; i < x; i++)
			arr[i] = scan.nextInt();
		Arrays.sort(arr);
		System.out.print(arr[0] + " ");
		for (int i = 1; i < x-1; i++)
			System.out.print(arr[i] + " ");
		System.out.print(arr[arr.length-1]);
	}
}

import java.util.*;

public class A347 {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();

		int[] ar = new int[n];
		for (int i = 0; i < n; i++) {
			ar[i] = scan.nextInt();
		}

		Arrays.sort(ar);

		for (int i = 0; i < n; i++) {
			System.out.print(ar[n - i - 1] + " ");
		}
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class DifferenceRow {

    public static void main(String[] args) {
        int n = 0;
        int [] a;
        int [] res;
        Scanner reader = new Scanner(System.in);
        n = reader.nextInt();
        a = new int[n];
        res = new int[n];
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        int posMax = 0;
        int posMin = 0;

        for(int i = 0; i < n; i++){
            int v = reader.nextInt();
            a[i] = v;
            if(v > max) {
                max = v;
                posMax = i;
            }
            if(v < min){
                min = v;
                posMin = i;
            }
        }

        res[0] = max;
        res[n-1] = min;
        for(int i = 0; i < n; i++){
            if(i == 0 && posMax != n - 1 && posMax != 0) res[posMax] = a[i];
            else if(i == n - 1 && posMin != n - 1 && posMin != 0) res[posMin] = a[i];
            else if(i > 0 && i < n-1 && i != posMax && i != posMin) res[i] = a[i];
        }

        Arrays.sort(res, 1, n-1);
        for(int i : res){
            System.out.print(i + " ");
        }
        System.out.println();
    }

}

    import java.util.Arrays;
    import java.util.Scanner;

    public class BlackJack {
        private static void swap(int[] arr, int i,int j){
            int temp=arr[i];
            arr[i]=arr[j];
            arr[j]=temp;
        }

        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int n=in.nextInt();
            int [] arr= new int[n];
            for(int i=0;i<n;i++){
                arr[i]=in.nextInt();
            }
            Arrays.sort(arr);
            for(int i=1,j=n-2;i<j;i+=2,j-=2){
                swap(arr,i,j);

            }

            for(int i=n-1;i>=0;i--)
                System.out.print(arr[i] + " ");
        }

    }

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.SortedSet;
import java.util.TreeSet;

public class DifferenceRow {
	public static SortedSet<String> res = new TreeSet<String>();
	public static int max = Integer.MIN_VALUE;
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();in.nextLine();
		List<Integer> list = new ArrayList<Integer>();
		for(int i = 0; i < n; i++)
			list.add(in.nextInt());
		permute(list,0);
		for(String s : res){
			String ans = s.substring(1, s.length()-1);
			System.out.println(ans.replaceAll(",", ""));
			break;
		}
	}
	public static void permute(List<Integer> arr, int k){
        for(int i = k; i < arr.size(); i++){
            java.util.Collections.swap(arr, i, k);
            permute(arr, k+1);
            java.util.Collections.swap(arr, k, i);
        }
        if (k == arr.size() -1){
         int val = arr.get(0) - arr.get(k);
         if(val == max)
        	 res.add(arr.toString());
         else if(val > max){
        	 res.clear();
        	 max = val;
        	 res.add(arr.toString());
         }
        }
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class a_201 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] nums = new int[n];
		for (int i = 0; i < nums.length; i++)
			nums[i] = in.nextInt();
		Arrays.sort(nums);
		int st = 0, end = nums.length - 1;
		while (st < end) {
			if (st % 2 == 0) {
				int temp = nums[st];
				nums[st] = nums[end];
				nums[end] = temp;
			}
			st++;
			end--;
		}
		for (int i = 0; i < nums.length; i++) {
			if (i > 0)
				System.out.print(" ");
			System.out.print(nums[i]);
		}
		System.out.println();
	}
}

import java.awt.Point;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.TreeSet;

import java.math.BigInteger;

public class Main {

	public static Reader in = new Reader();
	public static Writer out = new Writer();

	public static void main(String[] args) {
		int n = in.readInt();

		int[] a = in.readInts(n);

		Arrays.sort(a);

		for(int i=1, j=n-2; i<j; i+=2, j-=2) {
			a[i] ^= a[j];
			a[j] ^= a[i];
			a[i] ^= a[j];
		}

		for(int i=n-1; i>=0; i--)
			out.print(a[i]+" ");

		out.close();
	}

}

class Writer {

	private BufferedWriter output;

	public Writer() {
		output = new BufferedWriter(new OutputStreamWriter(System.out));
	}

	public Writer(String s) {
		try {
			output = new BufferedWriter(new FileWriter(s));
		} catch(Exception ex) { ex.printStackTrace(); System.exit(0);}
	}

	public void println() {
		try {
			output.append("\n");
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}

	public void print(Object o) {
		try {
			output.append(o.toString());
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}

	public void println(Object o) {
		try {
			output.append(o.toString()+"\n");
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}

	public void printf(String format, Object... args) {
		try {
			output.append(String.format(format, args));
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}

	public void printfln(String format, Object... args) {
		try {
			output.append(String.format(format, args)+"\n");
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}

	public void flush() {
		try {
			output.flush();
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}

	public void close() {
		try {
			output.close();
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}
}

class Reader {
	private BufferedReader input;
	private StringTokenizer line = new StringTokenizer("");

	public Reader() {
		input = new BufferedReader(new InputStreamReader(System.in));
	}

	public Reader(String s) {
		try {
			input = new BufferedReader(new FileReader(s));
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}

	public void fill() {
		try {
			if(!line.hasMoreTokens()) line = new StringTokenizer(input.readLine());
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}

	public double nextDouble() {
		fill();
		return Double.parseDouble(line.nextToken());
	}

	public String nextWord() {
		fill();
		return line.nextToken();
	}

	public int nextInt() {
		fill();
		return Integer.parseInt(line.nextToken());
	}

	public long nextLong() {
		fill();
		return Long.parseLong(line.nextToken());
	}

	public double readDouble() {
		double d = 0;
		try {
			d = Double.parseDouble(input.readLine());
		} catch(IOException io) {io.printStackTrace(); System.exit(0);}
		return d;
	}

	public int readInt() {
		int i = 0;
		try {
			i = Integer.parseInt(input.readLine());
		} catch(IOException io) {io.printStackTrace(); System.exit(0);}
		return i;
	}

	public int[] readInts(int n) {
		int[] a = new int[n];
		for(int i=0; i<n; i++)
			a[i] = nextInt();
		return a;
	}

	public void fillInts(int[] a) {
		for(int i=0; i<a.length; i++)
			a[i] = nextInt();
	}

	public long readLong() {
		long l = 0;
		try {
			l = Long.parseLong(input.readLine());
		} catch(IOException io) {io.printStackTrace(); System.exit(0);}
		return l;
	}

	public String readLine() {
		String s = "";
		try {
			s = input.readLine();
		} catch(IOException io) {io.printStackTrace(); System.exit(0);}
		return s;
	}
}

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Ziklon
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {

    int[] getBest(int[] a, int b[]) {
        for (int i = 0; i < a.length; i++) {
            if (a[i] < b[i]) return a;
            if (b[i] < a[i]) return b;
        }
        return a;
    }

    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.nextInt();
        int seq[] = new int[n];
        for (int i = 0; i < n; i++) seq[i] = in.nextInt();
        int ans[] = new int[n];

        Arrays.sort(seq);
        Arrays.fill(ans, (int) 1e+9);

        int tmp[] = new int[n];
        int add = 0;
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) tmp[i] = seq[i];
            else tmp[i] = seq[n - i];
        }

        ans = getBest(ans, tmp);
        for (int i = 0; i < n; i++) {
            if (i % 2 == 1) tmp[i] = seq[i];
            else tmp[i] = seq[n - i - 1];
        }
        ans = getBest(ans, tmp);

        out.print(ans);

    }
}

class InputReader {
    InputStream stream;
    byte[] buf = new byte[1024];
    int curChar, numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    private int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

}

class OutputWriter {

    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            if (i != 0) writer.print(' ');
            writer.print(arr[i]);
        }
    }

    public void close() {
        writer.close();
    }

}

import java.io.*;
import java.util.Arrays;
public class CodeForce1{

public static void main(String args[])throws IOException{

	BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
	int n=Integer.parseInt(in.readLine());
	String s[]=in.readLine().split(" ");
	int i=0,max,min;

	int arr[]=new int[n];
	while(i<n){
		int num=Integer.parseInt(s[i]);
		arr[i]=num;
		i++;
	}
	Arrays.sort(arr);
	i=n-1;
	while(i>=0){
		System.out.print(arr[i]+" ");
		i--;
	}
	System.out.println();

	}

}

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

/**
 *
 * @author Jigsaw
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
        int N = Integer.parseInt(br.readLine());
        String S[] = br.readLine().split(" ");
        int arr[] = new int[N];
        for(int n=0;n<N;n++){
            arr[n] = Integer.parseInt(S[n]);
        }
        int largest = 0;
        int smallest = 1001;
        for(int n=0;n<N;n++){
            if(largest<arr[n]){
                largest = arr[n];
            }
            if(smallest>arr[n]){
                smallest = arr[n];
            }
        }
        Arrays.sort(arr);
        arr[0] = largest;
        arr[N-1] = smallest;
        for(int n=0;n<N;n++){
            pw.print(arr[n]+" ");
        }
        pw.close();
    }

}

import java.util.*;

public class cf347A{

	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();

		int min = 10000;
		int min_index = -1;
		int max = -10000;
		int max_index = -1;
		String[] arr = new String[n];

		for(int i=0; i<n; i++)
		{

			arr[i] = sc.next();
			if(Integer.parseInt(arr[i])<min)
			{
				min = Integer.parseInt(arr[i]);
				min_index = i;
			}
			if(Integer.parseInt(arr[i]) > max)
			{
				max = Integer.parseInt(arr[i]);
				max_index = i;

			}

		}

		if(n>0)
		{
		arr[min_index] = "--";
		arr[max_index] = "--";
		Arrays.sort(arr);

		System.out.print(max+" ");
		}
		for(int i=2; i<n; i++)
			System.out.print(arr[i]+" ");
		if(n>1)
		System.out.print(min);
	}

}

import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class DifferenceRow {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String numberSpace = br.readLine();
        String integers = br.readLine();
        int numInts = Integer.parseInt(numberSpace);
        int arrNum[] = new int[numInts];
        StringTokenizer st = new StringTokenizer(integers);
        for (int i = 0; i < numInts; i++)
            arrNum[i] = Integer.parseInt(st.nextToken());
        Arrays.sort(arrNum);
        permKnuth(numInts, arrNum);
    }

    public static void permKnuth(int N, int arr[]) {
        int[] p = new int[N];     // permutation
        for (int i = 0; i < N; i++) {
            p[i] = i;
        }
        permKnuthLexi(p, arr);
    }

    private static void permKnuthLexi(int[] arrNum, int[] arr) {
        int sum = 0;
        int SumMax=0;
        String WinnerPermutation="";
        String givenPermutation="";
        for (int i = 0; i < arrNum.length; i++) {
            givenPermutation+=  arr[arrNum[i]] + " ";
            if (i + 1 < arrNum.length)
                sum += arr[arrNum[i]] - arr[arrNum[i+1]];
        }
        WinnerPermutation=givenPermutation;
        SumMax=sum;
        while (true) {
            int j = arrNum.length - 2;
            while (arrNum[j] >= arrNum[j + 1]) {
                if (j == 0) System.exit(0);
                j--;
            }
            int l = arrNum.length - 1;
            while (arrNum[j] >= arrNum[l]) {
                l--;
            }
            swap(arrNum, j, l);
            int k = j + 1;
            l = arrNum.length - 1;
            while (k < l) {
                swap(arrNum, k, l);
                k++;
                l--;
            }
            sum = 0;
            givenPermutation="";
            for (int i = 0; i < arrNum.length; i++) {
                givenPermutation+=arr[arrNum[i]] + " ";
                if (i + 1 < arrNum.length)
                    sum += arr[arrNum[i]] - arr[arrNum[i+1]];
            }
            if(sum>SumMax)   WinnerPermutation=givenPermutation;
            if(IsSortedReverse(arrNum))
                System.out.println(WinnerPermutation);
        }
    }
    public static boolean IsSortedReverse(int[] arr)
    {
        for (int i = 1; i < arr.length; i++)
        {
            if (arr[i - 1] < arr[i])
            {
                return false;
            }
        }
        return true;
    }
    private static void swap(int[] data, int i, int j) {
        int temp = data[i];
        data[i] = data[j];
        data[j] = temp;
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Trung Pham
 */
public class A {

    public static void main(String[] args) {
        Scanner in = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int[] data = new int[n];

        for (int i = 0; i < n; i++) {
            data[i] = in.nextInt();
        }
        Arrays.sort(data);
        int start = n - 1;
        int end = 0;

        String[] other = new String[n - 2];
        int index = 0;
        for (int i = 0; i < n; i++) {
            if (i != start && i != end) {
                other[index++] = "" + data[i];
            }
        }
        Arrays.sort(other);
        Arrays.sort(other, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                if (o1.length() == o2.length()) {
                    return o1.compareTo(o2);
                } else if (o1.charAt(0) != o2.charAt(0)) {
                    return o1.charAt(0) - o2.charAt(0);
                } else {
                    int temp = Math.min(o1.length(), o2.length());
                    String a = o1.length() < o2.length() ? o1 : o2;
                    String b = o1.length() < o2.length() ? o2 : o1;
                    int start = 0;
                    while (temp < b.length() && start < a.length()) {
                        if (b.charAt(temp) <= a.charAt(start)) {
                            return b.equals(o1) ? -1 : 1;
                        }
                        temp++;
                        start++;
                    }
                    if (start == b.length()) {
                        return b.equals(o1) ? -1 : 1;
                    } else if (temp == o2.length()) {
                        return b.equals(o1) ? 1 : -1;
                    } else {
                        return 0;
                    }
                }
            }
        });
        StringBuilder b = new StringBuilder();

        out.print(data[start] + " ");
        for (int i = 0; i < other.length; i++) {
            out.print(other[i] + " ");
        }
        out.print(data[end]);
        out.close();
    }

    static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    static int pow(int a, int b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        int val = pow(a, b / 2);
        if (b % 2 == 0) {

            return val * val;
        } else {
            return val * val * a;
        }
    }

//    static Point intersect(Point a, Point b, Point c) {
//        double D = cross(a, b);
//        if (D != 0) {
//            return new Point(cross(c, b) / D, cross(a, c) / D);
//        }
//        return null;
//    }
//
//    static Point convert(Point a, double angle) {
//        double x = a.x * cos(angle) - a.y * sin(angle);
//        double y = a.x * sin(angle) + a.y * cos(angle);
//        return new Point(x, y);
//    }
    static Point minus(Point a, Point b) {
        return new Point(a.x - b.x, a.y - b.y);
    }

    static Point add(Point a, Point b) {
        return new Point(a.x + b.x, a.y + b.y);
    }

    static double cross(Point a, Point b) {
        return a.x * b.y - a.y * b.x;
    }

    static class Point {

        int x, y;

        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public String toString() {
            return "Point: " + x + " " + y;
        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            //System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner fi = new Scanner (System.in);
        int n = fi.nextInt ();
        int A[] = new int [n];

        for (int i = 0; i < n; ++i) A[i] = fi.nextInt ();
        Arrays.sort(A);
        for (int i = n - 1; i >= 0; --i) System.out.print(A[i] + " ");
    }
}

import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class main {
    static StringBuilder out=new StringBuilder();
    static FastReader in=new FastReader();
    public static int[] getIntArray(int n){
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        return arr;
    }

    static int  mod=(int)1e9 +7;
    static int [][]dp;

    public static void solve(){
        int n=in.nextInt();
        Integer arr[]=new Integer[n];
        for(int i=0;i<arr.length;i++){
            arr[i]=in.nextInt();
        }
        Arrays.sort(arr, Collections.reverseOrder());
        for(int i=0;i<n;i++){
            out.append(arr[i]).append(' ');
        }
    }

    public static void main(String args[]){
        int t=1;
        while(t-->0){
            solve();
            out.append('\n');
        }
        System.out.println(out);
    }
}

class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}