#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif*/
	ll r,n;
	cin>>n;
	vector<ll>a;
	set<ll>b;
	for(ll i=0;i<n;i++)
	{
		ll z;
		cin>>z;
		a.push_back(z);
		b.insert(z);
	}
	auto it=r.begin();
	ll mx=*it;
	--it;
	ll tx=*it;
	if(b.size()==1 )
	{
		for(ll i=0;i<n;i++)
			cout<<a[0]<<endl;
	}
	else
	{
		for(ll i=0;i<n;i++)
			{if(a[i] != mx)
				cout<<mx<<endl;
				else
					cout<<tx<<endl;
			}
	}
	
	return 0;
}