#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define pri 1000000007
#define all(x) x.begin(),x.end()
#define mx 32
using namespace std;

void masterstroke(){
ll n;
cin>>n;
ll x;
vector <ll> ans;
for(ll i=0;i<n;i++){
	cin>>x;
	ans.PB(x);
}
  sort(all(ans));
ll e=ans.size();
ll f1=ans[e-1];
ll f2=ans[e-2];
for(ll i=0;i<n;i++){
	if(a[i]==f1){cout<<f2<<endl;}
	else cout<<f1<<endl;
}


}


int main() {
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++)masterstroke();
	
	// your code goes here
	return 0;
}