#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, INF = 1e18;
template <class T>
inline bool CHMAX(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool CHMIN(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
class SegmentTree {
 private:
  long long N;
  T initVal;
  std::vector<T> ary;
  std::function<T(T &, T &)> merge;
  void init(long long n) {
    while (N < n) N <<= 1;
    ary.resize(N << 1, initVal);
  }

 public:
  SegmentTree(long long n, T initVal, std::function<T(T &, T &)> f)
      : N(1), initVal(initVal), merge(f) {
    init(n);
  }
  inline void update(long long i, T val) {
    ary[i += N] = val;
    while (i > 1) {
      i >>= 1;
      ary[i] = merge(ary[i << i], ary[(i << 1) + 1]);
    }
  }
  inline void add(long long i, T val) { update(i, ary[i + N] + val); }
  inline T query(long long l, long long r) {
    if (l >= r) return initVal;
    T vr = initVal, vl = initVal;
    for (l += N, r += N; l != r; l >>= 1, r >>= 1) {
      if (l & 1) vl = merge(vl, ary[l++]);
      if (r & 1) vr = merge(vr, ary[--r]);
    }
    return merge(vl, vr);
  }
};
using ST = SegmentTree<long long>;
signed main() {
  long long N;
  cin >> N;
  vector<long long> a(N);
  for (long long i = (0); i < (N); i++) cin >> a[i];
  auto seg = ST(N, -1, [](long long &a, long long &b) { return max(a, b); });
  for (long long i = (0); i < (N); i++) seg.update(i, a[i]);
  for (long long i = (0); i < (N); i++) {
    if (i == 0)
      cout << seg.query(i + 1, N) << endl;
    else if (i == N - 1)
      cout << seg.query(0, N - 1) << endl;
    else
      cout << max(seg.query(0, i), seg.query(i + 1, N)) << endl;
  }
}
