#include <cstdio>
#define M 500010
#define SENTINEL 2000000000
int a[M];
int count=0;
void merge(int,int,int);
void mergeSort(int,int);
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	mergeSort(0,n);
	for(int i=0;i<n-1;i++)
		printf("%d ",a[i]);
	printf("%d\n%d\n",a[n-1],count);
	return 0;
}
void mergeSort(int left,int right){
	if(left+1<right){
		int mid=(left+right)/2;
		mergeSort(left,mid);
		mergeSort(mid,right);
		merge(left,mid,right);
	}
}
void merge(int left,int mid,int right){
	int n1=mid-left;
	int n2=right-mid;
	int L[n1+1],R[n2+1];
	for(int i=0;i<n1;i++)
		L[i]=a[left+i];
	for(int i=0;i<n2;i++)
		R[i]=a[mid+i];
	L[n1] = SENTINEL;
	R[n2] = SENTINEL;
	int i=0,j=0;
	for(int k=left;k<right;k++){
		count++;
		if(L[i]<=R[j]){
			a[k]=L[i];
			i++;
		}else{
			a[k]=R[j];
			j++;
		}
	}
}