#include<bits/stdc++.h>

using namespace std;

void NGE(int arr[] , int n){


        int res[n];
        //starting from reverse to get the right order for each element
        res[n-1] = -1;
        stack<int> s;
        s.push(arr[n-1]);
        for(int i =n-2;i>=0;i--){
            
            while(!s.empty() && arr[i]>s.top())
                s.pop();
            
            if(s.empty() )
                res[i] = -1;
            else
                res[i] = s.top();
            
            s.push(arr[i]);    
        }
        
    for(int i =0;i<n;i++)
        cout<<res[i]<<endl;
        
 
}
int main(){
    
    
    
    int n;
    cin>>n;
    int arr[n];
    for(int i =0;i<n;i++){
        cin>>arr[i];
    }
    
    NGE(arr , n);
    return 0;
}