#include<iostream>

using namespace std;

void sortiranje(long long int ,long long int []);

int main(void)
{
    long long int n,x=-1;

    cin>>n;

    long long int niz[n];

    if(n == 1)
    {
        cin>>niz[0];
        cout<<niz[0];
    }
    else{

    if(n == 2){
        cin>>niz[0]>>niz[1];
        x = niz[0];
        niz[0] = niz[1];
        niz[1] = x;
        cout<<niz[0]<<" "<<niz[1];
    }

    else{

    long long int niz2[n-1];

    for(int i=0;i<n;++i){
        cin>>niz[i];
        niz2[i] = niz[i];}

    sortiranje(n,niz2);

    for(int i=0;i<n;++i)
    {
        if(niz[i] != niz2[i])
        {
            for(int j=i;j<n;++j)
                if(niz2[i] == niz[j])
            {
                x = niz[i];
                niz[i] = niz[j];
                niz[j] = x;
                break;
            }
        }
        else continue;
    break;
    }
    if(x == -1)
    {
        x = niz[n-1];
        niz[n-1] = niz[n-2];
        niz[n-2] = x;
    }
    for(int i=0;i<n;++i)
        cout<<niz[i]<<" ";
       }
    }
    return 0;
}
void sortiranje(long long int n,long long int a[])
{
    int x;
    for(long long int *p=a;p<a+n-1;p++)
        for(long long int *k=p+1;k<a+n;k++)
        if(*p<*k)
        {
            x=*p;
            *p=*k;
            *k=x;
        }
       return;
}