/** * @FileName a.cpp * @Author kanpurin * @Created 2020.05.26 23:14:06 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int main() { int n;cin >> n; vector a(n); map mp; for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i]] = i; } set st; for (int i = 0; i < n; i++) { st.insert(a[i]); cout << *st.rbegin() << " "; if (mp[a[i]] == i) { st.erase(a[i]); } } return 0; }