#include #include #include using namespace std; int main() { int n; cin >> n; vector a(n); for(int &x : a) cin >> x; vector smeta(n); stack stek; for(int i = 0; i < n; i++) { while(!stek.empty() && a[i] > stek.top()) { stek.pop(); } if(stek.empty()) smeta[i] = -1; else smeta[i] = stek.top(); stek.push(a[i]); } for(int x : smeta) cout << x << " "; cout << endl; return 0; }