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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] str = new string[2 * n];
            str = Console.ReadLine().Split();
            int[] niz = new int[n];
            int[] sortiran=new int[n];
            for (int i = 0; i < n; i++)
            {
                niz[i] = Convert.ToInt32(str[i]);
                sortiran[i]=Convert.ToInt32(str[i]);
            }
            for (int i = 0; i < n-1; i++)
            {
                for (int j = 0; j < n-1; j++)
                {
                    if (sortiran[j] < sortiran[j + 1])
                    {
                        int pom = sortiran[j];
                        sortiran[j] = sortiran[j + 1];
                        sortiran[j + 1] = pom;
                    }
                }
            }
            int br=0;
            for (int i = 0; i < n; i++)
            {
                if (niz[i] == sortiran[i]) br++;
                else break;  
            }
            if (br == n)
            {
                int pom = niz[n - 2];
                niz[n - 2] = niz[n - 1];
                niz[n - 1] = pom;
            }
            else
            {
                int pom=niz[br];
                niz[br] = sortiran[br];
                for (int i = n-1; i >= 0; i--)
                {
                    if (niz[i] == niz[br])
                    {
                        niz[i] = pom;
                        break;
                    }
                }
            }
            for (int i = 0; i < n; i++)
            {
                Console.Write(niz[i] + " ");
            }
            Console.ReadKey();
        }
    }
}