import java.util.Scanner;

public class Main {

    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();
        }
        int temp=0;
        if(n==2){
            temp=a[0];
            a[0]=a[1];
            a[1]=temp;
        }
        else {
            int max = 0;
            int maxpos = 0;
            boolean moze=false;
            int b=0;
                while(!moze){
                    max=0;
                    for (int i = b; i < n; i++) {
                        if (a[i] >= max) {
                            max = a[i];
                            maxpos = i;
                        }
                    }
                    if (maxpos==0){
                    }
                    else if (a[maxpos]>=a[maxpos-1]){
                        moze=true;
                    }
                    b++;
                }
                for (int i = 0; i < n; i++) {
                    if (a[i] <= max) {
                        temp = a[i];
                        a[i] = a[maxpos];
                        a[maxpos] = temp;
                        break;
                    }
                }
            }

            for (int b : a
            ) {
                System.out.print(b + " ");
            }


    }
}