123456789101112131415161718192021222324
#include<iostream>#include<stack>using namespace std;const int N=3000010;int a[N],f[N];stack<int>s;int n;int main(void){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=n;i>=1;i--) { while(!s.empty()&&a[s.top()]<=a[i]) s.pop(); f[i]=s.empty()?0:s.top(); s.push(i); } for(int i=1;i<=n;i++) printf("%d ",f[i]); return 0;}