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)
        {
            Int64 n = Int64.Parse(Console.ReadLine());
            Int64 i, j;
            Int64[] a = new Int64[n];
            var ul1 = Console.ReadLine().Split();
            for (i = 0; i < n; i++)
            {
                a[i] = Int64.Parse(ul1[i]);
            }
            if (n == 2)
            {
                Console.WriteLine("{0} {1}", a[1], a[0]);
            }
            else
            {
                Int64 br = 0, k1, k2;
                for (i = 0; i < n; i++)
                {
                    for (j = i + 1; j < n; j++)
                    {
                        if (a[i] == a[j])
                        {
                            k1 = i;
                            k2 = j;
                            br++;
                        }
                    }
                }
                if (br > 0)
                {
                    for (i = 0; i < n; i++)
                    {
                        Console.Write(a[i] + " ");
                    }
                    Console.WriteLine();
                }
                else
                {
                    br = 0;
                    Int64 br2 = 0;
                    Int64 p;
                    for (i = n-1; i > 0; i--)
                    {
                        if (a[i] < a[i - 1] && br == 0 && br2==0)
                        {
                            br++;
                            p = a[i];
                            a[i] = a[i - 1];
                            a[i - 1] = p;
                        }
                        if (a[i] > a[i - 1] && br == 0 && br2 == 0)
                        {
                            br2++;
                            p = a[i];
                            a[i] = a[i - 1];
                            a[i - 1] = p;
                        }
                    }
                    if (br > 0)
                    {
                        for (i = 0; i < n; i++)
                        {
                            Console.Write(a[i] + " ");
                        }
                        Console.WriteLine();
                    }
                    if (br2 > 0)
                    {
                        for (i = 0; i < n; i++)
                        {
                            Console.Write(a[i] + " ");
                        }
                        Console.WriteLine();
                    }
                }
            }
        }
    }
}