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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] a = Console.ReadLine().Split();

            

            if (n == 2)
            {
                Console.WriteLine(a[1] + " " + a[0]);
            }
            else
            {
                int indeks = 0;
                int max = int.MinValue;
                for (int i = 1; i < n; i++)
                {
                    if (max < Convert.ToInt32(a[i]))
                    {
                        max = Convert.ToInt32(a[i]);
                        indeks = i;
                    }
                }

                for (int i = 0; i < n; i++)
                {
                    if (Convert.ToInt32(a[i]) <= max)
                    {
                        a[indeks] = a[i];
                        a[i] = Convert.ToString(max);
                        break;
                    }
                }
                for (int i = 0; i < n; i++)
                {
                    if (i == n - 1)
                        Console.Write(a[i]);
                    else
                        Console.Write(a[i] + " ");
               }
            }

        }
    }
}