#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  int index = 1;
  int f = a.at(0);
  int s = -1;
  int f_cnt = 0;
  for (int i = 1; i < N; i++) {
    if (a.at(i) > f) {
      index = i + 1;
      f_cnt = 0;
      s = f;
      f = max(a.at(i), f);
    } else if (a.at(i) == f) {
      f_cnt++;
    } else {
      if (a.at(i) > s) s = max(s, a.at(i));
    }
  }
  if (f_cnt >= 2) {
    for (int i = 0; i < N; i++) {
      cout << f << endl;
    }
  } else {
    for (int i = 1; i < N + 1; i++) {
      if (i == index) {
        cout << s << endl;
      } else
        cout << f << endl;
    }
  }
}
