const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
const arr = (await readline()).split(",").map(Number);
const res = Array.from({ length: arr.length }, () => -1);
const stack = [];
for (let i = 0; i < arr.length * 2; i++) {
const idx = i % arr.length;
while (stack.length > 0 && arr[stack[stack.length - 1]] < arr[idx]) {
const index = stack.pop();
res[index] = arr[idx];
}
stack.push(idx);
}
console.log(res.join(" "));
})();