#include <stdio.h>
#include <stdlib.h>

int int_compare(const long* a, const long* b)
{
    if (*a < *b) {
        return 1;
    } else if (*a > *b) {
        return -1;
    }
    return 0;
}

int main(void)
{
    int n;
    scanf("%d", &n);

    long* arr = calloc(n, sizeof(long));

    for (int i = 0; i < n; i++) {
        scanf("%ld", &arr[i]);
    }

    long* sorted = calloc(n, sizeof(long));

    for (int i = 0; i < n; i++) {
        sorted[i] = arr[i];
    }

    qsort(sorted, n, sizeof(long), (int (*)(const void*, const void*))(*int_compare));

    long max = sorted[0];
    long second_max = sorted[1];

    for (int i = 0; i < n; i++) {
        printf("%ld\n", arr[i] == max ? second_max : max);
    }

    free(arr);
    free(sorted);

    return 0;
}
