#include <bits/stdc++.h>
int main(void) {
  int array[200000], i, max, second, num;
  scanf("%d", &num);
  for (i = 0; i < num; i++) {
    scanf("%d", &array[i]);
  }
  max = second = array[0];
  for (i = 0; i < num; i++) {
    if (array[i] > max) {
      second = max;
      max = array[i];
    }
  }
  for (i = 0; i < num; i++) {
    if (array[i] < max) {
      printf("%d\n", max);
    } else {
      printf("%d\n", second);
    }
  }
  return 0;
}
