#include<stdio.h>
#define DEF 1000000
int count=0;

int L[10000];
int R[10000];



void sort(int A[],int n,int lift,int right);
void merge(int A[],int n,int left,int mid,int right);

int main(){
int number;
scanf("%d",&number);

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

sort(A,number,0,number);

for(i=0;i<number;i++){
    if(i==number-1){printf("%d",A[i]);}
    else {printf("%d ",A[i]);}
    
}

    printf("\n");
    printf("%d\n",count);
    
    
    
    return 0;
}


void merge(int A[],int n,int left,int mid,int right){
    int a1=mid-left;
    int a2=right-mid;
    
    int i;
    for(i=0;i<a1;i++){L[i]=A[left+1];}
    for(i=0;i<a2;i++){R[i]=A[mid+1];}
    
    L[a1]=R[a2]=DEF;
    
    i=0;    
    int j=0;
    int k;


    for(k=left;k<right;k++){
        count++;
        
        if(L[i]<=R[j]){
            A[k]=L[i];
            i++;
        }
        
        else{
            A[k]=R[j];
            j++;
            
        }
        
    }
    
}


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



