#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=3e6+10,inf=1e9+10;
const ll INF=1e18+10;
int n,k;
stack<int>s;
int a[N];
int ans[N];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=n;i>=1;i--){
while(!s.empty()&&a[i]>a[s.top()])
s.pop();
ans[i]=s.empty()?0:s.top();
s.push(i);
}
for(int i=1;i<=n;i++)
cout<<ans[i]<<" ";
return 0;
}