#include <vector>
#include <cmath>
#include <limits>
#include <iostream>

template<typename T>
class Segtree{
  int nbin;
  T param_def;
  std::vector<T> seg_vec;
  std::function<T(T, T)> seg_func;
  T segtree_query_partial(int a, int b, int k, int l, int r){
    if(r <= a || b <= l) return param_def;
    if(a <= l && r <= b) return seg_vec[k];
    const T v_l = segtree_query_partial(a, b, k*2+1, l, (l+r)/2);
    const T v_r = segtree_query_partial(a, b, k*2+2, (l+r)/2, r);
    return seg_func(v_l, v_r);
  }
  auto max_bit(int32_t n){
    n = n & 0xFFFF0000 ? n & 0xFFFF0000 : n;
    n = n & 0xFF00FF00 ? n & 0xFF00FF00 : n;
    n = n & 0xF0F0F0F0 ? n & 0xF0F0F0F0 : n;
    n = n & 0xCCCCCCCC ? n & 0xCCCCCCCC : n;
    n = n & 0xAAAAAAAA ? n & 0xAAAAAAAA : n;
    return n;
  }
  public:
  Segtree(const std::vector<T>& data, const std::function<T(T, T)>& _seg_func, const T _param_def) :
    seg_func(_seg_func), param_def(_param_def) {
      nbin = max_bit(data.size()-1)*2;
      seg_vec.resize(nbin*2-1, param_def);
      auto insert_top = seg_vec.begin();
      insert_top += nbin-1;
      std::copy(data.cbegin(), data.cend(), insert_top);
      for(int i = nbin-2; i >= 0; i--){
        seg_vec[i] = seg_func(seg_vec[i*2+1], seg_vec[i*2+2]);
      }
    }
  void update(int i, int x){
    i += nbin-1;
    seg_vec[i] = x;
    while(i > 0){
      i = (i-1)/2;
      seg_vec[i] = seg_func(seg_vec[i*2+1], seg_vec[i*2+2]);
    }
  }
  T query(int a, int b){
    return segtree_query_partial(a, b, 0, 0, nbin);
  }
};

int main(){
  int N;
  std::cin >> N;
  std::vector<int>A_arr(N);
  for(int i = 0; i < N; i++){
    std::cin >> A_arr[i];
  }

  Segtree<int> seg(A_arr, [](int l, int r){return std::max(l, r);}, -1);
  for(int i = 0; i < N; i++){
    std::cout << std::max(seg.query(0, i), seg.query(i+1, N)) << "\n";
  }

  return 0;
}


