#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;

struct max_t
{
	int operator()(int a, int b)const
	{
		return std::max(a, b);
	}
};
template<class T, class Op = std::plus<>>class seg_tree
{
	std::vector<T> vec;
	T unit;
	std::size_t sz;
	Op op;
	static std::size_t get_size(std::size_t s)
	{
		std::size_t ret = 1;
		while (ret < s)
		{
			ret <<= 1;
		}
		return ret;
	}
public:
	seg_tree(std::size_t size, T u = T(), Op f = Op()) :vec(), unit(u), sz(get_size(size)), op(f)
	{
		vec.assign(2 * sz, unit);
	}
	template<class Range>void set(Range const& rng)
	{
		std::size_t i = 0;
		for (auto&& v : rng)
		{
			vec[i + sz] = v;
			if (++i >= sz)
			{
				break;
			}
		}
		for (auto s = sz / 2; s > 0; s /= 2)
		{
			for (auto i : boost::irange<std::size_t>(0, s))
			{
				vec[(i + s)] = op(vec[2 * (i + s)], vec[2 * (i + s) + 1]);
			}
		}
	}
	T operator()(std::size_t start, std::size_t end)const
	{
		T L = unit, R = unit;
		for (std::size_t a = start + sz, b = end + sz; a < b; a >>= 1, b >>= 1)
		{
			if (a & 1)
			{
				L = op(L, vec[a++]);
			}
			if (b & 1)
			{
				R = op(vec[--b], R);
			}
		}
		return op(L, R);
	}
	void update(std::size_t i, T const& v)
	{
		auto k = i + sz;
		vec[k] = v;
		while (k >>= 1)
		{
			vec[k] = op(vec[2 * k], vec[2 * k + 1]);
		}
	}
};

void Main()
{
	int N;
	std::cin >> N;
	std::vector<int> vec(N);
	for (auto& v : vec)
	{
		std::cin >> v;
	}
	seg_tree<int, max_t> tree(N);
	tree.set(vec);
	std::cout << tree(1, N) << std::endl;
	for (auto i : boost::irange(1, N - 1))
	{
		std::cout << std::max(tree(0, i - 1), tree(i + 1, N)) << std::endl;
	}
	std::cout << tree(0, N - 1) << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}