#include using namespace std; //#define int long long typedef long long ll; typedef pairpint; typedef vectorvint; typedef vectorvpint; #define pb push_back #define mp make_pair #define fi first #define se second #define ln <void chmin(T &t,U f){if(t>f)t=f;} templatevoid chmax(T &t,U f){if(tM; rep(i,N)chmax(M[A[i]],i); rep(i,N)isend[i]=M[A[i]]==i; sets; rep(i,N){ if(i)printf(" "); s.insert(A[i]); printf("%d",*s.rbegin()); if(isend[i])s.erase(A[i]); }puts(""); return 0; }