#include using namespace std; int n; const int N = 1e5 + 10; int a[N]; int stk[N], tt; int res[N]; int main() { cin >> n; for (int i = 1; i <= n; i++)cin >> a[i]; for (int i = n; i >= 1; i--) { while (tt && a[stk[tt]] > a[i]) { res[stk[tt]]=i; tt--; } stk[++tt]=i; } for (int i = 1; i <= n; i++) res[i]?printf("%d ",a[res[i]]):printf("-1 "); return 0; }