#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
long long n, q, a[N], seg[N << 2];
long long mrg(long long x1, long long x2) { return max(x1, x2); }
void build(int idx, int from, int to) {
  if (from == to) {
    seg[idx] = a[from];
    return;
  }
  int mid = (from + to) >> 1;
  build(idx << 1, from, mid);
  build(idx << 1 | 1, mid + 1, to);
  seg[idx] = mrg(seg[idx << 1], seg[idx << 1 | 1]);
}
long long query(int idx, int from, int to, int l, int r) {
  if (from >= l && to <= r) return seg[idx];
  if (from > r || to < l) return 0LL;
  int mid = (from + to) >> 1;
  long long x1 = query(idx << 1, from, mid, l, r);
  long long x2 = query(idx << 1 | 1, mid + 1, to, l, r);
  return mrg(x1, x2);
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  build(1, 1, n);
  cout << query(1, 1, n, 2, n) << endl;
  for (int i = 2; i < n; i++) {
    cout << max(query(1, 1, n, 1, i - 1), query(1, 1, n, i + 1, n)) << endl;
  }
  cout << query(1, 1, n, 1, n - 1);
}
