#include <bits/stdc++.h>
#include<string>
using namespace std;
int main(){
int  n,a[200000]={},b[200000]={};
cin>>n;
for (int i=0;i<n;i++){
    cin>>a[i];
    b[i]=a[i];

}
sort(a,a+n);
for (int i=0;i<n;i++){
    if(b[i]==a[n-1])
    cout<<a[n-2]<<' ';
else cout<<a[n-1]<<" ";}
}
