unittest
{
	assert( [ "1", "3" ].solve == 0 );			// 追加ケース
	assert( [ "2", "2 3" ].solve == 3 );		// 追加ケース
	
	assert( [ "4", "2 2 1 3" ].solve == 7 );
	assert( [ "7", "1 1 1 1 1 1 1" ].solve == 6 );
}



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

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

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	as.sort!( ( x, y ) => y < x );
	
	if( as.length == 1 ) return 0;
	if( as.length == 2 ) return as[ 0 ];
	
	auto ans = as[ 0 ] + as[ 1 ];
	auto l = as[ 1 ];
	auto c = as[ 0 ];
	auto r = as[ 2 ];
	foreach( a; as[ 3 .. $ ] )
	{
		if( l < r )
		{
			ans += r;
			r = a;
		}
		else
		{
			ans += l;
			l = a;
		}
	}
	return ans;
}
