function main(_stdin) {
    const stdin = _stdin.trim().split('\n');
    const n = Number(stdin.shift());
    const S = stdin.shift().split(' ').map(Number);
    const cnt = [0];

    mergeSort(S, 0, n, cnt);

    console.log(S.join(' '));
    console.log(cnt[0]);
}

function merge(A, left, mid, right,cnt){
    const lefts = A.slice(left, mid);
    const rights = A.slice(mid, right);
    lefts.push(Infinity);
    rights.push(Infinity);

    let leftsIdx = 0;
    let rightsIdx = 0;

    for (let i = left; i < right; i++) {
        cnt[0] += 1;
        if(lefts[leftsIdx] <= rights[rightsIdx]) {
            A[i] = lefts[leftsIdx];
            leftsIdx++;
        } else {
            A[i] = rights[rightsIdx];
            rightsIdx++;
        }
    }
}


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


main(require('fs').readFileSync('/dev/stdin', 'utf8'));

