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)
        {
            int n = int.Parse(Console.ReadLine());
            int[] niz = new int[n];
            string line = Console.ReadLine();
            var data = line.Split(' ');
            int max = -1;
            int t1 = -1;
            int t2 = -1;
            for (int i = 0; i < n; i++)
            {
                niz[i] = int.Parse(data[i]);
                if (niz[i] >= max && i > 0)
                {
                    max = niz[i];
                    t1 = i;
                }
            }
            for (int i = 0; i < n; i++)
            {
                if (niz[i] <= niz[t1] && t1 != i)
                {
                    t2 = i;
                    break;
                }
            }
            if (t2 == -1)
            {
                int p = niz[0];
                niz[0] = niz[t1];
                niz[t1] = p;
            }
            else
            {
                int p = niz[t1];
                niz[t1] = niz[t2];
                niz[t2] = p;
            }
            for (int i = 0; i < n; i++)
            {
                Console.Write(niz[i] + " ");
            }
        }
    }
}