#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long

int main(){
	int n;
	cin>>n;
	int a[n];
	int ma=0,sma=0;
	rep(i,n){
		cin>>a[i];
		if(a[i]>ma){sma=ma;ma=a[i];}
		else if(a[i]>sma){sma=a[i];}
	}
	rep(i,n){
		if(a[i]==ma)cout << sma<<endl;
		else cout << ma << endl;
	}
}
