#include <bits/stdc++.h>
using namespace std;
const int M = 200005;
int main() {
  int n;
  vector<int> A(n);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
  }
  vector<int> left(n), right(n);
  for (int i = 0; i < n; ++i) {
    if (i == 0) {
      left[i] = A[i];
    } else {
      left[i] = max(A[i], left[i - 1]);
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    if (i == n - 1) {
      right[i] = A[n - 1];
    } else {
      right[i] = max(A[i], right[i + 1]);
    }
  }
  for (int i = 0; i < n; ++i) {
    if (i == 0) {
      cout << right[1] << endl;
    } else if (i == n - 1) {
      cout << left[i - 1] << endl;
    } else {
      cout << max(left[i - 1], right[i + 1]) << endl;
    }
  }
  cout << endl;
  return 0;
}
