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