#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
using namespace std;

int main() {
	int n,s1,s2,k;
  int a[200002];
	cin >> n;
   for(int i=0;i<n;i++){
        cin<<a[i];
    }
   for(int i=0;i<n;i++){
　　if(s2<a[i]){
             if(s1<a[i]){
                   s2=s1;
                   s1=a[i];
                   k=i;
}
          else
                  s2=a[i];
}
for(int i=0;i<n;i++){
　　　if(i!=k)
                cout<<s1<<endl;
            else
                 cout<<s2<<endl;
}
}

}