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)
        {
            Int64 n = Int64.Parse(Console.ReadLine());
            Int64[] a = new Int64[n];
            Int64 max = -1;
            Int64 p=-1;
            var ulaz = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                a[i] = Int64.Parse(ulaz[i]);
                if (a[i] > max)
                {
                    max = a[i];
                    p = i;
                }
            }
            if (n == 2)
            {
                Console.WriteLine("{0} {1}", a[1], a[0]);
            }
            else
            {
                if (p != 0)
                {
                    Int64 q = a[p];
                    a[p] = a[0];
                    a[0] = q;
                }
                else
                {
                    Int64 max1 = a[1];
                    Int64 q1 = 1;
                    a[0] = -1;
                    for (Int64 i = 2; i < n; i++)
                    {
                        if (a[i] > max1)
                        {
                            q1 = i;
                        }
                    }
                    Int64 p1 = a[1];
                    a[1] = a[q1];
                    a[q1] = p1;
                }
                Console.Write(max + " ");
                for (Int64 i = 1; i < n; i++)
                {
                    Console.Write(a[i] + " ");
                }
            }
        }
    }
}