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)
        {
            ulong n = ulong.Parse(Console.ReadLine());
            int m = 0;
            int[] a = new int[n];
            int[] b = new int[n];
            string[] s = Console.ReadLine().Split();
            for (ulong i = 0; i < n; i++)
            {
                a[i] = int.Parse(s[i]);
                b[i] = a[i];
            }
            Array.Sort(b);
            Array.Reverse(b);
            for (ulong i = 0; i < n-1; i++)
            {
                if (b[i] == b[i + 1]) m++;
            }
            int x, q = 0;
            ulong p = 0;
            if (n == 2)
            {
                x = a[0];
                a[0] = a[1];
                a[1] = x;
            }
            else
            {
                ulong i = 0;
                while (q == 0 && i < n)  
                {
                    if (a[i] != b[i])
                    {
                        for (ulong j = i + 1; j < n; j++)
                        {
                            if (a[j] == b[i]) p = j;
                        }
                        x = a[i];
                        a[i] = a[p];
                        a[p] = x;
                        q++;
                    }
                    else if (i == n - 1 && m == 0) 
                    {
                        x = a[i];
                        a[i] = a[i - 1];
                        a[i - 1] = x;
                    }
                    i++;
                }
            }
            for (ulong i = 0; i < n; i++)
            {
                Console.Write(a[i] + " ");
            }
        }
    }
}