#include<stdio.h>
#define N 10000000;
int A[50000];
int L[50000],R[500000];
int count=0;
void Merge(int,int,int);
void Mergesort(int,int);
int main(){
  int i,j;
  scanf("%d",&j);
  for(i=0; i<j; i++){
    scanf("%d",&A[i]);
  }
  Mergesort(0,j);
  for(i=0;i<j;i++){
    printf("%d",A[i]);
    if(i<j-1){
      printf(" ");
    }
  }
  printf("\n%d\n",count);
  return 0;
}
void Merge(int left,int mid,int right){
  int n1,n2,i,j,k;
  n1=mid - left;
  n2= right - mid;
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  R[n2]=L[n1]=N;
  i=j=0;
  for(k=left;k<right;k++){
    count++;
      if(L[i]<=R[j]){
	A[k]=L[i];
	i++;
      }
	else{
	  A[k]=R[j];
	  j++;
	}
  }
}
void Mergesort(int left,int right){
  int mid;
  if(left + 1 < right){
    mid=(left + right)/2;
    Mergesort(left,mid);
    Mergesort(mid,right);
    Merge(left,mid,right);
  }
}