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

typedef struct{
    short int br;
    ll index;
}polje;

bool poredi(polje a, polje b)
{
    return(a.br>b.br);
}

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n;
    cin>>n;
    if(n==2)
    {
        ll a1,a2;
        cin>>a1>>a2;
        cout<<a2<<' '<<a1;
    }
    else
    {
        polje a[n]; //a nam je za sortiranje, b za poredenje i stampanje
        short int b[n];
        for(ll i=0;i<n;i++)
        {
            a[i].index=i;
            cin>>a[i].br;
            b[i]=a[i].br;
        }
        sort(a,a+n,poredi);
        ll brc=0;
        while(a[brc].br==b[brc])
            brc++;
        if(brc==n)
            swap(b[n-1],b[n-2]);
        else
            swap(b[brc],b[a[brc].index]);
        for(ll i=0;i<n;i++)
            cout<<b[i]<<' ';
    }
}