let n = read_int ()
let a = Array.init n @@ fun _ -> Scanf.scanf "%d\n" @@ fun d -> d
let f (m,(x,tf)) t = if t = x && tf then (m,(x,false)) else if t >= m then (t,(x,tf)) else (m,(x,tf))
let ans = Array.map (fun x -> let p = (Array.fold_left (fun (m,(n,tf)) t -> f (m,(n,tf)) t) (0,(x,true)) a) in fst p) a
let () = Array.iter (fun x -> print_int x; print_newline ()) ans