#include<fstream>
#include<string>
#include<iostream>
#include<sstream>
#include<iterator>
#include<cmath>

using namespace std;


int main(){
 int N;
 cin >> N;
 int a[N];
 int i;
 int j;
 for(i=0;i<N;++i){
     cin >> a[i];
   }
  int tmp = 0;
  int best;
  int hukusuu=0;
 for(i=0;i<1;++i){
   for(j=1;j<N;++j){
     if(tmp < a[j]){
       tmp = a[j];
       best = j;
       hukusuu = 0;}
     else if(tmp == a[j]){
       hukusuu++;}}
   cout << tmp << endl;
 }
 if(a[0]>=tmp){
   for(i=1;i<N;++i){
     cout << a[0] << endl;
   }
  else if(hukusuu>0){
    for(i=1;i<N;++i){
    cout << tmp << endl;
    }}
   else{
    for(i=1;i<N;++i){
    if(i!=best){cout << tmp << endl;}
      else{
        int newtmp = 0;
        for(j=0;j<N;++j){
          if(j!=best)newtmp=max(newtmp,a[j]);}
        cout << newtmp << endl;
      }
    }
   }
 }  
 return 0;
}
