#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1000000007;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int N;
int A[200020];
void solve() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vi maxL(N), maxR(N);
  maxL[0] = A[0];
  maxR[N - 1] = A[N - 1];
  for (int i = 1; i < N; i++) {
    maxL[i] = max(maxL[i - 1], A[i]);
    maxR[N - 1 - i] = max(maxR[N - 1 - i + 1], A[N - 1 - i]);
  }
  cout << maxR[1] << '\n';
  for (int i = 1; i < N - 1; i++) {
    cout << max(maxL[i - 1], maxR[i + 1]) << '\n';
  }
  cout << maxL[N - 1] << '\n';
  return;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
