#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;
long long gcd(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return (x * y) / gcd(x, y); }
long long a[200000];
long long f[200000];
long long b[200000];
int main() {
  long long n, m = -1;
  cin >> n;
  for (int i = (int)0; i < (int)n; ++i) cin >> a[i];
  for (int i = (int)0; i < (int)n; ++i) {
    if (m < a[i]) m = a[i];
    f[i] = m;
  }
  m = -1;
  for (int i = (int)0; i < (int)n; ++i) {
    if (m < a[n - 1 - i]) m = a[n - 1 - i];
    b[i] = m;
  }
  for (int i = (int)0; i < (int)n; ++i) {
    if (i == 0)
      cout << b[n - 2] << endl;
    else if (i == n - 1)
      cout << f[n - 2] << endl;
    else
      cout << max(f[i - 1], b[i - 1]) << endl;
  }
  return 0;
}
