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;
            string h = "";
            int n = int.Parse(Console.ReadLine());
            string x = Console.ReadLine();
            string[] Z = x.Split(' ');
            
            int[] b = new int[n];
            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 (n == 2)
            {
                
                for (int q = 0; q < n; q++)
                {
                    Console.Write(a[q]);
                    Console.Write(" ");
                }
            }
            else
                if (a[0] != b[0])
                {
                    int index = Array.IndexOf(b, a[0]);
                    p = b[0];
                    b[0] = a[0];
                    b[index] = p;
                    for (int i = 0; i < n; i++)
                    {
                        Console.Write(b[i]);
                        Console.Write(" ");
                    }
                }
                else
                {
                    if (b[1] != a[1])
                    {
                        int index = Array.IndexOf(b, a[1]);
                        p1 = b[1];
                        b[1] = a[1];
                        b[index] = p1;
                        for (int u = 0; u < n; u++)
                        {
                            Console.Write(b[u]);
                            Console.Write(" ");
                        }

                    }
                }
            
                Console.ReadLine();

        }
    }
}