import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
import std.string;
void merge(T)(T left, T right, T ary, ref int count)
{
    T left2 = left.dup;
    T right2 = right.dup;
    ptrdiff_t i = 0;
    ptrdiff_t j = 0;
    for (ptrdiff_t k = 0; k < ary.length; k++)
    {
        count++;
        if (left2.length > i && (right2.length <= j || left2[i] <= right2[j]))
        {
            ary[k] = left2[i];
            i++;
        }
        else if (right2.length > j)
        {
            ary[k] = right2[j];
            j++;
        }
    }
}
void merge_sort(T)(T ary, ref int count)
{
    if (ary.length == 1)
        return;
    T left = ary[0..$ / 2];
    T right = ary[$ / 2..$];
    merge_sort(left, count);
    merge_sort(right, count);
    merge(left, right, ary, count);
}
void main()
{
    int count;
    readln();
    int[] a = readln().strip.split(' ').map!(x => x.to!int).array;
    merge_sort(a, count);
    writeln(a.map!(x => x.to!string).join(' '));
    writeln(count);
}

