#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define AMAX 100000
#define MAX 100000000

int temp[AMAX],cnt=0;

void merge(int [AMAX],int,int,int);
void mergeSort(int [AMAX],int,int);


int main(){
  int i,n;
  int A[AMAX];
  
  scanf("%d",&n);

  for(i=0; i<n; i++)
    scanf("%d",&A[i]);

  mergeSort(A,0,n);

  for(i=0; i<n; i++)
    i<n-1 ? printf("%d ",A[i]) : printf("%d\n",A[i]);

  printf("%d\n",cnt);

  return 0;
}

void mergeSort(int A[AMAX],int l,int r){
  int m;

  if(l+1 < r){
    m = (l+r)/2;
    mergeSort(A,l,m);
    mergeSort(A,m,r);
    merge(A,l,m,r);
  }
}

void merge(int A[AMAX],int l,int m,int r){
  int i,j,k,n1=m-l,n2=r-m;
  int *L,*R;

  L=(int *)malloc(sizeof(int)*(n1+1));
  R=(int *)malloc(sizeof(int)*(n2+1));

  for(i=0; i<=n1-1; i++)
    L[i] = A[l+i];

  for(i=0; i<=n2-1; i++)
    R[i] = A[m+i];

  L[n1] = MAX;
  R[n2] = MAX;
  i = 0;
  j = 0;

  for(k=l; k<=r-1; k++)
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
      cnt++;
    }
    else {
      A[k] = R[j];
      j++;
      cnt++;
    }
}

