#include <iostream>

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 pom = knj[i];
            knj[i] = knj[j];
            knj[j] = pom;

            long long ind1 = 0,ind2 =N-1,lepota1 = 0,lepota2=0,lepota = 0;
            while(knj[ind1] > knj[ind1+1])
            {
                lepota1++;
                ind1++;
            }
            while(knj[ind2] > knj[ind2-1])
            {
                lepota2++;
                ind2--;
            }
            if(lepota1 > lepota2)
                lepota = lepota1;
            else
                lepota = lepota2;
            if(lepota > maxlepota)
            {
                maxlepota = lepota;
                max1 = i;
                max2 = j;
            }
            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;
}