#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	std::vector<int> A(n + 1, 0);
	for(int i = 0; i < n; i++) A[i + 1] = std::max(A[i], a[i]);
	
	int tmp = 0;
	std::vector<int> ans;
	for(int i = n - 1; i >= 0; i--) {
		ans.push_back(std::max(A[i], tmp));
		tmp = std::max(tmp, a[i]);
	}
	for(auto v: ans) printf("%d\n", v);
	return 0;
}
