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