#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long mod = 1e9 + 7;
const long long least = -1e9;
const long long most = 1e9;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> a(n + 2, least);
  for (long long x = 1; x <= n; x++) cin >> a[x];
  vector<long long> pref = a, suff = a;
  for (long long x = 1; x <= n; x++) pref[x] = max(pref[x], pref[x - 1]);
  for (long long x = n - 1; x > 0; x--) suff[x] = max(suff[x], suff[x + 1]);
  for (long long x = 1; x <= n; x++) {
    cout << max(pref[x - 1], suff[x + 1]) << " ";
  }
  return 0;
}
