#include <iostream>
using namespace std;

int main()
{
    int n, temp;
    bool isti = true;
    cin >> n;
    int* x = new int[n];
    for(int i = 0; i < n; i++) {
        cin >> x[i];
        if(i) {
            if(x[i - 1] == x[i]) {
                isti = false;
            }
            for(int j = 0; j < i; j++) {
                if(x[j] < x[i]) {
                    temp = x[j];
                    x[j] = x[i];
                    x[i] = temp;
                    for(int i = 0; i < n; i++) {
                        cout << x[i] << " ";
                    }
                    return 0;
                }
            }
        }
    }
    if(isti) {
        temp = x[n - 2];
        x[n - 2] = x[n - 1];
        x[n - 1] = temp;
    }
    for(int i = 0; i < n; i++) {
        cout << x[i] << " ";
    }
    return 0;
}