#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
long long POW(long long b, long long p) {
  long long Ans = 1;
  while (p) {
    if (p & 1) Ans = (Ans * b);
    b = (b * b);
    p >>= 1;
  }
  return Ans;
}
long long BigMod(long long b, long long p, long long Mod) {
  long long Ans = 1;
  while (p) {
    if (p & 1) Ans = (Ans * b) % Mod;
    b = (b * b) % Mod;
    p >>= 1;
  }
  return Ans % Mod;
}
long long ModInverse(long long b, long long Mod) {
  return BigMod(b, Mod - 2, Mod);
}
string tostr(long long n) {
  stringstream rr;
  rr << n;
  return rr.str();
}
void deb(istream_iterator<string> it) { cout << endl; }
template <typename T, typename... Args>
void deb(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ",   ";
  deb(++it, args...);
}
const int MAXN = 200000 + 5;
int lg[MAXN + 1];
int st[MAXN][32];
int mx(int L, int R) {
  int j = lg[R - L + 1];
  return max(st[L][j], st[R - (1 << j) + 1][j]);
}
int main() {
  lg[1] = 0;
  for (int i = 2; i <= MAXN; i++) lg[i] = lg[i / 2] + 1;
  int N;
  cin >> N;
  int a[N + 2];
  for (int i = 0; i < N; i++) cin >> a[i];
  for (int i = 0; i < N; i++) st[i][0] = a[i];
  for (int j = 1; j <= 30; j++)
    for (int i = 0; i + (1 << j) <= N; i++)
      st[i][j] = max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
  cout << mx(1, N - 1) << "\n";
  for (int i = 1; i < N; i++) {
    cout << max(mx(0, i - 1), mx(i + 1, N - 1)) << "\n";
  }
}
