Scanner sc=new Scanner(System.in);
Stack<Integer> st=new Stack<>();
int n=sc.nextInt();
int arr[]=new int[n];
int ans[]=new int[n];
for(int i=0 ; i<n ; i++)
arr[i]=sc.nextInt();
st.push(0);
boolean check=true;
for(int i=1 ; i<2*n-1 ; i++)
{
if(i>n-1)
{
i=i%n;
check=false;
}
if(arr[i]>arr[st.peek()])
{
while(!st.isEmpty() && arr[i]>arr[st.peek()] && i!=st.peek())
{
// System.out.println(arr[st.peek()] + " --> " + arr[i]);
// int j=binaryS(arr[st.peek()] , 0 , n , arr);
// ans[j]=arr[i];
ans[st.peek()]=arr[i];
st.pop();
}
if(!st.isEmpty() && i>=st.peek() && !check)
break;
if(check)
st.push(i);
}
else if(arr[i]<arr[st.peek()])
{
if(check)
st.push(i);
if(check==false && i>=st.peek()-1)
break;
}
}
while(!st.isEmpty())
{
// System.out.println(arr[st.peek()] + " --> " + "-1 ");
// int j=binaryS(arr[st.peek()] , 0 , n , arr);
// ans[j]=-1;
ans[st.peek()]=-1;
st.pop();
}
for(int i:ans)
System.out.println(i);