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