#![allow(unused_mut, unused_macros, unused_variables, unused_assignments, non_snake_case, unused_imports, dead_code)]

use std::collections::{HashMap, BinaryHeap, BTreeMap};

// [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 から拝借
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    // ABC128-C-Switches用に拡張
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, $t);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// 可愛い可愛い、お手製のライブラリ達
macro_rules! p {
    ($t:expr) => {
        println!("{}", $t);
    };
}
macro_rules! debug {
    ($t:expr) => {
        println!("{:?}", $t);
    };
}
fn gcd(a:usize, b:usize) -> usize {
    if b == 0 {return a};
    gcd(b, a % b)
}
fn lcm(a:usize, b:usize) -> usize {
    a / gcd(a, b) * b
}

use std::cmp::max;

// エントリーポイント
fn main() {
    input! {
        N:usize,
        A:[usize; N],
    }
    let max_left = {
        let mut max_v = vec![A[0]];
        for a in A.iter().skip(1) {
            max_v.push(max(*max_v.last().unwrap(), *a));
        }
        max_v
    };
    let max_right = {
        let mut max_v = vec![*A.last().unwrap()];
        for a in A.iter().rev().skip(1) {
            max_v.push(max(*max_v.last().unwrap(), *a));
        }
        max_v.reverse();
        max_v
    };
    let max_list = {
        let mut max_v = vec![max_right[1]];
        for n in 0..N {
            if N <= n + 2 {break;}
            max_v.push(max(max_left[n], max_right[n + 2]));
        }
        max_v.push(max_left[max_left.len() - 2]);
        max_v
    };
    for v in max_list {
        p!(v);
    }
}
