#include <iostream>
using namespace std;

int main()
{
    int N;
    cin >> N;
    short maximum1 =0;
    int maximumIndex1=0;
    short maximum2=0;
    int maximumIndex2=0;
    short A[N];
    int t;
    int i;
    for(i=0; i<N; i++)
    {
        cin >>A[i];
        if(A[i]>maximum2)
        {
            maximum2=A[i];
            maximumIndex2=i;

        if(maximum1<maximum2)
        {
            t=maximum1;
            maximum1=maximum2;
            maximum2=t;
            t=maximumIndex1;
            maximumIndex1=maximumIndex2;
            maximumIndex2=t;
        }
        }

    }
    if (maximumIndex1==0)
    {


    if (maximum1!=maximum2)

		
            if(maximumIndex2==1 && maximum2!=A[2])
        {
            t=A[maximumIndex1];
            A[maximumIndex1]=A[maximumIndex2];
            A[maximumIndex2]=t;

        }
        else
        {
            t=A[maximumIndex1+1];
            A[maximumIndex1+1]=A[maximumIndex2];
            A[maximumIndex2]=t;

        }
    }
        else
        {
            A[maximumIndex1]=A[0];
            A[0]=maximum1;

        }
    for(i=0; i<N; i++)
            cout << A[i] << " ";

return 0;
}