#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int num;
  int num2;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  num = A[N - 1];
  num2 = A[N - 2];
  for (int i = 0; i < N; ++i) {
    if (A[i] == num) {
      cout << num2 << endl;
    } else {
      cout << num << endl;
    }
  }
}
