#include using namespace std; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define REP(i,n) for (int i = 0; i < (n); i++) // ------------------------------------- typedef pair PII; int A[100001]; int main() { int N; cin >> N; map m; REP(i, N) { int ai; scanf("%d", &ai); m[ai] = i; A[i] = ai; } set s; REP(i, N) { if (i > 0) _P(" "); int ai = A[i]; s.insert(ai); _P("%d", *s.rbegin()); if (m[ai] == i) s.erase(ai); } _P("\n"); return 0; }