import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] agrs) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Stack<Integer> stack = new Stack<>();
StringBuilder sb = new StringBuilder();
int n = Integer.parseInt(br.readLine());
String[] arr = br.readLine().split(" ");
String[] ans = new String[n];
stack.push(0);
for(int i=1; i<n; i++) {
while(!stack.isEmpty() &&
Integer.parseInt(arr[stack.peek()])<Integer.parseInt(arr[i])) {
ans[stack.peek()] = arr[i];
stack.pop();
}
stack.push(i);
}
while(!stack.isEmpty()) { ans[stack.pop()] = "-1"; }
for(String s : ans) { sb.append(s).append(" "); }
System.out.println(sb);
}
}