#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n,x;
    cin>>n;
    vector<int> v;
    vector<int> v1;
    for(int i=0;i<n;i++){
        cin>>x;
        v.push_back(x);
        v1.push_back(x);
    }
    sort(v.begin(),v.end());
    int i=0;
    while(v[n-i-1]==v1[i] && i<n-2){
        cout<<v1[i]<<" ";
        i++;
    }
    if(i==n-2){
        cout<<v1[n-1]<<" "<<v1[n-2];
        return 0;
    }
    int y=0;
    cout<<v[n-i-1]<<" ";
    for(int j=i+1;j<n;j++){
        if(v1[j]==v[n-i-1]){
            y=j;
        }
    }
    for(int j=i+1;j<n;j++){
        int k=j;
        if(y==j){
            j=i;
        }
        cout<<v1[j]<<" ";
        j=k;
    }
    return 0;
}