#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, a[N], x[N], y[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    x[i] = max(x[i - 1], a[i]);
  }
  for (int i = n; i >= 1; i--) {
    y[i] = max(y[i - 1], a[i]);
  }
  for (int i = 1; i <= n; i++) {
    cout << max(x[i - 1], y[i + 1]) << endl;
  }
  return 0;
}
