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

namespace ConsoleApp14
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            string s;
            s = Console.ReadLine();
            string[] words = s.Split(' ');
            for (int i = 0; i < n; i++)
            {
                a[i]=int.Parse(words[i]);
            }
            int min = 10;
            int max = -1;
            for (int i = 0; i < n; i++)
            {
                if (a[i] > max) max = a[i];
                if (a[i] < min) min = a[i];
            }
            if (n == 2) Console.WriteLine(a[1]+" "+a[0]);
            else if(n==3)
            {
                if (a[1]==max)
                {
                    if (a[0] == min) Console.WriteLine(a[0]+" "+a[2]+" "+a[1]);
                    else Console.WriteLine(a[1] + " " + a[0] + " " + a[2]);
                }
                else if(a[1]==min)
                {
                    if (a[0] == max) Console.WriteLine(a[0] + " " + a[2] + " " + a[1]);
                    else Console.WriteLine(a[1] + " " + a[0] + " " + a[2]);
                }
                else Console.WriteLine(a[2] + " " + a[1] + " " + a[0]);
            }
            else if(n==4)
            {
                if(a[0]==min)
                {
                    if(a[3]==max) Console.WriteLine(a[0] + " " + a[2] + " " + a[1]+" "+a[3]);
                    else if(a[2]==max) Console.WriteLine(a[0] + " " + a[1] + " " + a[3] + " " + a[2]);
                    else if(a[1]==max) Console.WriteLine(a[0] + " " + a[3] + " " + a[2] + " " + a[1]);
                }
                else if(a[1]==min)
                {
                    if(a[3]==max) Console.WriteLine(a[1] + " " + a[0] + " " + a[2] + " " + a[3]);
                    else if (a[0] == max) Console.WriteLine(a[0] + " " + a[3] + " " + a[3] + " " + a[0]);
                    else if(a[2]==max) Console.WriteLine(a[0] + " " + a[1] + " " + a[3] + " " + a[2]);
                }
                else if(a[2]==min)
                {
                    if(a[3]==max) Console.WriteLine(a[2] + " " + a[1] + " " + a[0] + " " + a[3]);
                    else if(a[1]==max) Console.WriteLine(a[1] + " " + a[0] + " " + a[2] + " " + a[3]);
                    else if(a[0]==max) Console.WriteLine(a[0] + " " + a[2] + " " + a[1] + " " + a[3]);
                }
                else if(a[3]==min)
                {
                    if (a[0] == max) Console.WriteLine(a[0] + " " + a[2] + " " + a[1] + " " + a[3]);
                    else if (a[2] == max) Console.WriteLine(a[0] + " " + a[1] + " " + a[3] + " " + a[2]);
                    else if (a[1] == max) Console.WriteLine(a[1] + " " + a[0] + " " + a[2] + " " + a[3]);

                }
            }
           else
            {
                Console.Write(a[1]+" "+a[0]);
                for (int i = 2; i < n; i++)
                {
                    Console.Write(a[i]+" ");
                }
                Console.WriteLine();
            }
        }
    }
}