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());
            double[] a = new double[n];
            int i, j, k = 0, v;
            double br = 0, max = 0, p;
            double l = Math.Pow(10, n-1);
            var b = Console.ReadLine().Split();
            for (i = 0; i < n; i++)
            {
                a[i] = int.Parse(b[i]);
            }
            if (n == 2)
            {
                p = a[0];
                a[0] = a[1];
                a[1] = p;
                Console.WriteLine((int)a[0] + " " + (int)a[1]);
            }
            else
            {
                for (i = 0; i < n; i++)
                {
                    br += a[i] * (double)l;
                    l /= 10;
                }
                max = br;
                for (i = 0; i < n - 1; i++)
                {
                    for (j = i + 1; j < n; j++)
                    {
                        p = a[i];
                        a[i] = a[j];
                        a[j] = p;
                        l = Math.Pow(10, n - 1);
                        br = 0;
                        for (v = 0; v < n; v++)
                        {
                            br += a[v] * (double)l;
                            l /= 10;
                        }
                        if (br > max)
                        {
                            max = br;
                            k = 1;
                        }
                        p = a[i];
                        a[i] = a[j];
                        a[j] = p;
                    }
                }
                if (k == 0)
                {
                    p = a[n-1];
                    a[n-1] = a[n-2];
                    a[n-2] = p;
                    for (i = 0; i < n; i++)
                    {
                        Console.Write((int)a[i] + " ");
                    }
                }
                else
                {
                    for (i = n - 1; i >= 0; i--)
                    {
                        a[i] = max % 10;
                        max = max / 10;
                    }
                    for (i = 0; i < n; i++)
                    {
                        Console.Write((int)a[i] + " ");
                    }
                }
            }

        }
    }
}