# include <bits/stdc++.h>

using namespace std;

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",max(A[0],A[1]),min(A[0],A[1]));
    else
    {
        sort(A,A + n, greater<int>());
        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;
}