#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector <int> v;
    int pr, a;
    cin >> pr >> a;
    v.push_back(pr);
    v.push_back(a);
    int razlika = a - pr;
    pr = a;
    int p = 0, q = 1;
    for(int i = 2; i < n; i++){
        cin >> a;
        v.push_back(a);
        if(razlika != 9){
            if(razlika < a - pr){
                razlika = a - pr;
                p = i - 1;
                q = i;
            }
        }
        pr = a;
    }
    if(razlika < 0){
        p = n - 2;
        q = n - 1;
    }
    swap(v[p], v[q]);
    for(int i = 0; i < n; i++){
        cout << v[i] << " ";
    }
    return 0;
}