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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int p = 0;
            int p1 = 0;
            int g = 0;
            int n = int.Parse(Console.ReadLine());
            string x = Console.ReadLine();
            string[] Z = x.Split(' ');

            int[] c = new int[n];
            int[] b = new int[n];

            for (int u = 0; u < n; u++)      //obrnuto b
                c[u] = int.Parse(Z[u]);
            Array.Reverse(c);

            for (int u = 0; u < n; u++)      //neporedani
                b[u] = int.Parse(Z[u]);


            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = int.Parse(Z[i]);

            Array.Sort(a);      //Poredani su
            Array.Reverse(a);  // opadajuci max -min
            if (Enumerable.SequenceEqual(a, b) == true)
                for (int i = 0; i < n; i++)
                {
                    Console.Write(a[i]);
                    Console.Write(" ");
                }
            else
            {
                if (n == 2)
                {

                    for (int q = 0; q < n; q++)
                    {
                        Console.Write(a[q]);
                        Console.Write(" ");
                    }
                }
                else
                    while (g < n)
                        if (a[g] != b[g])
                        {
                            int index = Array.IndexOf(b, a[g]);
                            int index1 = Array.IndexOf(c, a[g]);
                            if (index != n - index1)
                            {
                                p = b[g];
                                b[g] = a[g];
                                b[n - index1 - 1] = p;
                            }
                            else
                            {
                                p = b[g];
                                b[g] = a[g];
                                b[index] = p;
                            }
                            for (int i = 0; i < n; i++)
                            {
                                Console.Write(b[i]);
                                Console.Write(" ");
                            }
                            break;
                        }
                        else
                        {
                            g++;
                            if (b[g] != a[g])
                            {
                                int index = Array.IndexOf(b, a[g]);
                                int index1 = Array.IndexOf(c, a[g]);
                                if (index != n - index1)
                                {
                                    p = b[g];
                                    b[g] = a[g];
                                    b[n - index1 - 1] = p;
                                }
                                else
                                {
                                    p1 = b[g];
                                    b[g] = a[g];
                                    b[index] = p1;
                                }
                                for (int u = 0; u < n; u++)
                                {
                                    Console.Write(b[u]);
                                    Console.Write(" ");
                                }

                                break;
                            }

                            g++;


                        }
            }
            Console.ReadLine();
        }


    }
}