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

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string s = Console.ReadLine();
            string[] vs = s.Split();
            int[] vn = new int[n];
            for (int i = 0; i < n; i++)
            {
                vn[i] = Convert.ToInt32(vs[i]);
            }
            int max = 0;
            int i0 = 0;
            for (int i = 0; i < n; i++)
            {
                if (vn[i] > max)
                {
                    max = vn[i];
                    i0 = i;
                }
            }
            if (vn[i0] != vn[0])
            {
                int pomoc = vn[i0];
                vn[i0] = vn[0];
                vn[0] = pomoc;
            }
            else
            {
                max = 0;
                for (int i = 1; i < n; i++)
                {
                    if (vn[i] > max)
                    {
                        max = vn[i];
                        i0 = i;
                    }
                }
            }
            for (int i = 0; i < n; i++)
            {
                Console.Write(vn[i] + " ");
            }
        }
    }
}