#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
    cin>>n;
    int a[n],memo1=0, memo2=0,index=-1;
    for(int i=0;i<n;i++){
            cin>>a[i];
            if(a[i]>memo1){memo1=a[i];index=i;}
    }
  	sort(a,a+n,greater<int>());
    for(int i=0;i<n;i++){cout<<(i==index?a[1]:memo1)<<endl;}
}
