#include <bits/stdc++.h>
using namespace std;

typedef uint64_t ll;

int main(){

    int n, p;
    cin >> n;

    vector<ll> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];

    if (n == 2){
        cout << v[1] << " " << v[0] << endl;
        return 0;
    }

    int max_i;
    bool find_ = 0;
    for (int i = 0; i < n - 1; i++){
        max_i = i;
        for (int j = i + 1; j < n; j++)
            if (v[max_i] < v[j] && v[i] < v[j])
                max_i = j;

        if (max_i > 0){
            swap(v[i], v[max_i]);
            find_ = 1;
            break;
        }
    }

    if (find_)
        swap(v[v.size() - 1], v[v.size() - 2]);

    for (auto i : v)
        cout << i << " ";
    cout << endl;

    return 0;
}