<?php
$n = trim(fgets(STDIN));
$a = [];
for ($i = 0; $i < $n; $i++) {
    $a[$i] = trim(fgets(STDIN));
}

arsort($a);
$first = current($a);
for ($j = 0; $j < $n; $j++) {
    $a_tmp = $a;
    if ($a_tmp[$j] == $first) {
        unset($a_tmp[$j]);
        $first = current($a_tmp);
    }
    echo $first . PHP_EOL;
}
