#include<stdio.h>
#define SENTINEL 1600000

void Merge(int *,int,int,int);
void Sort(int *,int,int,int);

int cnt, L[SENTINEL], R[SENTINEL];

int main(){
  int A[SENTINEL],n,i;

  scanf("%d",&n);

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

  for(i=0;i<n;i++){
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");

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

  return 0;
}


void Merge(int *A,int l,int m,int r){
  int n1,n2,i,j,k;

  n1 = m - l;
  n2 = r - m;

  for(i = 0;i<n1;i++){
    L[i] = A[l + i];
  }
  for(i = 0;i<n2;i++){
    R[i] = A[m + i];
  }

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

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

void Sort(int *A,int n,int l,int r){
  int m;
  if(l+1 < r){
    m = (l + r)/2;
    Sort(A,n,l,m);
    Sort(A,n,m,r);
    Merge(A,l,m,r);
  }
}

