#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  int N;
  cin>>N;
  int a[N];
  int saidai = 0;
  int saidai2 = 0;
  for(int i = 0;i>N;i++){
    cin>>a[i];
    saidai = max(saidai,a[i]);
  }
  int saidaiko = 0;
  for(int i = 0;i<N;i++){
    if(a[i] == saidai){
      saidaiko++;
    }
  }
  if(saidaiko > 1){
    for(int i = 0;i<N;i++){
      cout << saidai << endl;
    }
    return 0
  }
  else{
    for(int i = 0;i<N;i++){
      if(a[i] != saidai){
        saidai2 = max(saidai2,a[i]);
      }
    }
    for(int i = 0;i<N;i++){
      if(a[i] != saidai){
        cout << saidai << endl;
      }
      else{
        cout << saidai2 << endl;
      }
    }
  }
  return 0;
}
      
    