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

int main()
{
    long int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++) {cin>>a[i]; b[i]=a[i];}
    if(n==2) cout<<a[1]<<" "<<a[0];
    else
    {
        int ind=1;
        sort(b,b+n);
        for(int i=0;i<n-1 && ind;i++)
        {
            if(a[i]!=b[n-i-1])
            {
                //cout<<a[i]<<" "<<b[n-i-1]<<endl;
                int i1=i;
                ind=0;
                while(a[i1]!=b[n-i-1]) i1++;
                //cout<<a[i1]<<endl;
                int pom=a[i1];
                a[i1]=a[i];
                a[i]=pom;
                //cout<<a[i]<<" "<<b[n-i-1]<<endl;
            }
        }
        if(ind){
                int pom=a[n-1];
                a[n-1]=a[n-2];
                a[n-2]=pom;}
        for(int i=0;i<n;i++) cout<<a[i]<<" ";
    }
    return 0;
}