#include<stdio.h>

//???????????????????????????????????????

int count = 0;

void merge(int A[],int left,int mid,int right){
  int n1,n2;
  int L[5000],R[5000];
  int k,l,m;
  int INFTY = 10000;

  n1 = mid - left;
  n2 = right - mid;

  for(k=0;k<n1;k++){
    L[k]=A[k+left];
  }
  for(l=0;l<n2;l++){
    R[l]=A[l+mid];
  }

  L[n1] = INFTY;
  R[n2] = INFTY;

  k = 0;
  l = 0;
  for(m=left;m<=right-1;m++){
    if(L[k]<=R[l]){
      A[m] = L[k];
      k++;
    } else {
      A[m] = R[l];
      l++;
    }
    count++;
  }
}

void mergeSort(int A[],int left,int right){
  if(left+1 < right){
    int mid = (left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int main(){
  int N;
  int i,k;
  int A[500000];

  scanf("%d\n",&N);
  for(i=0;i<=N-1;i++){
    scanf("%d",&A[i]);
  }

  mergeSort(A,0,N);

  for(k=0;k<=N-1;k++){

    printf("%d",A[k]);
    if(k<N-1){
        printf(" ");
    }
  }
  printf("\n%d\n",count);

  return 0;
}