#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) {
    int leftmax = 0;
    for (int j = 0; j < i; j++) {
      if (leftmax == A[j]) break;
      leftmax = max(leftmax, A[j]);
    }
    int rightmax = 0;
    for (int j = N - 1; j > i; j--) {
      if (rightmax == A[j]) break;
      rightmax = max(rightmax, A[j]);
    }
    cout << max(leftmax, rightmax) << endl;
  }
}
