#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

struct Elem {
    int val;
    int index;
};

int main() {
    int n;
    cin >> n;
    auto a = vector<Elem>(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].val;
        a[i].index = i;
    }
    sort(a.begin(), a.end(), [](auto x, auto y) { return x.val < y.val; });

    auto ans = vector<int>(n);
    for (int i = 0; i < n - 1; i++) {
        cout << *max_element(a.begin() + (i + 1), a.begin() + (i + 1) + (n - 1)) << "\n";
        ans[a[i].index] = a.back().val;
    }

    ans[a.back().index] = (a.rbegin() + 1)->val;
    for (auto a : ans) {
        cout << a << "\n";
    }

    return 0;
}
