#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e+14;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
void Yes() {
  cout << "Yes" << endl;
  exit(0);
}
void No() {
  cout << "No" << endl;
  exit(0);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int A[200200];
  for (int i = 0; i < N; i++) cin >> A[i];
  int l[200200], r[200200];
  l[0] = 0, r[N + 1] = 0;
  for (int i = 1; i <= N; i++) {
    l[i] = max(l[i - 1], A[i - 1]);
  }
  for (int i = 1; i <= N; i++) {
    r[i] = max(r[i + 1], A[i - 1]);
  }
  for (int i = 0; i < N; i++) {
    int ans = max(l[i], r[i + 2]);
    cout << ans << endl;
  }
  return 0;
}
