#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, max = 0, second_max = 0, max_count;
  scanf("%d\n", &n);
  int a[n];
  for (int i; i < n; i++) {
    scanf("%d\n", &a[i]);
  }
  for (int i; i < n; i++) {
    if (max < a[i]) {
      second_max = max;
      max = a[i];
      max_count = 1;
    } else if (max == a[i]) {
      max_count++;
    } else if (max < a[i] && second_max < a[i]) {
      second_max = a[i];
    }
  }
  if (max_count > 1) {
    for (int i; i < n; i++) {
      printf("%d\n", max);
    }
  } else {
    for (int i; i < n; i++) {
      if (max == a[i]) {
        printf("%d\n", second_max);
      } else {
        printf("%d\n", max);
      }
    }
  }
}
