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

namespace Ludi_Kami
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string lin = Console.ReadLine();
            string[] a = lin.Split(' ');
            int[] sortiran = new int[n];
            int[] original = new int[n];
            for(int i = 0;i<n;i++)
            {
                sortiran[i] = int.Parse(a[i]);
                original[i] = sortiran[i];
            }
            Array.Sort(sortiran);
            Array.Reverse(sortiran);
            int temp, index = 0;
            bool promena = false;
            for (int i = 0; i < n; i++)
            {
                if(sortiran[i] != original[i])
                {
                    for(int j = 0;j<n;j++)
                    {
                        if(original[j] == sortiran[i])
                        {
                            index = j;
                            break;
                        }

                    }
                    temp = original[i];
                    original[i] = original[index];
                    original[index] = temp;
                    promena = true;
                }
            }
            if(!promena)
            {
                temp = original[n - 1];
                original[n - 1] = original[n - 2];
                original[n - 2] = temp;
            }
            for (int i = 0; i < n; i++)
            {
                Console.Write(original[i].ToString() + " ");
            }
            Console.ReadLine();
        }
    }
}