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

int main() {
  long long N;
  cin >> N;
  vector<long long> v(N);
  for (long long i = 0; i < N; i++) {
    cin >> v.at(i);
  }
  
  sort.(v.begin(),v.end());
  long long m1 = v.at(N-1);
  long long m2 = v.at(N-2);
  
  for (long long i = 0; i < N; i++) {
    if (v.at(i) == m1) {
      cout << m2 << endl;
    }
    else {
      cout << m1 << ebdl;
    }
  }
  
  
}

