#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long A, B, i, j;
  cin >> A;
  unsigned long long answer[A];
  for (i = 0; i < A; i++) cin >> answer[i];
  unsigned long long* maximum1index = max_element(answer, answer + A);
  unsigned long long maximum1 = *maximum1index;
  unsigned long long maximum2 = 0;
  for (i = 0; i < A; i++) {
    if (answer[i] > maximum2 && answer[i] < maximum1) maximum2 = answer[i];
  }
  for (i = 0; i < A; i++) {
    if (answer[i] == maximum1) {
      cout << maximum2 << endl;
    } else {
      cout << maximum1 << endl;
    }
  }
  return 0;
}
