#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int c_head[n + 1];
  int c_tail[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  c_head[0] = 0;
  c_tail[n] = 0;
  for (int j = 1; j <= n; j++) {
    c_head[j] = max(c_head[j - 1], a[j - 1]);
    c_tail[n - j] = max(c_tail[n - j + 1], a[n - j]);
  }
  for (int k = 0; k < n; k++) {
    if (k == 0) {
      cout << c_tail[0] << endl;
    } else if (k == n - 1) {
      cout << c_head[n - 1] << endl;
    } else {
      cout << max(c_head[k - 1], c_tail[k + 1]) << endl;
    }
  }
  return 0;
}
