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)
        {
            long n = long.Parse(Console.ReadLine());
            long[] a = new long[n];
            long i;
            long p, t;
            var ulaz = Console.ReadLine().Split();
            for(i = 0; i < n; i++)
            {
                a[i] = long.Parse(ulaz[i]);
            }
            if (n == 2)
            {
                t = a[0];
                a[0] = a[1];
                a[1] = t;
                Console.Write(a[0]);
                Console.Write(" ");
                Console.Write(a[1]);
            }
            else
            {
                long max;
                max = a[0];
                for(i = 1; i < a.Length; i++)
                {
                    if(a[i] > max)
                    {
                        max = a[i];
                    }
                }
                //Console.WriteLine(max);
                if (max == a[0])
                {
                    long max1;
                    max1 = a[1];
                    for (i = 2; i < a.Length; i++)
                    {
                        if (a[i] > max1)
                        {
                            
                            p = max1;
                            max1 = a[i];
                            a[i] = p;
                        }
                    }
                    Console.Write(max);
                    Console.Write(" ");
                    Console.Write(max1);
                    Console.Write(" ");
                    for(i = 2; i < a.Length; i++)
                    {
                        Console.Write(a[i]);
                        Console.Write(" ");
                    }
                }
                else
                {
                    long max2;
                    max2 = a[0];
                    for(i = 1; i < a.Length; i++)
                    {
                        if(a[i] > max2)
                        {
                            long m;
                            m = max2;
                            max2 = a[i];
                            a[i] = m;
                        }
                    }
                    Console.Write(max2); 
                    Console.Write(" ");
                    for(i = 1; i < a.Length; i++)
                    {
                        Console.Write(a[i]);
                        Console.Write(" ");
                    }
                }
            }
        }
    }
}