#include <stdio.h>
#include <stdlib.h>

void main()
{
    long N;
    scanf("%ld", &N);
    long Ntemp = N;
    long i, j = 0;
    long arr[N], *pokarr, temparr[N], *pokarrtemp;
    for(i = 0; i < N; i++){
        scanf("%ld", &arr[i]);
        temparr[i] = arr[i];
    }
    pokarr = arr;
    pokarrtemp = temparr;
    sort(pokarrtemp, N);

    long raz1 = 0, *r1, raz2 = 0, *r2;
    r1 = &raz1;
    r2 = &raz2;

    if(diff(pokarr, pokarrtemp, N, r1, r2) == 0)
    {
        int p = 0;
        for(i = 0; i < N-1; i++)
        {
            if(*(pokarr+i) == *(pokarr+i+1)) p = 1;
        }
        if(p==0){
            long q = arr[N-1];
            arr[N-1] = arr[N-2];
            arr[N-2] = q;
        }

    } else
    {
        long t = *(pokarr+raz1);
        *(pokarr+raz1) = *(pokarr+raz2);
        *(pokarr+raz2) = t;
    }
    for(i = 0; i < N; i++) printf("%ld ", arr[i]);

}

int diff(long* arr, long* arrtemp, long N, long* r1, long* r2)
{
    long i;
    for(i = 0; i < N; i++)
    {
        if(*(arr+i)!=*(arrtemp+i)){
            *r1 = i;
            long j;
            for(j = i; j < N; j++)
            {
                if(*(arrtemp+i) == *(arr+j)) *r2 = j;
            }
            return 1;
        }
    }
    return 0;
}


void sort(long* arr, long N)
{
    long temp;
    long i, j;
    for(i = 0; i < N-1; i++){
        for(j = i; j < N; j++){
            if(*(arr+i) < *(arr+j))
            {
                temp = *(arr+i);
                *(arr+i) = *(arr+j);
                *(arr+j) = temp;
            }
        }
    }
}