using System;
using System.Linq;

namespace Polica
{
    class Program
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            if (N >= 2)
            {
                string[] niz = Console.ReadLine().Split(' ');
                int[] A = niz.Select(x => int.Parse(x)).ToArray();
                int br = 0;
                for (int i = 0; i < N; i++)
                {
                    if (A[i] > 9 || br == 2 || A[i] < 0)
                    {
                        goto end;
                    }
                    if (A[i] == 0)
                    {
                        br++;
                    }
                }
                double max = 0, maxx = 0;
                int j = 0;
                for (int i = N - 1; i >= 0; i--)
                {
                    max += A[j++] * Math.Pow(Convert.ToDouble(10), Convert.ToDouble(i));
                }
                maxx = max;
                int pom;
                double nb = 0;
                    for (int i = 0; i < N - 1; i++)
                    {
                        for (j = i + 1; j < N; j++)
                        {
                            nb = 0;
                            pom = A[i];
                            A[i] = A[j];
                            A[j] = pom;
                            int m = 0;
                            for (int k = N - 1; k >= 0; k--)
                            {
                                nb += A[m++] * Math.Pow(Convert.ToDouble(10), Convert.ToDouble(k));
                            }
                            pom = A[j];
                            A[j] = A[i];
                            A[i] = pom;
                            if (nb > max)
                            {
                                max = nb;
                            }
                        }
                    }
                if(max == maxx)
                {
                    nb = 0;
                    pom = A[N - 1];
                    A[N - 1] = A[N - 2];
                    A[N - 2] = pom;
                    int l = 0;
                    for (int k = N - 1; k >= 0; k--)
                    {
                        nb += A[l++] * Math.Pow(Convert.ToDouble(10), Convert.ToDouble(k));
                    }
                    max = nb;
                }
                int[] broj = max.ToString().ToCharArray().Select(x => (int)Char.GetNumericValue(x)).ToArray();
                for (int i = 0; i < N; i++)
                {
                    Console.Write(broj[i] + " ");
                }
            }
            end:;
        }
    }
}