#include <iostream>

using namespace std;

void zameni(long int b, int A[100000], long int n){
    int p;
    int max = A[b];
    long int br = b;

    if(n - b == 2){
        p = A[b];
        A[b] = A[b + 1];
        A[b + 1] = p;
    } else {
    for(long int i = b+1; i < n; i++){
        if(A[i] >= max){
            max = A[i];
            br = i;
        }
    }

    if(A[b] == max){
        zameni(b + 1, A, n);
    } else {
        p = A[br];
        A[br] = A[b];
        A[b] = p;
    }
}
}
int main()
{
    long int n;
    int A[100000];
    int max;

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

    max = A[0];
    for(long int i = 1; i < n; i++){
        if(A[i] > max){
            max = A[i];
        }
    }

    if(A[0] != max || A[1] != max ){
        zameni(0, A, n);
    }
    for(long int i = 0; i < n; i++){
        cout << A[i] << " ";
    }

    return 0;
}