#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll mod = 1000000007;
ll mod2 = 998244353;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n), b(n), c(n);
  for (int i = (int)(0); i < (int)(n); i++) {
    cin >> a[i];
  }
  b[0] = a[0];
  c[n - 1] = a[n - 1];
  for (int i = (int)(1); i < (int)(n); i++) b[i] = max(b[i - 1], a[i]);
  for (int i = (int)(n - 2); i >= (int)(0); i--) c[i] = max(c[i + 1], a[i]);
  for (int i = (int)(0); i < (int)(n); i++) {
    if (i == 0) {
      cout << c[1] << endl;
      continue;
    }
    if (i == n - 1) {
      cout << b[n - 1] << endl;
      continue;
    }
    cout << max(b[i - 1], c[i + 1]) << endl;
  }
}
