#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  vector<long long> a(N);
  for (int i = 0; i < (int)(N); i++) cin >> a.at(i);
  for (int i = 0; i < (int)(N); i++) {
    long long l, r;
    for (long long j = 0; j <= i; j++) {
      l = max(l, a.at(j));
    }
    for (long long j = i + 2; j < N; j++) {
      r = max(r, a.at(j));
    }
    cout << max(r, l) << endl;
  }
}
