#include <iostream>

using namespace std;

long maksimum(long arr[], long n, long p = 0) {
    long t = arr[p];
    for (long i = p; i < n; i++) {
        if (arr[i] >= t) {
            t = arr[i];
        }
    }

    return t;
}

long indexOf(long arr[], long n, long x) {
    for (long i = 0; i < n; i++) {
        if (arr[i] == x) {
            return i;
        }
    }
}

int main() {

    long n;
    cin >> n;

    long niz[n];
    for (long i = 0; i < n; i++) {
        cin >> niz[i];
    }

    if (n == 2) {
        swap(niz[0], niz[1]);
    } else {
        long maks = maksimum(niz, n);
        if (maks == niz[0]) {
            maks = maksimum(niz, n, 1);
            if (maks == niz[1]) {
                int m = maksimum(niz, n, 2);
                swap(niz[1], niz[indexOf(niz, n, m)]);
            } else {
                swap(niz[1], niz[indexOf(niz, n, maks)]);
            }
        } else {
            swap(niz[0], niz[indexOf(niz, n, maks)]);
        }
    }

    for (int i = 0; i < n; i++) {
        cout << niz[i] << " ";
    }

    return 0;
}