#include <bits/stdc++.h>
using namespace std;
struct SegTree {
  int seg_tree_size = 1;
  int nums_size;
  vector<long long> data;
  SegTree(int origin_size, vector<long long> a) {
    while (seg_tree_size < origin_size) seg_tree_size *= 2;
    nums_size = seg_tree_size;
    seg_tree_size = seg_tree_size * 2 - 1;
    data = vector<long long>(seg_tree_size, -1);
    for (int i = 0; i < origin_size; i++) {
      update(i, a[i]);
    }
  }
  void update(int k, int a) {
    k += (seg_tree_size - nums_size);
    data[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      data[k] = max(data[k * 2 + 1], data[k * 2 + 2]);
    }
  }
  int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return -1;
    if (a <= l && r <= b)
      return data[k];
    else {
      int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return max(vl, vr);
    }
  }
  int query(int a, int b) { return query(a, b, 0, 0, nums_size); }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  SegTree st(n, v);
  cout << st.query(1, n) << endl;
  for (int i = 1; i < n - 1; i++) {
    cout << max(st.query(0, i - 1), st.query(i + 1, n)) << endl;
  }
  cout << st.query(0, n - 1) << endl;
}
