//https://ncode.syosetu.com/n4830bu/318/ #include using namespace std; int main() { int N; cin >> N; vector A(N); for (auto&& a : A) { cin >> a; } vector R(N, -1); vector seen(N); for (int i = N - 1; i >= 0; i--) { int a = A[i]; if (!seen[a]) { seen[a] = true; R[i] = a; } } set maine; for (int i = 0; i < N; i++) { int l = A[i], r = R[i]; maine.insert(l); cout << *maine.rbegin() << " \n"[i == N - 1]; if (r != -1) maine.erase(r); } }