#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <typename T>
T gcd(T m, T n) {
  return n == 0 ? m : gcd(n, m % n);
}
template <typename T>
T lcm(T m, T n) {
  return n * m / gcd(n, m);
}
signed main(void) {
  long long num;
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; ++i) cin >> a[i];
  vector<long long> b(n);
  vector<long long> c(n);
  b[0] = a[0];
  c[n - 1] = a[n - 1];
  for (long long i = 1; i < n; ++i) {
    b[i] = max(a[i], b[i - 1]);
    c[n - 1 - i] = max(a[n - 1 - i], b[n - i]);
  }
  for (long long i = 0; i < n; ++i) {
    if (i == 0) {
      cout << c[i + 1] << endl;
    } else if (i == n - 1) {
      cout << b[i - 1] << endl;
    } else {
      cout << max(b[i - 1], c[i + 1]) << endl;
    }
  }
}
