#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
int N;
int A[200005], L[200005], R[200005];
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N; ++i) {
    if (i == 0) continue;
    if (i == 1) {
      L[i] = A[0];
      continue;
    }
    L[i] = max(L[i - 2], A[i - 1]);
  }
  for (int i = N - 1; i >= 0; --i) {
    if (i == N - 1) continue;
    if (i == N - 2) {
      R[i] = A[N - 1];
      continue;
    }
    R[i] = max(R[i + 2], A[i + 1]);
  }
  for (int i = 0; i < N; ++i) {
    if (i == 0) {
      cout << R[0] << endl;
      continue;
    }
    if (i == N - 1) {
      cout << L[N - 1] << endl;
      continue;
    }
    int a = max(L[i], R[i]);
    cout << a << endl;
  }
  return 0;
}
