let N = Int(readLine()!)!
let arr = readLine()!.split(separator: " ").map{ Int(String($0))! }
var answer = Array(repeating: -1, count: N)
var stack = [Int]()
for (index, number) in arr.enumerated() {
while !stack.isEmpty && arr[stack.last!] < number {
answer[stack.last!] = number
stack.removeLast()
}
stack.append(index)
}
print(answer.map{String($0)}.joined(separator: " "))