๐งธ ํ๊ณผ ๊ฐ์ ์ ํ์ ๋ฌธ์ ์ด๋ค.
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');
const N = +input.shift();
const nums = input[0].split(" ").map((el, index) => [index, +el]);
const stack = [];
stack.push(nums[0]);
const answer = new Array(N).fill(-1);
for (let i = 1; i < N; i++) {
while (stack.length) {
if (stack[stack.length - 1][1] < nums[i][1]) {
answer[stack[stack.length - 1][0]] = nums[i][1];
stack.pop();
} else break;
}
stack.push(nums[i]);
}
console.log(answer.join(" "));