
#include <stdio.h>
void mergesort( int [],int,int);
void merge(int [],int,int,int);

int c =0, n ;

int main()
{
  int i ;
  scanf("%d", &n);
  int s[n];
  for( i = 0; i < n; i++){
    scanf("%d" , &s[i]);
  }
  mergesort(s , 0 ,n );
  for ( i = 0; i < n; i++){
    printf("%d", s[i]);
    if ( i != n-1){printf(" ");}
  }
  printf("\n%d\n",c);
  return 0;
}
void mergesort( int a[] ,int lef,int rig){
    
  if ( lef +1 < rig){
    int mid = ( lef + rig)/2;
    mergesort( a , lef ,mid);
    mergesort(a , mid ,rig);
    merge (a ,lef ,mid ,rig);
  }
}
void merge ( int a[] , int lef , int mid ,int rig){
  int k,none = mid - lef,i,j,	ntwo = rig - mid, l[none ], r[ ntwo];
  for (i = 0; i < none;i++ ){
    l[i] = a[lef+ i];
  }
  for ( i = 0; i < ntwo ; i++){
    r[i] = a[mid + i];
  }l[none] = 100000001;r[ntwo]= 1000000001; i= 0;j= 0;
  for (k = lef ;k < rig ;k++ ){
    c++;
    if (l[i] <= r[j]){
      a[k] = l[i];
      i = i + 1;
    }else{ 
      a[k] = r[j];
      j = j + 1;
    }
  }
}


