#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
using namespace std;

int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i=0; i< N; i++) cin >> A[i];
  auto B = A;
  sort(B.begin(), B.end());
  int ma1 = B.back();
  int ma2 = B[B.size()-2];
  
  for(int i=0; i < N; i++){
    if(A[i] == ma) cout << ma2 << endl;
    else cout << ma << endl;
  }
}
  
