include[HTML_REMOVED]
using namespace std;
const int N=10010;
int n;
int stk[N],tt;
int main()
{
cin>>n;
for(int i=0;i[HTML_REMOVED]>x;
while(tt&&stk[tt]>=x)tt–;
if(tt)cout<<stk[tt]<<” “;
else cout<<”-1”<<” “;
stk[++tt]=x;
}
return 0;
}