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

int main()
{
	int i, n, x, y;
	cin >> n;
	int a[n], b[n];
	for(i=0; i<n; i+=1)
	{
		cin >> a[i];
		b[i]=a[i];
	}
	sort(b, b+n);
	for(i=0; i<n; i+=1)
	{
		x=a[i];
		y=lower_bound(b, b+n, x)-b;
		if(y==n-1)
			cout << b[n-2] << endl;
		else
			cout << b[n-1] << endl;
	}
}