#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  vector<int> C(n);
  int count = 0;
  int max = 0;
  cin >> A.at(0);
  for (int i = 1; i < n; i++) {
    cin >> A.at(i);
    if (A.at(i) > max) {
      max = A.at(i);
    }
  }
  for (int i = 0; i < n; i++) {
    if (A.at(i) == max) {
      C.at(i) = 1;
      count += 1;
    }
  }
  int second_max = 0;
  if (count == 1) {
    for (int i = 0; i < n; i++) {
      if (C.at(i) == 0) {
        if (second_max < A.at(i)) second_max = A.at(i);
      }
    }
    for (int i = 0; i < n; i++) {
      if (C.at(i) == 0) {
        cout << max << endl;
      } else {
        cout << second_max << endl;
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      cout << max << endl;
    }
  }
}
