<?php
$n = trim(fgets(STDIN));
$a = [];
for ($i = 0; $i < $n; $i++) {
    $a[$i] = trim(fgets(STDIN));
}
 
arsort($a);
for ($j = 0; $j < $n; $j++) {
    $a_tmp = $a;
    $a_tmp[$j] = 0;
    $first = current($a_tmp);
    if ($first == 0) {
        $first = current(array_slice($a_tmp, 1, 1, true));
    }
    echo $first . PHP_EOL;
}