#include <bits/stdc++.h>

using namespace std;

int main()
{
    int N;
    long long int maxlepota = 0;
    int max1,max2;
    cin >> N;
    int *knj = new int[N];
    int *res = new int[N];
    for(int i = 0;i < N;i++)
    {
        cin >> knj[i];
    }
    for(int i = 0;i < N;i++)
    {
        res[i] = knj[i];
    }
    for(int i = 0; i < N;i++)
    {
        for(int j = i+1; j < N;j++)
        {
            int lepota = 0;
            int pom = knj[i];
            knj[i] = knj[j];
            knj[j] = pom;

            for(int k = 0;k<N;k++)
            {
                lepota += knj[k] * pow(10,N-k);
            }

            if(lepota > maxlepota)
            {
                max1 = i;
                max2 = j;
                maxlepota = lepota;
            }

            pom = knj[i];
            knj[i] = knj[j];
            knj[j] = pom;
        }
    }

    int p = res[max1];
    res[max1] = res[max2];
    res[max2] = p;

    for(int i = 0;i< N;i++)
    {
        cout << res[i] << " ";
    }
    return 0;
}