function merge(A,left,mid,right){
    let n = mid-left;
    let m = right -mid;
    let L = A.slice(left,mid);
    let R = A.slice(mid,right);
    L.push(Infinity);
    R.push(Infinity);
    let i = 0,
        j = 0;
    for(let k =left;k<right;k++){
        if(L[i]<=R[j]){
            A[k] = L[i];
            i++;
        }else{
            A[k] = R[j];
            j++;
        }
        steps++;
    }
}

function mergeSort(A,left,right){
    if(left+1<right){
        let mid = Math.floor((left+right)/2);
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }
}

let lines = require("fs").readFileSync("/dev/stdin","utf-8").trim().split("\n");
let count = parseInt(lines[0]);
let nums = lines[1].split(" ").map(Number);
let steps = 0;
mergeSort(nums,0,count);
console.log(nums.join(" "));
console.log(steps);
