#include <bits/stdc++.h>
int main() {
  int n;
  int max = 0;
  int max1 = 0;
  int count = 0;
  int a[200000];
  int ans[200000];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > max) {
      max1 = max;
      max = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (max == a[i]) {
      count += 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (count != 0) {
      ans[i] = max;
    } else {
      if (a[i] == max) {
        ans[i] = max1;
      } else {
        ans[i] = max;
      }
    }
    printf("%d\n", ans[i]);
  }
  return 0;
}
