#include<bits/stdc++.h>
using namespace std;
priority_queue<int>Q;
int A[200001];
int main(){
	int a,i,m,s=0;
	cin>>a;
	for(i=1;i<=a;i++)cin>>A[i],Q.push(A[i]);
	m=Q.top(),Q.pop(),s=Q.top();
	for(i=1;i<=a;i++)if(A[i]==m)cout<<s<<endl;
		else cout<<m<<endl;
}