#include "bits/stdc++.h"
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

constexpr auto inf = 1e9;

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using ll = long long;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n, -1);
	for (auto& x : a)
	{
		cin >> x;
	}

	int maxnum = *max_element(all(a));

	vector<int> tmp(n);
	copy(all(a), tmp);

	sort(all(tmp));

	for (int i = 0; i < n; i++)
	{
		int ans = 0;

		if (tmp[n-1] == tmp[n-2])
		{
			ans = a[n - 1];
		}
		else
		{
			if (maxnum == a[i])
			{
				ans = tmp[n - 2];
			}
		}

		cout << ans << endl;
	}

	return 0;
}
