#include<bits/stdc++.h>
using namespace std;
 

   int main(){
      int N;
      cin >> N;
     vector <int> vec(N);
       vector <int> vec1(N);
       
     for(int i=0;i<N;i++){
       cin >> vec[i];
         vec1[i] = vec[i];
     }
       int max = *max_element(vec.begin(),vec.end());
       rep(i,N){
           if(vec1[i] == max){
               sort(vec.begin(),vec.end());
               cout << vec[N-2] << endl;
           }
           else cout << max << endl;
    }
   }
