#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main() 
{ 
	SPEED
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; ++i)
    {
    	cin >> arr[i];
    }

    int brr[n] = {0};
    int larg = -1;
    for (int i = 0; i < n; ++i)
    {
    	if (arr[i]>larg)
    	{
    		larg = arr[i];
    	}
    }
    for (int i = 0; i < n; ++i)
    {
    	if (arr[i]==larg)
    	{
    		brr[i] = -1;
    	}
    }

    int larg2 = -1;
    for (int i = 0; i < n; ++i)
    {
    	if (arr[i]>larg2 && arr[i]<larg)
    	{
    		larg2 = arr[i];
    	}
    }
    if (larg2==-1)
    {
    	larg2 = larg;
    }

    for (int i = 0; i < n; ++i)
    {
    	if (brr[i]==-1)
    	{
    		brr[i] = larg2;
    	}
    	else
    	{
    		brr[i] = larg;
    	}
    }


    for (int i = 0; i < n; ++i)
    {
    	cout << brr[i] << '\n';
    }
    return 0;      
} 