模板
#include <bits/stdc++.h>
using i64 = long long;
std::vector<int> stk(100000);//用数组模拟栈,特点是先进后出。
int tt;//表示栈顶。
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
for (int i = 0; i < n; i ++) {
int x;
std::cin >> x;
while (tt && stk[tt] >= x) {
tt --;//表示出栈。
}
if (tt) {
std::cout << stk[tt] << " ";
} else {
std::cout << -1 << " ";
}
stk[++ tt] = x;
}
return 0;
}