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

namespace DrugiZadatak
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long[] a = new long[n];
            long x = 0;
            long z = 0;
            long y = 0;
            for (long i = 0; i < n; i++)
            {
                a[i] = long.Parse(Console.ReadLine());
            }
            long max = -9223372036854775808;
            if (n == 2)
            {
                x = a[0];
                a[0] = a[1];
                a[1] = x;
                for (long i = 0; i < n; i++)
                {
                    Console.Write(a[i] + " ");
                }
            }
            else
            {
                for (long i = 1; i < n; i++)
                {
                    if (a[i] > max)
                    { 
                        max = a[i];
                        y = i;
                    }
                }
                for (long i = 0; i < n; i++)
                {
                    if (a[i] < max)
                    {
                        a[y] = a[i];
                        a[i] = max;
                        break;
                    }
                }
            }
            for (long i = 0; i < n; i++)
            {
                Console.Write(a[i] + " ");
            }
        }
    }
}