#include <iostream>

using namespace std;

void sortt(int a[], int n){
    int maks = a[0];
    int i_max = 0;
    int i_max_poc = 0;
    int i;
    for (i = 0; i < n; ++i){
        start:
        if (a[i] > maks){
            maks = a[i];
            i_max = i;
        }
    }
    if (i_max_poc == n){
        int temp;
        temp = a[n-1];
        a[n-1] = a[n-2];
        a[n-2] = temp;
    }
    else if (i_max == i_max_poc){
        i_max_poc++;
        i_max++;
        maks = a[i_max_poc];
        i = i_max_poc;
        goto start;
    } else {
        int temp;
        temp = a[i_max];
        a[i_max] = a[i_max_poc];
        a[i_max_poc] = temp;
    }
}

int main(){
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i){
        cin >> a[i];
    }

    sortt(a, n);

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

    return 0;
}