using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = Convert.ToInt64(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            long[] x = new long[N];
            long maxi = 0;
            long maxj = 0;
            bool bilopro = false;
            for(int i = 0;i<N;i++)
                x[i] = Convert.ToInt64(s[i]);
            for(int i = 0;i<N;i++)
            {
                for(int j = 0;j<N;j++)
                {
                    if(x[j]>x[i])
                    {
                        maxi = i;
                        maxj = j;
                        bilopro = true;
                    }
                }
                if (bilopro) break;
            }
            if(!bilopro)
            {
                maxi = N - 1;
                maxj = N - 2;
            }
            long t = x[maxi];
            x[maxi] = x[maxj];
            x[maxj] = t;
            string r = "";
            for (int i = 0; i < N; i++)
                r += " " + x[i].ToString();
                Console.WriteLine(r);
        }
    }
}