#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n + 1, -1);
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    b[i + 1] = max(b[i + 1], a[i]);
    for (int j = i + 2; j < n; ++j) {
      b[j] = b[j - 1];
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      b[i] = max(b[i], a[j]);
    }
  }
  for (int i = 0; i < (n); ++i) cout << b[i] << endl;
}
