#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; ++i) cin >> a[i];
  vector<long long> l(n);
  vector<long long> r(n);
  l[0] = a[0];
  r[n - 1] = a[n - 1];
  for (long long i = 1; i < n; ++i) {
    l[i] = max(l[i - 1], a[i]);
    r[n - i - 1] = max(l[n - i], a[n - i - 1]);
  }
  for (long long i = 0; i < n; ++i) {
    if (i == 0)
      cout << r[1] << endl;
    else if (i == n - 1)
      cout << l[n - 2] << endl;
    else
      cout << max(l[i - 1], r[i + 1]) << endl;
  }
}
