def merge( tS, left, mid, right )
	n1 = mid - left;
	n2 = right - mid;
	tL = tS[ left ... mid ];
	tR = tS[ mid ... right ];	
	tL.push( 1000000001 )
	tR.push( 1000000001 )
	i = j = 0
	for k in ( left ... right )
		$cnt += 1
		if tL[i] <= tR[j]
			tS[k] = tL[i]
			i += 1
		else
			tS[k] = tR[j]
			j += 1
		end
	end
end

def mergeSort( tS, left, right )
	if left+1 < right
		mid = ( left+right )/2
		mergeSort( tS, left, mid )
		mergeSort( tS, mid, right )
		merge( tS, left, mid, right )
	end
end

n = gets.to_i
arrS = gets.split( " " ).map { |val| val.to_i }
$cnt = 0
mergeSort( arrS, 0, n )
puts( arrS.join( " " ) )
puts( $cnt )