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