#include <bits/stdc++.h>
using namespace std;
vector<int> st(4 * 200005, 0);
vector<int> ar(200005, 0);
void build(int l, int r, int i) {
  if (l == r) {
    st[i] = ar[l];
    return;
  }
  build(l, ((l + r) / 2), i * 2);
  build(((l + r) / 2) + 1, r, i * 2 + 1);
  st[i] = max(st[i * 2], st[i * 2 + 1]);
}
int query(int l, int r, int al, int ar, int i) {
  if (l > ar or r < al) return 0;
  if (l >= al and r <= ar) return st[i];
  return max(query(l, ((l + r) / 2), al, ar, i * 2),
             query(((l + r) / 2) + 1, r, al, ar, i * 2 + 1));
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> ar[i];
  build(1, n, 1);
  cout << query(1, n, 2, n, 1) << "\n";
  for (int i = 2; i <= n - 1; i++) {
    cout << max(query(1, n, i, i - 1, 1), query(1, n, i + 1, n, 1)) << "\n";
  }
  cout << query(1, n, 1, n - 1, 1) << "\n";
  return 0;
}
