unittest
{
	assert( [ "3", "1", "4", "3" ].parse.expand.solve == "4\n3\n4" );
	assert( [ "2", "5", "5" ].parse.expand.solve == "5\n5" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto as = new long[ n ];
	foreach( ref a; as )
	{
		input.popFront;
		a = input.front.to!( long );
	}
	return tuple( as );
}

auto solve( long[] as )
{
	auto ls = new long[ as.length ];
	auto lm = 0L;
	for( auto i = 0L; i < as.length; i++ )
	{
		lm = max( lm, as[ i ] );
		ls[ i ] = lm;
	}
	
	auto rs = new long[ as.length ];
	auto rm = 0L;
	for( auto i = as.length.signed - 1; 0 <= i; i-- )
	{
		rm = max( rm, as[ i ] );
		rs[ i ] = rm;
	}
	
	auto anss = new long[ as.length ];
	foreach( i, ref ans; anss )
	{
		if(      i == 0               ) ans = rs[ 1 ];
		else if( i == anss.length - 1 ) ans = ls[ $ - 2 ];
		else                            ans = max( ls[ i - 1 ], rs[ i + 1 ] );
	}
	return anss.to!( string[] ).join( "\n" );
}
