use std::{ collections::{BTreeSet, HashMap, HashSet, VecDeque}, fmt::Debug, io::stdin, str::FromStr, sync::OnceLock, }; use proconio::marker::Chars; fn main() { proconio::input! { n: u64, a: [u64; n], } let mut s = a.clone(); s.sort_unstable(); let s = s .windows(2) .filter(|s| s[0] == s[1]) .map(|s| s[0]) .collect::>(); let mut r = a.clone(); for s in s { let first = a.iter().position(|a| *a == s).unwrap(); let last = a.iter().rposition(|a| *a == s).unwrap(); for i in first..=last { r[i] = std::cmp::max(r[i], s); } } println!( "{}", r.into_iter() .map(|r| format!("{r}")) .collect::>() .join(" ") ); }