#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<long long> A(N), B;
  for (int i = 0; i < N; i++) cin >> A[i];
  B = A;
  sort(B.begin(), B.end());
  long long M = *max_element(A.begin(), A.end());
  if (M == B[1]) {
    for (int i = 0; i < N; i++) cout << M << endl;
  } else {
    for (int i = 0; i < N; i++) {
      if (A[i] == M)
        cout << B[1] << endl;
      else
        cout << M << endl;
    }
  }
  return 0;
}
