#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), left(n), right(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  left.at(0) = a.at(0);
  right.at(n - 1) = a.at(n - 1);
  for (int i = 1; i < n; i++) {
    left.at(i) = max(left.at(i - 1), a.at(i));
    right.at(n - i - 1) = max(right.at(n - i), a.at(n - i - 1));
  }
  cout << right.at(0) << endl;
  for (int i = 1; i < n - 1; i++) {
    cout << max(left.at(i - 1), right.at(i + 1)) << endl;
  }
  cout << left.at(n - 1) << endl;
  return 0;
}
