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