unittest
{
	assert( [ "4", "2 3 7 9" ].parse.expand.solve == 7 );
	assert( [ "8", "3 1 4 1 5 9 2 6" ].parse.expand.solve == 8 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
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.strip.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	auto mm = as.reduce!( max, min );
	return mm[ 0 ] - mm[ 1 ];
}
