#include <bits/stdc++.h>
int main(void) {
  int n;
  scanf("%d", &n);
  int ary[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &ary[i]);
  }
  int max = 0, snd = 0, wst = 200001, k = 0;
  for (int i = 0; i < n; i++) {
    if (ary[i] > max) {
      max = ary[i];
      k = 1;
    } else if (ary[i] == max) {
      k++;
    } else if (max > ary[i] && ary[i] > snd) {
      snd = ary[i];
    } else if (ary[i] < wst) {
      wst = ary[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (max != wst) {
      if (k > 1) {
        printf("%d\n", max);
      } else {
        if (ary[i] != max) {
          printf("%d\n", max);
        } else {
          printf("%d\n", snd);
        }
      }
    } else {
      printf("%d\n", max);
    }
  }
  return 0;
}
