#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, a[200000], max, sec, I = 0;
  cin >> n;
  cin >> a[0];
  max = a[0];
  sec = max;
  for (i = 1; i < n; i++) {
    cin >> a[i];
    if (a[i] > max) {
      sec = max;
      max = a[i];
      I = i;
    } else if (a[i] > sec)
      sec = a[i];
  }
  for (i = 0; i < I; i++) cout << max << endl;
  cout << sec << endl;
  for (i = I + 1; i < n; i++) cout << max << endl;
}
