#include<stdio.h>
//#include<stdlib.h>
#define INTFY 20000000
int S[500000],l;

void mergesort(int*,int,int);
void merge(int*,int,int,int);

int main(){
  int n,i;
  scanf("%d",&n);
   for(i=0;i<n;i++){
     scanf("%d",&S[i]);
  }
  mergesort(S,0,n);
  for(i=0;i<n;i++){
    if(i>0)printf(" ");
    printf("%d",S[i]);
 }
 printf("\n");
    printf("%d\n",l);
  return 0;
}

void mergesort(int A[],int left,int right){
  int mid,i;
  for(i=0;i<15;i++){
  printf("%d ",A[i]);
}printf("\n");

  if(left+1<right){
    mid = (left+right)/2;
    mergesort(A,left,mid);
    mergesort(A,mid,right);
    merge(A,left,mid,right);
  }
}

void merge(int A[],int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  int L[250000],R[250000],i,j=0,k;
  L[n1]=INTFY;
  R[n2]=INTFY;
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }

  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  i=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i+=1;
      l++;
    }
    else{
      A[k]=R[j];
      j=j+1;
      l++;
    }
  }
}

