# include <bits/stdc++.h>

using namespace std;

void CountingSort(int arr[], int n)
{
    int RANGE = 0;
    for (int k = 0; k < n; ++k)
    {
        if (arr[k] > RANGE )
        {
            RANGE = arr[k];
        }
    }
    int count[RANGE + 1], i;
    for (int k = 0; k < RANGE + 1; ++k)
    {
        count[k]=0;
    }
    for(i = 0; i < n; ++i)
    {
            count[arr[i]] = count[arr[i]] + 1;
    }
    for (i = 1; i <= RANGE; ++i)
    {
        count[i] = count[i] + count[i-1];
    }
    int output[n];
    for (i = 0; i < n; ++i)
    {
        output[count[arr[i]]-1] = arr[i];
        count[arr[i]] = count[arr[i]] - 1;
    }
    for (i = 0; i < n; ++i)
    {
        arr[i] = output[i];
    }
}

void unazad(int arr[], int start, int end)
{
    if (start >= end)
    return;

    int temp = arr[start];
    arr[start] = arr[end];
    arr[end] = temp;
    unazad(arr, start + 1, end - 1);
}

int main()
{

    int n,i,p,i1;
    scanf("%d",&n);
    int A[n];
    int B[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&A[i]);
        B[i]=A[i];
    }
    if(n==1)
        printf("%d",A[0]);
    else if(n==2)
        printf("%d %d",A[1],A[0]);
    else
    {
        CountingSort(A,n);
        unazad(A,0,n);
        bool x=true;
        int br=0,ix;
        while(x)
        {
            if(A[br]!=B[br])
            {
                x=false;
                ix=br+1;
                i1=br;
            }
            br++;
        }
        int maks=0,i2;
        for(i=ix;i<n;i++)
        {
            if(B[i]>maks)
            {
                maks=B[i];
                i2=i;
            }
        }
        p=B[i1];
        B[i1]=B[i2];
        B[i2]=p;
        for(i=0;i<n;i++)
            printf("%d ",B[i]);
    }
    return 0;
}