use self::sparse_table::SparseTable;
use std::cmp::min;
use std::collections::BinaryHeap;

const INF: i64 = 1 << 50;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let a: Vec<i64> = sc.vec(n);
    let odd_a: Vec<_> = a
        .iter()
        .enumerate()
        .map(|(i, &a)| if i % 2 == 1 { (a, i) } else { (INF, 0) })
        .collect();
    let even_a: Vec<_> = a
        .iter()
        .enumerate()
        .map(|(i, &a)| if i % 2 == 0 { (a, i) } else { (INF, 0) })
        .collect();
    let odd = sparse_table::SparseTable::from(&odd_a, (INF, 0), min);
    let even = sparse_table::SparseTable::from(&even_a, (INF, 0), min);

    let mut heap = BinaryHeap::new();
    heap.push((0, 0, n, false));
    let mut ans = vec![];
    while let Some((_, l, r, swap)) = heap.pop() {
        let (odd, even) = if swap { (&even, &odd) } else { (&odd, &even) };
        let (first_min, first_pos) = even.get(l, r);
        let (second_min, second_pos) = odd.get(first_pos, r);
        ans.push(first_min);
        ans.push(second_min);

        if first_pos - l > 0 {
            let t = even.get(l, first_pos).0;
            heap.push((-t, l, first_pos, swap));
            assert_ne!(INF, t);
        }
        if second_pos - (first_pos + 1) > 0 {
            let t = odd.get(first_pos + 1, second_pos).0;
            heap.push((-t, first_pos + 1, second_pos, !swap));
            assert_ne!(INF, t);
        }
        if r - (second_pos + 1) > 0 {
            let t = even.get(second_pos + 1, r).0;
            heap.push((-t, second_pos + 1, r, swap));
            assert_ne!(INF, t);
        }
    }

    for i in 0..n {
        if i > 0 {
            sc.write(" ");
        }
        sc.write(ans[i]);
    }
    sc.write("\n");
}

pub mod sparse_table {

    pub struct SparseTable<T, F> {
        data: Vec<Vec<T>>,
        op: F,
    }

    impl<T, F> SparseTable<T, F>
    where
        T: Copy,
        F: Fn(T, T) -> T,
    {
        pub fn from(v: &[T], init: T, op: F) -> Self {
            let size = v.len().next_power_of_two();
            let count = size.trailing_zeros() as usize + 1;
            let mut data = vec![vec![init; size]; count];
            for (i, v) in v.iter().cloned().enumerate() {
                data[0][i] = v;
            }
            for c in 1..count {
                for i in 0..size {
                    let next = ::std::cmp::min(size - 1, i + (1 << (c - 1)));
                    data[c][i] = op(data[c - 1][i], data[c - 1][next]);
                }
            }

            SparseTable { data: data, op: op }
        }

        /// get the result for [l, r)
        pub fn get(&self, l: usize, r: usize) -> T {
            assert!(l < r);
            let length = r - l;
            if length == 1 {
                return self.data[0][l];
            }
            let block_size = length.next_power_of_two() >> 1;
            let c = block_size.trailing_zeros() as usize;
            let left = self.data[c][l];
            let right = self.data[c][r - block_size];
            (self.op)(left, right)
        }
    }
}
pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 177532