import std.stdio, std.string, std.conv, std.algorithm, std.range;

void main() {
    int n = readln.chomp.to!int;
    int[] a = new int[n];
    foreach (i; 0 .. n) {
        a[i] = readln.chomp.to!int;
    }
    int[] b = a.dup.sort!("a > b").array;
    foreach (x; a) {
        if (x != b[0]) b[0].writeln;
        else b[1].writeln;
    }
}