unittest
{
	assert( [ "20 30 70 90", "3" ].parse.expand.solve == 150 );
	assert( [ "10000 1000 100 10", "1" ].parse.expand.solve == 100 );
	assert( [ "10 100 1000 10000", "1" ].parse.expand.solve == 40 );
	assert( [ "12345678 87654321 12345678 87654321", "123456789" ].parse.expand.solve == 1524157763907942 );
}



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 qhsd = input.front.split.to!( long[] );
	input.popFront;
	auto n = input.front.to!( long );
	return tuple( [ tuple( qhsd[ 0 ], 0.25 ), tuple( qhsd[ 1 ], 0.50 ), tuple( qhsd[ 2 ], 1.00 ), tuple( qhsd[ 3 ], 2.00 ) ], n );
}

auto solve( Tuple!( long, double )[] qhsd, long n )
{
	// n以下のサイズで一番コスパが良いものをできるだけ買う
	auto m = qhsd[ 0 ];
	foreach( x; qhsd[ 1 .. $ ].filter!( ( a ) => a[ 1 ] <= n ) )
	{
		if( x[ 0 ] / x[ 1 ] < m[ 0 ] / m[ 1 ] ) m = x;
	}
	auto k = cast( long )( n / m[ 1 ] ) * m[ 0 ];
	auto r = n % m[ 1 ];
	if( r == 0 ) return k;
	
	// 端数を他のもので補う
	auto ans = long.max;
	foreach( x; qhsd.filter!( ( a ) => a[ 1 ] <= r ) )
	{
		ans = min( ans, k + cast( long )( r / x[ 1 ] ) * x[ 0 ] );
	}
	return ans;
}
