#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
signed main() {
  long long n;
  cin >> n;
  vector<long long> migi(n), hidari(n);
  long long a[n];
  for (long long i = 0; i < (n); i++) cin >> a[i];
  long long now = 0;
  for (long long i = 0; i < (n); i++) {
    hidari[i] = max(now, a[i]);
    now = a[i];
  }
  now = 0;
  for (long long i = n - 1; i >= 0; i--) {
    migi[i] = max(now, a[i]);
    now = a[i];
  }
  for (long long i = 0; i < (n); i++) {
    if (!i)
      cout << migi[i] << endl;
    else if (i == n - 1)
      cout << hidari[i] << endl;
    else
      cout << max(migi[i + 1], hidari[i - 1]) << endl;
  }
  return 0;
}
