#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  std::vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  int lmax = 0, rmax = 0, MAX;
  for (int i = 0; i < n; i++) {
    lmax = *max_element(v.begin(), v.begin() + i);
    rmax = *max_element(v.begin() + i + 1, v.end());
    MAX = max(lmax, rmax);
    cout << MAX << endl;
  }
  return 0;
}
