#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  int larg = arr[0];
  int idx = 0;
  for (int i = 1; i < n; ++i) {
    if (arr[i] > larg) {
      larg = arr[i];
      idx = i;
    }
  }
  int larg2 = -1;
  for (int i = 0; i < n; ++i) {
    if (arr[i] > larg2 && arr[i] < larg) {
      larg2 = arr[i];
    }
  }
  if (larg2 == -1) {
    larg2 = larg;
  }
  int brr[n];
  for (int i = 0; i < n; ++i) {
    brr[i] = larg;
  }
  brr[idx] = larg2;
  for (int i = 0; i < n; ++i) {
    cout << brr[i] << '\n';
  }
  return 0;
}
