#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  vector<long long> a(N);
  cin >> a[0];
  long long amax_1 = a[0];
  long long amax_2 = a[0];
  for (long long i = 1; i < N; i++) {
    cin >> a[i];
    if (a[i] > amax_1) {
      amax_2 = amax_1;
      amax_1 = a[i];
    }
    if (a[i] > amax_2 && a[i] < amax_1) {
      amax_2 = a[i];
    }
  }
  long long cnt = 0;
  for (long long i = 0; i < N; i++) {
    if (a[i] == amax_1) {
      cnt++;
    }
  }
  for (long long i = 0; i < N; i++) {
    if (cnt > 1)
      cout << amax_1 << endl;
    else {
      if (amax_1 == a[i])
        cout << amax_2 << endl;
      else
        cout << amax_1 << endl;
    }
  }
}
