#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int first = 0;
  int second = 0;
  for (int i = 0; i < N; i++) {
    first = max(first, A[i]);
  }
  for (int i = 0; i < N; i++) {
    if (A[i] < first) second = max(second, A[i]);
  }
  bool allsame = true;
  for (int i = 0; i < N; i++) {
    if (A[i] != first) allsame = false;
  }
  if (allsame) {
    for (int i = 0; i < N; i++) {
      cout << first << endl;
    }
  } else {
    for (int i = 0; i < N; i++) {
      if (A[i] == first)
        cout << second << endl;
      else
        cout << first << endl;
    }
  }
  return 0;
}
