#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, arr[1000000], r;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  if (arr[n - 1] == arr[n - 2]) {
    for (long long i = 0; i < n; i++) {
      cout << arr[n - 1] << "\n";
    }
  } else {
    for (long long i = 0; i < n; i++) {
      if (arr[i] == arr[n - 2]) {
        r = i;
      }
    }
    for (long long i = 0; i < n; i++) {
      if (i != r) {
        cout << arr[n - 1] << "\n";
      } else {
        cout << arr[n - 2] << "\n";
      }
    }
  }
}
