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