#include using i64 = long long; int main() { int n; std::cin >> n; std::vector a(n); std::map pos; for (int i = 0; i < n; i++) { std::cin >> a[i]; pos[a[i]] = i; } std::set s; for (int i = 0; i < n; i++) { s.insert(a[i]); std::cout << *s.rbegin() << " "; if (pos[a[i]] == i) s.erase(a[i]); } std::cout << std::endl; return 0; }