#include <bits/stdc++.h>
using namespace std;
int64_t mod = 1e9 + 7;
int64_t INF = 1e18;
double EPS = 0.00000001;
int main() {
  int64_t n;
  cin >> n;
  vector<int64_t> a(n);
  for (int64_t i = 0; i < n; i++) cin >> a[i];
  vector<int64_t> b, c;
  b = c = a;
  for (int64_t i = 0; i < n - 1; i++) {
    b[i + 1] = max(b[i + 1], b[i]);
  }
  for (int64_t i = n - 1; i > 0; i--) {
    c[i - 1] = max(c[i - 1], c[i]);
  }
  for (int64_t i = 0; i < n; i++) {
    if (i == 0) {
      cout << (c[i]) << endl;
    } else if (i == n - 1) {
      cout << (b[i]) << endl;
    } else {
      cout << (max(b[i - 1], c[i + 1])) << endl;
    }
  }
  return 0;
}
