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