#include <iostream>
#include <algorithm>
using namespace std;
int cnt=0;

void merge(int a[],int left, int mid, int right){
    int i = left, j = mid+1;
    int *b = new int[right-left+1];
    int k = 0;
 while(i <= mid && j <= right){
    if(a[i] <= a[j]){
       b[k] = a[i];
       k++;
       i++;
  }
    else{
       b[k] = a[j];
       j++;
       k++;
    }
    cnt++;
 }
 while(i <= mid){
    b[k] = a[i];
    i++;
    k++;
    cnt++;
 }
 while(j <= right){
    b[k] = a[j];
    j++;
    k++;
    cnt++;
 }
 for(i = left, k = 0; i <= right; ++i, ++k){
    a[i] = b[k];
 }
 
}
void mergeSort(int a[], int left, int right){
    if(left < right){
      int mid=(left + right)/2;
      mergeSort(a,left,mid);
      mergeSort(a,mid+1,right);
      merge(a,left, mid, right);
 }
}

int main(){
   int n;
   cin >> n;
   int a[n];
   for(int i=0;i<n;i++){
      cin>>a[i];
   }
   mergeSort(a,0,n-1);
   for(int i = 0;i < n;i++){
      if(i == n-1)
        cout << a[i] << endl;
      else
        cout << a[i] << ' ';
   }
   cout << cnt << endl;
}
