#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
int main(void) {
  lint N;
  cin >> N;
  vector<lint> A(N);
  for (lint i = 0; i < (N); i++) cin >> A[i];
  int p;
  lint left_max, right_max, all_max;
  for (int i = 0; i < N; ++i) {
    auto it_pre_i = next(A.begin(), i);
    auto it_next_i = next(A.begin(), i + 1);
    (i == 0) ? left_max = 0 : left_max = *(max_element(A.begin(), it_pre_i));
    (i == N - 1) ? right_max = 0
                 : right_max = *(max_element(it_next_i, A.end()));
    all_max = max(left_max, right_max);
    cout << all_max << endl;
  }
  return 0;
}
