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


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 )

n = int( raw_input() )
arrS = [ int( val ) for val in raw_input().split( ' ' ) ]
cnt = 0
mergeSort( arrS, 0, n )
print( " ".join( map( str, arrS ) ) )
print( cnt ) def merge( tS, left, mid, right ):
	global cnt
	n1 = mid - left;
	n2 = right - mid;
	tL = tS[ left : mid ];
	tR = tS[ mid : right ];	
	tL.append( 1000000001 )
	tR.append( 1000000001 )
	i = j = 0
	for k in range( left, right ):
		cnt += 1
		if tL[i] <= tR[j]:
			tS[k] = tL[i]
			i += 1
		else:
			tS[k] = tR[j]
			j += 1 merge global cnt n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid tL = tS[ left : mid ] tL tS[ left : mid ] tS left : mid left mid tR = tS[ mid : right ] tR tS[ mid : right ] tS mid : right mid right tL.append( 1000000001 ) tL.append tL append 1000000001 tR.append( 1000000001 ) tR.append tR append 1000000001 i = j = 0 i 0 = j = 0 j 0 for k in range( left, right ):
		cnt += 1
		if tL[i] <= tR[j]:
			tS[k] = tL[i]
			i += 1
		else:
			tS[k] = tR[j]
			j += 1 k range( left, right ) range left right cnt += 1 cnt 1 if tL[i] <= tR[j]:
			tS[k] = tL[i]
			i += 1
		else:
			tS[k] = tR[j]
			j += 1 tL[i] <= tR[j] tL[i] tL i tR[j] tR j tS[k] = tL[i] tS[k] tS k tL[i] tL i i += 1 i 1 tS[k] = tR[j] tS[k] tS k tR[j] tR j j += 1 j 1 tS tS left left mid mid right right 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 ) mergeSort if left+1 < right:
		mid = ( left+right )/2
		mergeSort( tS, left, mid )
		mergeSort( tS, mid, right )
		merge( tS, left, mid, right ) left+1 < right left+1 left 1 right mid = ( left+right )/2 mid ( left+right )/2 left+right left right 2 mergeSort( tS, left, mid ) mergeSort tS left mid mergeSort( tS, mid, right ) mergeSort tS mid right merge( tS, left, mid, right ) merge tS left mid right tS tS left left right right n = int( raw_input() ) n int( raw_input() ) int raw_input() raw_input int( val ) for val in raw_input().split( ' ' ) for val in raw_input().split( ' ' ) val raw_input().split( ' ' ) ().split () raw_input split ' ' for val in raw_input().split( ' ' ) int( val ) int val arrS = [ int( val ) for val in raw_input().split( ' ' ) ] arrS [ int( val ) for val in raw_input().split( ' ' ) ] cnt = 0 cnt 0 mergeSort( arrS, 0, n ) mergeSort arrS 0 n print( " ".join( map( str, arrS ) ) ) print " ".join( map( str, arrS ) ) " ".join " " join map( str, arrS ) map str arrS print( cnt ) print cnt 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 ) 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 ) mergeSort arrS = [ int( val ) for val in raw_input().split( ' ' ) ] [ int( val ) for val in raw_input().split( ' ' ) ] arrS def merge( tS, left, mid, right ):
	global cnt
	n1 = mid - left;
	n2 = right - mid;
	tL = tS[ left : mid ];
	tR = tS[ mid : right ];	
	tL.append( 1000000001 )
	tR.append( 1000000001 )
	i = j = 0
	for k in range( left, right ):
		cnt += 1
		if tL[i] <= tR[j]:
			tS[k] = tL[i]
			i += 1
		else:
			tS[k] = tR[j]
			j += 1 def merge( tS, left, mid, right ):
	global cnt
	n1 = mid - left;
	n2 = right - mid;
	tL = tS[ left : mid ];
	tR = tS[ mid : right ];	
	tL.append( 1000000001 )
	tR.append( 1000000001 )
	i = j = 0
	for k in range( left, right ):
		cnt += 1
		if tL[i] <= tR[j]:
			tS[k] = tL[i]
			i += 1
		else:
			tS[k] = tR[j]
			j += 1 merge n = int( raw_input() ) int( raw_input() ) n cnt = 0 0 cnt
def merge( tS, left, mid, right ):
	global cnt
	n1 = mid - left;
	n2 = right - mid;
	tL = tS[ left : mid ];
	tR = tS[ mid : right ];	
	tL.append( 1000000001 )
	tR.append( 1000000001 )
	i = j = 0
	for k in range( left, right ):
		cnt += 1
		if tL[i] <= tR[j]:
			tS[k] = tL[i]
			i += 1
		else:
			tS[k] = tR[j]
			j += 1


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 )

n = int( raw_input() )
arrS = [ int( val ) for val in raw_input().split( ' ' ) ]
cnt = 0
mergeSort( arrS, 0, n )
print( " ".join( map( str, arrS ) ) )
print( cnt )