#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline long long toLL(string s) {
  long long v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < (long long)(n); i++) cin >> a[i];
  vector<long long> r(n, 0), l(n, 0);
  l[0] = a[0];
  for (long long i = (1); i < (n); ++i) {
    l[i] = max<long long>(a[i], a[i - 1]);
  }
  r[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    r[i] = max<long long>(a[i], a[i + 1]);
  }
  for (long long i = 0; i < (long long)(n); i++) {
    long long ans = 0;
    if (i > 0) ans = max(l[i - 1], ans);
    if (i < n - 1) ans = max(ans, r[i + 1]);
    cout << ans << endl;
  }
  return 0;
}
