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

namespace Polica
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split();
            uint[] a = new uint[N];
            uint[] b = new uint[N];
            for (int i = 0; i < N; i++)
            {
                a[i] = uint.Parse(str[i]);
                b[i] = uint.Parse(str[i]);
            }
            bool p = true;
            int br = 1;
            int brp = 0;
            Array.Sort(b);
            Array.Reverse(b);
            if (N == 2) Console.WriteLine(a[1] + " " + a[0]);
            else
            {
                uint i = 0;
                while (p)
                {
                    if (i == N) p = false;
                    else if (a[i] == b[i]) i++;
                    else
                    {
                        for (int j = N-1; j > i; j--)
                        {
                            if (a[j] == b[i])
                            {
                                uint pom = a[i];
                                a[i] = a[j];
                                a[j] = pom;
                                brp++;
                                break;
                            }
                        }
                        p = false;

                    }
                }
                if (brp == 0)
                {
                    for (int s = 0; s < N - 1; s++)
                    {
                        if (a[s] == a[s + 1])
                        {
                            uint pom = a[s];
                            a[s] = a[s + 1];
                            a[s + 1] = pom;
                            brp++;
                            break;
                        }
                    }
                    if (brp == 0)
                    {
                        uint pom = a[N-1];
                        a[N-1] = a[N-2];
                        a[N-2] = pom;
                    }
                }
                for (int k = 0; k < N; k++)
                {
                    Console.Write(a[k] + " ");
                }
                Console.WriteLine();
            }

        }
    }
}