<?php
$r = [];
fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%d", $a);
$first = $a; $second = $a;
$r[] = $a;
for ($i=0; $i < $n - 1; $i++) {
    fscanf(STDIN, "%d", $a);
    if ($first < $a) {
        $second = $first;
        $first = $a;
    } elseif ($second < $a) {
        $second = $a;
    }
    $r[] = $a;
}
for ($i=0; $i < $n; $i++) {
    echo ($r[$i] === $first ? $second : $first)."\n";
}
?>