use std::io::{read_to_string, stdin}; fn main() { let temp = read_to_string(stdin()).unwrap(); let mut iter = temp .split_ascii_whitespace() .map(|x| x.parse::().unwrap()); let n = iter.next().unwrap(); let arr = (0..n).map(|i| (i + 1, iter.next().unwrap())); let mut stack = vec![]; for e in arr { if stack.is_empty() { stack.push(e); print!("{} ", 0); } else { while let Some(top) = stack.last() { if top.1 >= e.1 { stack.pop(); } else { break; } } if stack.is_empty() { stack.push(e); print!("{} ", 0); } else { print!("{} ", stack.last().unwrap().0); stack.push(e); } } } }