#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
signed main() {
  long long N;
  cin >> N;
  vector<long long> a(N);
  long long ma = 0;
  set<long long> id;
  for (long long(i) = (0); (i) < (N); (i)++) {
    cin >> a[i];
    if (i != 0) {
      if (chmax(ma, a[i]) || a[i] == ma) {
        id.insert(i);
      }
    }
  }
  cout << ma << endl;
  if (a[0] > ma) {
    for (long long(i) = (0); (i) < (N - 1); (i)++) {
      cout << a[0] << endl;
    }
  } else if (a[0] == ma || id.size() >= 2) {
    for (long long(i) = (0); (i) < (N - 1); (i)++) {
      cout << ma << endl;
    }
  } else {
    long long ma2 = 0;
    for (long long(i) = (0); (i) < (N); (i)++) {
      if (i == 1) continue;
      chmax(ma2, a[i]);
    }
    cout << ma2 << endl;
    for (long long(i) = (0); (i) < (N - 2); (i)++) {
      cout << ma << endl;
    }
  }
}
