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