import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = sc.nextInt();
Stack<Integer> s = new Stack<>();
s.push(0);
int[] ans = new int[n];
for(int i=1;i<n;i++){
while (!s.isEmpty() && arr[i]>arr[s.peek()]) {
ans[s.pop()]=arr[i];
}
s.push(i);
}
while(!s.isEmpty()){
ans[s.pop()]=-1;
}
for (int a : ans)
System.out.print(a + " ");
System.out.println();
}
}
what is wrong with this code , cannot pass all test cases