#include <bits/stdc++.h>
using namespace std;

constexpr int mxn = 1e5 + 10;

int a[mxn], ans[mxn];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    fill(ans, ans + n, INT_MAX);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    stack<int> p;
    for (int i = 0; i < n; i++) {
        while (!p.empty() && a[i] > a[p.top()]) {
            ans[p.top()] = a[i];
            p.pop();
        }
        p.push(i);
    }
    for (int i = 0; i < n; i++) {
        if (ans[i] == INT_MAX)
            cout << '*';
        else
            cout << ans[i];
        cout << " \n"[i == n - 1];
    }
}