use std::{ collections::{BTreeSet, HashMap, HashSet, VecDeque}, fmt::Debug, io::stdin, str::FromStr, sync::OnceLock, }; use proconio::marker::Chars; fn main() { proconio::input! { n: usize, a: [u64; n], } let mut s = a .iter() .copied() .enumerate() .map(|(i, v)| (v, i)) .collect::>(); s.sort_unstable(); let s = { let mut t = Vec::new(); let mut i = 0; while i < n { let (value, first) = s[i]; let mut last = first; i += 1; while i < n { let (value2, idx) = s[i]; if value != value2 { break; } last = idx; i += 1; } t.push((value, first, last)); } t }; let mut r = a.clone(); for (value, first, last) in s { r[first..=last].fill(value); // for i in first..=last { // r[i] = std::cmp::max(r[i], value); // } } println!( "{}", r.into_iter() .map(|r| format!("{r}")) .collect::>() .join(" ") ); }