#include <bits/stdc++.h>
void merge(int arr[], int l, int m, int r) {
  int n1 = m - l + 1;
  int n2 = r - l;
  int L[n1], R[n2];
  for (int i = 0; i < n1; ++i) {
    L[i] = arr[l + i];
  }
  for (int i = 0; i < n2; ++i) {
    R[i] = arr[i + m + 1];
  }
  int i = 0, j = 0, k = l;
  while (i < n1 && j < n2) {
    if (L[i] <= R[j]) {
      arr[k] = L[i];
      i++;
    } else {
      arr[k] = R[j];
      j++;
    }
    k++;
  }
  while (i < n1) {
    arr[k++] = L[i++];
  }
  while (j < n2) {
    arr[k++] = R[j++];
  }
}
void mergeSort(int arr[], int l, int r) {
  if (l < r) {
    int m = l + (r - l) / 2;
    mergeSort(arr, l, m);
    mergeSort(arr, m + 1, r);
    merge(arr, l, m, r);
  }
}
int main(int argc, char const *argv[]) {
  int n;
  scanf("%d", &n);
  int arr[n];
  for (int i = 0; i < n; ++i) {
    scanf("%d", &arr[i]);
  }
  int max = arr[0];
  int x;
  for (int i = 0; i < n; i++) {
    if (arr[i] > max) {
      max = arr[i];
      x = i;
    }
  }
  mergeSort(arr, 0, n - 1);
  for (int i = 0; i < n; i++) {
    if (i != x)
      printf("%d\n", arr[n - 1]);
    else {
      printf("%d\n", arr[n - 2]);
    }
  }
  return 0;
}
