#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int fmax = max(arr[0], arr[1]);
  int index;
  if (fmax == arr[0])
    index = 0;
  else
    index = 1;
  int smax = min(arr[0], arr[1]);
  for (int i = 2; i < n; i++) {
    if (arr[i] > fmax) {
      smax = fmax;
      fmax = arr[i];
      index = i;
    } else if (arr[i] < fmax && arr[i] > smax) {
      smax = arr[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == index)
      cout << smax << endl;
    else
      cout << fmax << endl;
  }
  return 0;
}
