#include <bits/stdc++.h>
using namespace std;
int merge_sort(int a[],int left,int right){
    if(left+1<right)
    {   int mid=(left+right)/2;
        return merge_sort(a,left,mid)+merge_sort(a,mid,right)+right-left;}
    else return 0;
};
int main()
{   int n;
    cin>>n;int a[n];for(int i=0;i<n;i++) {cin>>a[i];}
    sort(a,a+n);
    for(int i=0;i<n;i++)
        if(i==n-1)cout<<a[i]<<endl; else cout<<a[i]<<' ';
    cout<<merge_sort(a,0,n)<<endl;
    return 0;
}
