#include <bits/stdc++.h> 

using namespace std;

int c = 0;

void merge(int arr[], int l, int m, int r) 
{ 
    int i, j, k; 
    int left_r = m - l + 1; 
    int right_l =  r - m; 
  
    
    int L[left_r], R[right_l]; 
      
    for (i = 0; i < left_r; i++) 
        L[i] = arr[l + i]; 
    for (j = 0; j < right_l; j++) 
        R[j] = arr[m + 1+ j]; 
  
    i = 0; 
    j = 0;  
    k = l;  
    while (i < left_r && j < right_l) 
    { 
        if (L[i] <= R[j]) 
        { 
            arr[k] = L[i]; 
            i++; 
            c++;
        } 
        else
        { 
            arr[k] = R[j]; 
            j++; 
            c++;
        } 
        k++; 
    } 
  
    while (i < left_r) 
    { 
        arr[k] = L[i]; 
        i++; 
        k++; 
        c++;
    } 
  
  
    while (j < right_l) 
    { 
        arr[k] = R[j]; 
        j++; 
        k++; 
        c++;
    } 
} 


void mergeSort(int arr[], int l, int r) 
{
    if (l < r) 
    { 
        int m = l+(r-l)/2; 
  
        mergeSort(arr, l, m); 
        mergeSort(arr, m+1, r); 
  
        merge(arr, l, m, r); 
    }
    else return;
} 

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;
            cout << c << endl;
      return 0;
    }
    cout << a[i] << " ";
  }
}
