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

namespace Petlja_B___Polica
{
    class Program
    {

        static int NadjiMax(int[] niz,int p,int n)
        {

            int max = -1;
            int index=-1;

            for(int i=p;i<n;i++)
            {
                if(niz[i]>=max)
                {
                    max = niz[i];
                    index = i;
                }
            }

            return index;
        }
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            int[] a = new int[n];

            for (int i = 0; i < n; i++)
            {
                a[i] = Convert.ToInt32(str[i]);
            }

            if (n==2)
            {
                Console.WriteLine(str[1] +" "+ str[0]);
            }
            else
            {
                bool zamena = false;
                int j = 0;
                while(zamena != true)
                {
                    int k=NadjiMax(a, j, n);
                    if (j == k)
                        j++;
                    else
                    {
                        int temp = a[j];
                        a[j] = a[k];
                        a[k] = temp;
                        zamena = true;
                    }
                }

                if(zamena==false)
                {
                    int temp = a[n-1];
                    a[n-1] = a[n-2];
                    a[n-2] = temp;
                }

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

            }


            Console.ReadLine();
        }
    }
}