#include <iostream>
using namespace std;

main()
{
            int n;
            cin>>n;
            int a[n];
            for (int t=0; t<n; t++)
            {
                cin>>a[t];
            }
            if (n==2)
            {
                int p = a[0];
                a[0] = a[1];
                a[1] = p;
            }
            else
            {
                short br=0;
                for (int i1=0 ; i1 < n && br==0; i1++)
                {
                    int max=a[i1];  int maxid=0;
                    for (int i = i1+1; i < n; i++)
                    {
                        if (max < a[i])
                        {
                            max = a[i];
                            maxid = i;
                        }
                    }
                    if (a[i1] != max)
                    {
                        int p = a[i1];
                        a[i1] = a[maxid];
                        a[maxid] = p;
                        br++;
                    }
                }
                if (br == 0)
                {
                    int p = a[n - 2];
                    a[n-2] = a[n-1];
                    a[n-1] = p;
                }

            }
            for (int i = 0; i < n - 1; i++)
            {
                cout<<a[i]<<" ";
            }
            cout<<a[n - 1]<<" ";

        }