#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int i, j, cnt;
  int n;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  int ma = 0, ma2 = 0;
  for (i = 0; i < n; i++) {
    if (ma < a[i]) {
      ma = a[i];
      cnt = i;
    }
  }
  for (i = 0; i < n; i++) {
    if (ma2 < a[i] && a[i] != ma) {
      ma2 = a[i];
    }
  }
  if (ma2 == 0) ma2 = ma;
  for (i = 0; i < cnt; i++) {
    cout << ma << endl;
  }
  cout << ma2 << endl;
  for (i = cnt + 1; i < n; i++) {
    cout << ma << endl;
  }
}
