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